public SliderField(
      Bitmap thumb,
      Bitmap sliderBackground,
      Bitmap sliderBackgroundFocus,
      int numStates,
      int initialState,
      int xLeftBackMargin,
      int xRightBackMargin,
      long style) {
    super(style);

    if (initialState > numStates || numStates < 2) {}
    _imageThumb = thumb;
    _imageSlider = sliderBackground;
    _imageSliderFocus = sliderBackgroundFocus;
    _numStates = numStates;
    setState(initialState);

    _xLeftBackMargin = xLeftBackMargin;
    _xRightBackMargin = xRightBackMargin;

    _rop = _imageSlider.hasAlpha() ? Graphics.ROP_SRC_ALPHA : Graphics.ROP_SRC_COPY;

    _thumbWidth = thumb.getWidth();
    _thumbHeight = thumb.getHeight();

    initBitmaps();
  }
 private void copy(Bitmap src, int x, int y, int width, int height, Bitmap dest) {
   int[] argbData = new int[width * height];
   src.getARGB(argbData, 0, width, x, y, width, height);
   for (int tx = 0; tx < dest.getWidth(); tx += width) {
     for (int ty = 0; ty < dest.getHeight(); ty += height) {
       dest.setARGB(argbData, 0, width, tx, ty, width, height);
     }
   }
 }
Example #3
0
  public BitmapButtonField(Bitmap normalState, Bitmap focusState, long style) {
    super(Field.FOCUSABLE | style);

    if ((normalState.getWidth() != focusState.getWidth())
        || (normalState.getHeight() != focusState.getHeight())) {

      throw new IllegalArgumentException("Image sizes don't match");
    }

    _bitmaps = new Bitmap[] {normalState, focusState};
  }
  // Similar to TextFields layout()
  protected void layout(int width, int height) {
    if (width < 0 || height < 0) throw new IllegalArgumentException();

    // We'll take all we can get
    _totalWidth = width;

    // The largest of the two image heights
    _totalHeight = Math.max(_imageSlider.getHeight(), _imageThumb.getHeight());

    setExtent(_totalWidth, _totalHeight);
  }
  private void paintSliderBackground(Graphics g, Bitmap left, Bitmap middle, Bitmap right) {
    int sliderHeight = _imageSlider.getHeight();
    int sliderBackYOffset = (_totalHeight - sliderHeight) >> 1;

    // Left
    g.drawBitmap(0, sliderBackYOffset, _xLeftBackMargin, sliderHeight, left, 0, 0); // lefttop
    // Middle
    g.tileRop(
        _rop,
        _xRightBackMargin,
        sliderBackYOffset,
        _totalWidth - _xLeftBackMargin - _xRightBackMargin,
        sliderHeight,
        middle,
        0,
        0); // top
    // Right
    g.drawBitmap(
        _totalWidth - _xRightBackMargin,
        sliderBackYOffset,
        _xRightBackMargin,
        sliderHeight,
        right,
        0,
        0); // lefttop
  }
  /**
   * Constructor.
   *
   * @param text The text to be displayed on the button
   * @param style Combination of field style bits to specify display attributes
   */
  public BOC(String dboc, String iboc, String tboc) {
    super(Field.NON_FOCUSABLE);
    try {
      _width = Display.getWidth();
      switch (_width) {
        case 480:
          f2 = 20;

          dbmp = Bitmap.getBitmapResource("bocdom480.jpg");
          ibmp = Bitmap.getBitmapResource("bocinter480.jpg");
          tbmp = Bitmap.getBitmapResource("boctotal480.jpg");
          _height = 60;
          break;
        case 360:
          f2 = 19;
          dbmp = Bitmap.getBitmapResource("bocdom360.png");
          ibmp = Bitmap.getBitmapResource("bocinter360.png");
          tbmp = Bitmap.getBitmapResource("boctotal360.png");
          _height = 60;
          break;
        default:
          f2 = 17;
          dbmp = Bitmap.getBitmapResource("bocdom320.png");
          ibmp = Bitmap.getBitmapResource("bocinter320.png");
          tbmp = Bitmap.getBitmapResource("boctotal320.png");

          _height = 60;
          break;
      }
      _dboc = dboc;
      _iboc = iboc;
      _tboc = tboc;
      FontFamily ff1 = FontFamily.forName("BBAlpha Serif");
      font = ff1.getFont(Font.PLAIN, f2);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }
  }
  public void paint(Graphics g) {
    // Calculate the slider position
    int sliderHeight = _imageSlider.getHeight();
    int sliderBackYOffset = (_totalHeight - sliderHeight) >> 1;

    // Determine a Background Color for the slider
    int backgroundColor = _defaultBackgroundColour;
    if (_backgroundSelectedColours != null || _backgroundColours != null) {

      if (_selected) {
        backgroundColor =
            _backgroundSelectedColours != null
                ? _backgroundSelectedColours[getState()]
                : _defaultSelectColour;
      } else if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
        backgroundColor =
            _backgroundColours != null ? _backgroundColours[getState()] : _defaultHoverColour;
      } else {
        backgroundColor = _defaultBackgroundColour;
      }
    }
    g.setColor(backgroundColor);
    g.fillRect(1, sliderBackYOffset + 1, _totalWidth - 2, sliderHeight - 2);

    if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
      paintSliderBackground(
          g, _imageSliderFocusLeft, _imageSliderFocusCenter, _imageSliderFocusRight);
    } else {
      paintSliderBackground(g, _imageSliderLeft, _imageSliderCenter, _imageSliderRight);
    }

    // Calculate the thumb position
    int thumbXOffset = ((_totalWidth - _thumbWidth) * _currentState) / _numStates;

    // Draw the thumb
    g.drawBitmap(
        thumbXOffset,
        (_totalHeight - _thumbHeight) >> 1,
        _thumbWidth,
        _thumbHeight,
        _imageThumb,
        0,
        0);
  }
  /**
   * Cuts up the background image and margins you provide to make the left, center, and right
   * bitmaps
   */
  public void initBitmaps() {
    int height = _imageSlider.getHeight();

    _imageSliderLeft = new Bitmap(_xLeftBackMargin, height);
    _imageSliderCenter =
        new Bitmap(_imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
    _imageSliderRight = new Bitmap(_xRightBackMargin, height);

    copy(_imageSlider, 0, 0, _xLeftBackMargin, height, _imageSliderLeft);
    copy(
        _imageSlider,
        _xLeftBackMargin,
        0,
        _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin,
        height,
        _imageSliderCenter);
    copy(
        _imageSlider,
        _imageSlider.getWidth() - _xRightBackMargin,
        0,
        _xRightBackMargin,
        height,
        _imageSliderRight);

    _imageSliderFocusLeft = new Bitmap(_xLeftBackMargin, height);
    _imageSliderFocusCenter =
        new Bitmap(_imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin, height);
    _imageSliderFocusRight = new Bitmap(_xRightBackMargin, height);

    copy(_imageSliderFocus, 0, 0, _xLeftBackMargin, height, _imageSliderFocusLeft);
    copy(
        _imageSliderFocus,
        _xLeftBackMargin,
        0,
        _imageSlider.getWidth() - _xRightBackMargin - _xLeftBackMargin,
        height,
        _imageSliderFocusCenter);
    copy(
        _imageSliderFocus,
        _imageSlider.getWidth() - _xRightBackMargin,
        0,
        _xRightBackMargin,
        height,
        _imageSliderFocusRight);
  }
Example #9
0
  public FreemapMainScreen() {
    super(DEFAULT_MENU);

    m_this = this;
    int size = 20;
    m_contextMenuItems = new Vector(size);
    m_MiniMenuItems = new Vector(size);
    for (int i = 0; i < size; ++i) {
      m_contextMenuItems.addElement(null);
      m_MiniMenuItems.addElement(null);
    }
    m_initial_locale = Locale.getDefaultInputForSystem();

    waiting_dialog =
        new Dialog(
            "please wait...",
            new String[] {"Hide"},
            null,
            Dialog.OK,
            Bitmap.getPredefinedBitmap(Bitmap.HOURGLASS));

    isLandscapeScreen = getVisibleWidth() > getVisibleHeight() ? 1 : 0;
  }
  public UIExampleListStyleButtonFieldScreen() {

    super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT);

    setTitle("ListStyleButtonField Example");

    Bitmap caret = Bitmap.getBitmapResource("chevron_right_black_15x22.png");

    ListStyleButtonField one = new ListStyleButtonField("Music", caret);
    one.setChangeListener(this);
    add(one);

    ListStyleButtonField two = new ListStyleButtonField("Photos", caret);
    two.setChangeListener(this);
    add(two);

    ListStyleButtonField three = new ListStyleButtonField("Extras", caret);
    three.setChangeListener(this);
    add(three);

    ListStyleButtonField four = new ListStyleButtonField("Settings", caret);
    four.setChangeListener(this);
    add(four);

    ListStyleButtonField five = new ListStyleButtonField("Shuffle Songs", 0);
    five.setChangeListener(this);
    add(five);

    _explanation = new UIExampleScreen();
    _explanation.setTitle("ListStyleButtonField Explanation");

    LabelField explanationLabel =
        new LabelField(
            "The ListStyleButtonField looks like a list row, but is just a simple button. Good for use with a small finite set of elements.");
    explanationLabel.setPadding(5, 5, 5, 5);
    _explanation.add(explanationLabel);
  }
  /**
   * Field implementation.
   *
   * @see net.rim.device.api.ui.Field#paint(Graphics)
   */
  protected void paint(Graphics graphics) {
    // First draw the background colour and picture

    switch (Display.getWidth()) {
      case 480:
        graphics.drawBitmap(12, 10, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(167, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.drawBitmap(324, 10, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 18, 40);
        graphics.drawText(_iboc, 173, 40);
        graphics.drawText(_tboc, 330, 40);
        break;
      case 360:
        graphics.drawBitmap(15, 10, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(185, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 28, 40);
        graphics.drawText(_iboc, 198, 40);
        graphics.drawBitmap(15, 65, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.drawText(_tboc, 130, 95);
        break;
      default:
        graphics.drawBitmap(15, 9, dbmp.getWidth(), dbmp.getHeight(), dbmp, 0, 0);
        graphics.drawBitmap(166, 10, ibmp.getWidth(), ibmp.getHeight(), ibmp, 0, 0);
        graphics.setFont(font);
        graphics.setColor(Color.DARKSLATEGRAY);
        graphics.drawText(_dboc, 18, 40);
        graphics.drawText(_iboc, 172, 40);
        graphics.drawBitmap(15, 65, tbmp.getWidth(), tbmp.getHeight(), tbmp, 0, 0);
        graphics.drawText(_tboc, 110, 95);
        break;
    }
  }