Force Orientation Change to Landscape at StartUp

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Force Orientation Change to Landscape at StartUp

Post by dcpbarrington » Tue Dec 23, 2014 3:45 am

LiveCode Mobile Developers,

I have an App that I want to work on both mobile phones and tables and I'm running into a challenge. I'm using LiveCode 6.7.1 rc4, but have had the same issue with previous versions.

I have the App set up to initially start in Portrait mode and have enabled the mobileAllowedOrientations to support any configuration.

Things work great on the phone when the initial orientation is Portrait, but I want app to come up in Landscape mode when it is installed on a tablet.

I'm trying to force the application to be in Landscape orientation without the user changing the device orientation to Portrait and then back to landscape. So force the Display Orientation = Landscape

I created the following function to try to force the orientation to change to Landscape on the first card, but when changes the stack orientation, the display orientation still remains in Portrait. The card has a scroll area that needs to re-adjusted as well.

Code: Select all

function setDisplayOrientationToDevice
   
   if environment() is not "mobile" then exit setDisplayOrientationToDevice
   
-- App defines the dimensions based on the device to fit the tablet or phone
   put the uPortraitSize of this stack into tPortraitSize
   put the uLandscapeSize of this stack into tLandscapeSize
-- Scroll area is sized based on the orientation
   if scrollGroupID is not Empty then
      put the uPortraitSize of scrollGroupID into tGroupPortraitSize
      put the uLandscapeSize of scrollGroupID into tGroupLandscapeSize
   else
      put Empty into tGroupPortraitSize
      put Empty into tGroupLandscapeSize
   end if
   
   put mobileDeviceOrientation() into tOrientation
   put mobileOrientation() into tScreenOrientation
   
   answer info "Enter Device Orientation = " & tOrientation && "Screen Orientation = " & tScreenOrientation
   
   if tOrientation contains "portrait" then
      if scrollID is not Empty AND tGroupPortraitSize is not Empty then
         mobileControlSet scrollID, "rect", tGroupPortraitSize
      end if
      if tPortraitSize is not Empty then
         answer info "Setting Stack to " & tPortraitSize
         set the  rect of this stack to tPortraitSize
      end if
   else if tOrientation contains "landscape" then
       if tLandscapeSize is not Empty then
         answer info "Setting Stack to Landscape " & tLandscapeSize
         set the rect of this stack to tLandscapeSize
      end if
      if scrollID is not Empty and tGroupLandscapeSize is not Empty then
         answer info "Setting Scroll Group to " & tGroupLandscapeSize
         --set the rect of tScrollGroupID to tGroupLandscapeSize
         mobileControlSet scrollID, "rect", tGroupLandscapeSize
      end if
   end if
   
   put mobileDeviceOrientation() into tOrientation
   put mobileOrientation() into tScreenOrientation
   
   answer info "Exit Device Orientation = " & tOrientation && "Screen Orientation = " & tScreenOrientation
   
end setDisplayOrientationToDevice
Enter Device Orientation = "Landscape Right" Screen Orientation = "Portrait"
Enter Device Orientation = "Landscape Right" Screen Orientation = "Portrait"
so the stack resize doesn't do anything

The display goes from a full screen Portrait display to a portrait display that has two large black squares on each side.
So it looks like it has stretched the display to the landscape dimensions, but the applications still thinks it is in Portrait mode.

Is there any way to force the Screen Orientation to change without physically turning the device?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Force Orientation Change to Landscape at StartUp

Post by jacque » Tue Dec 23, 2014 8:29 pm

I think (but haven't tested) that you can control this in a preOpenStack handler. In preOpenStack, check the orientation and if it is landscape, set the allowedOrientations to only the landscape options. If it is portrait, allow all orientations. If that doesn't work, try the same thing in a startup handler.

After the app has finished launching (after an openCard handler, usually) you can reset the allowedOrientations to allow full rotations again so that the user can change it at will.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Force Orientation Change to Landscape at StartUp

Post by MaxV » Mon Dec 29, 2014 3:36 pm

There is no way, at the present you have to build 2 separates apps, one for tablet, one for mobile phone. It's a bug: http://quality.runrev.com/show_bug.cgi?id=11146
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Force Orientation Change to Landscape at StartUp

Post by dcpbarrington » Wed Jan 14, 2015 6:46 pm

Thanks MaxV

I was coming to your conclusion. Unfortunately you cannot define both Portrait and Landscape initial orientations in Android like you can in iOS. Don't know if that is an Android or LiveCode limitation, but it is frustrating that you need to create two releases to get the initial functionality to work.

Thanks for your post.
Dan

Post Reply