mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
09/26/13 06:53 PM (12 years ago)

Quick Tut: Lock to Portrait or Landscape Only Android Core 3.0

This differs a little bit if you want to lock your screen to Portrait or Landscape with the new Android 3.0 core. Quick Steps: 1. Open your AndroidManifest.xml file 2. Go to around line: 96 or search for this: <activity android:name=".BT_activity_host" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/hostThemeWithTitle" android:uiOptions="splitActionBarWhenNarrow" ></activity> 3. You will be adding this configuration portion to the end of the activity: android:screenOrientation="portrait" or android:screenOrientation="landscape" It will look like this: <activity android:name=".BT_activity_host" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/hostThemeWithTitle" android:uiOptions="splitActionBarWhenNarrow" android:screenOrientation="sensorPortait"></activity> This will lock the entire app to Portrait or Landscape. Edited with fix from @AlanMac
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
09/26/13 07:08 PM (12 years ago)
Perfect! Thanks!! Cheers! -- Smug
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
09/27/13 06:59 AM (12 years ago)
Thanks. So the rotation setting in the CP is just ignored in the new 3.0 core then, you need to do this to actually lock it? Have you tinkered with not locking the BT activity host and tried to lock individual activities? Curios if it gets overriden if you are using the BT tab controller. This has been the problem with every rotation lock hack I've tried to deploy on either platform. An easy way to control rotation per screen in BT is at the top of my list for feature requests. It just seems like since BT has all the activities/viewcontrollers subclassed that there has to be a simpler way. Rotations. Auto Layouts. That stuff just keeps getting more problematic with all these new devices and trying to build custom screens!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
09/27/13 07:07 AM (12 years ago)
Havent tried much. I just noticed that the activities per plugin were not in the manifest so I used the activity host. Yes, the control panel ignore my rotation rule at least with my non tablet device LG Optimus mobile phone. It rotated so.. I guess I would just have to add the non rotate rule in the java class for each plugin but I haven't tried yet! I'm sure I'll get to it at some point so I will report back!
 
Annonymous
Profile
09/27/13 07:51 AM (12 years ago)
No worries, I've not hammered on Android rotation as much as iOS yet. I know you can set the initial state of a screen orientation in the activity- And you can use this in the oncreate() to override that- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); But will the BT controllers override that? They seems to in iOS so just curious if that is still the case with the new Androind core. I'm guessing it will. I need to update and tinker around.....
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
01/10/14 03:13 AM (11 years ago)
Hi @mysps, I tried this and it works a treat, except that on my device, it always flips the screen upside down! I fixed this with one small enhancement to your example that I wanted to share, which is to use android:screenOrientation="sensorPortait" (note the deliberate mis-spelling is needed). This allows the device to be used in portrait upside down or the right way up. Did anyone work out how to apply this to a specific plugin instead of the whole app? Cheers, Alan
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
01/10/14 03:52 AM (11 years ago)
Oh thanks Alan I'll update the original post. About the specific plugin, I'll take a look and report back. I think Sandeep had a solution for that somewhere buried in the forums :)
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
01/21/14 02:50 PM (11 years ago)
Thanks guys, I just tried that and it works a treat! Farcat
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.