From 67684881cf48676e53ccc3454de07b8dec80ea61 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Tue, 22 Jan 2019 17:36:34 +0100 Subject: [PATCH] Apply visibility at the beginning of the animation Such that elements are more in sync, and this is also how it was handled previously. Furthermore we ensure that surface visibility is correct after the animation for both show and hide. Test: Show/hide IM Bug: 111084606 Change-Id: I47b3d3b430fa38f80203276b9984df1f71008f6e --- .../android/view/InsetsAnimationControlImpl.java | 16 +++++++++------- core/java/android/view/InsetsController.java | 14 +++++++------- core/java/android/view/InsetsSourceConsumer.java | 2 -- .../view/SyncRtSurfaceTransactionApplier.java | 11 +++++++++-- .../notification/ActivityLaunchAnimator.java | 2 +- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 7291d0b2f10cc..625ddc2549cca 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -127,16 +127,18 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll final Insets offset = Insets.subtract(mShownInsets, mPendingInsets); ArrayList params = new ArrayList<>(); if (offset.left != 0) { - updateLeashesForSide(INSET_SIDE_LEFT, offset.left, params, state); + updateLeashesForSide(INSET_SIDE_LEFT, offset.left, mPendingInsets.left, params, state); } if (offset.top != 0) { - updateLeashesForSide(INSET_SIDE_TOP, offset.top, params, state); + updateLeashesForSide(INSET_SIDE_TOP, offset.top, mPendingInsets.top, params, state); } if (offset.right != 0) { - updateLeashesForSide(INSET_SIDE_RIGHT, offset.right, params, state); + updateLeashesForSide(INSET_SIDE_RIGHT, offset.right, mPendingInsets.right, params, + state); } if (offset.bottom != 0) { - updateLeashesForSide(INSET_SIDE_BOTTOM, offset.bottom, params, state); + updateLeashesForSide(INSET_SIDE_BOTTOM, offset.bottom, mPendingInsets.bottom, params, + state); } SyncRtSurfaceTransactionApplier applier = mTransactionApplierSupplier.get(); applier.scheduleApply(params.toArray(new SurfaceParams[params.size()])); @@ -171,7 +173,7 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll return Insets.max(Insets.min(insets, mShownInsets), mHiddenInsets); } - private void updateLeashesForSide(@InsetSide int side, int inset, + private void updateLeashesForSide(@InsetSide int side, int offset, int inset, ArrayList surfaceParams, InsetsState state) { ArraySet items = mSideSourceMap.get(side); // TODO: Implement behavior when inset spans over multiple types @@ -182,10 +184,10 @@ public class InsetsAnimationControlImpl implements WindowInsetsAnimationControll mTmpMatrix.setTranslate(source.getFrame().left, source.getFrame().top); mTmpFrame.set(source.getFrame()); - addTranslationToMatrix(side, inset, mTmpMatrix, mTmpFrame); + addTranslationToMatrix(side, offset, mTmpMatrix, mTmpFrame); state.getSource(source.getType()).setFrame(mTmpFrame); - surfaceParams.add(new SurfaceParams(leash, 1f, mTmpMatrix, null, 0, 0f)); + surfaceParams.add(new SurfaceParams(leash, 1f, mTmpMatrix, null, 0, 0f, inset != 0)); } } diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 4f9ecd5753263..8e773799d1881 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -329,6 +329,11 @@ public class InsetsController implements WindowInsetsController { WindowInsetsAnimationControlListener listener = new WindowInsetsAnimationControlListener() { @Override public void onReady(WindowInsetsAnimationController controller, int types) { + if (show) { + showDirectly(types); + } else { + hideDirectly(types); + } mAnimator = ObjectAnimator.ofObject( controller, new InsetsProperty(), @@ -356,11 +361,6 @@ public class InsetsController implements WindowInsetsController { private void onAnimationFinish() { mAnimationDirection = DIRECTION_NONE; - if (show) { - showOnAnimationEnd(types); - } else { - hideOnAnimationEnd(types); - } } }; // TODO: Instead of clearing this here, properly wire up @@ -369,14 +369,14 @@ public class InsetsController implements WindowInsetsController { controlWindowInsetsAnimation(types, listener); } - private void hideOnAnimationEnd(@InsetType int types) { + private void hideDirectly(@InsetType int types) { final ArraySet internalTypes = InsetsState.toInternalType(types); for (int i = internalTypes.size() - 1; i >= 0; i--) { getSourceConsumer(internalTypes.valueAt(i)).hide(); } } - private void showOnAnimationEnd(@InsetType int types) { + private void showDirectly(@InsetType int types) { final ArraySet internalTypes = InsetsState.toInternalType(types); for (int i = internalTypes.size() - 1; i >= 0; i--) { getSourceConsumer(internalTypes.valueAt(i)).show(); diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index f48318cd7d0a4..cccfd870a3e45 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -109,7 +109,6 @@ public class InsetsSourceConsumer { return; } mVisible = visible; - applyHiddenToControl(); applyLocalVisibilityOverride(); mController.notifyVisibilityChanged(); } @@ -119,7 +118,6 @@ public class InsetsSourceConsumer { return; } - // TODO: Animation final Transaction t = mTransactionSupplier.get(); if (mVisible) { t.show(mSourceControl.getLeash()); diff --git a/core/java/android/view/SyncRtSurfaceTransactionApplier.java b/core/java/android/view/SyncRtSurfaceTransactionApplier.java index 0270acb3aea70..85457cb48218a 100644 --- a/core/java/android/view/SyncRtSurfaceTransactionApplier.java +++ b/core/java/android/view/SyncRtSurfaceTransactionApplier.java @@ -77,7 +77,11 @@ public class SyncRtSurfaceTransactionApplier { t.setAlpha(params.surface, params.alpha); t.setLayer(params.surface, params.layer); t.setCornerRadius(params.surface, params.cornerRadius); - t.show(params.surface); + if (params.visible) { + t.show(params.surface); + } else { + t.hide(params.surface); + } } /** @@ -121,13 +125,14 @@ public class SyncRtSurfaceTransactionApplier { * @param windowCrop Crop to apply. */ public SurfaceParams(SurfaceControl surface, float alpha, Matrix matrix, - Rect windowCrop, int layer, float cornerRadius) { + Rect windowCrop, int layer, float cornerRadius, boolean visible) { this.surface = surface; this.alpha = alpha; this.matrix = new Matrix(matrix); this.windowCrop = new Rect(windowCrop); this.layer = layer; this.cornerRadius = cornerRadius; + this.visible = visible; } @VisibleForTesting @@ -147,5 +152,7 @@ public class SyncRtSurfaceTransactionApplier { @VisibleForTesting public final int layer; + + public final boolean visible; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java index e1b231b96693c..333239e77d1b5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ActivityLaunchAnimator.java @@ -268,7 +268,7 @@ public class ActivityLaunchAnimator { m.postTranslate(0, (float) (mParams.top - app.position.y)); mWindowCrop.set(mParams.left, 0, mParams.right, mParams.getHeight()); SurfaceParams params = new SurfaceParams(app.leash, 1f /* alpha */, m, mWindowCrop, - app.prefixOrderIndex, mCornerRadius); + app.prefixOrderIndex, mCornerRadius, true /* visible */); mSyncRtTransactionApplier.scheduleApply(params); }