How to honor "Auto-Rotate Off" on Android

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bamakojeff
Posts: 19
Joined: Tue Dec 06, 2022 6:53 pm

How to honor "Auto-Rotate Off" on Android

Post by bamakojeff » Sat May 04, 2024 7:25 pm

I've written the code for an Android app to display properly whether it's in landscape or portrait orientation. Everything works exactly as I expect except that if I go into the Android settings and turn off "Auto-Rotate", my app still rotates when the device is rotated.

Does anyone know how I can query that status? Does Android broadcast the change, and can I read that somewhere?

I'm looking for something like:

Code: Select all

on systemAppearanceChanged
   if the systemAppearance = "dark" then
      ...
   end if
end systemAppearanceChanged
which we use to know if the device is running in "light" or "dark" mode. But I can't find anything similar for whether an Android device has locked rotation or not.

Thanks.

Jeff

Klaus
Posts: 13862
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to honor "Auto-Rotate Off" on Android

Post by Klaus » Sat May 04, 2024 7:40 pm

Hi Jeff,

you can catch the "orientationchanged" message on the mobile platform.
Query the new orientation (portrait/landscape) with the "mobileDeviceOrientation()" function.


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4016
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to honor "Auto-Rotate Off" on Android

Post by bn » Sat May 04, 2024 10:28 pm

Jeff,

mobileOrientationLocked()

should do what you want.

Kind regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9848
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to honor "Auto-Rotate Off" on Android

Post by FourthWorld » Sun May 05, 2024 4:45 am

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bamakojeff
Posts: 19
Joined: Tue Dec 06, 2022 6:53 pm

Re: How to honor "Auto-Rotate Off" on Android

Post by bamakojeff » Mon May 06, 2024 8:13 pm

Thank you gentlemen for your responses. Unfortunately, they did not solve my problem (but maybe that's me). Here's what I understand about the working of these commands. Please let me know if I have misunderstood something.

@Klaus
The orientationChanged message fires regardless of whether the user has locked rotation or not in Android. If the user locks rotation to portrait mode and then rotates the phone to landscape, orienationChanged still fires, and if I query the orientation with mobileOrienation, it dutifully tells me that the phone is in landscape mode. Neither of these tells me if the user has allowed these orientations.

@Bernd
mobileOrientationLocked() tells me if my program has locked rotation. It does not (at least as far as I can find) tell me if the user has locked rotation at the OS level.

My app can work in either portrait or landscape mode. But if the user locks their device to a particular orientation, then I want the app to honor that.

The livecode engine could honor that by not passing orientationChanged messages when the OS has locked orientation. Or I am happy for my app to enforce that by using mobileSetAllowedOrientations to limit what orientations the app allows or by using mobileLockOrientation to lock the app in a particular orientation. But to make either work in the app in response to the user's choice, my app has to know that the user has locked rotation at the OS level. I cannot find any way on Android to either alert my app when the user locks/unlocks rotation or to query whether rotation is locked at the OS level.

Jeff

Klaus
Posts: 13862
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to honor "Auto-Rotate Off" on Android

Post by Klaus » Mon May 06, 2024 8:45 pm

Hi Jeff,

sorry, looks like I did not understand your problem correctly.


Best

Klaus

bwmilby
Posts: 454
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: How to honor "Auto-Rotate Off" on Android

Post by bwmilby » Tue May 07, 2024 4:34 pm

Simplest way is to just use the resizeStack message to make any geometry changes. If rotation is locked on the device you should not get a resizeStack message.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

bamakojeff
Posts: 19
Joined: Tue Dec 06, 2022 6:53 pm

Re: How to honor "Auto-Rotate Off" on Android

Post by bamakojeff » Tue May 07, 2024 6:29 pm

Thanks Brian. Obviously I am doing something wrong, because I am using resizeStack to handle the geometry changes when the device is rotated, and it definitely fires regardless of whether Auto-Rotation is on or off on Android. It happens in a simulator in Android Studio and it happens on my Android phone. And this bug report seems to say it's been an issue for a long time: https://quality.livecode.com/show_bug.cgi?id=20916

If you've got a case where resizeStack does not trigger if auto-rotation is set on android, I would so appreciate it you could tell me what you did to get that result, but because I've been unable to find any way to get Livecode to honor auto-rotation settings in Android.

Thanks.

Jeff

stam
Posts: 2736
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to honor "Auto-Rotate Off" on Android

Post by stam » Tue May 07, 2024 7:11 pm

Jeff,
it doesn't seem to be your code - the 6 year old bug you link has clearly been assessed as a bug affecting android (and not iPhone) and is exactly what you're describing, if I understood your issue correctly.

Perhaps post a question in the bug report? Richard has done so previously to no avail, but perhaps it has been more difficult to fix than one expects, or has been de-prioritised... but not sure why it would, seems like an important bug to me...

S.

bwmilby
Posts: 454
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: How to honor "Auto-Rotate Off" on Android

Post by bwmilby » Tue May 07, 2024 7:41 pm

I’ll need to go back and look at the code in SivaSiva. I guess that app locks the orientation much more so it isn’t noticed as much. Most of it locks to portrait or landscape. I only have an old Pixel to test Android and have not built for it in quite a while. The only rotation issue I recall is the one mentioned where you can’t force Android to redraw in a new orientation until the device rotates to that orientation.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”