[Android] Custom PiP: save and restore popup size

Nicolas Pomepuy git at videolan.org
Mon Jun 13 12:54:52 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun  9 10:14:30 2022 +0200| [f864dba380085b1de7216a9823f986882df1eedd] | committer: Duncan McNamara

Custom PiP: save and restore popup size

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

 .../tools/src/main/java/org/videolan/tools/Settings.kt     |  1 +
 .../src/org/videolan/vlc/gui/view/PopupLayout.kt           | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 42617456c..79a58adf2 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -165,6 +165,7 @@ const val PERMISSION_NEVER_ASK = "permission_never_ask"
 
 const val WIDGETS_BACKGROUND_LAST_COLORS = "widgets_background_last_colors"
 const val WIDGETS_FOREGROUND_LAST_COLORS = "widgets_foreground_last_colors"
+const val CUSTOM_POPUP_HEIGHT = "custom_popup_height"
 
 class DeviceInfo(context: Context) {
     val pm = context.packageManager
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.kt
index dd5e3c419..c3644a45e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.kt
@@ -28,16 +28,21 @@ import android.content.Context
 import android.graphics.PixelFormat
 import android.graphics.Point
 import android.util.AttributeSet
+import android.util.DisplayMetrics
 import android.view.*
 import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.content.getSystemService
 import androidx.core.view.GestureDetectorCompat
 import org.videolan.libvlc.interfaces.IVLCVout
 import org.videolan.libvlc.util.AndroidUtil
+import org.videolan.tools.CUSTOM_POPUP_HEIGHT
+import org.videolan.tools.Settings
+import org.videolan.tools.putSingle
 import org.videolan.vlc.R
 
 class PopupLayout : ConstraintLayout, ScaleGestureDetector.OnScaleGestureListener, View.OnTouchListener {
 
+    private lateinit var screenSize: DisplayMetrics
     private var vlcVout: IVLCVout? = null
     private var windowManager: WindowManager? = null
     private var gestureDetector: GestureDetectorCompat? = null
@@ -110,8 +115,16 @@ class PopupLayout : ConstraintLayout, ScaleGestureDetector.OnScaleGestureListene
     private fun init(context: Context) {
         windowManager = context.applicationContext.getSystemService()
 
+        screenSize = DisplayMetrics().also { windowManager!!.defaultDisplay.getMetrics(it) }
         popupWidth = context.resources.getDimensionPixelSize(R.dimen.video_pip_width)
         popupHeight = context.resources.getDimensionPixelSize(R.dimen.video_pip_height)
+        val ratio = popupWidth.toFloat() / popupHeight.toFloat()
+        val customPopupHeight = Settings.getInstance(context).getInt(CUSTOM_POPUP_HEIGHT, -1)
+        if (customPopupHeight != -1) {
+            popupHeight = customPopupHeight
+            popupWidth = (popupHeight.toFloat() * ratio).toInt()
+        }
+
         val params = WindowManager.LayoutParams(
                 popupWidth,
                 popupHeight,
@@ -182,6 +195,7 @@ class PopupLayout : ConstraintLayout, ScaleGestureDetector.OnScaleGestureListene
 
     override fun onScaleEnd(detector: ScaleGestureDetector) {
         setViewSize(popupWidth, popupHeight)
+        Settings.getInstance(context).putSingle(CUSTOM_POPUP_HEIGHT, popupHeight)
         scaleFactor = 1.0
     }
 



More information about the Android mailing list