[Android] Video player: initial orientation lock locks in the current orientation

Nicolas Pomepuy git at videolan.org
Thu Jul 11 09:45:50 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Jul 11 07:54:26 2019 +0200| [f7a535ab75f9871e0e7434e2b48992f2d132b6d7] | committer: Nicolas Pomepuy

Video player: initial orientation lock locks in the current orientation

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

 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
index 6dd0605b0..c2d2617c9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.kt
@@ -672,14 +672,6 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
     override fun onConfigurationChanged(newConfig: Configuration) {
         super.onConfigurationChanged(newConfig)
         currentScreenOrientation = newConfig.orientation
-        if (screenOrientation == 98) {
-            @StringRes val message: Int
-            if (currentScreenOrientation == Configuration.ORIENTATION_LANDSCAPE)
-                message = R.string.locked_in_landscape_mode
-            else
-                message = R.string.locked_in_portrait_mode
-            rootView?.let { UiTools.snacker(it, message) }
-        }
 
         if (touchDelegate != null) {
             val dm = DisplayMetrics()
@@ -2691,8 +2683,20 @@ open class VideoPlayerActivity : AppCompatActivity(), IPlaybackSettingsControlle
     }
 
     private fun toggleOrientation() {
-        screenOrientation = 98 //Rotate button
+        //screen is not yet locked. We invert the rotation to force locking in the current orientation
+        if (screenOrientation != 98) {
+            currentScreenOrientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) Configuration.ORIENTATION_LANDSCAPE else Configuration.ORIENTATION_PORTRAIT
+        }
+        screenOrientation = 98//Rotate button
         requestedOrientation = getScreenOrientation(screenOrientation)
+
+        //As the current orientation may have been artificially changed above, we reset it to the real current orientation
+        currentScreenOrientation = resources.configuration.orientation
+        @StringRes val message = if (currentScreenOrientation == Configuration.ORIENTATION_LANDSCAPE)
+            R.string.locked_in_landscape_mode
+        else
+            R.string.locked_in_portrait_mode
+        rootView?.let { UiTools.snacker(it, message) }
     }
 
     private fun resetOrientation(): Boolean {



More information about the Android mailing list