Why navigationMovement for FOCUSABLE LabeField is bypassed in Blackberry?

324 Views Asked by At

I have a LabelField whith style FOCUSABLE and many focusable Fields after it, and I overrided the navigationMovement method of the LabelField.

The problem is that: the code never enters in the new implementation of navigationMovement but the focus is normally moved from LabelField to next Field without passing by navigationMovement implementation !

PS, I also tested using debugger to ensure that it never gets into its implementation.

Why is this happening and how to catch navigationMovement event for FOCUSABLE LabelField ?

CODE:
Here's the class:

public abstract class FocusableLabelField extends LabelField {
public boolean isDownUnfocused = false;

public FocusableLabelField(String text) {
    super(text, FOCUSABLE);
}

protected void drawFocus(Graphics graphics, boolean on) {
        // DO NOTHING, FOCUS IS HANDLED IN PAINT
}

protected void paint(Graphics graphics) {
    if(isDownUnfocused == true)
        graphics.setColor(0xFFFFFF);
    else {
        if(isFocus())
            graphics.setColor(0xFFFFFF);
        else {
            graphics.setColor(0x777777);
        }
    }
    super.paint(graphics);
}

protected void onFocus(int direction) {
    isDownUnfocused = false;
    onFocusing();
    super.onFocus(direction);
}

public abstract void onFocusing();

public void redraw() {
    invalidate();
}

protected boolean navigationMovement(int dx, int dy, int status, int time) {
    //TODO CHECK WHY IT'S NOT ENTERING HERE !
    if(dy>0)
        isDownUnfocused = true;
    invalidate(); // IF REMOVED NO EFFECT WILL BE APPLIED
    return super.navigationMovement(dx, dy, status, time);
}
}

And here's how I use it in a screen:

FocusableLabelField field = new FocusableLabelField("title") {
    public void onFocusing() {
        // some logic in the screen is done here ...
    }
} ;
1

There are 1 best solutions below

3
Nate On

I just ran your exact code in an app on a 5.0 8900 simulator, and a 7.1 9900 simulator, and I did see your navigationMovement() called. However, I'm not 100% sure it's being called when you want it to.

I don't know exactly what you're trying to do, but looking at the code above, it looks like you're just trying to add custom drawing for the focus colors. Is that right?

If so, I don't know exactly why you even need to override navigationMovement(). Why not use code like this:

public abstract class FocusableLabelField extends LabelField {

   public FocusableLabelField(String text) {
      super(text, FOCUSABLE);
   }

   protected void drawFocus(Graphics graphics, boolean on) {
      // DO NOTHING, FOCUS IS HANDLED IN PAINT
   }

   protected void paint(Graphics graphics) {  
      int oldColor = graphics.getColor();
      if(isFocus())
         graphics.setColor(0xFFFFFF);
      else {
         graphics.setColor(0x777777);
      }
      super.paint(graphics);
      graphics.setColor(oldColor);
   }

   protected void onFocus(int direction) {
      onFocusing();
      invalidate();
      super.onFocus(direction);
   }

   protected void onUnfocus() {
      invalidate();
      super.onUnfocus();
   }

   public abstract void onFocusing();
}