Blackberry Custom Image Field with active and normal Images

public class ImageField extends BitmapField {
 Bitmap mNormal;
 Bitmap mFocused;
 Bitmap mActive;
 int mWidth;
 int mHeight;

 public ImageField(Bitmap normal, Bitmap focused, Bitmap active, 
 long align) {
  super(active, align | ImageField.FOCUSABLE);
  mNormal = normal;
  mFocused = focused;
  mActive = active;
  mWidth = mFocused.getWidth();
  mHeight = mFocused.getHeight();
 }

 protected void paint(Graphics graphics) {
  Bitmap bitmap = null;
  switch (getVisualState()) {
  case VISUAL_STATE_NORMAL:
   bitmap = mNormal;
   break;
  case VISUAL_STATE_FOCUS:
   bitmap = mFocused;
   break;
  case VISUAL_STATE_ACTIVE:
   bitmap = mActive;
   break;
  default:
   bitmap = mNormal;
  }
  graphics.drawBitmap(0, 0, bitmap.getWidth(), 
  bitmap.getHeight(),
    bitmap, 0, 0);
 }

 public int getPreferredWidth() {
  return mWidth;
 }

 public int getPreferredHeight() {
  return mHeight;
 }

 protected void layout(int width, int height) {
  setExtent(mWidth, mHeight);
 }
}

Comments

Popular posts from this blog

Input filter (space not allowed) for EditText

Android Versions details

English - Formal and Informal words