10-27-2011 10:43 AM
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.
10-27-2011 12:06 PM
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.
10-27-2011 02:25 PM
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.
10-27-2011 03:54 PM
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...
10-27-2011 04:25 PM
You can perform your reconciliation in the same invokeLater I mentioned previously.