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
Developer
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified
Accepted Solution

TrackBall/TrackPad Navigation Between Multiple GridFieldManagers

I am not bad with ui's for the Storm.  However, I am doing my first port to TrackBall/TrackPad BlackBerry's, and I am finding it slightly more challenging than I thought.

 

They way my screens layout, it appears that a custom manager holding multiple GridFieldMangers is the easiest way to go to achieve my goals.  However, I ran into a problem.  When I use a TrackBall to go from one GridFieldManager to another GridFieldManager, the proper field it not getting focus.

 

For example; If the field on the very lower right cell of the top GridFieldManager has focus and I move focus to the bottom GridFieldManager, the top LEFT cell gets focus.  I want the top RIGHT cell to get focus so the movement is fluid.

 

The only thought I have so far is:

  1. When a  cell in the bottom row of the of the top GridField loses focus, I set a variable to identify the button that is losing focus.
  2. I would have to set this variable to null if the navigation movement doesn't go the the bottom GridFieldManager.
  3. When the top left cell of the bottom GridFieldManager gets focus, I do a check to see if a cell from the bottom row of the top GridField just lost focus.  If it did I access the variable that identifies the button that lost focus and use that information to give focus to the appropriate button for fluid trackBall navigation movement.

This would also have to be reversed for going from the bottom GridFieldManager to the top GridFieldManager.

 

This seems terribly complicated for something that I think a lot of developers would run into. So my question is, Am I making this more complicated than it needs to be or am I on the right path?

 

Any thoughts are appreciated.

 

Thanks!

 

 

Say, if anyone can think of other keywords people might use for this search, please tag them.

BlackBerry Development Advisor
MSohm
Posts: 14,864
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: TrackBall/TrackPad Navigation Between Multiple GridFieldManagers

You are on the right path here. 

 

The focus order for trackpad/trackball devices moves in the order you describe.  When focus moves to a field in another manager, it is normal behaviour for the field in the top left area of the manager to receive focus.  This applies for all managers, not just GridFieldManager.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified

Re: TrackBall/TrackPad Navigation Between Multiple GridFieldManagers

Hi Mark;

 

I know your busy, thanks for taking the time to answer a simple beginners question.

 

I am off to code some more.

Developer
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified

Re: TrackBall/TrackPad Navigation Between Multiple GridFieldManagers

Here is my code for a custom button field with a getField() command for the switch statement.  You will have to modify the code slightly for a standard button field.

 

 


private boolean IsTouchScreen =  Touchscreen.isSupported();
private CustomButtonField CurrentFocusButtonField = null;

 

public void focusChanged(Field field, int eventtype) {

        if (!IsTouchScreen){

            //if statement for Top GridField
            if (field == <bottom left button of top GridField> && eventtype == FOCUS_GAINED && CurrentFocusButtonField != null){
                eventbutton = ((CustomButtonField)CurrentFocusButtonField).getButton();
                CurrentFocusButtonField = null;
                switch (eventbutton){
                    case CustomButtonField.BUTTON1:
                        <button to get focus if navigating from BUTTON1>.setFocus();
                        break;
                    case CustomButtonField.BUTTON2:
                        <button to get focus if navigating from BUTTON2>.setFocus();
                        break;
                }
            }

 

            //if statement for Top GridField
            else if (field == <top left button of bottom GridField> && eventtype == FOCUS_GAINED && CurrentFocusButtonField != null){
                eventbutton = ((CustomButtonField)CurrentFocusButtonField).getButton();
                CurrentFocusButtonField = null;
                switch (eventbutton){
                    case CustomButtonField.LOWERBUTTON1:
                        <button to get focus if navigating from LOWERBUTTON1>.setFocus();
                        break;
                    case CustomButtonField.LOWERBUTTON2:
                        <button to get focus if navigating from LOWERBUTTON2>.setFocus();
                        LineWeightButton.setFocus();
                        break;
                }
            }
            else if (field instanceof CustomButtonField && eventtype == FOCUS_LOST){
                CurrentFocusButtonField = (CustomButtonField)field;
            }
        }
    }

Developer
JamesColeman
Posts: 266
Registered: ‎04-24-2009
My Device: Not Specified

Re: TrackBall/TrackPad Navigation Between Multiple GridFieldManagers

My apologies, My second comment statement identified the wrong GridField.

 

Changed             //if statement for Top GridField

to                            //if statement for Bottom GridField

 

private boolean IsTouchScreen =  Touchscreen.isSupported();
private CustomButtonField CurrentFocusButtonField = null;

 

public void focusChanged(Field field, int eventtype) {

        if (!IsTouchScreen){

            //if statement for Top GridField
            if (field == <bottom left button of top GridField> && eventtype == FOCUS_GAINED && CurrentFocusButtonField != null){
                eventbutton = ((CustomButtonField)CurrentFocusButtonField).getButton();
                CurrentFocusButtonField = null;
                switch (eventbutton){
                    case CustomButtonField.BUTTON1:
                        <button to get focus if navigating from BUTTON1>.setFocus();
                        break;
                    case CustomButtonField.BUTTON2:
                        <button to get focus if navigating from BUTTON2>.setFocus();
                        break;
                }
            }

 

            //if statement for Bottom GridField
            else if (field == <top left button of bottom GridField> && eventtype == FOCUS_GAINED && CurrentFocusButtonField != null){
                eventbutton = ((CustomButtonField)CurrentFocusButtonField).getButton();
                CurrentFocusButtonField = null;
                switch (eventbutton){
                    case CustomButtonField.LOWERBUTTON1:
                        <button to get focus if navigating from LOWERBUTTON1>.setFocus();
                        break;
                    case CustomButtonField.LOWERBUTTON2:
                        <button to get focus if navigating from LOWERBUTTON2>.setFocus();
                        LineWeightButton.setFocus();
                        break;
                }
            }
            else if (field instanceof CustomButtonField && eventtype == FOCUS_LOST){
                CurrentFocusButtonField = (CustomButtonField)field;
            }
        }
    }