[Android] Foldable: prevent the advanced player options to be cut off by the hinge

Nicolas Pomepuy git at videolan.org
Mon Jul 4 12:09:47 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul  4 09:22:38 2022 +0200| [ff7712c4521d6e865562f657a53d9a4e178f4fdf] | committer: Duncan McNamara

Foldable: prevent the advanced player options to be cut off by the hinge

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

 .../vlc-android/res/layout-land/audio_player.xml       | 15 +++++++++++----
 application/vlc-android/res/layout/audio_player.xml    | 15 +++++++++++----
 .../videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt  | 18 ++++++++++++++++++
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.kt  |  4 ++++
 4 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/application/vlc-android/res/layout-land/audio_player.xml b/application/vlc-android/res/layout-land/audio_player.xml
index 71c24ff79..21708350f 100644
--- a/application/vlc-android/res/layout-land/audio_player.xml
+++ b/application/vlc-android/res/layout-land/audio_player.xml
@@ -804,15 +804,22 @@
                 app:srcCompat="@drawable/ic_arrow_right"
                 tools:visibility="visible" />
 
-        <androidx.appcompat.widget.ViewStubCompat
-                android:id="@+id/player_options_stub"
+        <FrameLayout
                 android:layout_width="0dp"
                 android:layout_height="0dp"
-                android:layout="@layout/player_options"
+                android:elevation="32dp"
+                android:id="@+id/player_options_container"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent" />
+                app:layout_constraintTop_toTopOf="parent">
+
+            <androidx.appcompat.widget.ViewStubCompat
+                    android:id="@+id/player_options_stub"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout="@layout/player_options" />
+        </FrameLayout>
 
         <androidx.appcompat.widget.ViewStubCompat
                 android:id="@+id/bookmarks_stub"
diff --git a/application/vlc-android/res/layout/audio_player.xml b/application/vlc-android/res/layout/audio_player.xml
index 1bc8842d5..21c1a37e9 100644
--- a/application/vlc-android/res/layout/audio_player.xml
+++ b/application/vlc-android/res/layout/audio_player.xml
@@ -741,15 +741,22 @@
                 app:srcCompat="@drawable/ic_arrow_right"
                 tools:visibility="visible" />
 
-        <androidx.appcompat.widget.ViewStubCompat
-                android:id="@+id/player_options_stub"
+        <FrameLayout
                 android:layout_width="0dp"
                 android:layout_height="0dp"
-                android:layout="@layout/player_options"
+                android:elevation="32dp"
+                android:id="@+id/player_options_container"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintTop_toTopOf="parent" />
+                app:layout_constraintTop_toTopOf="parent">
+
+            <androidx.appcompat.widget.ViewStubCompat
+                    android:id="@+id/player_options_stub"
+                    android:layout_width="match_parent"
+                    android:layout_height="match_parent"
+                    android:layout="@layout/player_options" />
+        </FrameLayout>
 
         <androidx.appcompat.widget.ViewStubCompat
                 android:id="@+id/bookmarks_stub"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index 2d6b2b7fb..fbd75dd36 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -3,6 +3,7 @@ package org.videolan.vlc.gui.helpers
 import android.annotation.SuppressLint
 import android.content.DialogInterface
 import android.support.v4.media.session.PlaybackStateCompat
+import android.view.Gravity
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -17,6 +18,7 @@ import androidx.leanback.widget.BrowseFrameLayout.OnFocusSearchListener
 import androidx.lifecycle.LifecycleObserver
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
+import androidx.window.layout.FoldingFeature
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
@@ -29,12 +31,14 @@ import org.videolan.vlc.PlaybackService
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.PlayerOptionItemBinding
 import org.videolan.vlc.gui.AudioPlayerContainerActivity
+import org.videolan.vlc.gui.BaseActivity
 import org.videolan.vlc.gui.DiffUtilAdapter
 import org.videolan.vlc.gui.audio.EqualizerFragment
 import org.videolan.vlc.gui.dialogs.*
 import org.videolan.vlc.gui.helpers.UiTools.addToPlaylist
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.media.PlayerController
+import org.videolan.vlc.util.getScreenHeight
 import org.videolan.vlc.util.isTalkbackIsEnabled
 
 private const val ACTION_AUDIO_DELAY = 2
@@ -138,6 +142,20 @@ class PlayerOptionsDelegate(val activity: FragmentActivity, val service: Playbac
 
             rootView.setOnClickListener { hide() }
         }
+        val windowInfoLayout = if (activity is VideoPlayerActivity) activity.windowLayoutInfo else if (activity is BaseActivity) activity.windowLayoutInfo else null
+        val foldingFeature = windowInfoLayout?.displayFeatures?.firstOrNull() as? FoldingFeature
+        if (foldingFeature?.isSeparating == true && foldingFeature.occlusionType == FoldingFeature.OcclusionType.FULL && foldingFeature.orientation == FoldingFeature.Orientation.HORIZONTAL) {
+            val halfScreenSize = activity.getScreenHeight() - foldingFeature.bounds.bottom
+            val lp = (rootView.layoutParams as ViewGroup.MarginLayoutParams)
+            lp.height = halfScreenSize
+            if (lp is FrameLayout.LayoutParams) lp.gravity = Gravity.BOTTOM
+            rootView.layoutParams = lp
+        } else {
+             val lp = (rootView.layoutParams as ViewGroup.MarginLayoutParams)
+            lp.height = FrameLayout.LayoutParams.MATCH_PARENT
+            if (lp is FrameLayout.LayoutParams) lp.gravity = Gravity.BOTTOM
+            rootView.layoutParams = lp
+        }
         setup()
         rootView.visibility = View.VISIBLE
         if (Settings.showTvUi) AppScope.launch {
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 8b2ebd07d..bd8117d50 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
@@ -71,6 +71,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
 import androidx.window.layout.FoldingFeature
 import androidx.window.layout.WindowInfoTracker
+import androidx.window.layout.WindowLayoutInfo
 import kotlinx.coroutines.*
 import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.onEach
@@ -155,6 +156,8 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
     private var wasPaused = false
     private var savedTime: Long = -1
 
+    lateinit var windowLayoutInfo: WindowLayoutInfo
+
     /**
      * For uninterrupted switching between audio and video mode
      */
@@ -504,6 +507,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                         .collect { layoutInfo ->
                             overlayDelegate.foldingFeature = layoutInfo.displayFeatures
                                     .firstOrNull() as? FoldingFeature
+                            windowLayoutInfo = layoutInfo
                         }
             }
         }



More information about the Android mailing list