[Android] Add a setting to disable the sensor for the video player lock

Nicolas Pomepuy git at videolan.org
Wed Jun 23 04:10:54 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun 22 06:53:09 2021 +0200| [afa672cf463d6bc3ce2a2743f79dd8a428e2c180] | committer: Nicolas Pomepuy

Add a setting to disable the sensor for the video player lock

A "landscape reverse" entry has also been added
Fixes #1494

> https://code.videolan.org/videolan/vlc-android/commit/afa672cf463d6bc3ce2a2743f79dd8a428e2c180
---

 application/resources/src/main/res/values/arrays.xml          |  2 ++
 application/resources/src/main/res/values/strings.xml         |  2 ++
 .../tools/src/main/java/org/videolan/tools/Settings.kt        |  1 +
 application/vlc-android/res/xml/preferences_video.xml         |  6 ++++++
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt     | 11 +++++++++--
 5 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/application/resources/src/main/res/values/arrays.xml b/application/resources/src/main/res/values/arrays.xml
index 21725331d..c69181bd9 100644
--- a/application/resources/src/main/res/values/arrays.xml
+++ b/application/resources/src/main/res/values/arrays.xml
@@ -237,12 +237,14 @@
         <item>@string/screen_orientation_sensor</item>
         <item>@string/screen_orientation_portrait</item>
         <item>@string/screen_orientation_landscape</item>
+        <item>@string/screen_orientation_landscape_reverse</item>
         <item>@string/screen_orientation_last_locked</item>
     </string-array>
     <string-array name="screen_orientation_values" translatable="false">
         <item>99</item>
         <item>102</item>
         <item>101</item>
+        <item>103</item>
         <item>98</item>
     </string-array>
 
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 61a84949b..6dafcae04 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -829,6 +829,8 @@
     <string name="add_all_button">Add all</string>
     <string name="add_new_only_button">Add new only</string>
     <string name="discovery_failed">Discovery failed for: %s</string>
+    <string name="lock_use_sensor_title">Lock with sensor</string>
+    <string name="lock_use_sensor_summary">When the orientation is locked, use the sensor to allow the reverse orientation</string>
     <plurals name="duplication_two_options_secondary">
         <item quantity="one">This item is already in this playlist.</item>
         <item quantity="other">These items are already in this playlist.</item>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 52306d630..7a1dccb00 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -80,6 +80,7 @@ const val SAVE_BRIGHTNESS = "save_brightness"
 const val BRIGHTNESS_VALUE = "brightness_value"
 const val POPUP_KEEPSCREEN = "popup_keepscreen"
 const val POPUP_FORCE_LEGACY = "popup_force_legacy"
+const val LOCK_USE_SENSOR = "lock_use_sensor"
 
 const val VIDEO_PAUSED = "VideoPaused"
 const val VIDEO_SPEED = "VideoSpeed"
diff --git a/application/vlc-android/res/xml/preferences_video.xml b/application/vlc-android/res/xml/preferences_video.xml
index 954e9f913..3d223ca69 100644
--- a/application/vlc-android/res/xml/preferences_video.xml
+++ b/application/vlc-android/res/xml/preferences_video.xml
@@ -94,6 +94,12 @@
                 android:key="popup_keepscreen"
                 android:summary="@string/popup_keepscreen_summary"
                 android:title="@string/popup_keepscreen_title"/>
+        <CheckBoxPreference
+                app:singleLineTitle="false"
+                android:defaultValue="true"
+                android:key="lock_use_sensor"
+                android:summary="@string/lock_use_sensor_summary"
+                android:title="@string/lock_use_sensor_title"/>
 
         <ListPreference
                 app:singleLineTitle="false"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index a8cfa96bf..cdfcb63ad 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -406,10 +406,11 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         overlayDelegate.playerUiContainer = findViewById(R.id.player_ui_container)
 
         val screenOrientationSetting = Integer.valueOf(settings.getString(SCREEN_ORIENTATION, "99" /*SCREEN ORIENTATION SENSOR*/)!!)
+        val sensor = settings.getBoolean(LOCK_USE_SENSOR, true)
         orientationMode = when (screenOrientationSetting) {
             99 -> PlayerOrientationMode(false)
-            101 -> PlayerOrientationMode(true, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
-            102 -> PlayerOrientationMode(true, ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT)
+            101 -> PlayerOrientationMode(true, if (sensor) ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE else ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
+            102 -> PlayerOrientationMode(true, if (sensor) ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
             103 -> PlayerOrientationMode(true, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
             98 -> PlayerOrientationMode(true, settings.getInt(LAST_LOCK_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE))
             else -> PlayerOrientationMode(true, getOrientationForLock())
@@ -435,6 +436,12 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         // 100 is the value for screen_orientation_start_lock
         try {
             requestedOrientation = getScreenOrientation(orientationMode)
+            //as there is no ActivityInfo.SCREEN_ORIENTATION_SENSOR_REVERSE_LANDSCAPE, now that we are in reverse landscape, enable the sensor if needed
+            if (screenOrientationSetting == 103 && sensor){
+                orientationMode = PlayerOrientationMode(true,ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
+                requestedOrientation = getScreenOrientation(orientationMode)
+            }
+
             if (orientationMode.locked) settings.putSingle(LAST_LOCK_ORIENTATION, requestedOrientation)
         } catch (ignored: IllegalStateException) {
             Log.w(TAG, "onCreate: failed to set orientation")



More information about the Android mailing list