2010-03-01 56 views
0

您知道某種方式讓programmaticaly在屏幕上顯示不同的typing indicators
我知道我可以簡單地繪製位圖,但我想爲任何RIM操作系統版本通用。
此外,還有一個setMode(int)功能4.2.1,但4.3,它已經過時......BlackBerry - 以編程方式顯示打字模式指示燈

任何建議會有所幫助,謝謝!

+0

我不確定我是否rstand,你想顯示打字指示器,除了已提供的?你想讓他們在RIM OS 4.1+上工作嗎? – 2010-03-01 15:18:07

+0

我想在RIM 4.1+中的自定義情況下顯示標準指示器(例如自定義輸入)。 – 2010-03-02 11:35:40

回答

1

,因爲沒有替代品,我做了provided images樣本:

alt text http://img42.imageshack.us/img42/6692/typeindicator.jpg alt text 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); 
      } 
     }); 
    } 
}