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
Contributor
adm220
Posts: 29
Registered: ‎08-09-2011
My Device: CURVE 8520
My Carrier: Oi
Accepted Solution

Blocking screen rotation - 4.6.1 SDK

[ Edited ]

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(true);
                System.out.println(UiApplication.getUiApplication().isPaintingSuspended());

                return;

            }
        } else {
            if (UiApplication.getUiApplication().isPaintingSuspended())
                UiApplication.getUiApplication().suspendPainting(false);
            loadingDialog.close();
        }
        super.invalidate();
    }
}

 


Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blocking screen rotation - 4.6.1 SDK

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. 

Please use plain text.
Developer
BeroboInc
Posts: 123
Registered: ‎07-08-2011
My Device: Torch 9800, Bold 9700
My Carrier: Bell, Rogers

Re: Blocking screen rotation - 4.6.1 SDK

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().setAcceptableDirections(Display.DIRECTION_NORTH);


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.

 

 

Berobo Inc.
Police Scanner Radio / Alarm Clock lets you listen to Police scanners in your area!
http://www.berobo.com
_________________________________________________
Please click the Like button to thank the user that has helped you and
please mark post as solved when you have found the solution to your problem.
Please use plain text.
Developer
BeroboInc
Posts: 123
Registered: ‎07-08-2011
My Device: Torch 9800, Bold 9700
My Carrier: Bell, Rogers

Re: Blocking screen rotation - 4.6.1 SDK

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.

 

 

Berobo Inc.
Police Scanner Radio / Alarm Clock lets you listen to Police scanners in your area!
http://www.berobo.com
_________________________________________________
Please click the Like button to thank the user that has helped you and
please mark post as solved when you have found the solution to your problem.
Please use plain text.
Contributor
adm220
Posts: 29
Registered: ‎08-09-2011
My Device: CURVE 8520
My Carrier: Oi

Re: Blocking screen rotation - 4.6.1 SDK

thank you for reply.... i had tried to use sublayout only doing getEventLock and trying print a dialog but, although the block rotate screen works, the dialog did not display.
am I be able to deploy 2 different versions on appworld, one with 4.6 to some devices and other with 5.0 to another?
Please use plain text.
Contributor
adm220
Posts: 29
Registered: ‎08-09-2011
My Device: CURVE 8520
My Carrier: Oi

Re: Blocking screen rotation - 4.6.1 SDK

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(true);
                System.out.println(UiApplication.getUiApplication().isPaintingSuspended());

                return;

            }
        } else {
            // if (UiApplication.getUiApplication().isPaintingSuspended())
            // UiApplication.getUiApplication().suspendPainting(false);
            loadingDialog.close();
        }

 

Please use plain text.
New Member
toby21
Posts: 4
Registered: ‎09-22-2011
My Device: storm 9530
My Carrier: verizon

Re: Blocking screen rotation - 4.6.1 SDK

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?

Please use plain text.
Contributor
adm220
Posts: 29
Registered: ‎08-09-2011
My Device: CURVE 8520
My Carrier: Oi

Re: Blocking screen rotation - 4.6.1 SDK

I dont think so. Maybe if you are developing to 4.6 sdk ehehhe.
Please use plain text.
New Member
toby21
Posts: 4
Registered: ‎09-22-2011
My Device: storm 9530
My Carrier: verizon

Re: Blocking screen rotation - 4.6.1 SDK

sorry

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blocking screen rotation - 4.6.1 SDK

[ Edited ]

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.

Please use plain text.