BitmapField FieldChangeListener problem

Hello

I use BitmapField as a button with the two FieldChangeListener and

FocusChangeListener in my application.

In FocusChangeListener I change just image of bitmapfield

and in FieldChangeListener, I gave a single action.

Problem is when BitmapField won the development, called FieldChangeListener

What could be the solution to prevent this?

I want action to call only to click and not on the FOCUS_GAINED event

Hello

Instead of domain change listener tries with method "click browsing..."

----------------------------------------------------------------------------------------------------------------------------------------------------------

Press 'Congratulations' if it helps

Tags: BlackBerry Developers

Similar Questions

  • ObjectChoiceField FieldChangeListener problem

    Hi all

    I'm coding an application for 4.5 but testing on BB 9500.

    I want to a few call webservice on the choice of an ObjectChoiceField.

    But the problem is that the FieldChangeListener of the ObjectChoiceField fires on the development as well as on the selection of the field.

    How to distinguish two event?

    Thaks for your help in advance.

    Hi all

    I found the solution to my problem.

    Below is sample code for the solution.

    ObjectChoiceField myObjectField= new ObjectChoiceField("",new String[] { "" }, 0, FIELD_LEFT)
    {
        protected void fieldChangeNotify(int context)
        {
        new myObjectField_change_method();
        }
        public void focusChangeNotify(int arg0)
        {
        super.focusChangeNotify(arg0);
        }
    };
    

    In the code above myObjectField_change_method() is a method to be triggered when the field is selected.

  • Animated GIF problem

    Hello

    I use a GIF image for the design of the loading bar

    The image is a black & white gif image that is his black image with white animation on it. but the problem is when I tried to load the image in the encodedImage holding corruption when shading is displayed. I tried the app with thread of animation. Also, I tried to draw the picture in a class that extends BitMapField. the problem still persists. Any idea on a question also

    This is the code that I had to use for gifs:

    Standard paint:

        protected void paint(Graphics graphics)
        {
            //Call super.paint. This will draw the first background
            //frame and handle any required focus drawing.
            super.paint(graphics);
    
            //Don't redraw the background if this is the first frame.
            if (_currentFrame != 0)
            {
                //Draw the animation frame.
                graphics.drawImage(_image.getFrameLeft(_currentFrame), _image.getFrameTop(_currentFrame),
                    _image.getFrameWidth(_currentFrame), _image.getFrameHeight(_currentFrame), _image, _currentFrame, 0, 0);
            }
        }
    

    The paint that I used:

        protected void paint(Graphics graphics)
        {
            for ( int i = 0; i <= _currentFrame; i ++ ) {
                graphics.drawImage(_image.getFrameLeft(i),
                                   _image.getFrameTop(i),
                                   _image.getFrameWidth(i),
                                   _image.getFrameHeight(i),
                                   _image,
                                   i,
                                   0, 0);
            }
        }
    
  • Addition of BitmapFields to Horizontal Manager

    Hi all

    I have a popupscreen (VerticalFieldmanager) I added an editfield, a LabelFieldby directly by calling (editfield or labelfield) and a Horizontal add field (horizontalField), calling for this horizontalField, I added four BitmapFields

    Problem:

    (1) I need padding or space between four bitmapFields

    (2) how to resize BitmapFields

    (3) how to draw a Rectangle when BitmapField is concentrated, where to write this method, what precauctions must be in subpaint (Graphics g)

    Help:

    If anyone has some tutorial or examples graphics or managers, please specify a link. Documentation is not clear in detail, when to use subLayout and subpaint

    I suggest you familiarize yourself with

    http://NA.BlackBerry.com/eng/developers/

    Note the resources option that brings you here:

    http://NA.BlackBerry.com/eng/developers/resources/

    From there, there are many places to search for information on other issues you may have, and this

    In particular, in this case, I suggest you look at the videos section, there you will find two very helpful videos on the screens and managers, which fills some basic information you need.

    In addition, all your questions are answered in various posts on this forum, I suggest do you good research tour and see what you find.

    Good luck.

  • BitmapField on the touch screen problem

    Hello

    I have a simple form with two fields of bitmap and I want to take the events of button CLICK on each field. But the problem is that my program behaves like I always click on the first button even if I click on the other.

    How can I solve this, what someone has any ideas?

    The code is below. Thank you...

    public final class TouchEventInjectorScreen extends MainScreen {
        private LabelField labelField;
        private BitmapField button1;
        private BitmapField button2;
    
        public TouchEventInjectorScreen() {
    
            setTitle("Touch Demo");
    
            labelField = new LabelField("");
            add(labelField);
            button1 = new BitmapField(Bitmap.getBitmapResource("1.png"),BitmapField.FOCUSABLE){
                protected void onFocus(int direction) {
    
                    super.onFocus(direction);
                }
                protected boolean touchEvent(TouchEvent message) {
                    if(message.getEvent() == TouchEvent.CLICK){
    
                        System.out.println("1");
                    }
                    return true;
                }
            };
            button2 = new BitmapField(Bitmap.getBitmapResource("2.png"),BitmapField.FOCUSABLE){
                protected void onFocus(int direction) {
    
                    super.onFocus(direction);
                }
    
                protected boolean touchEvent(TouchEvent message) {
                    if(message.getEvent() == TouchEvent.CLICK){
    
                        System.out.println("2");
                    }
                    return true;
                }
            };
            HorizontalFieldManager h1 = new HorizontalFieldManager();
            h1.add(button1);
            add(h1);
            add(new LabelField(""));
            HorizontalFieldManager h2 = new HorizontalFieldManager();
            h2.add(button2);
            add(h2);
    
        }
    
    }
    

    When I shot the screen always 1 is printed in the system.out

    If you try to manage the events button on the two fields that have defined the style as focusable, then there are two ways to handle them.

    1. management of the key by its parent event. Is to say, add 2 focusable components Manager then manage the key event in the Manager himself. Here is the code snippet

    class MyManager extends VerticalFieldManager
    {
    protected boolean touchEvent (TouchEvent message)
    {
    switch (message.getEvent ())
    {
    case TouchEvent.CLICK:
    int x = message.getX (1);
    int y = message.getY (1);
    int index = getFieldAtLocation (x, y);
    Field field = getField (index);
    System.out.println ("field->" + index);
    field.setFocus ();
    break;
    }
    Returns true;
    }
    }

    class touch screen extends screen
    {
    Private button1 As BitmapField;
    private BitmapField button2;

    public TouchScreen()
    {
    Button1 = new BitmapField (Bitmap.getBitmapResource ("1.png"), BitmapField.FOCUSABLE);
    Button2 = new BitmapField (Bitmap.getBitmapResource ("2.png"), BitmapField.FOCUSABLE);
    Manager of MyManager = new MyManager();
    Manager.Add (button1);
    Manager.Add (button2);
    Add (Director);
    }
    }

    2. This step is to manage the key event at the level of the component itself. In this case, you must first make sure that this place where we clicked on belongs to the targeted component. because the targeted component key event will be called first by default. This is possible by getting the x, the position and the region where we clicked and check if it is located in the region of this element, otherwise returns false, the event goes to the next component. If the x position is located in the region of a component, handle touch event in this case.

    Here is the code snippet

    class MyBitmapField extends BitmapField
    {
    protected boolean touchEvent (TouchEvent message)
    {
    switch (message.getEvent ())
    {
    case TouchEvent.CLICK:
    If (message.getY (1))<>
    Returns false;
    If (message.getY (1) > getHeight())
    Returns false;
    If (message.getX (1))<>
    Returns false;
    If (message.getX (1) > getWidth())
    Returns false;

    you code here
    break;
    }
    Returns true;
    }
    }

  • problem in the view of the BitmapFields in HorizontalFieldManager in a line of Blackberry Storm

    I had created a HorizontalFieldManager & BitmapFields said that.

    In Blackberry Storm, Display.getWidth () is 480. I want to use 450 first to add some BitmapFields to LHS of the screen I have create running m & add 2 BitmapFields initially to RHS of the screen.

    2 BimapFields that I want to show initially added to the constructor r & othsr BitmapFields that I m create runtime r added afterwords love...

    class MyCanvas extends MainScreen{
    
    MyCanvas(){
    
    hfm_BitmapField = new HorizontalFieldManager(){            protected void sublayout(int maxWidth, int maxHeight) {                    super.sublayout(maxWidth, maxHeight);                     setExtent(Display.getWidth()-30, 60);                    }         };
    
    startBitmap = Bitmap.getBitmapResource("start.png");        startBitmapField = new BitmapField(startBitmap, BitmapField.ACTION_INVOKE | BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);hfm_BitmapField.add(startBitmapField);
    
    endBitmap = Bitmap.getBitmapResource("end.png");        endBitmapField = new BitmapField(endBitmap, BitmapField.ACTION_INVOKE | BitmapField.FIELD_HCENTER | BitmapField.FIELD_RIGHT);hfm_BitmapField.add(endBitmapField);
    
    drawBitmap();} 
    
    public void drawBitmap(){
    
    bitmap[i] = new Bitmap(50, 50); Graphics g = new Graphics(bitmap[i]);g.drawLine(5,5,25,25); bitmapField[i] = new BitmapField(bitmap[i]); synchronized(UiApplication.getEventLock()) { hfm.add(bitmapField[i]); }
    
    }
    

    I want startBitmapField & endBitmapField at RHS & bitmapField [i] that I m creating the runtime to LHS of HorizontalFieldManagers.

    I m thinking to add 2 HorizontalFieldManagers. 1 for 1 for startBitmapField & endBitmapField & bitmapField [i]. But how to add 2 HorizontalFieldManagers or any other FieldManagers in a row?

    Any solution? How to do?

    Solved my problem.

  • Strange problem of onFocus BitmapField

    Hello, at least, this is:

    I have a set of BitmapField to change the image once it is 'focused', it works, but I get this popup dialog whenever it "focuses" or "unfocuses":

    Code:

    button1 = new BitmapField(b1, Field.FIELD_HCENTER|BitmapField.FOCUSABLE) {
                protected void onFocus(int direction) {
                    setBitmap(b2sel);
                }
                protected void onUnfocus() {
                    super.onUnfocus();
                    setBitmap(b1);
                }
    
                protected boolean navigationClick(int status, int time) {
                    button2.setFocus();
                    Dialog.inform("Button 1 Clicked!");
                    return true;
                }
    
            };
    

    Anyone know how I can stop the implementation of this dialog box?

    N/m... figured it out. Has had another shot of method.

  • Problem of placement for the BitmapField style

    I have a subclass the Bitmapfield like this, but the HCENTER and VCENTER styles do not work.  I have a 80 x 80 bitmapfield and bimaps that are smaller than that (like 32 x 32) appear in the upper left corner of the area of 80 x 80.  I want that they focus to this area.  How can I achieve this?  (there are several ApplicationFields in the custom handler)

    I can focus the image if I override the method object, but I still need the style bitmapfield FOCUSABLE.

    According to me, Miss me something very easy.

    public abstract class ApplicationField extends BitmapField{
    
            private Bitmap image;
    
            public ApplicationField(Bitmap image, long style) {
                super(image, Field.FOCUSABLE | Field.FIELD_HCENTER | Field.FIELD_VCENTER);
                this.image = image;
            }
    
            public int getPreferredHeight(){
                return 80;
            }
    
            public int getPreferredWidth(){
                return 80;
            }
    
    ....
    

    That is the answer... padding!

    ' public void setSpace (hSpace, hspace int int) {}
    super.setSpace (hSpace, hspace);
    }

  • BitmapField consumes all clicks on the screen

    Hello

    I hope someone can help me with this problem: I have a screen that has only BitmapField is on. When you click on this 'something' BitmapField should be here which works very well.

    The problem is that even if I click elsewhere on the screen the 'click' fires.

    This is the main code on the screen:

    VerticalFieldManager view = new VerticalFieldManager();
    
    Bitmap bm = Bitmap.getBitmapResource("image.jpg"); // size 60x60
    MyBitmapField bmf = new MyBitmapField(bm, BitmapField.FOCUSABLE);
    bmf.setChangeListener(this);
    view.add(bmf);
    add(view);
    

    And that the implementation of the 'MyBitmapField ':

    public class MyBitmapField extends BitmapField
    {
      public MyBitmapField(Bitmap bitmap)
      {
        super(bitmap);
      }
    
      public MyBitmapField(Bitmap bitmap, long style)
      {
        super(bitmap, style);
      }
    
      protected boolean navigationClick(int status, int time)
      {
        FieldChangeListener listener = getChangeListener();
        if (null != listener)
        {
          Dialog.alert("Clicked");
          listener.fieldChanged(this, 1);
          return true;
        }
    
        return super.navigationClick(status, time);
      }
    
      protected boolean touchEvent(TouchEvent message)
      {
        /*
        if (TouchEvent.CLICK == message.getEvent())
        {
          int index = this.getManager().getFieldAtLocation(message.getX(1), message.getY(1));
          if (index == -1)
              return super.touchEvent(message);
          Field field = this.getManager().getField(index);
          if (field != this)
            return super.touchEvent(message);
    
          FieldChangeListener listener = getChangeListener();
          if (null != listener)
            listener.fieldChanged(this, 1);
        }*/
        return super.touchEvent(message);
    }
    
    }
    

    In the touchEvent method is a point that I also tried - but that didn't work either.

    The fieldChanged Manager is as usual:

      public void fieldChanged(Field field, int arg)
      {
        if (field instanceof MyBitmapField)
        {
          MyBitmapField bmf = (MyBitmapField) field;
          Dialog.alert("Clicked: " + Integer.toString(arg));
        }
      }
    

    I'm actually on the 9550 Simulator.

    Can someone please help me and tell me what I need to do to avoid that the click event is fired even if I click outside the BitmapField (I also put a border, just to make it visible, it is not expanded).

    Thank you very much

    That's exactly how BlackBerry works, even if it is IMHO pretty buggy: the key CLICK event is translated into navigationClick() in the field that currently has the focus. The problem lies in the fact that EVENT moves the focus to the field under him that if there is an active field where you press the screen, otherwise the focus remains where it is.

    To overcome this obstacle, program your touchEvent similar to this:

    protected boolean touchEvent(TouchEvent message) {
      if (TouchEvent.CLICK == message.getEvent()) {
        int x = message.getX(1);
        int y = message.getY(1);
        XYRect myExtent;
        getExtent(myExtent);
        myExtent.translate(0, 0); // getX, getY values are relative to this field's upper-left corner
        if (!myExtent.contains(x, y)) {
          return true;
        }
      }
      return super.touchEvent(message);
    }
    

    You can allow a 'near miss' avoid the frustration of users - extend the myExtent in any quantity you want of each side.

  • TouchEvent &amp; FieldChangeListener both does not work

    Hello

    I have 2 bitmapfields and a buttonfield. I want that all fields to intercept the click event. Initially, I had added only fieldChangeListeners to all fields, but bitmap field has not answered them (despite making them Focusable). I added touchevent to handle events click for all areas, now all fields respond only touchEvents. Same buttonfield does not meet fieldChange that he met before adding the touchEvent.

    Can someone help me to know the problem and the solution for the same. I want that all fields to react to events through contact or normal by a click. Also in touchEvent as navigationClick added id, if the menu is not coming, but otherwise with the other menu click only just who should not and the fieldchangelistener should be handled.  Here's the code.

        private BitmapField  signOffBtn, profileBtn;
        private ButtonField btn;
    
        public LoggedUserScreen(UserBean user) {
            super();
            this.loggedUser = user;
            System.out.println("Into LoggedUserScreen : Got user");
            init();
            this.add(signOffBtn);
            this.add(profileBtn);
            this.add(btn);
        }
    
        private void init() {
            signOffBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE ) {
                protected boolean navigationClick(int status, int time) {
                    return true;    // handle click event
                }
            };
            profileBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE ) {
                protected boolean navigationClick(int status, int time) {
                    return true;    // handle click event
                }
            };
            btn = new ButtonField("button", BitmapField.HIGHLIGHT_SELECT |  BitmapField.FOCUSABLE);
            signOffBtn.setChangeListener(this);
            profileBtn.setChangeListener(this);
            btn.setChangeListener(this);
        }
    
        public void fieldChanged(Field field, int context) {
            if (field == signOffBtn) {
                System.out.println("********* SIGN OFF CLICKED");
            } else if (field == profileBtn) {
                System.out.println("********* PROFILE CLICKED");
            } else if (field == btn) {
                System.out.println("********* button CLICKED");
                System.exit(0);
            }
        }
    
       public int getFieldAtLocation(int x, int y)    {
             XYRect rect = new XYRect();
             int index = getFieldCount() -1;
             while (index >= 0)        {
                getField(index).getExtent(rect);
                if (rect.contains(x, y))
                    break;
                 --index;
             }
             return index;
      }
    
      protected boolean touchEvent(TouchEvent event) {
    
          switch(event.getEvent()) {
              case TouchEvent.DOWN:
                return true;
              case TouchEvent.MOVE:
                return true;
              case TouchEvent.UP:
                return true;
              case TouchEvent.CLICK:
                int index = getFieldAtLocation(event.getX(1), event.getY(1));
                // Ignore click events outside any fields
                if (index == -1)
                    return true;
    
                Field field = getField(index);
                if (field == signOffBtn) {
                    System.out.println("Touched SignOff");
                } else if (field == profileBtn) {
                    System.out.println("Touched Profile");
                } else if (field == btn) {
                    System.out.println("Touched Button");
                }
                return true;
          }
          return false;
      }
    

    Thank you

    Ago I already watched this about such removeFocus or setFocus (false) or more. But yes, your something.setFocus gave me the idea to setFocus on the screen itself for the development is removed from the key also and not on any component capable of intercepting the event.

    So if I add fieldChangeNotify (0); in signOffBtn navigationclick, profileBtn & btn, then I totally don't need to implement the touchEvent?

        private void init() {
            signOffBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE | ButtonField.FIELD_LEFT) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
            profileBtn = new BitmapField (Bitmap.getBitmapResource("icon.png"),  BitmapField.FOCUSABLE | ButtonField.FIELD_RIGHT ) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
            imageBtn = new ImageButton(Bitmap.getBitmapResource("icon.png"), Bitmap.getBitmapResource("icon.png"));
            btn = new ButtonField("button", BitmapField.HIGHLIGHT_SELECT |  BitmapField.FOCUSABLE | ButtonField.FIELD_RIGHT) {
                protected boolean navigationClick(int status, int time) {
                    fieldChangeNotify(0);
                    return super.navigationClick(status, time);    // handle click event
                }
            };
    
            signOffBtn.setChangeListener(this);
            profileBtn.setChangeListener(this);
            imageBtn.setChangeListener(this);
            btn.setChangeListener(this);
        }
    

    touchEvent is totally deleted & navigationClick is implemented for each button.

    Thank you. I just want to confirm, with this, my componetns everything will work for touch & non touch screen properly. 9530 Simulator touch screen reacts (left mouse click), but not touch that is a click (muose right clisk) does not do anything. So I was wondering...

  • Problem with PopupScreen.updateLayout)

    Hello guys '

    I have a problem with PopupScreen. I'm doing the cursor on the PopupScreen. This popupScreen includes BitmapField with transparent image. And the main screen is BitmapField larger than the size of the screen. I want to move the cursor (PopupScreen) on the BitmapField.

    You see what I'm doing here. And I found the solution how to move PopupScreen since the last post. Now, I am facing the problem when the cursor (PopupScreen) on the left. In other words, when I move the slider to the left, it is not clear previous position. I don't know why.

    It works fine when moves right.

    And it is not clear the previous, when position moves to the left.

    So, you can see the code that I use.

    import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.*;import net.rim.device.api.system.Bitmap;import net.rim.device.api.system.KeyListener;
    
    public class CursorField extends UiApplication {
    
      private InfoPopupScreen progressPopup;    int x = 180;  int y = 120;  ManagedScreen managedScreen;  Bitmap _bitmap1;  Bitmap _bitmap2;  Bitmap _bitmap;   int [] fillTrans = new int[100];
    
      public CursorField() {
    
          _bitmap = Bitmap.getBitmapResource("cursor1.png");        _bitmap1 = Bitmap.getBitmapResource("cursor1.png");       _bitmap2 = Bitmap.getBitmapResource("cursor2.png");
    
          for(int i = 0; i < 100; i++) {         fillTrans[i] = 0xFFFFFF;      }
    
          managedScreen = new ManagedScreen();      pushScreen(managedScreen);    }
    
      private class InfoPopupScreen extends PopupScreen implements KeyListener {
    
          protected void applyTheme() {         //Nothing     }
    
          public boolean keyStatus(int keycode, int time) {         return false;     }
    
          public boolean keyRepeat(int keycode, int time) {         return false;     }
    
          public boolean keyUp(int keycode, int time) {         return false;     }
    
          public InfoPopupScreen(Manager manager){          super(manager);       }
    
          protected boolean navigationMovement(int dx, int dy, int status, int time) {
    
              return true;      }
    
          protected void paintBackground(Graphics graphics) {           graphics.setBackgroundColor(16777215);        }
    
          public void sublayout(int width, int height){         super.sublayout(width, height);           setPosition(x, y);        }
    
          public boolean keyDown(int keycode, int time) {
    
              char key =  net.rim.device.api.ui.KeypadUtil.getKeyChar(keycode, net.rim.device.api.ui.KeypadUtil.MODE_UI_CURRENT_LOCALE);            //To left         if(key == 79 || key == 111) {             x = x - 5;                progressPopup.updateLayout();         }                      if(key == 73 || key == 105) {             x = x + 10;               progressPopup.updateLayout();         }
    
              if(key == net.rim.device.api.system.Characters.ESCAPE) {              this.close();         }         return true;      }
    
          public boolean keyChar(char key, int status, int time) {          return false;     }
    
          public boolean trackwheelRoll(int amount, int status, int time) {         return false;     }
    
          public boolean trackwheelUnclick( int status, int time ) {            return false;     }
    
          public boolean trackwheelClick( int status, int time ) {          super.trackwheelClick(status, time);          return true;      } }
    
      private class ManagedScreen extends MainScreen {      private BitmapField _cursorField;
    
          public ManagedScreen() {
    
              _cursorField = new BitmapField(_bitmap) {             public void paint(Graphics graphics) {                    graphics.setBackgroundColor(16777215);                    super.paint(graphics);                }         };
    
              FlowFieldManager manager = new FlowFieldManager(FlowFieldManager.USE_ALL_HEIGHT | FlowFieldManager.USE_ALL_WIDTH) {               public void paint(Graphics graphics) {                    graphics.setBackgroundColor(16777215);                    super.paint(graphics);                }         };
    
              manager.add(_cursorField);            progressPopup = new InfoPopupScreen(manager);
    
              Bitmap pic = Bitmap.getBitmapResource("background.jpg");          BitmapField picField = new BitmapField(pic);          add(picField);
    
              ButtonField _closeButton = new ButtonField("Push screen", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);         _closeButton.setChangeListener(new FieldChangeListener() {                public void fieldChanged(Field field, int context) {                  pushScreen(progressPopup);                }         });
    
              add(_closeButton);        } }
    
      public static void main(String[] args) {      CursorField application = new CursorField();      application.enterEventDispatcher();   }}
    

    I hope you can solve my problem.

    TNX in advance"

    Ttry this...   In paintBackground(), call clear after you set the background color.

  • List of the HorizontalFieldManager with scrolling focus problem

    Hello

    I'm doing a vertical list of horizontalfieldmanager with an icon and two text fields, but I'm having a problem when scrolling it. I used a nullField to manage focus. When I scroll to the top everything works well, but when I Ahmed to the bottom of the item appears on the edge of the screen.

    I guess that I did not understand how to manage the focusChange metodh and the metodh of the painting.

    All advice will be appreciated.

    Thank you, Andrea.

    //
        // Main screen for the application
        //
        private class MyMainScreen extends MainScreen
        {
            public MyMainScreen()
            {
                super(Manager.USE_ALL_WIDTH);
    
                for (int i = 0; i<20; i++) this.getMainManager().add(new PanelRow("off", "first text line", "second text line"));
            }
    
            private class PanelRow extends HorizontalFieldManager implements FocusChangeListener
            {
                private NullField nullField;
                private BitmapField icon;
                private ColorLabelField label1;
                private ColorLabelField label2;
    
                public PanelRow(String iconString, String label1String, String label2String)
                {
                    super(Manager.USE_ALL_WIDTH);
    
                    // Add null field
                    nullField = new NullField(NullField.FOCUSABLE);
                    nullField.setFocusListener(this);
                    super.add(nullField);
    
                    // Add bitmap
                    Bitmap offIcon = Bitmap.getBitmapResource("offButton.png");
                    icon = new BitmapField(offIcon, BitmapField.NON_FOCUSABLE | BitmapField.FIELD_LEFT);
                    super.add(icon);
    
                    // Add first and second text lines
                    VerticalFieldManager labelsVerticalManager = new VerticalFieldManager();
                    label1 = new ColorLabelField(label1String, LabelField.NON_FOCUSABLE | LabelField.FIELD_LEFT);
                    label2 = new ColorLabelField(label2String, LabelField.NON_FOCUSABLE | LabelField.FIELD_LEFT);
                    labelsVerticalManager.add(label1);
                    labelsVerticalManager.add(label2);
                    super.add(labelsVerticalManager);
                }
    
                public void focusChanged(Field field, int eventType)
                {
                    invalidate();
                }
    
                protected boolean navigationClick(int status, int time)
                {
                    fieldChangeNotify(FieldChangeListener.PROGRAMMATIC);
    
                    return true;
                }
    
                protected void paint(Graphics g)
                {
                    int oldBackground = g.getBackgroundColor();
    
                    if (nullField.isFocus())
                    {
                        g.setBackgroundColor(Color.CADETBLUE);
    
                        label1.setFontColor(Color.WHITE);
                        label2.setFontColor(Color.WHITE);
                    }
                    else
                    {
                        g.setBackgroundColor(Color.WHITE);
    
                        label1.setFontColor(Color.SLATEGRAY);
                        label2.setFontColor(Color.BLACK);
                    }
    
                    g.clear();
    
                    g.setBackgroundColor(oldBackground);
    
                    super.paint(g);
                }
            }
    
            //
            // Define a new colored labelfield class
            //
            public class ColorLabelField extends LabelField
            {
                public ColorLabelField(Object text, long style)
                {
                    super(text, style);
                }
    
                private int mFontColor = -1;
    
                public void setFontColor(int fontColor)
                {
                    mFontColor = fontColor;
                }
    
                protected void paint(Graphics graphics)
                {
                    if (-1 != mFontColor) graphics.setColor(mFontColor);
    
                    super.paint(graphics);
                }
            }
        }
    

    Then try to create your NullField with getFocusRect override: like this:

    nullField = new NullField(NullField.FOCUSABLE) {
      public void getFocusRect(XYRect rect) {
        getManager.getExtent(rect);
        rect.setLocation(0, 0);
      }
    };
    

    Paint won't help you - you must tell the system to the entire span developed in order to scroll properly. If the above fails, analyze your focusChanged eventType and make sure that your Manager is fully visible on the screen on FOCUS_GAINED. To do this, you need to use getManager () .getVerticalScroll () / getManager () .setVerticalScroll () as well as of your Manager and getHeight() getTop().

  • Custom development/unfocus listfield problem

    Hi guys,.

    I followed and adapted a few custom listfield and produced the code below. The layout fields works exactly as I intended, however, I ran into problems to repaint when the focus changes as I scroll around the fields.

    Scroll down the first elements in the list, focus changes as it should. When the focus switches to the listfield, who is at the bottom of the screen (as in the last field that is displayed, not necessarily the last field in the list), the target element is displayed correctly, but the text of all the other fields is preparing to the color that the target text must be. The fuzzy text remains then the color targeted until I do scroll up even once, when he again changes in how it should be.

    Sorry if it is not very clear... I can post screenshots if it's not understandable!

    The code used is the following:

    ListField custom

    public class MatchListField extends ListField implements FieldChangeListener
    {
        private boolean hasFocus;
        private static final int LIGHT_TEXT  = 0xe6ce03;
        private static final int DARK_TEXT  = 0x054b93;
        private final int[] cols = new int[]{ 0xe6ce03, 0xf9f1af, 0xf9f1af, 0xe6ce03 };
    
        public MatchListField()
        {
            super();
            setRowHeight( 50 );
        }   
    
        public int moveFocus(int amount, int status, int time)
        {
            invalidate();
            return super.moveFocus(amount,status,time);
        }
    
        public boolean isFocusable()
        {
            return true;
        }
    
        //Invoked when this field receives the focus.
        protected void onFocus(int direction)
        {
            hasFocus = true;
            super.onFocus(direction);
            invalidate();
        }
    
        //Invoked when a field loses the focus.
        protected void onUnfocus()
        {
            hasFocus = false;
            super.onUnfocus();
        }
    
        protected void paint( Graphics graphics )
        {
            //Get the current clipping region as it will be the only part that requires repainting
            XYRect redrawRect = graphics.getClippingRect();
            if(redrawRect.y < 0)
            {
                throw new IllegalStateException("Clipping rectangle is wrong.");
            }
    
            //Determine the start location of the clipping region and end.
            int rowHeight = getRowHeight();
    
            int curSelected;
    
            //If the ListField has focus determine the selected row.
            if (hasFocus)
            {
                 curSelected = getSelectedIndex();
            }
            else
            {
                curSelected = -1;
            }
    
            int startLine = redrawRect.y / rowHeight;
            int endLine = ( redrawRect.y + redrawRect.height - 1 ) / rowHeight;
            endLine = Math.min( endLine, getSize() );
            int y = startLine * rowHeight;
    
            //Setup the data used for drawing.
            int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight};
            int[] xInds = new int[]{0, getPreferredWidth(), getPreferredWidth(), 0};     
    
            //Draw each row
            for( ; startLine <= endLine; startLine++ )
            {
                if (startLine != curSelected)
                {
                    //Draw the non selected rows.
                    graphics.setColor( LIGHT_TEXT );
                    super.paint( graphics );
                }
                else
                {
                    //Draw the selected rows.
                    graphics.drawShadedFilledPath( xInds, yInds, null, cols, null );
                    graphics.setColor( DARK_TEXT );
                    super.paint( graphics );
                }
                //Assign new values to the y axis moving one row down.
                y += rowHeight;
                yInds[0] = y;
                yInds[1] = yInds[0];
                yInds[2] = y + rowHeight;
                yInds[3] = yInds[2];
    
            }
        }
    }
    

    Custom ListFieldCallback:

    public class MatchListCallback implements ListFieldCallback {
    
        private Vector _listElements = new Vector();
    
        public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width)
        {
            MatchListField matchList = ( MatchListField ) listField;
            MatchListRowManager rowManager = ( MatchListRowManager ) _listElements.elementAt( index );
            rowManager.drawRow( graphics, 0, y, width, matchList.getRowHeight() );
        }
    
        //Returns the object at the specified index.
        public Object get(ListField list, int index)
        {
            return _listElements.elementAt(index);
        }
    
        //Returns the first occurence of the given String, bbeginning the search at index,
        //and testing for equality using the equals method.
        public int indexOfList(ListField list, String p, int s)
        {
            //return listElements.getSelectedIndex();
            return _listElements.indexOf(p, s);
        }
    
        //Returns the screen width so the list uses the entire screen width.
        public int getPreferredWidth(ListField list)
        {
            return Display.getWidth();
        }
    
        //Adds a String element at the specified index.
        public void insert( String homeTeam, String awayTeam, int homeGoals, int awayGoals )
        {
            MatchListRowManager row = new MatchListRowManager();
            Bitmap badge1 = Bitmap.getBitmapResource( homeTeam + ".png" );
            Bitmap badge2 = Bitmap.getBitmapResource( awayTeam + ".png" );
    
            row.add( new BitmapField( badge1 ) );
            row.add( new LabelField( homeTeam, LabelField.USE_ALL_WIDTH | LabelField.ELLIPSIS ));
            row.add( new LabelField( homeGoals + " - " + awayGoals, LabelField.USE_ALL_WIDTH | LabelField.ELLIPSIS | DrawStyle.HCENTER ));
            row.add( new LabelField( awayTeam, LabelField.USE_ALL_WIDTH | LabelField.ELLIPSIS | LabelField.RIGHT ));
            row.add( new BitmapField( badge2 ) );
    
            _listElements.addElement( row );
        }
    
        //Erases all contents.
        public void erase()
        {
            _listElements.removeAllElements();
        }
    
    }
    

    The manager used for individual fields of page layout that make up each listfield:

    public class MatchListRowManager extends Manager
    {
    
        public MatchListRowManager()
        {
            super( 0 );
        }
    
        public void drawRow( Graphics g, int x, int y, int width, int height )
        {
            layout( width, height );
            setPosition( x, y );
            g.pushRegion( getExtent() );
            subpaint( g );
    
            g.popContext();
        }
    
        protected void sublayout(int width, int height )
        {
            int preferredWidth = getPreferredWidth();
    
            //badge 1 field
            Field field = getField( 0 );
            layoutChild( field, 40, 40 );
            setPositionChild( field, 0, 5 );
    
            //home team field
            field = getField( 1 );
            layoutChild( field, ( preferredWidth - 160 ) / 2, 40 );
            setPositionChild( field, 42, 10 );
    
            //score field
            field = getField( 2 );
            layoutChild( field, 80, 40 );
            setPositionChild( field, 42 + ( preferredWidth - 164 ) / 2, 10 );
    
            //away team field
            field = getField( 3 );
            layoutChild( field, ( preferredWidth - 160 ) / 2, 40 );
            setPositionChild( field, 42 + 80 + ( preferredWidth - 164 ) / 2, 10 );
    
            //badge2 field
            field = getField( 4 );
            layoutChild( field, 42, 40 );
            setPositionChild( field, preferredWidth - 40, 5 );
    
            setExtent( preferredWidth, getPreferredHeight() );
        }
    
        public int getPreferredWidth()
        {
            return Display.getWidth();
        }
    
        public int getPreferredHeight()
        {
            return 50;
        }
    
    }
    

    I've tested this using the Bold 9700 Simulator with the API 5.0.

    I had a quick glance at some of the other posts about personalized listfields and have had no joy to find a solution so far. I would be grateful if someone could point me in the right direction here.

    I only have a few months of experience with Java programming, and very little experience developing for BlackBerry, so if there are no other pointers of how I could put this implementation, then that would be most appreciated.

    Thanks in advance!

    Suddenly appeared to me...

    Use this.getCallback () to get the instance of MatchListCallback and then replaced two calls super.paint (graph) with:

    callBack.drawListRow (this, graphics, startLine, xInds [0]);

    Problem solved.

    Thanks for the help, he led me on the right track!

  • Listener Button problem

    This is my first attempt at development for the BB storm, and I use JDE 4.7.

    I started with a Hello World application, I found and I modified to add a simple button that says RED. When you click on I tried the wallpaper turn RED and change the button to say BLUE, when that is clicked on it turns BLUE changes back to RED button again.

    I've implemented this, use a standard listener ButtonField (which I call bhandler in my code). The program type of works, with the odd effect only on the Simulator is that when I click the button, the background color changes but a little menu appears. Anyone else seen this problem of menu? I don't expect to see a menu and I have not coded anything to ask for a menu appear when I click on this button.

    Here is my source code. The Manager is in bold. All the answers that I see not why only a menu would be most appreciated... Thank you.

    /**
    * HelloWorld.java
    * Copyright (C) 2001-2003 research In Motion Limited. All rights reserved.
    */
    package com.rim.samples.helloworld;

    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 import. *;
    Net.rim.device.api.ui.decor import. *;

    /*
    * BlackBerry applications that provide a user interface
    * must extend UiApplication.
    */
    SerializableAttribute public class HelloWorld extends UiApplication
    {
    Public Shared Sub main (String [] args)
    {
    create a new instance of the application
    and launch the application on the event thread
    HelloWorld APP = new HelloWorld();
    theApp.enterEventDispatcher ();
    }
    public HelloWorld()
    {
    a new screen
    pushScreen (new HelloWorldScreen());
    }
    }

    create a new screen that covers the screen, which provides
    standard behavior by default for BlackBerry applications
    final HelloWorldScreen class extends screen
    {
    public HelloWorldScreen()
    {

    call the constructor of the screen
    Super();

    Add a title to the screen
    LabelField title = new LabelField ("HelloWorld example", LabelField.ELLIPSIS
    | LabelField.USE_ALL_WIDTH);
    setTitle (title);

    Add the text "Hello World!" to the screen
    Add (new RichTextField ("Hello World!"));
                    
    First define the button handler
                    FieldChangeListener bhandler = new FieldChangeListener()
    {
    ' Public Sub fieldChanged (field field, int context)
    {
    ButtonField buttonField = field (ButtonField);
    If (buttonField.getLabel () is 'RED')
    {
    Bottom newback = BackgroundFactory.createSolidBackground (Color.RED);
    getMainManager () .setBackground (newback);
    buttonField.setLabel ("BLUE");
    }
    on the other
    {
    Bottom newback = BackgroundFactory.createSolidBackground (Color.BLUE);
    getMainManager () .setBackground (newback);
    buttonField.setLabel ("RED");
    }
    }
    };

    Define the button itself use Manager above, this one called RED
    ButtonField buttonField = new ButtonField ("RED");     Create a RED button
    buttonField.setChangeListener (bhandler);               Implement the handler for button defined above
                     
    Add (buttonField);  Adds the button to the screen.

    }

    Override the onClose() method to display a dialog to the user
    with "Goodbye!" when the application is closed
    public boolean onClose()
    {
    Dialog.Alert ("Goodbye!");
    System.Exit (0);
    Returns true;
    }
    }

    Solved in Java development.

  • How to set the transparent color in the BitmapField?

    I display some Bitmap using BitmapField, to create a screen as our Office Windows means icons followed by the name of the application. When I first time poster main screen it seeks it is transparent, but when I move the focus from one Bitmap to another, bitmaps are not rest transparent. I want transparent bitmaps after moving the slider too. How can I do? Does anyone have an idea?

    Thanks in advance...

    No problem, I was not angry at all.  I wanted to just make sure I understood your problem before giving an answer.

Maybe you are looking for