Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Chostislas
Posts: 23
Registered: ‎07-14-2011
My Device: 9300
Accepted Solution

Help Focus on managers

Hello guys!, I need your help cause I cannot find any solution focusing managers.

 

I have One manager(parent manager) which contains custom managers(child managers), and these have more fields like labels and edit fields. Right now, I want to focus ONLY the (child managers) as whole manager, im not interested on focus the fields inside of them(knowing that there are edit fields). All I could do is to focus the manager using setFocusListener but do not why the draw focus is not working.

 

 

Parent manager implements FocusChangeListner()

  -Childmanager.setChangeListener(parentManager)

    --LabelField

    --EditField

 

  -Chidlmanager.setChangeListener(parentManager)

--EditField

    --LabelField

 

 

 

Thanks a lot!

 

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help Focus on managers

You can't.  Managers do not accept focus.

 

But you can fake it.  Add a focusable NullField to the Manager, make everything else non focusable.  Add a Focus Change Listener to the NullField, and have this process, invalidate the Manager.  Then change the Manager so that before it paints itself, it checks to see if the NullField is inFocus, and if it is, it paints itself in a focused way - typically with a Blue background.

 

This question has been asked before to, similar answers have been given.  Search and you should find them.

 

Good luck. 

Please use plain text.
Contributor
Chostislas
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Thanks pete, I have read the solution of these forum ( http://supportforums.blackberry.com/t5/Java-Development/Cannot-Focus-on-a-Manager/m-p/538077/highlig...). I have tested both solutions, the method 1 works but it draws the focus at screen positions(0,0) Do you know how to get the positions of my manager/field?? the second one doesnt work dunno why,

 

thanks a lot

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,604
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help Focus on managers

Yes I think there are problems with both the supplied methods.

 

Method 1 assumes that the Manager's 'graphic' area and the Screen 'graphic' area are the same, which typically they will not be. 

 

The second one assumes that NullField has access to the graphic area of the Manager, again this is not valid.  Really the NullField can only paint on its own space, and it doesn't have any.

 

So ignore both these options, they are not valid.

 

I've also had a look and I can't actually find a Thread that discusses this and has a solution that will suit you.  So have a go at what I suggested above and we will help get that code working. 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Help Focus on managers

[ Edited ]

Just to elaborate slightly on what Peter has said: since you want access to your Manager's viewing area, you'll need to define some of the actions on the Manager's level.

 

One way to achieve this is to define a FocusChangeListener inside the Manager and attach that listener to the NullField. Inside that listener, simply invalidate the manager on focus changes. Override the Manager's paintBackground to check your NullField's isFocus(), pick a color depending on that and paint it (graphics.setBackgroundColor followed by graphics.clear is one of the possibilities - just don't forget to reset that background color to its previous value afterwards).

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Contributor
Chostislas
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Still without working... here is a similar code how i am trying to focus it. Consider that my testManager is attached to a screen. And i want to focus just the MyManager class.

 

Ty

 

 

public class MyManager extends HorizontalFieldManager implements FocusChangeListener{

    public MyManager(){
        NullField focus = new NullField(FOCUSABLE);
        focus.setFocusListener(this);

        VerticalFieldManager vfm = new VerticalFieldManager();
        vfm.add(new LabelField("Hello World2"));
        vfm.add(new LabelField("Hello World3"));

        this.add(new LabelField("Hello World"));
        this.add(vfm);
    }

    public void focusChanged(Field field,int eventType){    
        this.getManager().invalidate();
    }	

    protected void paintBackground(Graphics arg0) {
	arg0.setBackgroundColor(Color.LIGHTBLUE);
	super.paintBackground(arg0);
    }
}

public class TestManager extends VerticalFieldManager(){
    public TestManager(){
        this.add(new MyManager());
        this.add(new MyManager());
        this.add(new MyManager());
    }
}

 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Help Focus on managers

You forgot one line: add(focus); (or this.add(focus); as you seem to like).

 

In addition, super.paintBackground will probably achieve nothing. You can override your paintBackground like this:

protected void paintBackground(Graphics g) {
  int prevBg = g.getBackgroundColor();
  if (focus.isFocus()) {
    g.setBackgroundColor(Color.LIGHTBLUE);
  } else {
    g.setBackgroundColor(Color.WHITE);
  }
  g.clear();
  g.setBackgroundColor(prevBg);
}

 Should work much better.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Contributor
Chostislas
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Now there is a nother problem, I didnt start new forum cause the problem is relationed... The focus works when I navigate through the managers but when I click on them nothing happens even the managers didnt focus.

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Help Focus on managers

It is a different problem, but yes, it often needs to be solved at the same time. I was waiting for this question to be asked. :smileywink:

You need to override touchEvent on your Manager's level. The exact code is not so obvious, so I'll provide you with it:

protected boolean touchEvent(TouchEvent message) {
  int x = message.getX(1);
  int y = message.getY(1);
  if (message.getEvent() == TouchEvent.DOWN) {
    if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
      focus.setFocus();
    }
  }
  return super.touchEvent(message);
}

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Contributor
Chostislas
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

I use the default eclipse emulator(9550) and it is touchable, the method you gave me seems that works only in touchable phones... should I override the navigationClick or the trackwheelClick method with similar actions at Manager level to do this work on untouchable phones?

Please use plain text.