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
patilajayr
Posts: 415
Registered: ‎07-28-2010
My Device: 8000
Accepted Solution

Image button

Hello i am using image button focus and unfocus. my porblem is that when get focus on image and get unfoucs of image it will show blue color border. i dont want that blue border. 

         i dont know how should i remove that? i am attaching customeImageButton class bellow. i dont want on each side blue color border on image button. plese help me.

package com.api;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;

/* Customized ImageButton */
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Class Name      :       ColorManager
//Created On      :       14/11/2011
//Created By      :       Ajay Patil
//Purpose         :       This class is for Button field with a bitmap as its label
////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * Button field with a bitmap as its label.
 */
public class CustomImgButtonField extends ButtonField 
{
        private Bitmap bitmap;
        private Bitmap bitmapHighlight;
        private boolean highlighted = false;

        /**
         * Instantiates a new bitmap button field.
         * 
         * @param bitmap the bitmap to use as a label
         */
        public CustomImgButtonField(Bitmap bitmap, Bitmap bitmapHighlight)
        {
            this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER);
        }

        public CustomImgButtonField(Bitmap bitmap, Bitmap bitmapHighlight, long style)
        {
            super(style);
            this.bitmap = bitmap;
            this.bitmapHighlight = bitmapHighlight;
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
         */
        protected void layout(int width, int height) 
        {
                setExtent(getPreferredWidth(), getPreferredHeight());
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
         */
        public int getPreferredWidth() {
                return bitmap.getWidth();
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
         */
        public int getPreferredHeight() {
                return bitmap.getHeight();
        }
        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.ui.Graphics)
         */
        protected void paint(Graphics graphics) {
                super.paint(graphics);
                int width = bitmap.getWidth();
                int height = bitmap.getHeight();
                Bitmap b = bitmap;
                if (highlighted)
                    b = bitmapHighlight;
                graphics.drawBitmap(0, 0, width, height, b, 0, 0);
        }
        protected void onFocus(int direction)
        { 
        	this.setHighlight(true); super.onFocus(direction);
        }
        protected void onUnfocus() 
        { 
        	this.setHighlight(false); 
            super.onUnfocus(); 
        } 
        public void setHighlight(boolean highlight)
        {
            this.highlighted = highlight;           
        }
}

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Image button

extend BitmapField instead of ButtonField.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
patilajayr
Posts: 415
Registered: ‎07-28-2010
My Device: 8000

Re: Image button

thanks for reply me.

         but i want image button. now i am extend from Bitmapfield but still now working...

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Image button

i have a extended bitmapfield that reacts on navigationclick and the enter key, reports both to its fieldchangelistener. works good for years.

if you are unable to implement it yourself this may help you:
http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
patilajayr
Posts: 415
Registered: ‎07-28-2010
My Device: 8000

Re: Image button

i have that code. i want proper class runing. i want image button with focuse and unfocuse image change. i dont want button blue line border. please help me friends.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Image button

you don't use the code from the sample, i just checked it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
pankajace12
Posts: 206
Registered: ‎04-30-2011
My Device: BlackBerry Z10

Re: Image button

Hi,

 

Please use these two class:

 

use like :

'

BitmapButtonField _bbfCompose;

_bbfCompose = new BitmapButtonField("image.png","focusimage.png");

 

image.png is normal image, that you want to show, focusimage.png will appear when you will get focus over button..

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;


/**
* Implements all the stuff we don't want to do each time we need a new button
*/
public abstract class BaseButtonField extends Field
{
private XYRect _drawFocusTempRect = new XYRect();

public BaseButtonField()
{
this( 0 );
}

public BaseButtonField( long style )
{
super( Field.FOCUSABLE | style );
}

protected void layout( int width, int height )
{
setExtent( 10, 10 );
}

protected void drawFocus( Graphics g, boolean on )
{
getFocusRect( _drawFocusTempRect );

boolean oldDrawStyleFocus = g.isDrawingStyleSet( Graphics.DRAWSTYLE_FOCUS );
boolean notEmpty = g.pushContext( _drawFocusTempRect.x, _drawFocusTempRect.y, _drawFocusTempRect.width, _drawFocusTempRect.height, 0, 0 );

try {
if( notEmpty ) {
g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, on );
paintBackground( g );
paint( g );
}
} finally {
g.popContext();
g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus );
}
}

protected boolean keyChar( char character, int status, int time )
{
if( character == Characters.ENTER ) {
clickButton();
return true;
}
return super.keyChar( character, status, time );
}

protected boolean navigationClick( int status, int time )
{
clickButton();
return true;
}

protected boolean trackwheelClick( int status, int time )
{
clickButton();
return true;
}

protected boolean invokeAction( int action )
{
switch( action ) {
case ACTION_INVOKE: {
clickButton();
return true;
}
}
return super.invokeAction( action );
}

public void setDirty( boolean dirty ) {
// We never want to be dirty or muddy
}

public void setMuddy( boolean muddy ) {
// We never want to be dirty or muddy
}

/**
* A public way to click this button
*/
public void clickButton()
{
fieldChangeNotify( 0 );
}
}

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------


import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;

public class BitmapButtonField extends BaseButtonField
{
private Bitmap[] _bitmaps;
private static final int NORMAL = 0;
private static final int FOCUS = 1;

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.FOCUSABLE | style );

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

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

_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 ) {
// Nothing to do here
}
*/

protected void drawFocus( Graphics g, boolean on ) {
// Paint() handles it all
g.setDrawingStyle( Graphics.DRAWSTYLE_FOCUS, true );
paintBackground( g );
paint( g );
}
}

 

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------

 


Contributor
ahmednaserfinal
Posts: 43
Registered: ‎07-22-2012
My Device: curve

Re: Image button

really thanks patilajayr i searched for what you do