09-21-2011 03:26 PM - edited 09-21-2011 04:59 PM
Follow the latest code I made:
What's up guys!
I'm trying to run an app on curve 8520 and tourch 9800, so I am using sdk4.6.1.
I would like to block the screen rotation on torch but I know that SDK 4.6 there is no such API. I tried to override the paint method, and invalidate sublayout, trying to set the paintSuspend as true.
I need, besides blocking the rotation, ask the user to return to the correct orientation (portrait) but the dialog is not working.
My last code below:
public final class MyScreen extends MainScreen {
...
public void invalidate() {
String deviceName = DeviceInfo.getDeviceName();
int width = Display.getWidth();
int height = Display.getHeight();
System.out.println("diogo ------------display: " + width + " " + height + " name" + deviceName);
if (width == 480 && height == 360 && deviceName.equalsIgnoreCase("9800")) {
synchronized (UiApplication.getEventLock()) {
loadingDialog.setEscapeEnabled(false);
loadingDialog.doModal();
UiApplication.getUiApplication().suspendPainting(t rue);
System.out.println(UiApplication.getUiApplication( ).isPaintingSuspended());
return;
}
} else {
if (UiApplication.getUiApplication().isPaintingSuspen ded())
UiApplication.getUiApplication().suspendPainting(f alse);
loadingDialog.close();
}
super.invalidate();
}
}
Solved! Go to Solution.
09-21-2011 09:52 PM
Might be easier to upgrade your 8520 to OS 5.0!
I have not looked at your code seriously, but doing it in invalidate seems like a dangerous place to do it.
I would do it in sublayout. sublayout is called when the rotation is detected.
If you detect a rotation, then in sublayout, create an invokeLater (you won't be able to do this sort of thing in sublayout, so you need to start an new process). In the invokeLater push a new screen of your making. In that screen's sublayout, check the orientation using the width and height. When that detects the correct orientation. have it pop itself (in another invokeLater. I think this should work and hooks in to a defined place.
Ask if this is not clear.
09-21-2011 10:51 PM
I agree with Peter about the overriding invalidate.
Haven't actually ever seen that before. Likely very dangerous. You coud even trigger an infinite loop.
But prior release from OS 4.7 there was no api for fixing orientation.
I have noticed all apps I have created for os 4.5 never trigger a orientation change on the torch or anyother bb phone with tilt feature.
For os 4.7 build you can fix the orientation to portrait by executing the statement
net.rim.device.api.ui.Ui.getUiEngineInstance().set
before any pushScreen.
This however does not work if you are pushing a global screen with pushGlobalScreen due to limitations with global screens.
You have to do that statement just before any pushScreen becuase while your app is running at anytime the phone can be tilting.
09-21-2011 11:02 PM
opps sorry my os 4.5 apps do tilt except for anythng I do during call connect phone app.
So your best bet is to switch to OS 4.7 or 5.0 if possible.
09-22-2011 02:44 PM
09-22-2011 02:55 PM
this code works for the lock but does not show dialog.
protected void sublayout(int paramInt1, int paramInt2) {
String deviceName = DeviceInfo.getDeviceName();
int width = Display.getWidth();
int height = Display.getHeight();
System.out.println("diogo ------------display: " + width + " " + height + " name" + deviceName);
if (width == 480 && height == 360 && deviceName.equalsIgnoreCase("9800")) {
synchronized (UiApplication.getEventLock()) {
loadingDialog.setEscapeEnabled(false);
loadingDialog.doModal();
// UiApplication.getUiApplication().suspendPainting(t rue);
System.out.println(UiApplication.getUiApplication( ).isPaintingSuspended());
return;
}
} else {
// if (UiApplication.getUiApplication().isPaintingSuspen ded())
// UiApplication.getUiApplication().suspendPainting(f alse);
loadingDialog.close();
}
09-22-2011 03:00 PM
I AM TRYING TO FIGURE OUT IF I CAN TURN OFF THE SCREEN ROTATION ON MY BLACKBERRY STORM 9530. IS THIS THE RIGHT PLACE TO ASK THIS QUESTION?
09-22-2011 03:05 PM
09-22-2011 03:10 PM
sorry
09-22-2011 03:39 PM - edited 09-22-2011 04:58 PM
I would recommend that you do not use
synchronized (UiApplication.getEventLock()) {
}
And most importantly,if you do use it, do not attempt to put blocking operations in it. They will not work. And they can cause dead locks.
Always use invokeLater, unless you really, really have to wait, and then use invokeAndWait.
In this case, you are upsetting a key part of the processing of BlackBerry when it performs a screen rotation. You should not actually be blocking this operation. All you can do is put a screen in front of the 'rotated' screen that does not disappear until the rotation is reversed. If you attempt to stop the rotation you could cause your BlackBerry problems.
As I said in my original post, my recommended processing is to use sublayout to detect the wrong orientation, and then put up a hiding screen using invokeLater. I may have said blocking, but I meant blocking the view, not 'stopping', sorry if this was confusing The sublayout of the "Hiding" screen will be invoked when the orientation is changed again and when you detect the correct orientation, just pop that screen, again using invokeLater (do not do it in sublayout). And just to confirm, this 'popping' code in the sublayout of the pushed screen, not in the sublayout of the screen that you don't want the user to see rotated.
There is no need to use a synchronized block in this code and I would avoid it.