Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 62
Registered: ‎05-30-2011
My Device: 9200
My Carrier: Etisalat

Problem with my application's Background ?

I made a class extends from VerticalFieldManager to set a background to the application whole, the problem is that if there is a screen that have a lot of controls that exceeds the height of one screen there will be another screen down the first one to contain the other controls but with out the background and I want the background be set to all the screen up and down,

 

So any one can help ???? 

Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: Problem with my application's Background ?

Hi,
is your requirement is to fix the background image.
then
initialise this in your class --
VerticalFieldManager gp = new VerticalFieldManager(Manager.VERTICAL_SCROLL) {
protected void sublayout(int width,int height){
super.sublayout(width, height);
setExtent(Display.getWidth(),Display.getHeight());
}
};

and in class constructor add this --

super(NO_VERTICAL_SCROLL);

all the components u can add to "gp" and later add this gp to your background class instance and add that instance to this mainscreen.

Thanks & Regards
pp
Developer
Posts: 62
Registered: ‎05-30-2011
My Device: 9200
My Carrier: Etisalat

Re: Problem with my application's Background ?

It seems that u did not get what is my problem, so I will add my code

 

here is the class that extends from VerticalManager

 

public class MyMainScreen extends VerticalFieldManager {

private Bitmap bitmap = Bitmap.getBitmapResource("img/BGcopy_app480_320.png");
public MyMainScreen(long style) {

super(style);

}

protected void sublayout(int width, int height) {

super.sublayout(width, height);

setExtent(Display.getWidth(), Display.getHeight());

}
public void paint(Graphics graphics) {

// Draw the background image and then call paint.

 

graphics.drawBitmap(0, 0, Display.getWidth(), Display.getHeight(),bitmap, 0, 0);

super.paint(graphics);

}

}

 

and I call it like that 

 

MyMainScreen manager = new MyMainScreen(Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH);

Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: Problem with my application's Background ?

Hi,

  that verticalFieldManager did not overrided navigation movemnet... to layout the background when ever you scroll..

and hence take this call to **bleep** your background image and do as before i said...

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.system.Display;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.math.Fixed32;

/**
 * 
 */
public class GreyPanel extends VerticalFieldManager {
    private boolean imageBackGround = false;
    private Bitmap background = null;
    private int lastWidth;
    public GreyPanel(boolean imageBackGround) {
        this.imageBackGround = imageBackGround;
        if(imageBackGround){
            loadBackgroundImage("background.png");
        }
    }
    
    private void loadBackgroundImage(String image){
        lastWidth = Display.getWidth();
        EncodedImage DownArrow= EncodedImage.getEncodedImageResource(image);
        int currentWidthFixed32 = Fixed32.toFP(DownArrow.getWidth());
        int currentHeightFixed32 = Fixed32.toFP(DownArrow.getHeight());      
        // Get required image dimensions in Fixed Point Number      
        int requiredWidthFixed32 = Fixed32.toFP(Display.getWidth());
        int requiredHeightFixed32 = Fixed32.toFP(Display.getHeight());
        // Calculate the scaling factor
        int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
        int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);      
        // Resize the image
        background = DownArrow.scaleImage32(scaleXFixed32, scaleYFixed32).getBitmap();  
    }
   
    public void paint(Graphics graphics) {
        
        if(imageBackGround){
            
            graphics.drawBitmap(0,0,Display.getWidth(),Display.getHeight(),background,0,0); 
            //graphics.clear();
        }else{
            graphics.setBackgroundColor(Color.LIGHTGREY);//Color.BLACK);
            graphics.clear();
            super.paint(graphics);
        }
        super.paint(graphics);
    }
    
    public void sublayout(int maxWidth, int maxHeight) {
        super.sublayout(maxWidth, Integer.MAX_VALUE);
        if(lastWidth != Display.getWidth()){
            loadBackgroundImage("background.png");
        }
        int fieldCount = getFieldCount();
        int x = 0;
        int y = 0;
        Field child = null;
        
        for (int i = 0; i < fieldCount; i++) {
            child = this.getField(i);
            setPositionChild(child, x, y);
            layoutChild(child, getFieldWidth(child), Integer.MAX_VALUE);
            int childHeight = getFieldHeight(child);
            y = y + childHeight;
        }
        
        //this.setExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
        //setVirtualExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
        this.setExtent(getPreferredWidth(), getPreferredHeight());
    }
    
    private int getFieldWidth(Field f) {
        return Math.min(Math.max(Math.max(f.getContentWidth(), f.getWidth()), f.getPreferredWidth()), this.getPreferredWidth() );
    }
    
    private int getFieldHeight(Field f) {
        return Math.max(Math.max(f.getContentHeight(), f.getHeight()), f.getPreferredHeight());
        
    }
    
    public int getPreferredWidth() {
        return Display.getWidth();
    }
    
    public int getPreferredHeight() {
        return Display.getHeight();
    }
    
    protected boolean keyDown( int keycode, int status ) {
        invalidate();
        
        return super.keyDown( keycode, status );
    }
    
    protected boolean navigationMovement( int dx, int dy, int status, int time ) {
        invalidate();
        
        return super.navigationMovement( dx, dy, status, time );
    }
    
    protected int moveFocus(int amount, int status, int time) {
        invalidate();
        
        return super.moveFocus(amount, status, time);
    }
} 

add that gp to this class instance and add this to your mainscreen.

 

Thanks & Regards

             pp

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with my application's Background ?

I recommend reviewing this KB article, as I suspect it will explain what managers need to be set 'NOSCROLL etc to get the effect you want.

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644