From e308c480cbc663604e951457b168a4e04d832a2c Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 12 Nov 2021 13:40:38 +0800 Subject: [PATCH] Set window crop for TaskFragment open/close animation We don't want to show the TaskFragment window outside of its bounds. Bug: 201261613 Bug: 196173550 Test: test with settings app Change-Id: Idc627970abec95b8c6087a993802b32955449406 --- .../TaskFragmentAnimationAdapter.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationAdapter.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationAdapter.java index 194b6330d92cf..89d7a407e4594 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationAdapter.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskFragmentAnimationAdapter.java @@ -39,6 +39,8 @@ class TaskFragmentAnimationAdapter { final Transformation mTransformation = new Transformation(); final float[] mMatrix = new float[9]; + final float[] mVecs = new float[4]; + final Rect mRect = new Rect(); private boolean mIsFirstFrame = true; TaskFragmentAnimationAdapter(@NonNull Animation animation, @@ -76,6 +78,22 @@ class TaskFragmentAnimationAdapter { mTarget.localBounds.left, mTarget.localBounds.top); t.setMatrix(mLeash, mTransformation.getMatrix(), mMatrix); t.setAlpha(mLeash, mTransformation.getAlpha()); + + // Open/close animation may scale up the surface. Apply an inverse scale to the window crop + // so that it will not be covering other windows. + mVecs[1] = mVecs[2] = 0; + mVecs[0] = mVecs[3] = 1; + mTransformation.getMatrix().mapVectors(mVecs); + mVecs[0] = 1.f / mVecs[0]; + mVecs[3] = 1.f / mVecs[3]; + final Rect clipRect = mTarget.localBounds; + mRect.left = (int) (clipRect.left * mVecs[0] + 0.5f); + mRect.right = (int) (clipRect.right * mVecs[0] + 0.5f); + mRect.top = (int) (clipRect.top * mVecs[3] + 0.5f); + mRect.bottom = (int) (clipRect.bottom * mVecs[3] + 0.5f); + mRect.offsetTo(Math.round(mTarget.localBounds.width() * (1 - mVecs[0]) / 2.f), + Math.round(mTarget.localBounds.height() * (1 - mVecs[3]) / 2.f)); + t.setWindowCrop(mLeash, mRect); } /** Called after animation finished. */ @@ -157,8 +175,6 @@ class TaskFragmentAnimationAdapter { * Should be used for the animation of the {@link RemoteAnimationTarget} that has size change. */ static class BoundsChangeAdapter extends TaskFragmentAnimationAdapter { - private final float[] mVecs = new float[4]; - private final Rect mRect = new Rect(); BoundsChangeAdapter(@NonNull Animation animation, @NonNull RemoteAnimationTarget target) { super(animation, target);