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
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Orientation vs. direction problem

I'd like to my app to give the user the ability to lock the display in the current direction. As far as I can tell, there is no API to find the current direction; the closest one can get is the orientation. So if the display reports that the display is in ORIENTATION_LANDSCAPE, I don't know whether to tell the UiEngineInstance to allow DIRECTION_EAST or DIRECTION_WEST. (Not to mention that future devices might conceivably have DIRECTION_NORTH be ORIENTATION_LANDSCAPE.)

 

Is there a way to retrieve the current display direction, or some other way to lock the current display direction?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
Developer
CMY
Posts: 1,122
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Orientation vs. direction problem

If you do not like the orientation values, you can use the raw values to determine which part of the phone is facing up.
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Orientation vs. direction problem

What raw values? How would I use them?



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Orientation vs. direction problem

[ Edited ]

I've implemented a way to get the display direction, but I'd really like something better. This seems like an awful lot of work and it doesn't cover all cases reliably.

 

public static int getDisplayDirection() { Channel channel = AccelerometerSensor.openOrientationDataChannel(getApplication()); int orient = channel.getOrientation(); channel.close(); switch (orient) { case AccelerometerSensor.ORIENTATION_BOTTOM_UP: case AccelerometerSensor.ORIENTATION_TOP_UP: return Display.DIRECTION_NORTH; case AccelerometerSensor.ORIENTATION_LEFT_UP: return Display.DIRECTION_WEST; case AccelerometerSensor.ORIENTATION_RIGHT_UP: return Display.DIRECTION_EAST; default: // horizontal or unknown

// Assumes portrait orientation is DIRECTION_NORTH. switch (Display.getOrientation()) { case Display.ORIENTATION_LANDSCAPE: // THIS CASE IS A HACK, BUT NOTHING BETTER AVAILABLE return Display.DIRECTION_EAST; // might be Display.DIRECTION_WEST default: // for ORIENTATION_PORTRAIT and ORIENTATION_SQUARE // and when all else fails return Display.DIRECTION_NORTH; } } } }

 

 

Message Edited by Ted_Hopp on 09-09-2009 05:22 PM



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.