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!
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?
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.
you can catch the "orientationchanged" message on the mobile platform.
Query the new orientation (portrait/landscape) with the "mobileDeviceOrientation()" function.
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.
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.
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.
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...
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.