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
New Contributor
Posts: 8
Registered: ‎06-09-2011
My Device: 9800
My Carrier: Rogers
Accepted Solution

Why all my focused fields have blue background

 

Please tell me how to hide or remove the blue background of my focused fields.

The unfocused fields have no blue background.

 

Thanks,

 

9800 

 

public class SignInScreen extends MainScreen {
	public int displayWidth = Display.getWidth();
	public int displayHeight = Display.getHeight();
	CustomInputField cifUser = new CustomInputField((int)(displayWidth/4), (int)(displayHeight/4), (int)(displayWidth/2), (int)(displayHeight/16), 16, "Username", "Textbox.png");
	CustomInputField cifPW = new CustomInputField((int)(displayWidth/4), (int)(displayHeight/24), (int)(displayWidth/2), (int)(displayHeight/16), 16, "Password", "Textbox.png");
	public SignInScreen() {
		super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR | USE_ALL_WIDTH | USE_ALL_HEIGHT);
		VerticalFieldManager vfManager = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR | USE_ALL_WIDTH | USE_ALL_HEIGHT)
	    {
  			//Override the paint method to draw the background image.
            public void paint(Graphics graphics)
            {
                //Draw the background image and then call paint.
            	Bitmap newBGB = GPATools.ResizeTransparentBitmap(Bitmap.getBitmapResource("bg_pizza.jpg"), displayWidth,displayHeight, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);
            	graphics.drawBitmap(0,0,displayWidth,displayHeight,newBGB,0,0);
            	super.paint(graphics);
            }
         };
		HorizontalFieldManager hfManager = new HorizontalFieldManager() {
			// overrides the managers paintBackground method, this draws the background
			protected void paintBackground(Graphics graphics) {
				Bitmap newBar = GPATools.ResizeTransparentBitmap(Bitmap.getBitmapResource("back-bar.png"), displayWidth, displayHeight/10, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);
	        	graphics.drawBitmap(0,0,displayWidth,(int)(displayHeight/16),newBar,0,0);
				super.paint(graphics);
			}
            protected void sublayout( int maxWidth, int maxHeight ) 
            {
            	super.sublayout( maxWidth, maxHeight );
                XYRect extent = getExtent();
                int width = Math.max( extent.width, displayWidth);
                int height = Math.max( extent.height, (int)(displayHeight/16));
                setExtent( width, height);
            }

		CustomBitmapField bbfBack = new CustomBitmapField((int)(displayWidth/90), (int)(displayHeight/216),(int)(displayWidth/5), (int)(displayHeight/18), FIELD_VCENTER | FIELD_LEFT | FOCUSABLE, "back-button.png", "back-button-on.png");
		CustomBitmapField bbfForgotPW = new CustomBitmapField((int)(displayWidth*0.45), 0, (int)(displayWidth/3), (int)(displayHeight/16), FIELD_VCENTER | FIELD_RIGHT | FOCUSABLE, "forgot-password-on.png", "forgot-password-on.png");
		CustomBitmapField bbfLogo = new CustomBitmapField((int)(displayWidth/4), (int)(displayHeight/24), (int)(displayWidth/2), (int)(displayHeight/6), FIELD_VCENTER | FIELD_HCENTER, "logo_pizza_onebitedefault.png", "logo_pizza_onebitedefault.png");
		CustomBitmapField bbfSubmit = new CustomBitmapField((int)(displayWidth*0.3), (int)(displayHeight/24), (int)(displayWidth*0.4), (int)(displayHeight/12), FIELD_VCENTER | FIELD_HCENTER | FOCUSABLE, "button_submit_pizza.png", "Submit-button-on.png");
		CustomInputField noAccount = new CustomInputField((int)(displayWidth*0.3), (int)(displayHeight/24), (int)(displayWidth*0.6), (int)(displayHeight/18), 22, "Don't Have an Account?", "No Account");
		CustomBitmapField bbfSignUp = new CustomBitmapField((int)(displayWidth*0.3), 0, (int)(displayWidth*0.4), (int)(displayHeight/12), FIELD_VCENTER | FIELD_HCENTER | FOCUSABLE, "Sign-In-button-off.png", "Sign-In-button-on.png");
		bbfBack.setChangeListener(backListener);
		bbfForgotPW.setChangeListener(backListener);
		bbfSubmit.setChangeListener(submitListener);
		bbfSignUp.setChangeListener(backListener);
		hfManager.add(bbfBack);
		hfManager.add(bbfForgotPW);
		vfManager.add(hfManager);
		vfManager.add(bbfLogo);
		vfManager.add(cifUser);
		vfManager.add(cifPW);
		vfManager.add(bbfSubmit);
		vfManager.add(noAccount);
		vfManager.add(bbfSignUp);
        add(vfManager);
        noAccount.setFocus();
     }
}



package oneBiteScreen;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
/**
 * Button field with a bitmap as its label.
 */
public class CustomBitmapField extends Field {
        private Bitmap b, bitmap, bitmapHighlight;
        private int x, y, width, height; 
        public CustomBitmapField(int x, int y, int width, int height, long style, String offBitmap, String onBitmap) {
         	super(style);
        	this.width = width;
        	this.height = height;
        	this.bitmap = resizedImage(offBitmap, width, height);
        	this.bitmapHighlight = resizedImage(onBitmap, width, height);
	        this.b = this.bitmap;
	        setPosition(x,y);
        }
        protected void fieldChangeNotify(int context) {  
    		try {  
    			this.getChangeListener().fieldChanged(this, context);  
    			} catch (Exception exception) {  
    				}  
    		}
        protected boolean navigationClick(int status, int time){  
    		fieldChangeNotify(1);  
    		return true;  
    		}  
        protected void layout(int width, int height) {
        	setExtent(getPreferredWidth(), getPreferredHeight());
        }
        public int getPreferredWidth() {
          return width; 
        }
        public int getPreferredHeight() {
          return height;
        }
        protected void onFocus(int direction){
    		b = bitmapHighlight;  
    		invalidate();  
    		}  
        protected void onUnfocus(){
    		b = bitmap;  
    		invalidate();  
    		}
        protected void paint(Graphics graphics) {
            graphics.drawBitmap(0, 0, width, height, b, 0, 0);
        }
        public static Bitmap resizedImage(String imageName, int width, int height) {
            Bitmap actualBitmap = Bitmap.getBitmapResource(imageName);
            Bitmap resizedBitmap = new Bitmap(width, height);
            resizedBitmap.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
            actualBitmap.scaleInto(resizedBitmap, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_STRETCH);
            return resizedBitmap;
        }
}

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Why all my focused fields have blue background

Two immediate things:

1) For your main problem override drawFocus to do nothing:

protected void drawFocus(Graphics g, boolean on) {
}

 2) onUnfocus is not always called by the framework (that's a bug which I saw under many versions of BlackBerry OS). You are much better off using FieldChangeListener for switching bitmaps depending on the focused/unfocused state.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Why all my focused fields have blue background

[ Edited ]

Off topic I know, but can I recommend that you don't repeated create Bitmaps in paint processing like this:

 

Bitmap newBGB = GPATools.ResizeTransparentBitmap(Bitmap.getBitmapResource("bg_pizza.jpg"), displayWidth,displayHeight, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);

 

Since paint actually gets called quite frequently this has a significant performance impact.  if you recreate this in sublayout, then it will cope with tilts too.