03-07-2012 05:00 AM
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_HCENTE R|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#getPre ferredWidth() */ public int getPreferredWidth() { return bitmap.getWidth(); } /* (non-Javadoc) * @see net.rim.device.api.ui.component.ButtonField#getPre ferredHeight() */ 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; } }
Solved! Go to Solution.
03-07-2012 05:16 AM
03-07-2012 05:24 AM
thanks for reply me.
but i want image button. now i am extend from Bitmapfield but still now working...
03-07-2012 05:30 AM
03-07-2012 05:50 AM
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.
03-07-2012 05:59 AM
03-07-2012 12:52 PM
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 );
}
}
--------------------------------------------------
10-18-2012 06:03 PM