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
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified
Accepted Solution

issue with using getFieldAtLocation()

Within a manager, I have a BitmapField located at 96, 178.  Within that BitmapField's class, I call the below method:

 

 

private boolean isBlockAt( int loc_x, int loc_y ) {
boolean isBlock = true; // Assume block present

Dialog.inform( "isBlockAt()" );

Dialog.inform( "x= " + x + " loc_x= " + loc_x);
Dialog.inform( "y= " + y + " loc_y=" + loc_y);

Dialog.inform( "width=" + this.blockwidth );
Dialog.inform( "height=" + this.blockheight );

Dialog.inform( "index= "+ getManager( ).getFieldAtLocation( loc_x, loc_y ));

if( this.getManager( ).getFieldAtLocation( loc_x, loc_y ) == -1 )
isBlock = false;

return isBlock;
}

 

 And the output is:

 

isBlockAt()
x= 96 y=128
y= 178 loc_y= 178
width= 32
height= 32
index= 10

which is expected, except the index should be -1 as there is no field at the location 128, 178!

 

Basically, the BitmapField is 32 pixels wide, and located at x=96, therefore, the 32x32 block to the immediate right would be at 128, 178, and as there is no field there in the manager, the getFieldAtLocation() should return a -1, but instead it is returning the index (10) of the BitmapField from which we are calling the method (located at 96, 178).

 

What am I doing wrong (or is this a bug)?

 

Developer
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Confirmed - method does not perform as described in API

[ Edited ]

To illustrate, I have a "Game" screen with a custom delegate manager "GameScreenManager" that is the width and height of the display screen like so:

 

example of problem

 

That manager has each of the 10 blocks added to it (indexes 2-11), placing them on the screen as you see above.

 

The block at the lower left (with the yellow focus) is at manager (& screen) coordinates 96, 178, and is 32x32 pixels.  When I then ask getFieldAtLocation( 128, 178 ) to test if there is a field (ie a BitmapField or block) just to the right of the field in focus, rather than get a "-1" as documented in the API showing there is no field at that location within the manager, I get index 10 (which is equal to the block calling the method and in focus).

 

Further, when I ask getFieldAtLocation( 129, 179 ) (eg 1 pixel more right and down) it returns index 7, which is the block up and to the right of the focused block, and NOT "-1" as documented.

 

How does this funciton really work, since clearly it is not working as documented?

 

Patrick

 

Message Edited by Berrysoft on 01-15-2009 07:50 PM
Message Edited by Berrysoft on 01-15-2009 07:51 PM
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Confirmed - method does not perform as described in API

are you sure that you are calling the method from within the correct manager? because the method works only within the local extent.
as the method you are using seems not to be working (aforementioned problem nonwithstanding) i would suggest that you try to build your own coordinate-table.
use Field.getExtent() to retrieve the XYRect objects of each field you add (you can also see if they are relative to the screen or another manager) and check the cursor position against your own records.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: Confirmed - method does not perform as described in API

It is the correct manager (in fact, the only manager).

 

My guess is that because the custom manager places the fields at private x,y coordinates, that I'll have to override the method with my own custom behavior as the default behavior will not work.  Seems odd because one would think that the algorithm they used would work the same.

 

Maybe RIM will have a comment.

 

Highlighted
Developer
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: Confirmed - method does not perform as described in API

Ok, while I still think the default super class implementation should be able to handle this, I fixed this problem by simply overriding the method like so:

 

 

public int getFieldAtLocation(int x, int y) { int fieldIndex = -1; for( int i=2; i<this.getFieldCount( ); ++i ) { if( getField( i ).getExtent( ).contains( x, y ) ) { fieldIndex = i; break; } } return fieldIndex; }

 

 Note that I do nothing special, only what I believe the default method does exactly.  Weird, but at least this works.

 

 

Regular Contributor
Posts: 70
Registered: ‎06-15-2011
My Device: Bold 9900
My Carrier: Bell Canada

Re: Confirmed - method does not perform as described in API

Thank you Berrysoft! I hit the same thing and your solution works!  Well, works for 90% of my fields but nevertheless I'm much closer than I was before. 


It's so frustrating to keep finding "mystery" issues like this.