views:

70

answers:

1

Hi!
Do you know some way to programmaticaly show different typing indicators on the screen?
I know I can simply draw bitmap but I'd like to do it universally for any RIM OS version.
Also, there is a setMode(int) function in 4.2.1 but in 4.3 it's already deprecated...

Any suggestions will be helpful, thanks!

+1  A: 

since there is no alternatives, I made a sample with provided images:

alt text alt text

custom Title Field class code:

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;
    }
}

Sample of use code:

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);
            }
        });
    }
}
Max Gontar