1

I am interested in having a bitmap icon that when clicked will open a new screen. Now so far I have been using this link to achieve drawing the bitmap:

Blackberry Clickable BitmapField

This code is meant to draw a bitmap on the screen and evoke an action when clicked upon. It has two pictures with and without focus. I am calling it with:

CustomMenuButtonField buttonInstance = new CustomMenuButtonField("img1.png", "img2.png");
add(buttonInstance);

I have changed:

protected boolean navigationClick(int status, int time)
    {
        Alert.startVibrate(50);
        //fieldChangeNotify(0);
        return true;
    }

One issue I am having is that when I click outside the image in the field manager, the picture is still changed and an action is evoked (vibrates). From here it stays in the "focus" until I click on another text field on the window, but clicking on white space still does not change it. My question is should this be happening, and is there a way to limit it so the action is evoked JUST when you click the bitmap and not around it? Also is there a simple way to scale the bitmap into something of smaller size such as an icon? I am trying to position 4 icons that when clicked will open four different screens. If anyone knows anything about this any assistance would be appreciated. I just started Java so I'm an extreme novice.

Community
  • 1
  • 1
user1152440
  • 895
  • 2
  • 13
  • 25
  • Reading my post... I think my best advice is get away from the RIM toolkit. Eclipse was my favorite, there may be other tools available now. – Daniel B. Chapman Jan 27 '12 at 00:07

1 Answers1

1

Note: I'm highly biased against the Blackberry API.

It has been a long time since I did any work on the Blackberry (version 5) software so my advice might be totally out of date. (I think I was working version 5).

The components provided were totally inadequate for anything we needed to do that had a custom look and feel so we took the approach of overriding the Manager class to create custom components.

//Garbage code from a dead project
      /* (non-Javadoc)
       * @see net.rim.device.api.ui.Manager#paint(net.rim.device.api.ui.Graphics)
       */
      protected void paint(Graphics graphics) {
        if(style == Spinner.DRAW_ROUNDED_RECTANGLE)
          drawRoundedRectangluar(graphics);
        else
          drawRectangular(graphics);
      }

The rest of this is garbage so I'm only posting the idea of it

If you extend a button that works and replace the paint method (not unlike working with Swing, except infinitely more painful) you can basically do whatever you want. This would give you the ability to scale the image and do whatever you need.

However, I hope Blackberry has updated their API in the last few years. This project was painful and took about ~ 10 times the amount of work it should have to accomplish what you thought it should take.

Also, events need(ed?) to be consumed on the device otherwise they would automatically propagate (return true on the listeners to indicate the event is consumed.)

Without knowing the version and the exact API I'm afraid I can't be of more help other than saying I would highly recommend sticking with the absolute minimum requirements so it ports to all the devices OR try to accomplish the application through a mobile web interface (not always an option). I found the Blackberry to be a quagmire in my development time and I abandoned it.

When working with it I found writing the painting from scratch was faster than trying to make their components work consistently, its doable, and 95% of the swing tutorials will translate with very little additional work.

(Also, SWT is a little better fit for the API, you should check that out over at Eclipse--and if you're not using Eclipse for Blackberry development pick that up while you're at it. The RIM tools out of the box were horrible.)

Daniel B. Chapman
  • 4,647
  • 32
  • 42
  • Thank you for your advice Daniel. I am using the new eclipse environment with the blackberry plugin downloaded from the RIM site itself; the version of the eclipse plugin is 1.5 from http://us.blackberry.com/developers/javaappdev/javaplugin.jsp . When you say that events need to be consumed does that mean I need to leave fieldChangeNotify(0) inside the code uncommented? I am currently checking out the suggestions you posted, thanks again! – user1152440 Jan 27 '12 at 14:19
  • When I was referring to consumption: if you don't return true on an event it propagates onward (to other components). Since you mentioned your screen would stay until focus was lost I thought it might be the fact you didn't "consume" (return true) from your listener. I remember similar behavior on unconsumed events. – Daniel B. Chapman Jan 28 '12 at 03:28