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
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified
Accepted Solution

Issue in Button Field Listener

I created custom Button field in my app for Bold 9900 , and its works well, But whenever I keep the focus on the button using trackpad and Touched some where else in the screen the button field change listener is invoked. But the button change listener must be invoked only if I Touch over the button not else where . Please suggest me to fix this issue. 

 

Here is my code:

class LoginButton extends Field {
    	private Bitmap _currentPicture;
    	private Bitmap _onPicture;
    	private Bitmap _offPicture;    
    	private String name;
    	private int weight,size=35;
    		
    	LoginButton (String _text){
    		super(ButtonField.HIGHLIGHT_FOCUS | ButtonField.FOCUSABLE | Field.FIELD_HCENTER);
    		name = _text;
    		_offPicture = Bitmap.getBitmapResource("submit_over.png");
    		_onPicture = Bitmap.getBitmapResource("submit_normal.png");
    		weight= _offPicture.getWidth();
    		_currentPicture = _onPicture;    	
    		
    	}    	  	
    	public int getPreferredHeight(){
    		return _currentPicture.getHeight();
    	}
    	public int getPreferredWidth(){
    		return weight;
    	}    	
    	protected void onFocus(int direction){    		
    		_currentPicture = _offPicture;
    		invalidate();
    	}
    	protected void onUnfocus(){
    		
    		_currentPicture = _onPicture;
    		invalidate();
    	}
    	protected void layout(int width, int height) {
    		setExtent(Math.min( width, getPreferredWidth()), Math.min( height, getPreferredHeight()));
    	}
    	protected void drawFocus(Graphics graphics, boolean on)
    	{
    		if (on)
    		{
    			//Get the field size that is available from its manager.
    			XYRect rect = this.getManager().getContentRect();
    			graphics.setGlobalAlpha(50);
    		}
    	}
    	protected void paint(Graphics graphics) { 
    		graphics.setColor(0x04D5B21);
    		graphics.drawBitmap((getWidth() - _currentPicture.getWidth())/2, (getHeight() - _currentPicture.getHeight())/2, getWidth(), getHeight(), _currentPicture, 0, 0);        

    		FontFamily fontFamily[] = FontFamily.getFontFamilies();
    		this.setFont(fontFamily[0].getFont(FontFamily.SCALABLE_FONT,size).derive(Font.STYLE_BOLD, size,Ui.UNITS_px));
    		graphics.drawText(name,(_currentPicture.getWidth() - getFont().getAdvance(name)) / 2, (_currentPicture.getHeight() - fontFamily[0].getFont(FontFamily.SCALABLE_FONT,16).getHeight()) / 3);
    	}
    	protected boolean navigationClick(int status, int time){
    		fieldChangeNotify(1);
    		return true;
    	}
    	public boolean trackwheelClick(int status,int time){
    		fieldChangeNotify(1);
    		return true;
    	}
    	public boolean trackwheelUnclick(int status, int time) {
    		return false;
    	}
    	
    	public boolean keyChar(char key, int status, int time) {
    		boolean retval = false;
    		switch (key) {
    		case Characters.ENTER:
    			fieldChangeNotify(1);
    			retval = true;
    			break;
    		default:
    			retval = super.keyChar(key,status,time);
    		}
    		return retval;
    	}
    	public boolean keyDown(int keycode, int time) {
    		return false;
    	}
    	public boolean keyRepeat(int keycode, int time) {
    		return false;
    	}
    	public boolean keyStatus(int keycode, int time) {
    		return false;
    	}
    	public boolean keyUp(int keycode, int time) {
    		return false;
    	}   
    }
Please use plain text.
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

I think add your button in the verticalFieldmanager and add that manager in other manager.

Make your verticlefieldmanager focusable.

 

Regards,

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Issue in Button Field Listener

Thank you for the suggestion, I did like this.

 

HomeContentManager  MainContent = new MainContent();
HorizontalFieldManager Subtitle_Row	=	new HorizontalFieldManager(Field.USE_ALL_WIDTH);		
		Subtitle_Row.add(new EmptyField(1,5));
		LoginButton AddProfile=new LoginButton("Add Profile");
		AddProfile.setCookie("profile");
		AddProfile.setChangeListener(addProfileListener);		
		Subtitle_Row.add(AddProfile);
		LoginButton NewBtn =new LoginButton("Add+");
		NewBtn.setCookie("add");
		NewBtn.setChangeListener(addProfileListener);		
		Subtitle_Row.add(new EmptyField(1,5));
		Subtitle_Row.add(NewBtn);
		
		MainContent.add(Subtitle_Row);

 And My MainContent manager is the Common vertical field manager for all classes. 

final class HomeContentManager extends VerticalFieldManager {
	HomeContentManager() {
		super(Field.FIELD_HCENTER | Field.USE_ALL_WIDTH);		this.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource(Globals.HomeScreenBackground))); 
	}
	public void paint(Graphics graphics) {
		//graphics.setBackgroundColor(Color.BLACK);  
		super.paint(graphics);
	}   
	protected void sublayout( int maxWidth, int maxHeight )
	{
		int displayWidth = Display.getWidth();
		int displayHeight = Display.getHeight();

		super.sublayout( displayWidth, displayHeight);
		setExtent( displayWidth, displayHeight);
	}
}

 Now I made focusable for Subtitle_Row Manager but its not working. Also in all of others screens i face this issue. But its working in Trackpad devices(Since Trackpad devices doesn't have Touch Event)

Please use plain text.
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

Just try to make "Subtitle_Row" field VerticleFieldmanager.

Then check it.

 

Regards,

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Issue in Button Field Listener

I changed like this, 

VerticalFieldManager Subtitle_Row=new VerticalFieldManager(VerticalFieldManager.FOCUSABLE);

 

But no use whenever i kept focus over the button using Trackpad and Tocuhed the bottom of the screen the Addprofile Button listener is invoked.

Please use plain text.
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

Hi,

Put this in your maincontent manager.

 

protected void sublayout(int width, int height) {
setExtent(width, width);
super.sublayout(width, height);
}

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Issue in Button Field Listener

Hi milanvishal,


I already implemented the sublayout for Maincontent manager with display width and height. Now i replaced as like your suggestion, but no use.

Please use plain text.
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

ohhhhhhhhh,

So I think now issue is in your CustomButtonField.

Let me check it.

If I got any solution I will reply you back.

 

Regards,

 

 

Please use plain text.
Trusted Contributor
gopi
Posts: 126
Registered: ‎10-15-2010
My Device: Torch 9850
My Carrier: Not specified

Re: Issue in Button Field Listener

Okay thank you. meanwhile Me too trying here for solution.
Please use plain text.
Trusted Contributor
milanvishal
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Issue in Button Field Listener

See below code , Its my customButtonField. May be it is helpful to you. public class TwoBitmapCustomField extends BitmapField { private Bitmap bitmapOnFocus; private Bitmap bitmapOffFocus; int width = 0; int height = 0; public TwoBitmapCustomField(String actionCommand, String strOffFocus, String strOnFocus, long style) { super(Bitmap.getBitmapResource(strOffFocus), style); this.actionCommand = actionCommand; bitmapOnFocus = Bitmap.getBitmapResource(strOnFocus); bitmapOffFocus = Bitmap.getBitmapResource(strOffFocus); width = bitmapOnFocus.getWidth(); height = bitmapOnFocus.getHeight(); } protected void layout(int maxWidth, int maxHeight) { setExtent(Math.min(width, maxWidth), Math.min(height, maxHeight)); } protected void drawFocus(Graphics graphics, boolean on) { // Don't draw the default focus } public boolean isFocusable() { return true; } protected void paint(Graphics graphics) { if (isFocus()) { graphics.drawBitmap(0, 0, getWidth(), getHeight(), bitmapOnFocus, 0, 0); } else { graphics.drawBitmap(0, 0, getWidth(), getHeight(), bitmapOffFocus, 0, 0); } } protected void onFocus(int direction) { super.onFocus(direction); invalidate(); } protected void onUnfocus() { super.onUnfocus(); invalidate(); } } Regards,
Please use plain text.