From 5a4d91e54d304a4004cac86119811f493be04873 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Tue, 9 Mar 2021 15:17:09 -0800 Subject: [PATCH] Pass the transform from Launcher to SysUI Video: http://rcll/aaaaaabFQoRHlzixHdtY/hT5SXvaCy28P4UtfuoKiDw Bug: 181342797 Test: see video Change-Id: Id70d89b6dc82c7b9a33bd998b9ebdeb31703c37d --- .../android/quickstep/AbsSwipeUpHandler.java | 4 +- .../quickstep/RecentsAnimationController.java | 8 +++- .../util/SwipePipToHomeAnimator.java | 39 ++++++++++++++----- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index cf345e6083..7df86b99c7 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -1469,7 +1469,9 @@ public abstract class AbsSwipeUpHandler, Q extends mSwipePipToHomeAnimator.getDestinationBounds()); mRecentsAnimationController.setFinishTaskBounds( mSwipePipToHomeAnimator.getTaskId(), - mSwipePipToHomeAnimator.getDestinationBounds()); + mSwipePipToHomeAnimator.getDestinationBounds(), + mSwipePipToHomeAnimator.getFinishWindowCrop(), + mSwipePipToHomeAnimator.getFinishTransform()); mIsSwipingPipToHome = false; } } diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationController.java b/quickstep/src/com/android/quickstep/RecentsAnimationController.java index 646c5a0592..ec585cc667 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationController.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationController.java @@ -149,10 +149,14 @@ public class RecentsAnimationController { * accordingly. This should be called before `finish` * @param taskId for which the leash should be updated * @param destinationBounds bounds of the final PiP window + * @param windowCrop bounds to crop as part of final transform. + * @param float9 An array of 9 floats to be used as matrix transform. */ - public void setFinishTaskBounds(int taskId, Rect destinationBounds) { + public void setFinishTaskBounds(int taskId, Rect destinationBounds, Rect windowCrop, + float[] float9) { UI_HELPER_EXECUTOR.execute( - () -> mController.setFinishTaskBounds(taskId, destinationBounds)); + () -> mController.setFinishTaskBounds(taskId, destinationBounds, windowCrop, + float9)); } /** diff --git a/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java b/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java index 0ce50729ed..0a1a6e8ea0 100644 --- a/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java +++ b/quickstep/src/com/android/quickstep/util/SwipePipToHomeAnimator.java @@ -134,8 +134,9 @@ public class SwipePipToHomeAnimator extends ValueAnimator implements @Override public void onAnimationEnd(Animator animation) { - if (!mHasAnimationEnded) super.onAnimationEnd(animation); - SwipePipToHomeAnimator.this.onAnimationEnd(); + if (mHasAnimationEnded) return; + super.onAnimationEnd(animation); + mHasAnimationEnded = true; } }); addUpdateListener(this); @@ -223,14 +224,34 @@ public class SwipePipToHomeAnimator extends ValueAnimator implements return mDestinationBounds; } - private void onAnimationEnd() { - if (mHasAnimationEnded) return; + /** + * @return {@link Rect} of the final window crop in destination orientation. + */ + public Rect getFinishWindowCrop() { + final Rect windowCrop = new Rect(mAppBounds); + if (mSourceHintRectInsets != null) { + windowCrop.inset(mSourceHintRectInsets); + } + return windowCrop; + } - final SurfaceControl.Transaction tx = - PipSurfaceTransactionHelper.newSurfaceControlTransaction(); - mSurfaceTransactionHelper.reset(tx, mLeash, mDestinationBoundsTransformed, mFromRotation); - tx.apply(); - mHasAnimationEnded = true; + /** + * @return Array of 9 floats represents the final transform in destination orientation. + */ + public float[] getFinishTransform() { + final Matrix transform = new Matrix(); + final float[] float9 = new float[9]; + if (mSourceHintRectInsets == null) { + transform.setRectToRect(new RectF(mAppBounds), new RectF(mDestinationBounds), + Matrix.ScaleToFit.FILL); + } else { + final float scale = mAppBounds.width() <= mAppBounds.height() + ? (float) mDestinationBounds.width() / mAppBounds.width() + : (float) mDestinationBounds.height() / mAppBounds.height(); + transform.setScale(scale, scale); + } + transform.getValues(float9); + return float9; } private RotatedPosition getRotatedPosition(float fraction) {