From cd6172911edd115fbcd0e21bb342d6d1a4569b49 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Tue, 18 Jun 2024 13:43:06 -0700 Subject: [PATCH] Position PiP animation based on actual coordinates In the previous patchset, we assumed the left/top to be 0/0 which is not always the case. This could break, for instance, in ActivityEmbedding setup, where the pip-ing app is on the left side. Flag: NONE test fix Bug: 345327260 Test: Verify with apps support auto-enter PiP such as YouTube Change-Id: Ic2f3289cf0663d0687d5ccd7f4d0250066cb3f67 --- .../util/SwipePipToHomeAnimator.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java b/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java index e44f14819a..2b944bc311 100644 --- a/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java +++ b/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java @@ -164,22 +164,7 @@ public class SwipePipToHomeAnimator extends RectFSpringAnim { } if (sourceRectHint.isEmpty()) { - // Crop a Rect matches the aspect ratio and pivots at the center point. - // To make the animation path simplified. - if ((appBounds.width() / (float) appBounds.height()) > aspectRatio) { - // use the full height. - mSourceRectHint.set(0, 0, - (int) (appBounds.height() * aspectRatio), appBounds.height()); - mSourceRectHint.offset( - (appBounds.width() - mSourceRectHint.width()) / 2, 0); - } else { - // use the full width. - mSourceRectHint.set(0, 0, - appBounds.width(), (int) (appBounds.width() / aspectRatio)); - mSourceRectHint.offset( - 0, (appBounds.height() - mSourceRectHint.height()) / 2); - } - + mSourceRectHint.set(getEnterPipWithOverlaySrcRectHint(appBounds, aspectRatio)); // Create a new overlay layer. We do not call detach on this instance, it's propagated // to other classes like PipTaskOrganizer / RecentsAnimationController to complete // the cleanup. @@ -225,6 +210,26 @@ public class SwipePipToHomeAnimator extends RectFSpringAnim { addOnUpdateListener(this::onAnimationUpdate); } + /** + * Crop a Rect matches the aspect ratio and pivots at the center point. + */ + private Rect getEnterPipWithOverlaySrcRectHint(Rect appBounds, float aspectRatio) { + final float appBoundsAspectRatio = appBounds.width() / (float) appBounds.height(); + final int width, height; + int left = appBounds.left; + int top = appBounds.top; + if (appBoundsAspectRatio < aspectRatio) { + width = appBounds.width(); + height = (int) (width / aspectRatio); + top = appBounds.top + (appBounds.height() - height) / 2; + } else { + height = appBounds.height(); + width = (int) (height * aspectRatio); + left = appBounds.left + (appBounds.width() - width) / 2; + } + return new Rect(left, top, left + width, top + height); + } + private void onAnimationUpdate(RectF currentRect, float progress) { if (mHasAnimationEnded) return; final SurfaceControl.Transaction tx =