隨筆 - 35  文章 - 21  trackbacks - 0
          <2008年9月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜


          效果圖:


          點擊后:


          這是放出的第一個客戶自定制組件。比較簡單。
          黃色框,是改變了系統的焦點事件的效果。
          行為是這樣的,點擊 PopImageLabelField 將會改變圖標
          這里是向上的箭頭和向下的箭頭的交替變化。


           

          這可以用來提示,現在按鈕的狀態。
          有兩個類:
          ImageLabelField 是一個帶圖標的標志符。它也可以被單獨作為一個靜止的按鈕使用。
          PopImageLabelField  繼承了 ImageLabelField,并可以接受點擊事件,改變并顯示Image。


          /*
           * ImageLabel.java
           *
           * FlyCloud mobi, 2003-2008
           * guolin.mobi*gmail.com
           * Confidential and proprietary.
           */

          package app.ui.component;

          import net.rim.device.api.ui.*;
          import net.rim.device.api.ui.component.*;
          import net.rim.device.api.ui.container.*;
          import net.rim.device.api.system.*;

          public class ImageLabelField extends Field{
             
              protected Bitmap image;
              protected String text;
              protected int bgColor = 0x00FFFFFF;
              protected int fontColor = 0x00000000;
                         
              public ImageLabelField(String text, long style)
              {
                  super( style );
                  this.text = text;
              }
             
              public ImageLabelField( Bitmap image )
              {
                  super( Field.FOCUSABLE );
                  this.image = image ;
              }
             
              public ImageLabelField(String imagePath, String text )
              {
                  super( Field.FOCUSABLE );
                  this.text = text;
                  image = Bitmap.getBitmapResource( imagePath );   
              }
             
              public ImageLabelField( Bitmap image, String text)
              {
                  super( Field.FOCUSABLE );
                  this.text = text;
                  this.image = image;
              }
             
              protected void layout(int width, int height)
              {
                  setExtent( getPreferredWidth(), getPreferredHeight() );
              }
             
              protected void paint( Graphics g)
              {
                  // background
                  g.setColor( bgColor );
                  g.fillRect( 0, 0 , getPreferredWidth(), getPreferredHeight() );
                 
                  // image
                  int x = 0;
                  if( image != null )
                  {
                      int imageWidth =  image.getWidth();
                      int imageHeight = image.getHeight();
                     
                      g.drawBitmap( 1, ( getPreferredHeight() - imageHeight )/2,
                                   image.getWidth(), image.getHeight(), image, 0, 0);
                      x = image.getWidth() + 2;
                  }
                 
                  // Text
                  g.setColor( fontColor );
                  if( text != null )
                  g.drawText( text, x, 0);
              }
             
              public int getPreferredWidth()
              {
                  int imageWidth = 0 ;
                  int textWidth = ( new LabelField( text ) ).getPreferredWidth();
                 
                  if( image != null )
                  imageWidth = image.getWidth();
                 
                  return imageWidth +  textWidth + 2;
              }
             
              public int getPreferredHeight()
              {
                  int imageHeight = 0;
                  int textHeight = ( new LabelField( text ) ).getPreferredHeight();
                 
                  if( image != null )
                  imageHeight = image.getHeight();
                 
                  return (imageHeight > textHeight ? imageHeight : textHeight) + 2;
              }
             
              protected void drawFocus(Graphics g, boolean on)
              {
                  int tmpColor = g.getColor();
                  g.setColor( app.ui.skin.CustomerColor.FOCUS_RECT );
                  g.drawRect( 0, 0, getPreferredWidth(), getPreferredHeight() );
                  g.setColor( tmpColor );
              }
              
              protected boolean keyDown(int keycode, int time)
              {
                  if( Keypad.key( keycode ) == Keypad.KEY_ENTER)
                  { 
                          invalidate();
                  } 
                  else
                  {
                    fieldChangeNotify(1);
                    return false;
                  }
                 
                  fieldChangeNotify(1);
                  return true;
              }   
          }


          /*
           * PopImageLabel.java
           *
           * FlyCloud, 2003-2008
           * guolin.mobi*gmail.com
           * Confidential and proprietary.
           */

          package app.ui.component;

          import net.rim.device.api.ui.*;
          import net.rim.device.api.ui.component.*;
          import net.rim.device.api.ui.container.*;
          import net.rim.device.api.system.*;

          public class PopImageLabelField extends ImageLabelField
          {   
              private Bitmap imageUp;
              private Bitmap imageDown;
              private boolean statusUp;
             
              public PopImageLabelField( String text, long style )
              {
                  super( text , style );
                  imageUp = Bitmap.getBitmapResource( "arrow_collapse.gif" );
                  imageDown = Bitmap.getBitmapResource( "arrow_expand.gif" );
                  this.statusUp = false;
                  image = imageDown;
              }
             
              public PopImageLabelField( String pathImageUp, String pathImageDown, boolean statusUp, String text, long style)
              {
                  super( text , style);
                 
                  imageUp =  Bitmap.getBitmapResource( pathImageUp );
                  imageDown = Bitmap.getBitmapResource( pathImageDown );
                 
                  this.statusUp = statusUp;
                  if( this.statusUp )
                      image = imageUp;
                  else
                      image = imageDown;
              }
             
              public synchronized void keyAction()
              {
                  statusUp = !statusUp;
                 
                  if( this.statusUp )
                      image = imageUp;
                  else
                      image = imageDown;

                  invalidate();
              }
             
              protected boolean keyDown(int keycode, int time)
              {
                  if( Keypad.key( keycode ) == Keypad.KEY_ENTER)
                  {
                     keyAction();
                     invalidate();
                  } 
                  else
                  {
                    fieldChangeNotify(1);
                    return false;
                  }
                 
                  fieldChangeNotify(1);
                  return true;
              }
             
              protected void fieldChangeNotify(int context)
              {
                  try {
                      this.getChangeListener().fieldChanged(this, context);
                  } catch (Exception exception) {
                  }
              } 
          }

          posted on 2008-09-20 06:57 lincode 閱讀(421) 評論(0)  編輯  收藏 所屬分類: Blackberry
          主站蜘蛛池模板: 商河县| 成安县| 和顺县| 渭源县| 将乐县| 织金县| 高邑县| 上虞市| 文成县| 许昌县| 江都市| 铁岭县| 高雄市| 灌阳县| 浠水县| 大安市| 丰台区| 安阳县| 河北省| 上栗县| 河西区| 宝应县| 萨嘎县| 曲阳县| 岳阳市| 南华县| 宁蒗| 永春县| 三门峡市| 汉阴县| 喀什市| 东城区| 肃北| 阜平县| 游戏| 资阳市| 施甸县| 濮阳县| 临江市| 巩留县| 榆林市|