04-11-2010 10:17 AM
I'm fairly new to blackberry programming (but not Illiterate).
I have an app with lots of screens. Some of them need to have a fixed orientation depending on a bitmap's size chosen on the first screen. The same screens might even have different orientations on the lifetime of the app, because I can pop back to the first screen and choose another bitmap.
I'm using the 5.0 environment and the Storm (9550) emulator. The provided example (thanks keean) does work for the first screen.
Unfortunately, subsequent screens don't seem to regard this setting. I have created a getScreen method on my main class that controls all the screen pushing and popping. The following code tries to control the allowed directions for 4 screens that need it.:
if ((screenIndex == Config.SCREEN_SHOW_SCENE) ||
(screenIndex == Config.SCREEN_SELECT_PIC_CAMERA) ||
(screenIndex == Config.SCREEN_EDIT) ||
(screenIndex == Config.SCREEN_DONE))
if (image.getWidth() > image.getHeight())
directions = Display.DIRECTION_LANDSCAPE;
directions = Display.DIRECTION_PORTRAIT;
directions = Display.DIRECTION_LANDSCAPE|Display.DIRECTION_PORT
After this code I create the screen and push it on the screen stack. The direction of the screen is unaffected. After I rotate the simulator, the direction setting kicks in.
Also tried with DIRECTION_NORTH, EAST and WEST, to no avail.
I'm forced to rework the app to allow for any orientation, always listening to orientation changes to adjust the layout. This is far from ideal.
I could "force" the user to rotate the screen, but this is not reasonable.
I could also use drawTexturePath to rotate the elements on the screen, but although it is very fast, it would for force me to take care of all the layout of the screen's elements.
I hope that in a future release I'll be able to control direction as I see fit.
04-11-2010 06:19 PM
I would also like to know how do I know which direction is currently active. I can use Display.getOrientation(), but that only returns Orientation (landscape, portrait), not direction (north, east, west).
07-28-2010 11:33 AM
If all you want is to lock the orientation to either Landscape or Portrait, and never want to unlock it, then I found that the following trick will work.
Within the class that extends UiApplication, but before pushing any sceens to the stack :
Because the application return to the foreground with the screen locked it will render all screens in the locked orientation.
BE WARNED, this should only be done before screens are pushed to the stack or else the application will become unstable and will usually crash shortly after.