0

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 ...
    }
} ;
Ashraf Bashir
  • 9,686
  • 15
  • 57
  • 82
  • 1
    Can you post your LabelField subclass? At least the `navigationMovement()` method you're using? – Nate Jul 10 '12 at 21:16
  • Post is now updated with code. – Ashraf Bashir Jul 11 '12 at 09:28
  • This isn't your actual code, it it? That code doesn't even compile. You declare `isDownUnfocused` without even giving it a type (e.g. `boolean`), and then implement two methods with the same signature ... `protected void paint(Graphics);`. That's not legal Java. Please post the code that you're actually using, or it's very hard to help. Thanks. – Nate Jul 11 '12 at 22:44
  • Thanks Nate, I just removed some parameters that was sent to constructor and used in the object later. Post is now updated with the most recent code. – Ashraf Bashir Jul 12 '12 at 09:05

1 Answers1

0

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();
}
Nate
  • 31,017
  • 13
  • 83
  • 207
  • Because I want to keep the labels white colored if the focus is moved down. Simply I have horizontalFieldManager, I want to imitate paneview behavior using OS5, so the custom labels are the headers of paneview and if the navigation moves down, this means that the items in the screen under this HorizontalFieldManager are related to the label which I came from, that's why I want the label to stay white colored even if it loses focus if (and only if) navigation movement is to down – Ashraf Bashir Jul 12 '12 at 15:34
  • I use isDownUnfocused to detect which item in the HFM was the active paneview header and should be painted in white vene if it's not focused at the moment – Ashraf Bashir Jul 12 '12 at 15:36
  • @AshrafBashir, ok, thanks for the clarification. That would be good information to put in the question itself (in case others see that this is still not solved, and look at your question without reading all these comments). I think I understand what you're doing, and I would recommend doing it another way than via `navigationMovement()`. However, I would need to see some code that uses this class. For example, the manager that creates this `FocusableLabelField` and adds the fields below it. Can you show that? And do you have more than one "pane", or is there only one? – Nate Jul 15 '12 at 00:33