moveFromFullscreen, moveToFullscreen, animationType);
}
+ /**
+ * Cancel existing animation if the destination was modified.
+ */
+ void cancel(final BoundsAnimationTarget target) {
+ final BoundsAnimator existing = mRunningAnimations.get(target);
+ if (existing != null) {
+ // Cancel animation. Since its already started, send animation end to client.
+ if (DEBUG) Slog.d(TAG, "cancel: mTarget= " + target);
+ existing.cancelAndCallAnimationEnd();
+ }
+ }
+
@VisibleForTesting
BoundsAnimator animateBoundsImpl(final BoundsAnimationTarget target, Rect from, Rect to,
int animationDuration, @SchedulePipModeChangedState int schedulePipModeChangedState,
* @return true if bounds were updated to some non-empty value.
*/
boolean calculatePinnedBoundsForConfigChange(Rect inOutBounds) {
+ boolean animating = false;
if ((mBoundsAnimatingRequested || mBoundsAnimating) && !mBoundsAnimationTarget.isEmpty()) {
+ animating = true;
getFinalAnimationBounds(mTmpRect2);
} else {
mTmpRect2.set(inOutBounds);
if (updated) {
inOutBounds.set(mTmpRect3);
+ // The final boundary is updated while there is an existing boundary animation. Let's
+ // cancel this animation to prevent the obsolete animation overwritten updated bounds.
+ if (animating && !inOutBounds.equals(mBoundsAnimationTarget)) {
+ final DisplayContent displayContent = getDisplayContent();
+ displayContent.mBoundsAnimationController.getHandler().post(() ->
+ displayContent.mBoundsAnimationController.cancel(this));
+ }
// Once we've set the bounds based on the rotation of the old bounds in the new
// orientation, clear the animation target bounds since they are obsolete, and
// cancel any currently running animations
mBoundsAnimatingRequested = false;
mBoundsAnimating = true;
- mCancelCurrentBoundsAnimation = false;
mAnimationType = animationType;
// If we are changing UI mode, as in the PiP to fullscreen
mBoundsAnimationTarget, false /* forceUpdate */);
}
- if (finalStackSize != null) {
+ if (finalStackSize != null && !mCancelCurrentBoundsAnimation) {
setPinnedStackSize(finalStackSize, null);
} else {
// We have been canceled, so the final stack size is null, still run the
}
final @BoundsAnimationController.AnimationType int animationType = intendedAnimationType;
+ mCancelCurrentBoundsAnimation = false;
displayContent.mBoundsAnimationController.getHandler().post(() -> {
displayContent.mBoundsAnimationController.animateBounds(this, fromBounds,
finalToBounds, animationDuration, finalSchedulePipModeChangedState,