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
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?

Sorry to bump an old thread but has anyone figured out how to lock a certain orientation when pushed from a background thread?
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Anyone have any idea how the Orientation Lock aps work?

[ Edited ]

AccelerometerChannelConfig config = new AccelerometerChannelConfig( AccelerometerChannelConfig.TYPE_ORIENTATION, true, true, 1 );
Channel dataChannel = AccelerometerSensor.openChannel(app, config);

int orientation = dataChannel.getOrientation();
if( (orientation == AccelerometerSensor.ORIENTATION_TOP_UP) |
(orientation == AccelerometerSensor.ORIENTATION_BOTTOM_UP) ){
Ui.getUiEngineInstance().setAcceptableDirections( DirectionControl.DIRECTION_PORTRAIT );
} else {
Ui.getUiEngineInstance().setAcceptableDirections( DirectionControl.DIRECTION_LANDSCAPE );
}

 

dataChannel.close();

 

If you put that into a MenuItem, it should allow you to lock the orientation of any app that you open. It works for me in several background threads at least.

 

And to undo it you would call setAcceptableDirections( PORTRAIT | LANDSCAPE );

Message Edited by CMY on 09-20-2009 02:59 AM
Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?


CMY wrote:

AccelerometerChannelConfig config = new AccelerometerChannelConfig( AccelerometerChannelConfig.TYPE_ORIENTATION, true, true, 1 );
Channel dataChannel = AccelerometerSensor.openChannel(app, config);

int orientation = dataChannel.getOrientation();
if( (orientation == AccelerometerSensor.ORIENTATION_TOP_UP) |
(orientation == AccelerometerSensor.ORIENTATION_BOTTOM_UP) ){
Ui.getUiEngineInstance().setAcceptableDirections( DirectionControl.DIRECTION_PORTRAIT );
} else {
Ui.getUiEngineInstance().setAcceptableDirections( DirectionControl.DIRECTION_LANDSCAPE );
}

 

dataChannel.close();

 

If you put that into a MenuItem, it should allow you to lock the orientation of any app that you open. It works for me in several background threads at least.

 

And to undo it you would call setAcceptableDirections( PORTRAIT | LANDSCAPE );

Message Edited by CMY on 09-20-2009 02:59 AM

Hmm would I be able to get this to work in a background application that launches a global sceen or would I hav to lock the homescreen in order to lock my aplication?

Highlighted
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Anyone have any idea how the Orientation Lock aps work?

It should work in any background thread that you run, now how you get the background thread to start is another question. If you are trying to add this feature into BerrySlider / StormSlider to be used with other 3rd Party Apps, i'm guessing a MenuItem would be the best way to do it through the ApplicationMenuItemRepository. If it's just for your app only, then you can put it in the code for your global screen.
Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?


CMY wrote:
It should work in any background thread that you run, now how you get the background thread to start is another question. If you are trying to add this feature into BerrySlider / StormSlider to be used with other 3rd Party Apps, i'm guessing a MenuItem would be the best way to do it through the ApplicationMenuItemRepository. If it's just for your app only, then you can put it in the code for your global screen.

Okay makes sense now, I will try and impliment it and see how it goes.

 

Once again cmy comes to the rescue

Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?


CMY wrote:
It should work in any background thread that you run, now how you get the background thread to start is another question. If you are trying to add this feature into BerrySlider / StormSlider to be used with other 3rd Party Apps, i'm guessing a MenuItem would be the best way to do it through the ApplicationMenuItemRepository. If it's just for your app only, then you can put it in the code for your global screen.

Hmm seems to be workin, but it's hit or miss

 

If I launch the applicaion using the menu item I created the app will lock just fine. However if the app is launched any other way like for example I have the app launch when the backlight dims out, it will not lock the app then. 

 

I'm using the same exact method to lock the ap but one way works and the other is a no go.

 

Any suggestions on what to do wit that? haha

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Anyone have any idea how the Orientation Lock aps work?

I would guess that the accelerometer listener is turned off when the backlight is dim. This would explain why when you rotate your phone with the screen off, it will often light up with the previous orientation and the rotate real quick (or sometimes not rotate at all, lol). Also I think the rotation and subsequent relayout of the screen resets the backlight timer, which would cause the backlight to come back on if the orientation changed when the backlight was dim.
Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?

This would make sense.....that makes it a little harder to work with now haha.

 

I have it working perfectly for the menu item and when the icon is pressed. I'm trying to figure out if there is any way to get it to lock when the screen is already launched. I've tried placing the code into the backlightStateChange method and hoped by calling it only when the screen as active and not dimmed out it would work but it's still a no go.

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Anyone have any idea how the Orientation Lock aps work?

In your backlight state change launch a TimerTask or Thread that sleeps for maybe a second or two then calls the code to lock the orientation. That should give everything time to wake up after the backlight comes on.
Developer
Posts: 296
Registered: ‎12-07-2008
My Device: Not Specified

Re: Anyone have any idea how the Orientation Lock aps work?



CMY wrote:
In your backlight state change launch a TimerTask or Thread that sleeps for maybe a second or two then calls the code to lock the orientation. That should give everything time to wake up after the backlight comes on.

I tried that too, but it seems as if you have to run the code prior to launching the gui. It wont allow you to lock the actual global screen, it will allow you to lock the homescreen though. When you lock the homescreen the global screen will be locked also. 

 

With that being said I can only get it to work when using the menu item or the aplicaion icon. The other methods still will not work for me.

 

I've tried a timertask for up to 5 seconds and then I call the accelerometer code and then launch my aplication and it still doesn't seem to respond correctly. I'm trying to pinoint the issue right now though. 

 

It should be possible, just a matter of figuring out wen it's being called