开发者

Blackberry 4.5 - How to click on a .jpg image?

开发者 https://www.devze.com 2022-12-17 14:25 出处:网络
I m displaying a .jpg image in a BitmapField & adding it in a VerticalFieldManager. It is getting displayed but I cannot click on it.

I m displaying a .jpg image in a BitmapField & adding it in a VerticalFieldManager. It is getting displayed but I cannot click on it.

I m doing it like..

Bitmap bitmap = Bitmap.getBitmapResource("image.jpg");

BitmapField bitmapField = new BitmapField(bitmap , BitmapField.FOCUSABLE)        
    {
        protected boolean navigationClick(int status, int time )
        {
            //handle click event                
            return true;
        }
    };
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(bitmapField);
add(vfm_stamp);

But if I take a .png image like

Bitmap bitmap = Bitmap.getBitmapResource("image.png");

th开发者_如何学JAVAen it is clickable. Why so?

Blackberry 4.5 supports .jpg image format. It displays a .jpg image then why its not clickable ? I want to make it clickable.

How to do it ?


You could override the method onFocus() and change it's behavior while selected.

You could also create a BitmapButton that extends net.rim.device.api.ui.Field

You will need to setChangeListener() for your bitmapField


You can extand ButtonField:

package org.ci.blackberry.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;

public class BitmapButtonField45 extends ButtonField {
        private static final int STATE_NORMAL = 0;
        private static final int STATE_FOCUS = 1;
        private static final int STATE_ACTIVE = 2;
        Bitmap mNormal;
        Bitmap mFocused;
        Bitmap mActive;

        int mWidth;
        int mHeight;
        private int mState = STATE_NORMAL;

        public BitmapButtonField45(Bitmap normal, Bitmap focused, 
                Bitmap active) {
                super(CONSUME_CLICK);
                mNormal = normal;
                mFocused = focused;
                mActive = active;
                mWidth = mNormal.getWidth();
                mHeight = mNormal.getHeight();
        }
        public BitmapButtonField45(Bitmap normal, Bitmap focused) {
                this(normal, focused, focused);
        }
        protected void paint(Graphics graphics) {
                Bitmap bitmap = null;
                switch (getState()) {
                case STATE_NORMAL:
                        bitmap = mNormal;
                        break;
                case STATE_FOCUS:
                        bitmap = mFocused;
                        break;
                case STATE_ACTIVE:
                        bitmap = mActive;
                        break;
                default:
                        bitmap = mNormal;
                }
                graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                                bitmap, 0, 0);
        }

        public int getState() {
                return mState;
        }

        protected void applyTheme()
        {}
        protected void onFocus(int direction) {
                mState = STATE_FOCUS;
                super.onFocus(direction);
        }

        protected void onUnfocus() {
                mState = STATE_NORMAL;
                super.onUnfocus();
        }

        protected boolean navigationClick(int status, int time) {
                mState = STATE_ACTIVE;
                return super.navigationClick(status, time);
        }

        protected boolean navigationUnclick(int status, int time) {
                mState = STATE_NORMAL;
                return super.navigationUnclick(status, time);
        }

        public int getPreferredWidth() {
                return mWidth;
        }

        public int getPreferredHeight() {
                return mHeight;
        }

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

Examples of use: PuzzleApp.java

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号