summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/policy/PipSnapAlgorithm.java2
-rw-r--r--packages/SystemUI/res/layout/pip_menu_activity.xml89
-rw-r--r--packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java59
-rw-r--r--packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java81
-rw-r--r--packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java28
-rw-r--r--packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java45
6 files changed, 217 insertions, 87 deletions
diff --git a/core/java/com/android/internal/policy/PipSnapAlgorithm.java b/core/java/com/android/internal/policy/PipSnapAlgorithm.java
index ae31873492e9..95d714f1c3c7 100644
--- a/core/java/com/android/internal/policy/PipSnapAlgorithm.java
+++ b/core/java/com/android/internal/policy/PipSnapAlgorithm.java
@@ -321,7 +321,7 @@ public class PipSnapAlgorithm {
stackBounds.top));
boundsOut.set(stackBounds);
if (mIsMinimized) {
- boundsOut.offsetTo(boundedLeft, boundsOut.top);
+ boundsOut.offsetTo(boundedLeft, boundedTop);
return;
}
diff --git a/packages/SystemUI/res/layout/pip_menu_activity.xml b/packages/SystemUI/res/layout/pip_menu_activity.xml
index 5e49d058cd84..c6837fa30925 100644
--- a/packages/SystemUI/res/layout/pip_menu_activity.xml
+++ b/packages/SystemUI/res/layout/pip_menu_activity.xml
@@ -15,50 +15,55 @@
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/menu"
+ android:id="@+id/background"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#4D000000">
- <!-- The above background is only for the dismiss button ripple to show. -->
+ android:layout_height="match_parent">
- <ImageView
- android:id="@+id/dismiss"
- android:layout_width="@dimen/pip_action_size"
- android:layout_height="@dimen/pip_action_size"
- android:layout_gravity="top|end"
- android:padding="@dimen/pip_action_padding"
- android:contentDescription="@string/pip_phone_close"
- android:src="@drawable/ic_close_white"
- android:background="?android:selectableItemBackgroundBorderless" />
+ <!-- Menu layout -->
+ <FrameLayout
+ android:id="@+id/menu_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
- <!-- The margins for this container is calculated in the code depending on whether the
- actions_container is visible. -->
- <FrameLayout
- android:id="@+id/expand_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:id="@+id/expand_button"
- android:layout_width="60dp"
- android:layout_height="60dp"
- android:layout_gravity="center"
- android:contentDescription="@string/pip_phone_expand"
- android:background="?android:selectableItemBackgroundBorderless" />
- </FrameLayout>
+ <ImageView
+ android:id="@+id/dismiss"
+ android:layout_width="@dimen/pip_action_size"
+ android:layout_height="@dimen/pip_action_size"
+ android:layout_gravity="top|end"
+ android:padding="@dimen/pip_action_padding"
+ android:contentDescription="@string/pip_phone_close"
+ android:src="@drawable/ic_close_white"
+ android:background="?android:selectableItemBackgroundBorderless" />
- <FrameLayout
- android:id="@+id/actions_container"
- android:layout_width="match_parent"
- android:layout_height="@dimen/pip_action_size"
- android:layout_gravity="bottom"
- android:visibility="invisible">
- <LinearLayout
- android:id="@+id/actions_group"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_gravity="center_horizontal"
- android:orientation="horizontal"
- android:divider="@android:color/transparent"
- android:showDividers="middle" />
- </FrameLayout>
+ <!-- The margins for this container is calculated in the code depending on whether the
+ actions_container is visible. -->
+ <FrameLayout
+ android:id="@+id/expand_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+ <ImageView
+ android:id="@+id/expand_button"
+ android:layout_width="60dp"
+ android:layout_height="60dp"
+ android:layout_gravity="center"
+ android:contentDescription="@string/pip_phone_expand"
+ android:background="?android:selectableItemBackgroundBorderless" />
+ </FrameLayout>
+
+ <FrameLayout
+ android:id="@+id/actions_container"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/pip_action_size"
+ android:layout_gravity="bottom"
+ android:visibility="invisible">
+ <LinearLayout
+ android:id="@+id/actions_group"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_gravity="center_horizontal"
+ android:orientation="horizontal"
+ android:divider="@android:color/transparent"
+ android:showDividers="middle" />
+ </FrameLayout>
+ </FrameLayout>
</FrameLayout>
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java
index 86e2c4956070..2f9c3fc3368a 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivity.java
@@ -20,10 +20,12 @@ import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_ACT
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_CONTROLLER_MESSENGER;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_MOVEMENT_BOUNDS;
import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_STACK_BOUNDS;
+import static com.android.systemui.pip.phone.PipMenuActivityController.EXTRA_SHOW_MENU;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
@@ -35,6 +37,8 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.os.Handler;
@@ -71,13 +75,19 @@ public class PipMenuActivity extends Activity {
public static final int MESSAGE_POKE_MENU = 2;
public static final int MESSAGE_HIDE_MENU = 3;
public static final int MESSAGE_UPDATE_ACTIONS = 4;
+ public static final int MESSAGE_UPDATE_DISMISS_FRACTION = 5;
private static final long INITIAL_DISMISS_DELAY = 2000;
private static final long POST_INTERACTION_DISMISS_DELAY = 1500;
private static final long MENU_FADE_DURATION = 125;
+ private static final float MENU_BACKGROUND_ALPHA = 0.3f;
+ private static final float DISMISS_BACKGROUND_ALPHA = 0.8f;
+
private boolean mMenuVisible;
private final List<RemoteAction> mActions = new ArrayList<>();
+ private View mViewRoot;
+ private Drawable mBackgroundDrawable;
private View mMenuContainer;
private LinearLayout mActionsGroup;
private View mDismissButton;
@@ -85,6 +95,14 @@ public class PipMenuActivity extends Activity {
private int mBetweenActionPaddingLand;
private ObjectAnimator mMenuContainerAnimator;
+ private ValueAnimator.AnimatorUpdateListener mMenuBgUpdateListener =
+ new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ final float alpha = (float) animation.getAnimatedValue();
+ mBackgroundDrawable.setAlpha((int) (MENU_BACKGROUND_ALPHA*alpha*255));
+ }
+ };
private PointF mDownPosition = new PointF();
private PointF mDownDelta = new PointF();
@@ -109,6 +127,10 @@ public class PipMenuActivity extends Activity {
Pair<Rect, ParceledListSlice> data = (Pair<Rect, ParceledListSlice>) msg.obj;
setActions(data.first, data.second.getList());
break;
+ case MESSAGE_UPDATE_DISMISS_FRACTION:
+ float fraction = (float) msg.obj;
+ updateDismissFraction(fraction);
+ break;
}
}
});
@@ -130,7 +152,12 @@ public class PipMenuActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.pip_menu_activity);
- mMenuContainer = findViewById(R.id.menu);
+ mBackgroundDrawable = new ColorDrawable(Color.BLACK);
+ mBackgroundDrawable.setAlpha(0);
+ mViewRoot = findViewById(R.id.background);
+ mViewRoot.setBackground(mBackgroundDrawable);
+ mMenuContainer = findViewById(R.id.menu_container);
+ mMenuContainer.setAlpha(0);
mMenuContainer.setOnClickListener((v) -> {
expandPip();
});
@@ -222,10 +249,10 @@ public class PipMenuActivity extends Activity {
private void showMenu(Rect stackBounds, Rect movementBounds) {
if (!mMenuVisible) {
+ updateActionViews(stackBounds);
if (mMenuContainerAnimator != null) {
mMenuContainerAnimator.cancel();
}
-
notifyMenuVisibility(true);
updateExpandButtonFromBounds(stackBounds, movementBounds);
mMenuContainerAnimator = ObjectAnimator.ofFloat(mMenuContainer, View.ALPHA,
@@ -238,6 +265,7 @@ public class PipMenuActivity extends Activity {
repostDelayedFinish(INITIAL_DISMISS_DELAY);
}
});
+ mMenuContainerAnimator.addUpdateListener(mMenuBgUpdateListener);
mMenuContainerAnimator.start();
} else {
repostDelayedFinish(POST_INTERACTION_DISMISS_DELAY);
@@ -269,20 +297,24 @@ public class PipMenuActivity extends Activity {
}
}
});
+ mMenuContainerAnimator.addUpdateListener(mMenuBgUpdateListener);
mMenuContainerAnimator.start();
}
}
private void updateFromIntent(Intent intent) {
- Rect stackBounds = Rect.unflattenFromString(intent.getStringExtra(EXTRA_STACK_BOUNDS));
- Rect movementBounds = Rect.unflattenFromString(intent.getStringExtra(
- EXTRA_MOVEMENT_BOUNDS));
mToControllerMessenger = intent.getParcelableExtra(EXTRA_CONTROLLER_MESSENGER);
ParceledListSlice actions = intent.getParcelableExtra(EXTRA_ACTIONS);
if (actions != null) {
- setActions(stackBounds, actions.getList());
+ mActions.clear();
+ mActions.addAll(actions.getList());
+ }
+ if (intent.getBooleanExtra(EXTRA_SHOW_MENU, false)) {
+ Rect stackBounds = Rect.unflattenFromString(intent.getStringExtra(EXTRA_STACK_BOUNDS));
+ Rect movementBounds = Rect.unflattenFromString(intent.getStringExtra(
+ EXTRA_MOVEMENT_BOUNDS));
+ showMenu(stackBounds, movementBounds);
}
- showMenu(stackBounds, movementBounds);
}
private void updateExpandButtonFromBounds(Rect stackBounds, Rect movementBounds) {
@@ -365,6 +397,19 @@ public class PipMenuActivity extends Activity {
}
}
+ private void updateDismissFraction(float fraction) {
+ int alpha;
+ if (mMenuVisible) {
+ mMenuContainer.setAlpha(1-fraction);
+ final float interpolatedAlpha =
+ MENU_BACKGROUND_ALPHA * (1.0f - fraction) + DISMISS_BACKGROUND_ALPHA * fraction;
+ alpha = (int) (interpolatedAlpha*255);
+ } else {
+ alpha = (int) (fraction*DISMISS_BACKGROUND_ALPHA*255);
+ }
+ mBackgroundDrawable.setAlpha(alpha);
+ }
+
private void notifyRegisterInputConsumer() {
Message m = Message.obtain();
m.what = PipMenuActivityController.MESSAGE_REGISTER_INPUT_CONSUMER;
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
index badf64b90b8f..7dc455bd0d2c 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMenuActivityController.java
@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Manages the PiP menu activity.
+ * Manages the PiP menu activity which can show menu options or a scrim.
*
* The current media session provides actions whenever there are no valid actions provided by the
* current PiP activity. Otherwise, those actions always take precedence.
@@ -55,6 +55,7 @@ public class PipMenuActivityController {
public static final String EXTRA_ACTIONS = "actions";
public static final String EXTRA_STACK_BOUNDS = "stack_bounds";
public static final String EXTRA_MOVEMENT_BOUNDS = "movement_bounds";
+ public static final String EXTRA_SHOW_MENU = "show_menu";
public static final int MESSAGE_MENU_VISIBILITY_CHANGED = 100;
public static final int MESSAGE_EXPAND_PIP = 101;
@@ -101,6 +102,7 @@ public class PipMenuActivityController {
private ParceledListSlice mMediaActions;
private boolean mMenuVisible;
+ private boolean mStartActivityRequested;
private Messenger mToActivityMessenger;
private Messenger mMessenger = new Messenger(new Handler() {
@Override
@@ -135,6 +137,7 @@ public class PipMenuActivityController {
}
case MESSAGE_UPDATE_ACTIVITY_CALLBACK: {
mToActivityMessenger = msg.replyTo;
+ mStartActivityRequested = false;
// Mark the menu as invisible once the activity finishes as well
if (mToActivityMessenger == null) {
onMenuVisibilityChanged(false, true /* resize */);
@@ -179,6 +182,25 @@ public class PipMenuActivityController {
}
/**
+ * Updates the appearance of the menu and scrim on top of the PiP while dismissing.
+ */
+ public void setDismissFraction(float fraction) {
+ if (mToActivityMessenger != null) {
+ Message m = Message.obtain();
+ m.what = PipMenuActivity.MESSAGE_UPDATE_DISMISS_FRACTION;
+ m.obj = fraction;
+ try {
+ mToActivityMessenger.send(m);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Could not notify menu to show", e);
+ }
+ } else if (!mStartActivityRequested) {
+ startMenuActivity(null /* stackBounds */, null /* movementBounds */,
+ false /* showMenu */);
+ }
+ }
+
+ /**
* Shows the menu activity.
*/
public void showMenu(Rect stackBounds, Rect movementBounds) {
@@ -191,28 +213,8 @@ public class PipMenuActivityController {
} catch (RemoteException e) {
Log.e(TAG, "Could not notify menu to show", e);
}
- } else {
- // Start the menu activity on the top task of the pinned stack
- try {
- StackInfo pinnedStackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
- if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null &&
- pinnedStackInfo.taskIds.length > 0) {
- Intent intent = new Intent(mContext, PipMenuActivity.class);
- intent.putExtra(EXTRA_CONTROLLER_MESSENGER, mMessenger);
- intent.putExtra(EXTRA_ACTIONS, resolveMenuActions());
- intent.putExtra(EXTRA_STACK_BOUNDS, stackBounds.flattenToString());
- intent.putExtra(EXTRA_MOVEMENT_BOUNDS, movementBounds.flattenToString());
- ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0);
- options.setLaunchTaskId(
- pinnedStackInfo.taskIds[pinnedStackInfo.taskIds.length - 1]);
- options.setTaskOverlay(true, true /* canResume */);
- mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
- } else {
- Log.e(TAG, "No PIP tasks found");
- }
- } catch (RemoteException e) {
- Log.e(TAG, "Error showing PIP menu activity", e);
- }
+ } else if (!mStartActivityRequested) {
+ startMenuActivity(stackBounds, movementBounds, true /* showMenu */);
}
}
@@ -272,6 +274,39 @@ public class PipMenuActivityController {
}
/**
+ * Starts the menu activity on the top task of the pinned stack.
+ */
+ private void startMenuActivity(Rect stackBounds, Rect movementBounds, boolean showMenu) {
+ try {
+ StackInfo pinnedStackInfo = mActivityManager.getStackInfo(PINNED_STACK_ID);
+ if (pinnedStackInfo != null && pinnedStackInfo.taskIds != null &&
+ pinnedStackInfo.taskIds.length > 0) {
+ Intent intent = new Intent(mContext, PipMenuActivity.class);
+ intent.putExtra(EXTRA_CONTROLLER_MESSENGER, mMessenger);
+ intent.putExtra(EXTRA_ACTIONS, resolveMenuActions());
+ if (stackBounds != null) {
+ intent.putExtra(EXTRA_STACK_BOUNDS, stackBounds.flattenToString());
+ }
+ if (movementBounds != null) {
+ intent.putExtra(EXTRA_MOVEMENT_BOUNDS, movementBounds.flattenToString());
+ }
+ intent.putExtra(EXTRA_SHOW_MENU, showMenu);
+ ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0);
+ options.setLaunchTaskId(
+ pinnedStackInfo.taskIds[pinnedStackInfo.taskIds.length - 1]);
+ options.setTaskOverlay(true, true /* canResume */);
+ mContext.startActivityAsUser(intent, options.toBundle(), UserHandle.CURRENT);
+ mStartActivityRequested = true;
+ } else {
+ Log.e(TAG, "No PIP tasks found");
+ }
+ } catch (RemoteException e) {
+ mStartActivityRequested = false;
+ Log.e(TAG, "Error showing PIP menu activity", e);
+ }
+ }
+
+ /**
* Updates the PiP menu activity with the best set of actions provided.
*/
private void updateMenuActions() {
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
index 49d89a2bdd68..c4cf28c9a320 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
@@ -65,9 +65,9 @@ public class PipMotionHelper {
private static final int IME_SHIFT_DURATION = 300;
// The fraction of the stack width that the user has to drag offscreen to minimize the PiP
- private static final float MINIMIZE_OFFSCREEN_FRACTION = 0.2f;
- // The fraction of the stack height that the user has to drag offscreen to minimize the PiP
- private static final float DISMISS_OFFSCREEN_FRACTION = 0.35f;
+ private static final float MINIMIZE_OFFSCREEN_FRACTION = 0.3f;
+ // The fraction of the stack height that the user has to drag offscreen to dismiss the PiP
+ private static final float DISMISS_OFFSCREEN_FRACTION = 0.15f;
private Context mContext;
private IActivityManager mActivityManager;
@@ -234,12 +234,16 @@ public class PipMotionHelper {
/**
* Animates the PiP to the minimized state, slightly offscreen.
*/
- Rect animateToClosestMinimizedState(Rect movementBounds) {
+ Rect animateToClosestMinimizedState(Rect movementBounds,
+ AnimatorUpdateListener updateListener) {
cancelAnimations();
Rect toBounds = getClosestMinimizedBounds(mBounds, movementBounds);
if (!mBounds.equals(toBounds)) {
mBoundsAnimator = createAnimationToBounds(mBounds, toBounds,
MINIMIZE_STACK_MAX_DURATION, LINEAR_OUT_SLOW_IN, mUpdateBoundsListener);
+ if (updateListener != null) {
+ mBoundsAnimator.addUpdateListener(updateListener);
+ }
mBoundsAnimator.start();
}
return toBounds;
@@ -248,7 +252,8 @@ public class PipMotionHelper {
/**
* Flings the PiP to the closest snap target.
*/
- Rect flingToSnapTarget(float velocity, float velocityX, float velocityY, Rect movementBounds) {
+ Rect flingToSnapTarget(float velocity, float velocityX, float velocityY, Rect movementBounds,
+ AnimatorUpdateListener listener) {
cancelAnimations();
Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(movementBounds, mBounds,
velocityX, velocityY);
@@ -258,6 +263,9 @@ public class PipMotionHelper {
mFlingAnimationUtils.apply(mBoundsAnimator, 0,
distanceBetweenRectOffsets(mBounds, toBounds),
velocity);
+ if (listener != null) {
+ mBoundsAnimator.addUpdateListener(listener);
+ }
mBoundsAnimator.start();
}
return toBounds;
@@ -266,12 +274,15 @@ public class PipMotionHelper {
/**
* Animates the PiP to the closest snap target.
*/
- Rect animateToClosestSnapTarget(Rect movementBounds) {
+ Rect animateToClosestSnapTarget(Rect movementBounds, AnimatorUpdateListener listener) {
cancelAnimations();
Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(movementBounds, mBounds);
if (!mBounds.equals(toBounds)) {
mBoundsAnimator = createAnimationToBounds(mBounds, toBounds, SNAP_STACK_DURATION,
FAST_OUT_SLOW_IN, mUpdateBoundsListener);
+ if (listener != null) {
+ mBoundsAnimator.addUpdateListener(listener);
+ }
mBoundsAnimator.start();
}
return toBounds;
@@ -316,7 +327,7 @@ public class PipMotionHelper {
/**
* Animates the dismissal of the PiP off the edge of the screen.
*/
- Rect animateDragToEdgeDismiss(Rect pipBounds) {
+ Rect animateDragToEdgeDismiss(Rect pipBounds, AnimatorUpdateListener listener) {
cancelAnimations();
Point displaySize = new Point();
mContext.getDisplay().getRealSize(displaySize);
@@ -330,6 +341,9 @@ public class PipMotionHelper {
dismissPip();
}
});
+ if (listener != null) {
+ mBoundsAnimator.addUpdateListener(listener);
+ }
mBoundsAnimator.start();
return toBounds;
}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
index 80231a954e1a..c52fc3e87b0e 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java
@@ -16,6 +16,8 @@
package com.android.systemui.pip.phone;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.IActivityManager;
import android.content.Context;
import android.graphics.Point;
@@ -55,7 +57,7 @@ public class PipTouchHandler {
// Allow dragging the PIP to a location to close it
private static final boolean ENABLE_DISMISS_DRAG_TO_TARGET = false;
- private static final boolean ENABLE_DISMISS_DRAG_TO_EDGE = false;
+ private static final boolean ENABLE_DISMISS_DRAG_TO_EDGE = true;
private final Context mContext;
private final IActivityManager mActivityManager;
@@ -87,6 +89,13 @@ public class PipTouchHandler {
}
}
};
+ private ValueAnimator.AnimatorUpdateListener mUpdateScrimListener =
+ new AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ updateDismissFraction();
+ }
+ };
// Behaviour states
private boolean mIsMenuVisible;
@@ -124,7 +133,7 @@ public class PipTouchHandler {
@Override
public void onPipMinimize() {
setMinimizedStateInternal(true);
- mMotionHelper.animateToClosestMinimizedState(mMovementBounds);
+ mMotionHelper.animateToClosestMinimizedState(mMovementBounds, null /* updateListener */);
}
@Override
@@ -331,6 +340,22 @@ public class PipTouchHandler {
}
/**
+ * Updates the appearance of the menu and scrim on top of the PiP while dismissing.
+ */
+ void updateDismissFraction() {
+ if (mMenuController != null) {
+ Rect bounds = mMotionHelper.getBounds();
+ final float target = mMovementBounds.bottom + bounds.height();
+ float fraction = 0f;
+ if (bounds.bottom > target) {
+ final float distance = bounds.bottom - target;
+ fraction = Math.min(distance / bounds.height(), 1f);
+ }
+ mMenuController.setDismissFraction(fraction);
+ }
+ }
+
+ /**
* Sets the controller to update the system of changes from user interaction.
*/
void setPinnedStackController(IPinnedStackController controller) {
@@ -465,6 +490,9 @@ public class PipTouchHandler {
if (ENABLE_DISMISS_DRAG_TO_TARGET) {
mDismissViewController.updateDismissTarget(mTmpBounds);
}
+ if (ENABLE_DISMISS_DRAG_TO_EDGE) {
+ updateDismissFraction();
+ }
return true;
}
return false;
@@ -502,7 +530,8 @@ public class PipTouchHandler {
boolean isFlingToBot = isFlingTowardsEdge(touchState, 4 /* bottom */);
if (ENABLE_DISMISS_DRAG_TO_EDGE
&& (mMotionHelper.shouldDismissPip() || isFlingToBot)) {
- mMotionHelper.animateDragToEdgeDismiss(mMotionHelper.getBounds());
+ mMotionHelper.animateDragToEdgeDismiss(mMotionHelper.getBounds(),
+ mUpdateScrimListener);
MetricsLogger.action(mContext,
MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED,
METRIC_VALUE_DISMISSED_BY_DRAG);
@@ -517,7 +546,8 @@ public class PipTouchHandler {
// minimize offset adjusted
mMenuController.hideMenu();
} else {
- mMotionHelper.animateToClosestMinimizedState(mMovementBounds);
+ mMotionHelper.animateToClosestMinimizedState(mMovementBounds,
+ mUpdateScrimListener);
}
return true;
}
@@ -536,13 +566,14 @@ public class PipTouchHandler {
final PointF vel = mTouchState.getVelocity();
final float velocity = PointF.length(vel.x, vel.y);
if (velocity > mFlingAnimationUtils.getMinVelocityPxPerSecond()) {
- mMotionHelper.flingToSnapTarget(velocity, vel.x, vel.y, mMovementBounds);
+ mMotionHelper.flingToSnapTarget(velocity, vel.x, vel.y, mMovementBounds,
+ mUpdateScrimListener);
} else {
- mMotionHelper.animateToClosestSnapTarget(mMovementBounds);
+ mMotionHelper.animateToClosestSnapTarget(mMovementBounds, mUpdateScrimListener);
}
} else if (mIsMinimized) {
// This was a tap, so no longer minimized
- mMotionHelper.animateToClosestSnapTarget(mMovementBounds);
+ mMotionHelper.animateToClosestSnapTarget(mMovementBounds, null /* listener */);
setMinimizedStateInternal(false);
} else if (!mIsMenuVisible) {
mMenuController.showMenu(mMotionHelper.getBounds(), mMovementBounds);