[Android] Fix video player TV margins

Nicolas Pomepuy git at videolan.org
Tue Jun 30 14:06:25 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 25 11:16:53 2020 +0200| [7c87d8df0e19fc2890af4d3323e06a03c6bb972d] | committer: Nicolas Pomepuy

Fix video player TV margins

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

 .../src/main/res/drawable/ic_player_rotate.xml     |  4 +--
 .../resources/src/main/res/values-land/dimens.xml  |  2 +-
 application/vlc-android/res/layout/player.xml      |  2 +-
 application/vlc-android/res/layout/player_hud.xml  |  2 +-
 application/vlc-android/res/values/styles.xml      |  3 +-
 .../videolan/vlc/gui/video/VideoPlayerActivity.kt  | 40 ++++++++++++----------
 6 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/application/resources/src/main/res/drawable/ic_player_rotate.xml b/application/resources/src/main/res/drawable/ic_player_rotate.xml
index 2f3a0cace..9f28580db 100644
--- a/application/resources/src/main/res/drawable/ic_player_rotate.xml
+++ b/application/resources/src/main/res/drawable/ic_player_rotate.xml
@@ -1,6 +1,6 @@
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="36dp"
-    android:height="36dp"
+    android:width="28dp"
+    android:height="28dp"
     android:viewportWidth="36"
     android:viewportHeight="36">
   <path
diff --git a/application/resources/src/main/res/values-land/dimens.xml b/application/resources/src/main/res/values-land/dimens.xml
index 836b80fda..38075c607 100644
--- a/application/resources/src/main/res/values-land/dimens.xml
+++ b/application/resources/src/main/res/values-land/dimens.xml
@@ -3,7 +3,7 @@
     <dimen name="actionBarSize">48dp</dimen>
 
     <dimen name="large_margins_center">24dp</dimen>
-    <dimen name="small_margins_sides">8dp</dimen>
+    <dimen name="small_margins_sides">24dp</dimen>
 
 
 </resources>
\ No newline at end of file
diff --git a/application/vlc-android/res/layout/player.xml b/application/vlc-android/res/layout/player.xml
index a2d5cccf3..4e548b817 100644
--- a/application/vlc-android/res/layout/player.xml
+++ b/application/vlc-android/res/layout/player.xml
@@ -94,7 +94,7 @@
 
         <androidx.appcompat.widget.ViewStubCompat
                 android:id="@+id/player_hud_stub"
-                android:layout_width="800dp"
+                android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:layout="@layout/player_hud"
                 android:layout_alignParentBottom="true" />
diff --git a/application/vlc-android/res/layout/player_hud.xml b/application/vlc-android/res/layout/player_hud.xml
index f6583024e..b946baddd 100644
--- a/application/vlc-android/res/layout/player_hud.xml
+++ b/application/vlc-android/res/layout/player_hud.xml
@@ -27,7 +27,7 @@
 
     <androidx.constraintlayout.widget.ConstraintLayout
             android:id="@+id/progress_overlay"
-            android:layout_width="800dp"
+            android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:visibility="invisible"
             tools:theme="@style/Theme.VLC.Player"
diff --git a/application/vlc-android/res/values/styles.xml b/application/vlc-android/res/values/styles.xml
index 28c7b655e..7e09c4ef7 100644
--- a/application/vlc-android/res/values/styles.xml
+++ b/application/vlc-android/res/values/styles.xml
@@ -492,7 +492,8 @@
         <item name="android:shadowDx">0</item>
         <item name="android:shadowDy">2</item>
         <item name="android:shadowRadius">6</item>
-        <item name="android:padding">4dp</item>
+        <item name="android:paddingStart">4dp</item>
+        <item name="android:paddingEnd">4dp</item>
     </style>
 
     <style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar">
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 503008d99..a53c7d801 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
@@ -1982,7 +1982,7 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 hudBinding.playlistPrevious.visibility = if (show) View.VISIBLE else View.INVISIBLE
                 hudBinding.playlistNext.visibility = if (show) View.VISIBLE else View.INVISIBLE
             }
-            hudBinding.orientationToggle.visibility = if (isTv || AndroidDevices.isChromeBook) View.GONE else if (show) View.VISIBLE else View.INVISIBLE
+            hudBinding.orientationToggle.visibility = if (isTv || AndroidDevices.isChromeBook) View.INVISIBLE else if (show) View.VISIBLE else View.INVISIBLE
         }
         if (::hudRightBinding.isInitialized) {
             val secondary = displayManager.isSecondary
@@ -2045,12 +2045,6 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 hudBinding.statsClose.setOnClickListener { service.playlistManager.videoStatsOn.postValue(false) }
 
                 hudBinding.lifecycleOwner = this
-                val layoutParams = hudBinding.progressOverlay.layoutParams as RelativeLayout.LayoutParams
-                if (AndroidDevices.isPhone || !AndroidDevices.hasNavBar)
-                    layoutParams.width = LayoutParams.MATCH_PARENT
-                else
-                    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE)
-                hudBinding.progressOverlay.layoutParams = layoutParams
                 overlayBackground = findViewById(R.id.player_overlay_background)
                 navMenu = findViewById(R.id.player_overlay_navmenu)
                 if (!AndroidDevices.isChromeBook && !isTv
@@ -2067,15 +2061,6 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
 
                 if (seekButtons) initSeekButton()
 
-                //Set margins for TV overscan
-                if (isTv) {
-                    val hm = resources.getDimensionPixelSize(R.dimen.tv_overscan_horizontal)
-                    val vm = resources.getDimensionPixelSize(R.dimen.tv_overscan_vertical)
-
-                    val lp = vsc.layoutParams as RelativeLayout.LayoutParams
-                    lp.setMargins(hm, 0, hm, vm)
-                    vsc.layoutParams = lp
-                }
 
                 resetHudLayout()
                 updateOverlayPausePlay(true)
@@ -2110,6 +2095,9 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
 
 
     private fun updateHudMargins() {
+        //here, we override the default Android overscan
+        val overscanHorizontal = if (isTv) 32.dp else 0
+        val overscanVertical = if (isTv) resources.getDimension(R.dimen.tv_overscan_vertical).toInt() else 0
         if (::hudBinding.isInitialized) {
             val largeMargin = resources.getDimension(R.dimen.large_margins_center)
             val smallMargin = resources.getDimension(R.dimen.small_margins_sides)
@@ -2118,10 +2106,17 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
             applyMargin(hudBinding.playlistNext, largeMargin.toInt(), false)
             applyMargin(hudBinding.playerOverlayForward, largeMargin.toInt(), false)
 
-            applyMargin(hudBinding.playerOverlayTracks, smallMargin.toInt(), false)
+            applyMargin(hudBinding.playerOverlayTracks, if (!isTv) smallMargin.toInt() else overscanHorizontal, false)
             applyMargin(hudBinding.orientationToggle, smallMargin.toInt(), false)
             applyMargin(hudBinding.playerResize, smallMargin.toInt(), true)
-            applyMargin(hudBinding.playerOverlayAdvFunction, smallMargin.toInt(), true)
+            applyMargin(hudBinding.playerOverlayAdvFunction, if (!isTv) smallMargin.toInt() else overscanHorizontal, true)
+
+            hudBinding.playerOverlaySeekbar.setPadding(overscanHorizontal, 0, overscanHorizontal, 0)
+
+            if (isTv) {
+                applyMargin(hudBinding.playerOverlayTimeContainer, overscanHorizontal, false)
+                applyMargin(hudBinding.playerOverlayLengthContainer, overscanHorizontal, true)
+            }
 
             if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
                 hudBinding.playerSpaceLeft.setGone()
@@ -2130,7 +2125,9 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
                 hudBinding.playerSpaceLeft.setVisible()
                 hudBinding.playerSpaceRight.setVisible()
             }
-
+        }
+        if (::hudRightBinding.isInitialized) {
+            applyVerticalMargin(hudRightBinding.playerOverlayTitle, overscanVertical, false)
         }
     }
 
@@ -2139,6 +2136,11 @@ open class VideoPlayerActivity : AppCompatActivity(), PlaybackService.Callback,
         view.layoutParams = this
     }
 
+    private fun applyVerticalMargin(view: View, margin: Int, isBottom: Boolean) = (view.layoutParams as ConstraintLayout.LayoutParams).apply {
+        if (isBottom) bottomMargin = margin else topMargin = margin
+        view.layoutParams = this
+    }
+
     /**
      * hider overlay
      */



More information about the Android mailing list