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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 17
Registered: ‎04-09-2012
My Device: BB9900
My Carrier: 02

Bitmap on click

Hello guys, how do I listen to a click on a bitmap image in my code. I know

bitmapField1 = new BitmapField(mImgTable , BitmapField.FOCUSABLE)
         {
              protected boolean navigationClick(int status, int time )
              {
              }
 }

 That will do it, but my code is different. Here is where i declare my bitmap images 

public class CustomButtonScreen extends MainScreen{
	
	NewFlowFieldManager _manager = new NewFlowFieldManager();

	public CustomButtonScreen()
    {
		super();
		
        super.add(_manager);
        
        Bitmap composePic = Bitmap.getBitmapResource("compose.png");
        Bitmap homePic = Bitmap.getBitmapResource("home.png");
        Bitmap profilePic = Bitmap.getBitmapResource("profile.png");
        Bitmap searchPic = Bitmap.getBitmapResource("search.png");
        
        
       /*
          homePic.setChangeListener(new FieldChangeListener() {
         
            public void fieldChanged(Field f, int arg1) {
                NextScreen ns = new NextScreen();
                UiApplication.getUiApplication().pushScreen(ns);
            }
        });
        */
        _manager.add(new BitmapButtonField(homePic));
        _manager.add(new BitmapButtonField(searchPic));
        _manager.add(new BitmapButtonField(profilePic));
        _manager.add(new BitmapButtonField(composePic));
        
        setTitle("LWKMD 1.0");
    }
	
	public void paintBackground(Graphics graphics)
    {
        graphics.setBackgroundColor(Color.DARKRED);
        
        graphics.clear();
        
        super.paintBackground(graphics);
    }
	
	
	
}

 and the class where i draw the bitmap and add focus method

public class BitmapButtonField  extends BaseButtonField{
	
	private Bitmap[] _bitmaps;
	private static final int NORMAL = 0;
	private static final int FOCUS = 1;
	private static final int CURVE_X = 12; // X-axis inset of curve
	private static final int CURVE_Y = 12; // Y-axis inset of curve

	private static final int BACKGROUND_COLOR = 0xFFFFFF; // White
	
	private static final byte[] PATH_POINT_TYPES = {
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
	    Graphics.CURVEDPATH_END_POINT, 
	  
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_END_POINT, 
	    Graphics.CURVEDPATH_QUADRATIC_BEZIER_CONTROL_POINT,
	    Graphics.CURVEDPATH_END_POINT, 
	  };
	 
	  // Colors array for rounded rectangle gradient. Each color corresponds
	  // to one of the points in the point types array. Top light, bottom black.
	  private static final int[] PATH_GRADIENT = {
	    0xE3E3E3, 0xE3E3E3, 0xE3E3E3, 0xE3E3E3, 0xE3E3E3, 0xE3E3E3,
	  
	    0xC4C4C4, 0xC4C4C4, 0xC4C4C4, 0xC4C4C4, 0xC4C4C4, 0xC4C4C4
	  };

	
	  public BitmapButtonField( Bitmap normalState ){
		  
		  this( normalState, normalState, 0 );
	  }

	  public BitmapButtonField( Bitmap normalState, Bitmap focusState){
	
		  this( normalState, focusState, 0 );
	  }

	  public BitmapButtonField( Bitmap normalState, Bitmap focusState, long style ){
		
		  super( Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.FIELD_BOTTOM |Field.FOCUSABLE );

		  	if( (normalState.getWidth() != focusState.getWidth()) || (normalState.getHeight() != focusState.getHeight()) ){

		  		throw new IllegalArgumentException( "Image sizes don't match" );
		  	}

		  	setPadding(5,5,5,5);
	
		  	_bitmaps = new Bitmap[] { normalState, focusState };
	
	  }

	  public void setImage( Bitmap normalState ){
		
		_bitmaps[NORMAL] = normalState;
		invalidate();
	  }

	  public void setFocusImage( Bitmap focusState ){
		_bitmaps[FOCUS] = focusState;
		invalidate();
	  }

	  public int getPreferredWidth() {
		
		return _bitmaps[NORMAL].getWidth();
	  }

	  public int getPreferredHeight() {
		return _bitmaps[NORMAL].getHeight();
		}

	  protected void layout( int width, int height ) {
		setExtent( _bitmaps[NORMAL].getWidth(), _bitmaps[NORMAL].getHeight());
	  }

	  protected void paint( Graphics g ) {
		
		int index = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS ) ? FOCUS : NORMAL;
		g.drawBitmap( 0, 0, _bitmaps[index].getWidth(), _bitmaps[index].getHeight(), _bitmaps[index], 0, 0 );

	  }

	/**
	* With this commented out the default focus will show through
	* If an app doesn't want focus colours then it should override this and do nothing
	**/
	/*
	protected void paintBackground( Graphics g ) {
		
		g.clear();
		
	}
	
	*/
	
	protected void drawFocus( Graphics g, boolean on ) {
	// Paint() handles it all
	
		g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true );
		
		int width = getPreferredWidth();
		
	    int height = getPreferredHeight();
	    
	    int[] xPts = {
	    	      0, 0, CURVE_X, width - CURVE_X, width, width,
	    	      width, width, width - CURVE_X, CURVE_X, 0, 0
	    	    };
	    	    int[] yPts = {
	    	      CURVE_Y, 0, 0, 0, 0, CURVE_Y,
	    	      height - CURVE_Y, height, height, height, height, height - CURVE_Y
	    	    };
	    	    
		if(on){
			//drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, on, 0, 0, 500, 200);
			g.clear();
		    g.setGlobalAlpha(255);
		    g.setBackgroundColor(BACKGROUND_COLOR);
		    g.drawShadedFilledPath(xPts, yPts, PATH_POINT_TYPES, PATH_GRADIENT, null);
	        g.drawRoundRect(0, 0, height, width, CURVE_X * 2, CURVE_Y * 2);  
	       // g.fillRoundRect(0, 0, height, width, CURVE_X * 2, CURVE_Y * 2);  
	       // g.setColor(BORDER_COLOR);  
	        
		}
		
		paint(g);
	}
	
	
}
Developer
Posts: 87
Registered: ‎07-23-2009
My Device: Z30
My Carrier: XL

Re: Bitmap on click

hi,

you can override navigationclick or trackwheel click in you BitmapButtonField.

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

Re: Bitmap on click

And just to give you some code:

 

        Bitmap homePic = Bitmap.getBitmapResource("home.png");
        BitmapButtonField homepicField = new BitmapButtonField(homePic));

          homepicField.setChangeListener(new FieldChangeListener() {
        
            public void fieldChanged(Field f, int arg1) {
                NextScreen ns = new NextScreen();
                UiApplication.getUiApplication().pushScreen(ns);
            }
        });
        _manager.add(homepicField);