[Android] Allow users to force the legacy popup for PiP

Nicolas Pomepuy git at videolan.org
Tue Apr 9 10:51:16 CEST 2019


vlc-android | branch: force_custom_video_popup | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Apr  9 10:51:12 2019 +0200| [0e16a538f4696843ce6a94bc6f51544e218fba75] | committer: Nicolas Pomepuy

Allow users to force the legacy popup for PiP

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

 vlc-android/res/values/strings.xml                       |  3 +++
 vlc-android/res/xml/preferences_video.xml                |  6 ++++++
 .../org/videolan/vlc/gui/helpers/NotificationHelper.java |  7 +++++++
 .../videolan/vlc/gui/preferences/PreferencesVideo.java   |  4 +++-
 .../src/org/videolan/vlc/gui/video/PopupManager.java     |  2 +-
 .../org/videolan/vlc/gui/video/VideoPlayerActivity.java  |  4 +++-
 .../src/org/videolan/vlc/gui/view/PopupLayout.java       | 16 +++++++++-------
 7 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 3b13f96f9..334516079 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -690,4 +690,7 @@
     <string name="button_medialibrary_preferences">Go to Medialibrary preferences</string>
     <string name="light_theme">Light theme</string>
     <string name="theme_follow_system_mode">Follow system mode</string>
+    <string name="misc">Miscellaneous</string>
+    <string name="popup_force_legacy_title">Use custom Picture-in-Picture popup</string>
+    <string name="popup_force_legacy_summary">Use custom Picture-in-Picture resizable popup</string>
 </resources>
diff --git a/vlc-android/res/xml/preferences_video.xml b/vlc-android/res/xml/preferences_video.xml
index 06c57c386..d35e03d88 100644
--- a/vlc-android/res/xml/preferences_video.xml
+++ b/vlc-android/res/xml/preferences_video.xml
@@ -44,6 +44,12 @@
         android:summary="@string/video_transition_summary"
         android:title="@string/video_transition_title" />
 
+    <CheckBoxPreference
+        android:defaultValue="false"
+        android:key="popup_force_legacy"
+        android:summary="@string/popup_force_legacy_summary"
+        android:title="@string/popup_force_legacy_title" />
+
     <PreferenceCategory android:title="@string/controls_prefs_category">
         <CheckBoxPreference
             android:defaultValue="false"
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java b/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
index 8e8c8429c..8ae4782ba 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/NotificationHelper.java
@@ -145,6 +145,13 @@ public class NotificationHelper {
         channel.setDescription(description);
         channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
         notificationManager.createNotificationChannel(channel);
+
+        // Misc channel
+        name = appCtx.getString(R.string.misc);
+        channel = new NotificationChannel("misc", name, NotificationManager.IMPORTANCE_LOW);
+        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
+        notificationManager.createNotificationChannel(channel);
+
         // Recommendations channel
         if (AndroidDevices.isAndroidTv) {
             name = appCtx.getString(R.string.recommendations);
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
index 583d89e73..7480eacff 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.java
@@ -23,11 +23,12 @@
 package org.videolan.vlc.gui.preferences;
 
 import android.os.Bundle;
-import androidx.preference.Preference;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.R;
 
+import androidx.preference.Preference;
+
 public class PreferencesVideo extends BasePreferenceFragment {
 
     @Override
@@ -44,6 +45,7 @@ public class PreferencesVideo extends BasePreferenceFragment {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         findPreference("popup_keepscreen").setVisible(!AndroidUtil.isOOrLater);
+        findPreference("popup_force_legacy").setVisible(AndroidUtil.isOOrLater);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
index a37b1e63d..f221154f7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
@@ -281,7 +281,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
     @SuppressWarnings("deprecation")
     private void showNotification() {
         final PendingIntent piStop = KextensionsKt.getPendingIntent(mService, new Intent(Constants.ACTION_REMOTE_STOP));
-        final NotificationCompat.Builder builder = new NotificationCompat.Builder(mService)
+        final NotificationCompat.Builder builder = new NotificationCompat.Builder(mService, "misc")
                 .setSmallIcon(R.drawable.ic_notif_video)
                 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                 .setContentTitle(mService.getTitle())
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index d9029e2fe..b5c821677 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -491,7 +491,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
         final MediaWrapper mw = mService != null ? mService.getCurrentMediaWrapper() : null;
         if (mw == null || !AndroidDevices.pipAllowed
                 || !getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return;
-        if (AndroidDevices.hasPiP) {
+
+        boolean forceLegacy = Settings.INSTANCE.getInstance(this).getBoolean("popup_force_legacy", false);
+        if (AndroidDevices.hasPiP && !forceLegacy) {
             if (AndroidUtil.isOOrLater) try {
                 final SurfaceView videoSurface = (SurfaceView) (mVideoLayout != null ? mVideoLayout.findViewById(R.id.surface_video) : null);
                 final int height = videoSurface != null && videoSurface.getHeight() != 0 ? videoSurface.getHeight() : mw.getHeight();
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.java b/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.java
index 4f7ccf700..f002fc044 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/PopupLayout.java
@@ -29,7 +29,6 @@ import android.content.Context;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
 import android.os.Build;
-import androidx.core.view.GestureDetectorCompat;
 import android.util.AttributeSet;
 import android.view.Gravity;
 import android.view.MotionEvent;
@@ -39,8 +38,10 @@ import android.view.WindowManager;
 import android.widget.RelativeLayout;
 
 import org.videolan.libvlc.IVLCVout;
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.R;
-import org.videolan.vlc.VLCApplication;
+
+import androidx.core.view.GestureDetectorCompat;
 
 public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.OnScaleGestureListener, View.OnTouchListener {
     private static final String TAG = "VLC/PopupView";
@@ -100,7 +101,7 @@ public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.
             height = height * mScreenWidth / width;
             width = mScreenWidth;
         }
-        if (height > mScreenHeight){
+        if (height > mScreenHeight) {
             width = width * mScreenHeight / height;
             height = mScreenHeight;
         }
@@ -121,7 +122,7 @@ public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.
         final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                 mPopupWidth,
                 mPopupHeight,
-                WindowManager.LayoutParams.TYPE_PHONE,
+                AndroidUtil.isOOrLater ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : WindowManager.LayoutParams.TYPE_PHONE,
                 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                 PixelFormat.OPAQUE);
 
@@ -131,7 +132,7 @@ public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.
         mScaleGestureDetector = new ScaleGestureDetector(context, this);
         setOnTouchListener(this);
         mWindowManager.addView(this, params);
-        mLayoutParams = (WindowManager.LayoutParams)getLayoutParams();
+        mLayoutParams = (WindowManager.LayoutParams) getLayoutParams();
 
         updateWindowSize();
     }
@@ -178,10 +179,11 @@ public class PopupLayout extends RelativeLayout implements ScaleGestureDetector.
         mScaleFactor *= detector.getScaleFactor();
 
         mScaleFactor = Math.max(0.1d, Math.min(mScaleFactor, 5.0d));
-        mPopupWidth = (int) (getWidth()*mScaleFactor);
-        mPopupHeight = (int) (getHeight()*mScaleFactor);
+        mPopupWidth = (int) (getWidth() * mScaleFactor);
+        mPopupHeight = (int) (getHeight() * mScaleFactor);
         return true;
     }
+
     @Override
     public boolean onScaleBegin(ScaleGestureDetector detector) {
         return true;



More information about the Android mailing list