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
precisionpete
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified

Detecting if the screen has been rotated?

Is there a way to tell if the screen has been rotated? Ideally returning the direction?

 

I have an app that works with the accelerometer and allows the screen to rotate on the devices that allow it (e.g. 9800). I fthe screen rotates, I need to reorient the accelerometer values to work in that orientation.

 

However, I am having trouble on devices that do not allow rotation (e.g. 9900). I do not want to force no rotation. Rotation is good. I just need to detect if it has been rotated or not.

 

Checking the X and Y dimensions does not work as some devices are portrait and some landscape.

 

Ideas?

 

Thanks

 

 

Developer
precisionpete
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified

Re: Detecting if the screen has been rotated?

I see now there is a way to do it in OS6. But I need for OS4.7+.

 

Assumeing OS6 can do it, I hope the underlying info is there and just needs to be summarized? I hope.

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Detecting if the screen has been rotated?

[ Edited ]

I use Display.getHeight() and Display.getWidth().  Seems to work for me....

 

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

Re: Detecting if the screen has been rotated?

When the phone rotates, your screen's sublayout is called with the new width and height. Unfortunately, RIM chose to implement this UI re-layout in a strange order: first re-layout everything (calling layout/sublayout of all screens), then update values in the Display class.

Therefore, you will not be able to get accurate info from Display.getWidth, Display.getHeight and Display.getOrientation  from within your sublayout. You can, however, schedule such a check with the ubiquitous invokeLater - it will run after all pending UI operations (including Display values update) have completed.

----------------------------------------------------------
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
precisionpete
Posts: 264
Registered: ‎10-05-2010
My Device: Not Specified

Re: Detecting if the screen has been rotated?

Getting the dimensions and orientation are not a problem. My screen paint draws everything every time.

 

The problem is reconciling the current orientation versus the accelerometer orientation. 

 

If I lock the orientation in Display.DIRECTION_NORTH everything works on all devices.

 

However, if I allow Display.DIRECTION_NORTH|Display.DIRECTION_EAST,  and on the Torch the screen rotates to Landscape... I need detect that so that I can swap the X and Y accelerometer values to compensate for the rotation. 

 

The closest solution I can find is to assume that all devices that allow Portrait must allow rotation. Even then the user needs to satisfy the condition of DIRECTION_NORTH and ORIENTATION_PORTRAIT before I can detect that. It's really messy.

 

There must be a better way other than locking the device to DIRECTION_NORTH...

 


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

Re: Detecting if the screen has been rotated?

You can perform your reconciliation in the same invokeLater I mentioned previously.

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