[Android] Foldable: prevent audio tips to be displayed behind the hinge in portrait

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 07:58:58 2022 +0200| [f14e29cc6a258e27e5f11f5885ed84d7629e4a63] | committer: Duncan McNamara

Foldable: prevent audio tips to be displayed behind the hinge in portrait

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

 application/vlc-android/res/layout/audio_player_tips.xml     | 12 +++++++++---
 application/vlc-android/res/layout/audio_playlist_tips.xml   |  7 +++----
 .../org/videolan/vlc/gui/audio/AudioPlaylistTipsDelegate.kt  | 10 ++++++++--
 .../src/org/videolan/vlc/gui/audio/AudioTipsDelegate.kt      | 10 ++++++++--
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/res/layout/audio_player_tips.xml b/application/vlc-android/res/layout/audio_player_tips.xml
index 45a47fa33..cdd9e78b3 100644
--- a/application/vlc-android/res/layout/audio_player_tips.xml
+++ b/application/vlc-android/res/layout/audio_player_tips.xml
@@ -59,8 +59,7 @@
             android:id="@+id/guideline8"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:orientation="horizontal"
-            app:layout_constraintGuide_percent="0.5" />
+            android:orientation="horizontal"/>
 
     <TextView
             android:id="@+id/helpTitle"
@@ -74,7 +73,7 @@
             app:layout_constraintEnd_toStartOf="@+id/endGuideline"
             app:layout_constraintHorizontal_bias="0.5"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/close"
+            app:layout_constraintTop_toTopOf="@+id/topGuideline"
             app:layout_constraintVertical_chainStyle="packed"
             tools:text="Help title" />
 
@@ -103,6 +102,13 @@
             android:orientation="vertical"
             app:layout_constraintGuide_percent="1" />
 
+    <androidx.constraintlayout.widget.Guideline
+            android:id="@+id/topGuideline"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            app:layout_constraintGuide_percent="0" />
+
     <Button
             android:id="@+id/nextButton"
             style="@style/VLC.Tips.Button.Next"
diff --git a/application/vlc-android/res/layout/audio_playlist_tips.xml b/application/vlc-android/res/layout/audio_playlist_tips.xml
index a268201b2..110a0e1d2 100644
--- a/application/vlc-android/res/layout/audio_playlist_tips.xml
+++ b/application/vlc-android/res/layout/audio_playlist_tips.xml
@@ -70,7 +70,7 @@
             app:layout_constraintTop_toTopOf="@+id/close" />
 
     <androidx.constraintlayout.widget.Guideline
-            android:id="@+id/guideline8"
+            android:id="@+id/middleGuideline"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
@@ -80,8 +80,7 @@
             android:id="@+id/endGuideline"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:orientation="vertical"
-            app:layout_constraintGuide_percent="1" />
+            android:orientation="vertical"/>
 
     <TextView
             android:id="@+id/helpTitle"
@@ -120,7 +119,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:visibility="gone"
-            app:layout_constraintBottom_toTopOf="@+id/guideline8"
+            app:layout_constraintBottom_toTopOf="@+id/middleGuideline"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
             app:srcCompat="@drawable/tips_gesture_horizontal"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistTipsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistTipsDelegate.kt
index e8982d172..fd05bfd7c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistTipsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistTipsDelegate.kt
@@ -53,6 +53,7 @@ import org.videolan.vlc.gui.AudioPlayerContainerActivity
 import org.videolan.vlc.gui.helpers.TipsUtils
 import org.videolan.vlc.gui.helpers.UiTools.isTablet
 import org.videolan.vlc.media.MediaUtils
+import org.videolan.vlc.util.getScreenHeight
 import org.videolan.vlc.util.getScreenWidth
 import org.videolan.vlc.viewmodels.PlaylistModel
 
@@ -78,6 +79,7 @@ class AudioPlaylistTipsDelegate(private val activity: AudioPlayerContainerActivi
     private lateinit var helpTitle: TextView
     private lateinit var helpDescription: TextView
     private var rightGuidelineEndBound = 1F
+    private var middleGuidelineEndBound = 0.5F
 
     fun init(vsc: ViewStubCompat?) {
         vsc?.inflate()
@@ -134,8 +136,11 @@ class AudioPlaylistTipsDelegate(private val activity: AudioPlayerContainerActivi
         audioPlaylistTips.setVisible()
         activity.lifecycleScope.launch(Dispatchers.Main) { next() }
         (activity.windowLayoutInfo?.displayFeatures?.firstOrNull() as? FoldingFeature)?.let {foldingFeature ->
-            if (foldingFeature.occlusionType == FoldingFeature.OcclusionType.FULL && foldingFeature.orientation == FoldingFeature.Orientation.VERTICAL) {
-                rightGuidelineEndBound = foldingFeature.bounds.left.toFloat() / activity.getScreenWidth()
+            if (foldingFeature.occlusionType == FoldingFeature.OcclusionType.FULL) {
+                if (foldingFeature.orientation == FoldingFeature.Orientation.VERTICAL)
+                    rightGuidelineEndBound = foldingFeature.bounds.left.toFloat() / activity.getScreenWidth()
+                else
+                    middleGuidelineEndBound = (foldingFeature.bounds.bottom.toFloat() + ((activity.getScreenHeight() - foldingFeature.bounds.bottom.toFloat()) / 2)) / activity.getScreenHeight()
             }
         }
     }
@@ -280,6 +285,7 @@ class AudioPlaylistTipsDelegate(private val activity: AudioPlayerContainerActivi
         nextButton.setText(R.string.next_step)
 
         constraintSet.setGuidelinePercent(R.id.endGuideline, rightGuidelineEndBound)
+        constraintSet.setGuidelinePercent(R.id.middleGuideline, middleGuidelineEndBound)
         when (currentTip) {
             AudioPlaylistTipsStep.REMOVE -> {
                 if (activity.isTablet()){
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioTipsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioTipsDelegate.kt
index 8e754b372..058935357 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioTipsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioTipsDelegate.kt
@@ -46,6 +46,7 @@ import org.videolan.vlc.R
 import org.videolan.vlc.gui.AudioPlayerContainerActivity
 import org.videolan.vlc.gui.helpers.TipsUtils
 import org.videolan.vlc.gui.helpers.UiTools.isTablet
+import org.videolan.vlc.util.getScreenHeight
 import org.videolan.vlc.util.getScreenWidth
 
 class AudioTipsDelegate(private val activity: AudioPlayerContainerActivity) {
@@ -62,6 +63,7 @@ class AudioTipsDelegate(private val activity: AudioPlayerContainerActivity) {
     private lateinit var helpTitle: TextView
     private lateinit var helpDescription: TextView
     private var rightGuidelineEndBound = 1F
+    private var topGuidelineEndBound = 0F
 
     private val transition = Fade().apply {
         interpolator = AccelerateDecelerateInterpolator()
@@ -94,8 +96,11 @@ class AudioTipsDelegate(private val activity: AudioPlayerContainerActivity) {
         audioPlayerTips.setOnTouchListener { _, _ -> true }
         activity.lifecycleScope.launch(Dispatchers.Main) { next() }
         (activity.windowLayoutInfo?.displayFeatures?.firstOrNull() as? FoldingFeature)?.let {foldingFeature ->
-            if (foldingFeature.occlusionType == FoldingFeature.OcclusionType.FULL && foldingFeature.orientation == FoldingFeature.Orientation.VERTICAL) {
-                rightGuidelineEndBound = foldingFeature.bounds.left.toFloat() / activity.getScreenWidth()
+            if (foldingFeature.occlusionType == FoldingFeature.OcclusionType.FULL) {
+                if (foldingFeature.orientation == FoldingFeature.Orientation.VERTICAL)
+                    rightGuidelineEndBound = foldingFeature.bounds.left.toFloat() / activity.getScreenWidth()
+                else
+                    topGuidelineEndBound = foldingFeature.bounds.bottom.toFloat() / activity.getScreenHeight()
             }
         }
     }
@@ -123,6 +128,7 @@ class AudioTipsDelegate(private val activity: AudioPlayerContainerActivity) {
         nextButton.setText(R.string.next_step)
 
         constraintSet.setGuidelinePercent(R.id.endGuideline, rightGuidelineEndBound)
+        constraintSet.setGuidelinePercent(R.id.topGuideline, topGuidelineEndBound)
         when (currentTip) {
             AudioPlayerTipsStep.SWIPE_NEXT -> {
                 if (activity.isTablet()) {



More information about the Android mailing list