konstantinbueschel
2/12/2016 - 2:37 PM

Android orientation locking for Titanium - Originally posted on http://bencoding.com/2016/02/11/android-orientation-locking-for-titanium/

Android orientation locking for Titanium - Originally posted on http://bencoding.com/2016/02/11/android-orientation-locking-for-titanium/

<!-- 
add android:screenOrientation="portrait|landscape" to each of your activity tags 

Example:
-->
<?xml version="1.0" encoding="UTF-8"?>
<android xmlns:android="http://schemas.android.com/apk/res/android">
  <manifest xmlns:android="http://schemas.android.com/apk/res/android" >
    <application>
      <activity
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="portrait"
        android:name=".[REPLACE_ME]Activity">
        <intent-filter>
          <action android:name="android.intent.action.MAIN"/>
          <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
      </activity>
      <activity
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:name="org.appcelerator.titanium.TiActivity" 
        android:screenOrientation="portrait"/>
      <activity
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:name="org.appcelerator.titanium.TiTranslucentActivity"
        android:screenOrientation="portrait" android:theme="@style/Theme.AppCompat.Translucent"/>
    </application>
  </manifest>
</android>
/*
 * Next you will need to tell Alloy to only create Windows with a portrait 
 * orientation. This is super easy and can be done by adding one class to your 
 * app.tss as shown below.
 */
"Window" : {
        orientationModes :[
                Ti.UI.PORTRAIT
        ]
}
Q: Why lock at the Android Activity level, isn’t adding the Alloy style enough?
A: Unfortunately no. The Alloy style is applied after the window is created. So 
if the device is held in a landscape orientation you will see the window open and 
turn. Locking at the Android Activity level stops this behavior.

Q: Does this mean all of my Ti.UI.Window object will be locked in portrait?
A: Yes, this locks both at the Android Activity and Titanium object levels.

Q: Can I later change the orientation by updating my Ti.UI.Window orientation?
A: No, orientation is locked at the Android Activity level as well.