Android Autorotation

Auto-rotation seems to work right out of the box for iOS. For Android, it doesn't appear to be. How do I enable it?

Viewing 1 to 8 (8 Total)
Android Autorotation

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Auto-rotation seems to work right out of the box for iOS. For Android, it doesn't appear to be. How do I enable it?

Tags:
Posted on July 23, 2012 at 4:03 AM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: Android Autorotation

shouldRotateInterface and setFixedOrientation appear to only work for iOS, and I'm reading an earlier post by Josh saying that for Android, an NMML setting does the trick but doesn't elaborate on which setting that is.

Unfortunately, there's no information in the NMML spec (http://code.google.com/p/nekonme/source/browse/trunk/tools/command-line/spec.nmml) on this, nor any other post about this topic.

Posted on July 23, 2012 at 7:34 PM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Android Autorotation

currently, interface autorotation, fixed orientation, etc. only works for iOS.

However, you can check the static method nme.display.Stage.getOrientation() to get the current UI orientation and check it against Stage.OrientationLandscapeLeft, Stage.OrientationLandscapeRight, Stage.OrientationPortrait, Stage.OrientationPortraitUpsideDown.

The trick here is that iOS orientation is always the current orientation of the device (including Stage.OrientationFaceUp and Stage.OrientationFaceDown), but Android orientation is always the orientation of the UI. iOS differs from Android in that each view controller gets "permission" to rotate to a given orientation and the current device orientation is always accessible as well.

For the most part, all the same data is available for any of these platforms, but they do differ in how the data is used.

If you are an Android programmer we could easily partner to get it nailed pretty quickly! I already added handling for the magnetometer (where available) in the process of building out the accelerometer/gravity handling.

Posted on July 23, 2012 at 8:16 PM

beezir

beezir
Total Posts: 2
Joined: July 07, 2012

Re: Android Autorotation

Hmm, this is weird. I had to specifically disable it for Android to make it NOT auto-rotate. In the AndroidManifest.xml, it checks for "orientation" on your window tag in the nmml file. If it's set to nothing, it should autorotate. (I disabled auto-rotation by setting orientation="portrait" in my window tag for if="mobile").

Posted on July 23, 2012 at 8:22 PM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Android Autorotation

right, autorotation does work in android by default in the way you describe. However, customization in code beyond what you can do in NMML is not yet supported.

Posted on July 23, 2012 at 8:28 PM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Android Autorotation

Jon, if you're simply wondering what to put in your NMML to set a particular orientation and to prevent autorotation, just use orientation="portrait" or orientation="landscape" in the window tag of your NMML.

Posted on July 23, 2012 at 8:48 PM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: Android Autorotation

Thanks for the tips.

Currently, I find the following behavior happening.

If I set orientation to landscape or portrait, it locks to a specific orientation for those on Android. Flipping the device 180 degrees does not auto-rotate like it does on iOS.

If I set no orientation at all, it accepts ALL 4 orientations, allowing the game to switch from portrait to landscape. Not what I'm after.

So it sounds like, if I want to be able to auto-rotate within portrait and landscape for Android, that is something we'll need to come with on our own?

Posted on July 23, 2012 at 10:44 PM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: Android Autorotation

Yup, that is how the "landscape" and "portrait" settings in the Android manifest work. The settings you apply to the window tag in your NMML are passed directly to the manifest. In order to implement a custom behavior we'd want to allow for a "nosensor" orientation in the manifest, then handle orientations programmatically in the activity class.

Posted on July 24, 2012 at 8:50 PM