Avoid #finalResizePip after dismissal of PIP.
When dismissing PIP via the close button or via dragging to the dismiss area, #finalResizePip is being called which then sets the PIP task back to its PIP bounds when it should be set undefined already by the framework. Tap to close: The tap UP event causes a double-tap delay callback, which gets ran shortly after the close button is tapped. Since we are already dismissing and PipTouchHandler gets that callback, we will simply remove the double-tap callback. We will also shorten the hideMenu animation to 0 for this case. Drag to dismiss: The dismissal causes an animation, which then calls for a Resize-callback. There really is no need to do this for the case of dismissal, so we will avoid calling it. Bug: 155794931 Test: Dismiss both PIP and then try to get PIP enter secondary split-screen, and YouTube no longer stays black screen Change-Id: Ic93b210f9f3f7d8947f3fe36f5fa32886f8170ee
This commit is contained in:
@@ -399,11 +399,12 @@ public class PipMenuActivity extends Activity {
|
||||
}
|
||||
|
||||
private void hideMenu(Runnable animationEndCallback) {
|
||||
hideMenu(animationEndCallback, true /* notifyMenuVisibility */, false /* isDismissing */);
|
||||
hideMenu(animationEndCallback, true /* notifyMenuVisibility */, false /* isDismissing */,
|
||||
true /* animate */);
|
||||
}
|
||||
|
||||
private void hideMenu(final Runnable animationFinishedRunnable, boolean notifyMenuVisibility,
|
||||
boolean isDismissing) {
|
||||
boolean isDismissing, boolean animate) {
|
||||
if (mMenuState != MENU_STATE_NONE) {
|
||||
cancelDelayedFinish();
|
||||
if (notifyMenuVisibility) {
|
||||
@@ -419,7 +420,7 @@ public class PipMenuActivity extends Activity {
|
||||
mDismissButton.getAlpha(), 0f);
|
||||
mMenuContainerAnimator.playTogether(menuAnim, settingsAnim, dismissAnim);
|
||||
mMenuContainerAnimator.setInterpolator(Interpolators.ALPHA_OUT);
|
||||
mMenuContainerAnimator.setDuration(MENU_FADE_DURATION);
|
||||
mMenuContainerAnimator.setDuration(animate ? MENU_FADE_DURATION : 0);
|
||||
mMenuContainerAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
@@ -582,16 +583,20 @@ public class PipMenuActivity extends Activity {
|
||||
hideMenu(() -> {
|
||||
sendEmptyMessage(PipMenuActivityController.MESSAGE_EXPAND_PIP,
|
||||
"Could not notify controller to expand PIP");
|
||||
}, false /* notifyMenuVisibility */, false /* isDismissing */);
|
||||
}, false /* notifyMenuVisibility */, false /* isDismissing */, true /* animate */);
|
||||
}
|
||||
|
||||
private void dismissPip() {
|
||||
// Since tapping on the close-button invokes a double-tap wait callback in PipTouchHandler,
|
||||
// we want to disable animating the fadeout animation of the buttons in order to call on
|
||||
// PipTouchHandler#onPipDismiss fast enough.
|
||||
final boolean animate = mMenuState != MENU_STATE_CLOSE;
|
||||
// Do not notify menu visibility when hiding the menu, the controller will do this when it
|
||||
// handles the message
|
||||
hideMenu(() -> {
|
||||
sendEmptyMessage(PipMenuActivityController.MESSAGE_DISMISS_PIP,
|
||||
"Could not notify controller to dismiss PIP");
|
||||
}, false /* notifyMenuVisibility */, true /* isDismissing */);
|
||||
}, false /* notifyMenuVisibility */, true /* isDismissing */, animate);
|
||||
}
|
||||
|
||||
private void showSettings() {
|
||||
|
||||
@@ -237,7 +237,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
.spring(FloatProperties.RECT_Y, toBounds.top, mSpringConfig)
|
||||
.withEndActions(() -> mSpringingToTouch = false);
|
||||
|
||||
startBoundsAnimator(toBounds.left /* toX */, toBounds.top /* toY */);
|
||||
startBoundsAnimator(toBounds.left /* toX */, toBounds.top /* toY */,
|
||||
false /* dismiss */);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +335,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
final float estimatedFlingYEndValue =
|
||||
PhysicsAnimator.estimateFlingEndValue(mBounds.top, velocityY, mFlingConfigY);
|
||||
|
||||
startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */);
|
||||
startBoundsAnimator(xEndValue /* toX */, estimatedFlingYEndValue /* toY */,
|
||||
false /* dismiss */);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,30 +348,26 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
mAnimatedBoundsPhysicsAnimator
|
||||
.spring(FloatProperties.RECT_X, bounds.left, springConfig)
|
||||
.spring(FloatProperties.RECT_Y, bounds.top, springConfig);
|
||||
startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */);
|
||||
startBoundsAnimator(bounds.left /* toX */, bounds.top /* toY */,
|
||||
false /* dismiss */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates the dismissal of the PiP off the edge of the screen.
|
||||
*/
|
||||
void animateDismiss(float velocityX, float velocityY, @Nullable Runnable updateAction) {
|
||||
void animateDismiss() {
|
||||
mAnimatedBounds.set(mBounds);
|
||||
|
||||
// Animate off the bottom of the screen, then dismiss PIP.
|
||||
mAnimatedBoundsPhysicsAnimator
|
||||
.spring(FloatProperties.RECT_Y,
|
||||
mBounds.bottom + mBounds.height(),
|
||||
velocityY,
|
||||
0,
|
||||
mSpringConfig)
|
||||
.withEndActions(this::dismissPip);
|
||||
|
||||
// If we were provided with an update action, run it whenever there's an update.
|
||||
if (updateAction != null) {
|
||||
mAnimatedBoundsPhysicsAnimator.addUpdateListener(
|
||||
(target, values) -> updateAction.run());
|
||||
}
|
||||
|
||||
startBoundsAnimator(mBounds.left /* toX */, mBounds.bottom + mBounds.height() /* toY */);
|
||||
startBoundsAnimator(mBounds.left /* toX */, mBounds.bottom + mBounds.height() /* toY */,
|
||||
true /* dismiss */);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -440,7 +438,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
* This will also add end actions to the bounds animator that cancel the TimeAnimator and update
|
||||
* the 'real' bounds to equal the final animated bounds.
|
||||
*/
|
||||
private void startBoundsAnimator(float toX, float toY) {
|
||||
private void startBoundsAnimator(float toX, float toY, boolean dismiss) {
|
||||
if (!mSpringingToTouch) {
|
||||
cancelAnimations();
|
||||
}
|
||||
@@ -456,7 +454,9 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
|
||||
mAnimatedBoundsPhysicsAnimator
|
||||
.withEndActions(() -> {
|
||||
mPipTaskOrganizer.scheduleFinishResizePip(mAnimatedBounds);
|
||||
if (!dismiss) {
|
||||
mPipTaskOrganizer.scheduleFinishResizePip(mAnimatedBounds);
|
||||
}
|
||||
mAnimatingToBounds.setEmpty();
|
||||
})
|
||||
.addUpdateListener(mResizePipUpdateListener)
|
||||
|
||||
@@ -197,6 +197,7 @@ public class PipTouchHandler {
|
||||
if (topPipActivity.first != null) {
|
||||
MetricsLoggerWrapper.logPictureInPictureDismissByTap(mContext, topPipActivity);
|
||||
}
|
||||
mTouchState.removeDoubleTapTimeoutCallback();
|
||||
mMotionHelper.dismissPip();
|
||||
}
|
||||
|
||||
@@ -297,7 +298,7 @@ public class PipTouchHandler {
|
||||
@Override
|
||||
public void onReleasedInTarget(@NonNull MagnetizedObject.MagneticTarget target) {
|
||||
mHandler.post(() -> {
|
||||
mMotionHelper.animateDismiss(0, 0, null);
|
||||
mMotionHelper.animateDismiss();
|
||||
hideDismissTarget();
|
||||
});
|
||||
|
||||
|
||||
@@ -318,6 +318,14 @@ public class PipTouchState {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the timeout callback if it's in queue.
|
||||
*/
|
||||
public void removeDoubleTapTimeoutCallback() {
|
||||
mIsWaitingForDoubleTap = false;
|
||||
mHandler.removeCallbacks(mDoubleTapTimeoutCallback);
|
||||
}
|
||||
|
||||
void addMovementToVelocityTracker(MotionEvent event) {
|
||||
if (mVelocityTracker == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user