added respecting user-configured screen orientation locking on Android
authorHolger Schemel <info@artsoft.org>
Wed, 29 Mar 2023 06:02:33 +0000 (08:02 +0200)
committerHolger Schemel <info@artsoft.org>
Wed, 29 Mar 2023 06:16:24 +0000 (08:16 +0200)
On Android, locking the screen orientation to portrait or landscape
as configured by the user of the device was completely ignored so far.

This change adds respecting this device setting by using the setting
"fullUser" for the app's screen orientation activity (always use user
defined screen orientation) instead of the previously used setting
"fullSensor" (always use sensor-based rotation, regardless of any
user-configured locking of screen rotation).

The corresponding entry in the Android Manifest file was added only to
document this changed behaviour, even though it is in fact ignored, as
this activity setting is finally hard-coded in the Java activity code,
where it was changed to use the new behaviour.

build-projects/android/app/src/main/AndroidManifest.xml.tmpl
build-projects/android/app/src/main/java/org/libsdl/app/SDLActivity.java

index f264e833574b9480d49c77ca9da5cb828025195d..8331804d0c5a7ddd0730fed9e61a7c2f44832cf4 100644 (file)
@@ -47,6 +47,7 @@
                   android:alwaysRetainTaskState="true"
                   android:launchMode="singleInstance"
                  android:configChanges="keyboardHidden|orientation|screenSize"
+                 android:screenOrientation="fullUser"
                  android:preferMinimalPostProcessing="true"
                  android:exported="true"
                  >
index 9144949b619417e235d250b212d23fc3dd3b85c4..f8b3e1eb56ca6e363f1b2a1224084e1d89576fc8 100644 (file)
@@ -871,7 +871,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
         if (!is_portrait_allowed && !is_landscape_allowed) {
             if (resizable) {
                 /* All orientations are allowed */
-                req = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
+                req = ActivityInfo.SCREEN_ORIENTATION_FULL_USER;
             } else {
                 /* Fixed window and nothing specified. Get orientation from w/h of created window */
                 req = (w > h ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
@@ -881,7 +881,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
             if (resizable) {
                 if (is_portrait_allowed && is_landscape_allowed) {
                     /* hint allows both landscape and portrait, promote to full sensor */
-                    req = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
+                    req = ActivityInfo.SCREEN_ORIENTATION_FULL_USER;
                 } else {
                     /* Use the only one allowed "orientation" */
                     req = (is_landscape_allowed ? orientation_landscape : orientation_portrait);