Is it possible to restrict orientations on devices below a certain size?

Our app is a universal app, but on smaller devices we would prefer it to only use portrait, and larger devices can use either landscape or portrait.

I can get the actual devices screen size which is obviously the first step, but I’m not sure how to then override the supported orientations from build.settings.
Is it even possible to do that? [import]uid: 84115 topic_id: 34170 reply_id: 334170[/import]

Hi Alan,
I think the only way you can control this is to “override” the device’s native orientation/rotation feature and program your own using Corona’s orientation listener… and then only apply it if the device is a certain size, which you can detect: please refer to Rob’s recent blog post: http://www.coronalabs.com/blog/2012/12/11/device-detection-on-steroids/

In other words, you would set up only one orientation in “build.settings” and then program your own rotation in Corona. Some developers actually prefer to do this anyway.

Brent [import]uid: 200026 topic_id: 34170 reply_id: 135899[/import]

I already have

Runtime:addEventListener( "orientation", onOrientationChange )

which repositions my objects on rotation.

If I set build.settings to only use one orientation, would it still trigger my orientation listener?

I was under the impression that if you say the app only supports portrait, then the app wouldn’t be notified when the device was using a different orientation. [import]uid: 84115 topic_id: 34170 reply_id: 135906[/import]

Hi Alan,
I just tested this, and the Runtime listener still responds even if you have one orientation specified in your build settings.

Brent [import]uid: 200026 topic_id: 34170 reply_id: 135914[/import]

Ok great. I feel bad for not testing that first, my assumptions got the better of me. [import]uid: 84115 topic_id: 34170 reply_id: 135917[/import]

Hi Alan,
I think the only way you can control this is to “override” the device’s native orientation/rotation feature and program your own using Corona’s orientation listener… and then only apply it if the device is a certain size, which you can detect: please refer to Rob’s recent blog post: http://www.coronalabs.com/blog/2012/12/11/device-detection-on-steroids/

In other words, you would set up only one orientation in “build.settings” and then program your own rotation in Corona. Some developers actually prefer to do this anyway.

Brent [import]uid: 200026 topic_id: 34170 reply_id: 135899[/import]

I already have

Runtime:addEventListener( "orientation", onOrientationChange )

which repositions my objects on rotation.

If I set build.settings to only use one orientation, would it still trigger my orientation listener?

I was under the impression that if you say the app only supports portrait, then the app wouldn’t be notified when the device was using a different orientation. [import]uid: 84115 topic_id: 34170 reply_id: 135906[/import]

Hi Alan,
I just tested this, and the Runtime listener still responds even if you have one orientation specified in your build settings.

Brent [import]uid: 200026 topic_id: 34170 reply_id: 135914[/import]

Ok great. I feel bad for not testing that first, my assumptions got the better of me. [import]uid: 84115 topic_id: 34170 reply_id: 135917[/import]

I’ve just tried implementing this for a while now, but I’ve run into a problem.
I have limited the build settings to just use portrait, and rotated my display groups etc so that they are shown the correct way round.

However, x and y for touch events are completely messed up when I rotate. Since the device thinks it’s still portrait, if I move a touch horizontally it tracks as a vertical movement. Likewise, the screen width and height remain as they were when the screen was portrait, so although everything is in a group it’s a nightmare to position things in the correct place since display.contentWidth and display.contentHeight return incorrect values. Obviously I can just reassign those but it seems that it’s a lot of work to get it all working :-S [import]uid: 84115 topic_id: 34170 reply_id: 137721[/import]

I’ve just tried implementing this for a while now, but I’ve run into a problem.
I have limited the build settings to just use portrait, and rotated my display groups etc so that they are shown the correct way round.

However, x and y for touch events are completely messed up when I rotate. Since the device thinks it’s still portrait, if I move a touch horizontally it tracks as a vertical movement. Likewise, the screen width and height remain as they were when the screen was portrait, so although everything is in a group it’s a nightmare to position things in the correct place since display.contentWidth and display.contentHeight return incorrect values. Obviously I can just reassign those but it seems that it’s a lot of work to get it all working :-S [import]uid: 84115 topic_id: 34170 reply_id: 137721[/import]