黑莓 - 显示输入模式指示灯编程(BlackBerry - Show typing mode ind

2019-10-31 03:42发布

你知道一些方法来programmaticaly显示不同类型的指标在屏幕上?
我知道我可以简单地划位图,但我想任何RIM OS版本做普遍。
此外,还有一个setMode(INT) 4.2.1功能,但在4.3,它已经过时?

任何建议会有所帮助,谢谢!

Answer 1:

因为没有替代品,我做了一个样本提供的图像 :

替代文字http://img42.imageshack.us/img42/6692/typeindicator.jpg 替代文字http://img3.imageshack.us/img3/5259/inputind.jpg

自定义标题字段类代码:

class TITitleField extends Field implements DrawStyle {
    static final boolean mIsDimTheme = Integer.parseInt(DeviceInfo
            .getDeviceName().substring(0, 4)) < 8900;
    static final Bitmap ALT = Bitmap.getBitmapResource(mIsDimTheme ? 
            "typ_ind_alt_mode_Gen_Zen_328560_11.jpg" : 
            "typ_ind_alt_mode_Precsn_Zen_392908_11.jpg");
    static final Bitmap MULTITAP = Bitmap.getBitmapResource(mIsDimTheme ?
    "typ_ind_mltap_mode_Gen_Zen_328975_11.jpg" : 
    "typ_ind_mutlitap_mode_Precsn_Zen_452907_11.jpg");
    static final Bitmap NUMLOCK = Bitmap
        .getBitmapResource(mIsDimTheme ? 
            "typ_ind_num_lock_Gen_Zen_328568_11.jpg" : 
            "typ_ind_num_lock_Precsn_Zen_392925_11.jpg");
    static final Bitmap SHIFT = Bitmap.getBitmapResource(mIsDimTheme ? 
            "typ_ind_shift_mode_Gen_Zen_328574_11.jpg" : 
            "typ_ind_shift_mode_Precsn_Zen_392931_11.jpg");

    public static final int MODE_NONE = 0;
    public static final int MODE_ALT = 1;
    public static final int MODE_MULTITAP = 2;
    public static final int MODE_NUMLOCK = 3;
    public static final int MODE_SHIFT = 4;

    public void setTypingIndicatorMode(int mode) {
        mMode = mode;
        updateLayout();
    }

    public int getTypingIndicatorMode()
    {
        return mMode;       
    }

    int mWidth = 0;
    int mMode = 0;
    String mTitle = "";
    XYRect mIndicatorDestRect = new XYRect();

    public TITitleField() {
        this("");
    }

    public TITitleField(String title) {
        mTitle = title;
    }

    protected void paint(Graphics graphics) {
        graphics.drawText(mTitle, 0, 0, LEFT | ELLIPSIS, mWidth);
        if (0 != mMode) {
            graphics.drawBitmap(mIndicatorDestRect,getIndicator(mMode),0,0);
        }
    }

    private static Bitmap getIndicator(int mode) {
        Bitmap result = null;
        switch (mode) {
        case MODE_ALT:
            result = ALT;
            break;
        case MODE_MULTITAP:
            result = MULTITAP;
            break;
        case MODE_NUMLOCK:
            result = NUMLOCK;
            break;
        case MODE_SHIFT:
            result = SHIFT;
            break;
        case MODE_NONE:
            break;
        default:
            break;
        }
        return result;
    }

    protected void layout(int width, int height) {
        mWidth = width;
        if (0 != mMode) {
            Bitmap indicator = getIndicator(mMode);
            mIndicatorDestRect.width = indicator.getWidth();
            mIndicatorDestRect.height = indicator.getHeight();
            mIndicatorDestRect.y = 0;
            mIndicatorDestRect.x = mWidth - mIndicatorDestRect.width;
        }
        setExtent(width, getPreferredHeight());
    }

    public int getPreferredHeight() {
        int height = getFont().getHeight() + 4;
        if (0 != mMode) {
            int indicatorHeight = getIndicator(mMode).getHeight();
            height = Math.max(height, indicatorHeight);
        }
        return height;
    }
}

使用代码示例:

class Scr extends MainScreen {
    static final TITitleField mTitle = new TITitleField("Start");

    public Scr() {
        this.setTitle(mTitle);
    }

    protected void makeMenu(Menu menu, int instance) {
        super.makeMenu(menu, instance);

        int typingIndicatorMode = mTitle.getTypingIndicatorMode();

        if(typingIndicatorMode != mTitle.MODE_NONE)
        menu.add(new MenuItem("None Mode", 0, 0) {
            public void run() {
                mTitle.setTypingIndicatorMode(mTitle.MODE_NONE);
            }
        });

        if(typingIndicatorMode != mTitle.MODE_ALT)
        menu.add(new MenuItem("Alt Mode", 0, 0) {
            public void run() {
                mTitle.setTypingIndicatorMode(mTitle.MODE_ALT);
            }
        });

        if(typingIndicatorMode != mTitle.MODE_MULTITAP)
        menu.add(new MenuItem("Multitap Mode", 0, 0) {
            public void run() {
                mTitle.setTypingIndicatorMode(mTitle.MODE_MULTITAP);
            }
        });

        if(typingIndicatorMode != mTitle.MODE_NUMLOCK)
        menu.add(new MenuItem("NumLock Mode", 0, 0) {
            public void run() {
                mTitle.setTypingIndicatorMode(mTitle.MODE_NUMLOCK);
            }
        });

        if(typingIndicatorMode != mTitle.MODE_SHIFT)
        menu.add(new MenuItem("Shift Mode", 0, 0) {
            public void run() {
                mTitle.setTypingIndicatorMode(mTitle.MODE_SHIFT);
            }
        });
    }
}


文章来源: BlackBerry - Show typing mode indicator programmatically