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
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
Accepted Solution

TableLayoutManager focusing problem

[ Edited ]

I have 3  TableLayoutManagers on screen with a LabelField between them. All  of them are added in a VerticalFieldManager. TableLayoutManager  consists of multiple bitmaps in rows and columns. When i scroll vertically downwords in last row of 1st TableLayoutManager, focus is gained by right side field of a current field.  Insteaed of that i want the focus in  TableLayoutManager  should be released. LabelField is nonfocusable. So the focus should be on 1st field of 2nd TableLayoutManager. 

Same thing with 1st row of TableLayoutManager. When i scroll veritically upwords, focus is gained by field which is on the left side of the current field. I want the focus to be released from the TableLayoutManager. 

What changes should be done in navigaionMovement() ? Please help

 protected boolean navigationMovement(int dx, int dy, int status, int time)
    {
    	int focusIndex = getFieldWithFocusIndex();
    	int dirY = (dy > 0) ? 1 : -1;
    	int absY = Math.abs(dy);

    	for (int y = 0; y < absY; y++)
    	{
    		focusIndex += _columns * dirY;
    		if (focusIndex < 0 || focusIndex >= getFieldCount())
    		{
    			this.invalidate(); 
    			return false;
    		}
    		else
    		{
    			Field f = getField(focusIndex);
    			if (f.isFocusable())
    			{
    				f.setFocus();
    			}
    			else
    				y--; 
    		}
    	}

    	int dirX = (dx > 0) ? 1 : -1;
    	int absX = Math.abs(dx);

    	for (int x = 0; x < absX; x++)
    	{
    		focusIndex += dirX;
    		if (focusIndex < 0 || focusIndex >= getFieldCount())
    		{
    			this.invalidate(); 
    			return false;
    		}
    		else
    		{
    			Field f = getField(focusIndex);
    			if (f.isFocusable())
    			{
    				f.setFocus();
    			}
    			else
    				x--;     		
    		}
    	}

    	this.invalidate();
    	return true;
    }

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: TableLayoutManager focussing problem

"When i scroll vertically downwords in last row of 1st TableLayoutManager, focus is gained by right side field of a current field.  Insteaed of that i want the focus in  TableLayoutManager  should be released."

 

In TableLayoutManager, this requirement is suppsed to be addressed by this code:

 

"

      focusIndex += _columns * dirY;
    if (focusIndex < 0 || focusIndex >= getFieldCount())
    {
    this.invalidate();
    return false;
    }

"

 

I thought this code worked OK,  So can you debug this to make sure that in fact it actually is?  In otherwords, you should be returning false so that the navigationMovement is processed elsewhere. 

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: TableLayoutManager focussing problem

[ Edited ]

I have tried something which is somewhat working. But i am unable to move focus to previous manager from 1st row of tablelayoutmanager

 

protected boolean navigationMovement(int dx, int dy, int status, int time)
    {
    	int focusIndex = getFieldWithFocusIndex();
    	int dirY = (dy > 0) ? 1 : -1;
    	int absY = Math.abs(dy);

    	for (int y = 0; y < absY; y++)
      	{
    		focusIndex += _columns * dirY;
    		int currentRow = focusIndex/_columns;
    		if(dy == 1)
    		{
    			if(currentRow == _rows)
        		{
    				moveFocusToNextMnager(getManager());
        			return false;
        		}
    		}
    		else if(dy == -1)
    		{
    			if(currentRow == 1)
    			{
    				moveFocusToNextMnager(getManager());
    				return false;
    			}
    		}
    		
    		if (focusIndex < 0 || focusIndex >= getFieldCount())
    		{
    			this.invalidate();
    			return false;
    		}
    		else
    		{
    			Field f = getField(focusIndex);
    			if (f.isFocusable())
    			{
    				f.setFocus();
    			}
    			else
    				y--;
    		}
    	}

    	int dirX = (dx > 0) ? 1 : -1;
    	int absX = Math.abs(dx);

    	for (int x = 0; x < absX; x++)
    	{
    		focusIndex += dirX;
    		if (focusIndex < 0 || focusIndex >= getFieldCount())
    		{
    			this.invalidate(); 
    			return false;
    		}
    		else
    		{
    			Field f = getField(focusIndex);
    			if (f.isFocusable())
    			{
    				f.setFocus();
    			}
    			else
    				x--; 
    		}
    	}
    	this.invalidate(); 
    	return true;
    }

public static void moveFocusToNextMnager(Manager manager)
    {
        if (manager == null) {
            return;
        }
        
        int focusIndex = manager.getFieldWithFocusIndex() + 1;
        
        Field found = null;
        
        for (int i = focusIndex; i < manager.getFieldCount(); i++)
        {
            Field field = manager.getField(i);
            
            if (field.isFocusable())
            {
                found = field;
                
                break;
            }
        }
        
        if (found == null)
        {
            /* 
             * Not found recursively try parent
             */
            moveFocusToNextMnager(manager.getManager());
        }
        else {
            found.setFocus();
        }
    }

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: TableLayoutManager focusing problem

As noted, you should not have to do this, the Manager should do this for you.  Have you overridden navigationMovement in any other Field of Manager or the Screen that this is added to?

 

The code I highlighted should return false because the downwards scroll will take it off the end of the Manager.  The false should be handled elsewhere.  If that is not what you are see, then I will look at the problem.

 

You can simplify this problem by just having one TablelayoutManager and a focusable Field before and after it.  Then when scrolling down from the left hand column of the bottom row, focus should go to the focusable Field below that.  Can you try this?  So if you are still struggling with your own code, then create a simple test screen like this and see if it works.  If it fails, then paste the code in here, (with a link to the TableLayoutManager code so you don't have to paste all that in too).  That will give us something to play with.

 

OK?

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: TableLayoutManager focusing problem

[ Edited ]

I tried out as u said : "Added TableLayoutManager between to focusable LabelFields on a simply blanck screen." But i am facing same thing over here also. Focus remains in a last row when i scroll downwords from last row. Its gained  by field on the right side of a current field.

 

if (focusIndex < 0 || focusIndex >= getFieldCount())
{
this.invalidate();
return false;
}
This was not working for me to remove focus from current manager from last row so i was trying to check the last row of a manager.

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: TableLayoutManager focusing problem

You seem to have missed this comment:

"So if you are still struggling with your own code, then create a simple test screen .. and see if it works.  If it fails, then paste the code in here, (with a link to the TableLayoutManager code so you don't have to paste all that in too).  That will give us something to play with."

 

Can you please post up sample code of a single MainScreen screen, simple TableLayoutManager added to it, and a focusable Field above and below.  We can then try this out.  Make sure this code does NOT use any code that means we can't just cut and  paste the code into our own test project.  If possible attach the java source rather than pasting it. 

 

There are many variables potentially involved here and we don't have time to review all your code.  So you have to create something that is like your code, that demonstrates the problem, but external to your code so that we can investigate it. 

 

OK?

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: TableLayoutManager focusing problem

Frankly, this is the first time I've looked closely at TableLayoutManager. Surprisingly, navigationMovement implementation there looks overcomplicated and done with "brute force" approach. Overriding nextFocus would be much cleaner, though TableLayoutManager was created when nextFocus was much more limited (by the time it became better GridFieldManager was introduced - I know you had problems with it, but back then it was probably deemed to make TableLayoutManager obsolete).

 

In theory, the code Peter and you are talking about (with return false;) should properly take care of the problem. However, I'm not sure what sequence of moveFocus, nextFocus etc. calls happens internally in BlackBerry framework and how it is changed between OS versions.

 

Anyway, "return false;" from navigationMovement asks the parent manager to handle the event on its own. What kind of Manager are you using there?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: TableLayoutManager focusing problem

I am adding TableLayoutManager to VerticalFieldManager and adding it to screen. 

vfm = new VerticalFieldManager(Manager.FIELD_HCENTER|Manager.VERTICAL_SCROLL|Manager.HORIZONTAL_SCROLL);

 

 

 

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: TableLayoutManager focusing problem

[ Edited ]

@ Peter

Please Find attatchments of test screen and custom Manager as per u said.

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: TableLayoutManager focusing problem


JoVinz wrote:

I am adding TableLayoutManager to VerticalFieldManager and adding it to screen. 

 

vfm = new VerticalFieldManager(Manager.FIELD_HCENTER|Manager.VERTICAL_SCROLL|Manager.HORIZONTAL_SCROLL);

 

 

 


Nothing special, though I wonder how TableLayoutManager interacts with a Manager with HORIZONTAL_SCROLL. Need to review the code more to tell you anything definitive - not sure when I'll have a time, though.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!