[Android] Allow changing orientation when in unlocked mode

Nicolas Pomepuy git at videolan.org
Mon Jan 6 17:37:27 UTC 2025


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jan  6 15:19:40 2025 +0100| [edbf6ef317aceca46aa27ade7086fb7f03017d9f] | committer: Nicolas Pomepuy

Allow changing orientation when in unlocked mode

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

 .../vlc-android/res/layout/player_hud_right.xml    | 15 +++++++++++
 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  |  3 +++
 .../vlc/gui/video/VideoPlayerOverlayDelegate.kt    | 30 ++++++++++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/application/vlc-android/res/layout/player_hud_right.xml b/application/vlc-android/res/layout/player_hud_right.xml
index 288a5d0f35..9b97361ec2 100644
--- a/application/vlc-android/res/layout/player_hud_right.xml
+++ b/application/vlc-android/res/layout/player_hud_right.xml
@@ -160,6 +160,21 @@
                     android:paddingRight="16dp"
                     app:chipSpacing="16dp">
 
+                <com.google.android.material.chip.Chip
+                        android:id="@+id/orientation_quick_action"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        app:textStartPadding="0dp"
+                        app:textEndPadding="0dp"
+                        app:chipStartPadding="4dp"
+                        app:chipEndPadding="4dp"
+                        android:padding="4dp"
+                        app:iconStartPadding="4dp"
+                        app:iconEndPadding="4dp"
+                        android:onClick="onClick"
+                        app:chipBackgroundColor="@color/playerbackground"
+                        app:chipIcon="@drawable/ic_player_lock_portrait"
+                        app:chipIconTint="@color/white"/>
                 <com.google.android.material.chip.Chip
                         android:id="@+id/playback_speed_quick_action"
                         android:layout_width="wrap_content"
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 af3ce5635b..948bd845e3 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
@@ -1978,6 +1978,9 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 overlayDelegate.hideOverlay(false)
                 takeScreenshot()
             }
+            R.id.orientation_quick_action -> {
+                overlayDelegate.nextOrientation()
+            }
         }
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
index 1f253737f1..43c54adb11 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerOverlayDelegate.kt
@@ -705,6 +705,36 @@ class VideoPlayerOverlayDelegate (private val player: VideoPlayerActivity) {
             }
             hudBinding.orientationToggle.setImageDrawable(ContextCompat.getDrawable(player, drawable))
         }
+        if (::hudRightBinding.isInitialized) {
+            if (player.orientationMode.locked) {
+                val drawable = if (player.orientationMode.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || player.orientationMode.orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE || player.orientationMode.orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
+                    R.drawable.ic_player_lock_landscape
+                } else {
+                    R.drawable.ic_player_lock_portrait
+                }
+                hudRightBinding.orientationQuickAction.setVisible()
+                hudRightBinding.orientationQuickAction.chipIcon = ContextCompat.getDrawable(player, drawable)
+            } else hudRightBinding.orientationQuickAction.setGone()
+        }
+    }
+
+    fun nextOrientation() {
+        val orientations = arrayOf(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
+        val orientation = when (player.orientationMode.orientation) {
+            ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE -> orientations[0]
+            ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT -> orientations[1]
+            else -> orientations[orientations.indexOf(player.orientationMode.orientation) + 1]
+        }
+        player.setOrientation(orientation)
+        val string = when (orientation) {
+            ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> player.getString(R.string.screen_orientation_portrait)
+            ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT -> player.getString(R.string.screen_orientation_portrait_reverse)
+            ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE -> player.getString(R.string.screen_orientation_landscape)
+            else -> player.getString(R.string.screen_orientation_landscape_reverse)
+        }
+        showInfo(string, 1000)
+        updateOrientationIcon()
+        showOverlay()
     }
 
     fun updateRendererVisibility() {



More information about the Android mailing list