OSDN Git Service

Add ability to fling to dismiss PIP from anywhere
authorMady Mellor <madym@google.com>
Wed, 5 Apr 2017 00:25:43 +0000 (17:25 -0700)
committerMady Mellor <madym@google.com>
Tue, 25 Apr 2017 19:08:08 +0000 (12:08 -0700)
This is by default turned off and is behind a tuner flag.

Allows the PIP to be dismissed if it is flung towards the bottom center
of the screen and the finger is released within the bottom area of the
screen.

Test: Manual - enable tuner setting, have a PIP, position it at top of
      screen, long- fling it towards bottom center of screen, it dismisses.
Bug: 35358628
Change-Id: I2d3d50093f6523c7bb321e0486dab360095a398e

packages/SystemUI/res/values/strings.xml
packages/SystemUI/res/xml/tuner_prefs.xml
packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java

index 9fb884e..afc570f 100644 (file)
     <!-- PiP minimize description. [CHAR LIMIT=NONE] -->
     <string name="pip_minimize_description" translatable="false">Drag or fling the PIP to the edges of the screen to minimize it.</string>
 
+    <!-- PiP fling to dismiss title. [CHAR LIMIT=NONE]-->
+    <string name="pip_fling_dismiss_title" translatable="false">Fling to dismiss</string>
+
+    <!-- PiP fling to dismiss description. [CHAR LIMIT=NONE] -->
+    <string name="pip_fling_dismiss_description" translatable="false">Fling from anywhere on the screen to the bottom of the screen to dismiss the PIP.</string>
+
     <!-- Button to play the current media on picture-in-picture (PIP) [CHAR LIMIT=30] -->
     <string name="pip_play">Play</string>
 
index a685c79..523dd9f 100644 (file)
         android:summary="@string/pip_minimize_description"
         sysui:defValue="false" />
 
+      <com.android.systemui.tuner.TunerSwitch
+        android:key="pip_fling_dismiss"
+        android:title="@string/pip_fling_dismiss_title"
+        android:summary="@string/pip_fling_dismiss_description"
+        sysui:defValue="false" />
+
     </PreferenceScreen>
 
     <PreferenceScreen
index 67255d3..fc52a2e 100644 (file)
@@ -465,6 +465,26 @@ public class PipMotionHelper {
     }
 
     /**
+     * @return whether the gesture it towards the dismiss area based on the velocity when
+     *         dismissing.
+     */
+    public boolean isGestureToDismissArea(Rect pipBounds, float velX, float velY,
+            boolean isFling) {
+        Point endpoint = getDismissEndPoint(pipBounds, velX, velY, isFling);
+        // Center the point
+        endpoint.x += pipBounds.width() / 2;
+        endpoint.y += pipBounds.height() / 2;
+
+        // The dismiss area is the middle third of the screen, half the PIP's height from the bottom
+        Point size = new Point();
+        mContext.getDisplay().getRealSize(size);
+        final int left = size.x / 3;
+        Rect dismissArea = new Rect(left, size.y - (pipBounds.height() / 2), left * 2,
+                size.y + pipBounds.height());
+        return dismissArea.contains(endpoint.x, endpoint.y);
+    }
+
+    /**
      * @return the distance between points {@param p1} and {@param p2}.
      */
     private float distanceBetweenRectOffsets(Rect r1, Rect r2) {
index 3223f9f..f586ec6 100644 (file)
@@ -58,6 +58,7 @@ public class PipTouchHandler implements TunerService.Tunable {
     private static final String TAG = "PipTouchHandler";
 
     private static final String TUNER_KEY_MINIMIZE = "pip_minimize";
+    private static final String TUNER_KEY_FLING_DISMISS = "pip_fling_dismiss";
 
     // These values are used for metrics and should never change
     private static final int METRIC_VALUE_DISMISSED_BY_TAP = 0;
@@ -114,6 +115,8 @@ public class PipTouchHandler implements TunerService.Tunable {
 
     // Allow the PIP to be dragged to the edge of the screen to be minimized.
     private boolean mEnableMinimize = false;
+    // Allow the PIP to be flung from anywhere on the screen to the bottom to be dismissed.
+    private boolean mEnableFlingToDismiss = false;
 
     // Behaviour states
     private int mMenuState;
@@ -195,6 +198,7 @@ public class PipTouchHandler implements TunerService.Tunable {
 
         // Register any tuner settings changes
         Dependency.get(TunerService.class).addTunable(this, TUNER_KEY_MINIMIZE);
+        Dependency.get(TunerService.class).addTunable(this, TUNER_KEY_FLING_DISMISS);
 
         // Register the listener for input consumer touch events
         inputConsumerController.setTouchListener(this::handleTouchEvent);
@@ -238,14 +242,12 @@ public class PipTouchHandler implements TunerService.Tunable {
 
     @Override
     public void onTuningChanged(String key, String newValue) {
-        if (newValue == null) {
-            // Reset back to default
-            mEnableMinimize = false;
-            return;
-        }
         switch (key) {
             case TUNER_KEY_MINIMIZE:
-                mEnableMinimize = Integer.parseInt(newValue) != 0;
+                mEnableMinimize = newValue == null ? false : Integer.parseInt(newValue) != 0;
+                break;
+            case TUNER_KEY_FLING_DISMISS:
+                mEnableFlingToDismiss = newValue == null ? false : Integer.parseInt(newValue) != 0;
                 break;
         }
     }
@@ -631,8 +633,12 @@ public class PipTouchHandler implements TunerService.Tunable {
             final boolean isHorizontal = Math.abs(vel.x) > Math.abs(vel.y);
             final float velocity = PointF.length(vel.x, vel.y);
             final boolean isFling = velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond();
-            final boolean isFlingToBot = isFling
-                    && !isHorizontal && mMovementWithinDismiss && vel.y > 0;
+            final boolean isUpWithinDimiss = mEnableFlingToDismiss
+                    && touchState.getLastTouchPosition().y >= mMovementBounds.bottom
+                    && mMotionHelper.isGestureToDismissArea(mMotionHelper.getBounds(), vel.x,
+                            vel.y, isFling);
+            final boolean isFlingToBot = isFling && vel.y > 0 && !isHorizontal
+                    && (mMovementWithinDismiss || isUpWithinDimiss);
             if (ENABLE_DISMISS_DRAG_TO_EDGE) {
                 try {
                     mHandler.removeCallbacks(mShowDismissAffordance);