I'm trying to make touchable image which can focus when I scroll it by touchable button on device this is my code for touchable image:
class TouchBitmapField extends BitmapField {
Bitmap bitmap;
boolean second;
int width;
public TouchBitmapField(Bitmap startBitmap, long style, int width, boolean second) {
super(startBitmap, style);
this.second = second;
bitmap = startBitmap;
this.width = width;
}
protected void drawFocus(Graphics g, boolean on){
g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true );
if(on){
drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, on, width-(bitmap.getWidth()/2), 0, bitmap.getWidth(), bitmap.getHeight());
}
paint(g);
}
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
}
But the problem is that only transparent part of image can focus and I'm resising this Bitmap before create TouchBitmapField and as you maybe know resising bitmap remove transparent part and replace it with black. I tried this class http://www.patchou.com/2010/10/resizing-transparent-bitmaps-with-the-blackberry-jde/ to resize image but I have 25 images on my screen and it's inefficient. Any idea how to make border on image? Any efficient way to draw border in drawFocus(Graphics g, boolean on)
method?
The reason why you can only focus the transparent parts of an image is because (as far as I know)
drawFocus
is fired beforepaint
, causing the bitmap to be drawn last.I think this solution is what you're looking for. If you want something other than a solid colour as the border, you can play around with the
BorderFactory
.If you want your border to be overlapping your image, you can override your
paint
method and draw as you want.