From ff6b0f2dbf91fbd99b40a7b753a0e70189790ad7 Mon Sep 17 00:00:00 2001 From: Joshua Tsuji Date: Mon, 9 Mar 2020 14:55:19 -0400 Subject: [PATCH] Fix issues with Bubbles+IME. 1) System window inset bottom now includes IME height, so we were double counting the IME. Changed to stable inset (this is what PIP uses). 2) If you dismissed the stack while IME was up, we didn't tell the stack view when IME goes down since there were no bubbles. This meant you couldn't place bubbles where the IME used to be. 3) Flyout wasn't animating with the stack when avoiding IME. Changed to animate the flyout. Test: 1) Open IME, observe you can drag bubbles in the expected locations Test: 2) Dismiss bubble stack with IME up, close IME, observe you can drag bubbles where the IME used to be. Test: 3) Move stack to bottom of screen, add new bubble and quickly open IME, observe flyout animates up, close IME, observe flyout animates back down. Fixes: 141780462 Change-Id: Ied1d6da1edf946ca338bd908e52a3863c90ffd5a --- .../systemui/bubbles/BubbleController.java | 2 +- .../systemui/bubbles/BubbleStackView.java | 24 +++++++++++++++++-- .../animation/StackAnimationController.java | 15 ++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index f873f42dd9184..8f7ab5abe993c 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -1311,7 +1311,7 @@ public class BubbleController implements ConfigurationController.ConfigurationLi private class BubblesImeListener extends PinnedStackListenerForwarder.PinnedStackListener { @Override public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { - if (mStackView != null && mStackView.getBubbleCount() > 0) { + if (mStackView != null) { mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); } } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index 8cc10d9d148fb..96c887fe3915e 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -126,6 +126,11 @@ public class BubbleStackView extends FrameLayout { @VisibleForTesting static final int FLYOUT_HIDE_AFTER = 5000; + private static final PhysicsAnimator.SpringConfig FLYOUT_IME_ANIMATION_SPRING_CONFIG = + new PhysicsAnimator.SpringConfig( + StackAnimationController.IME_ANIMATION_STIFFNESS, + StackAnimationController.DEFAULT_BOUNCINESS); + /** * Interface to synchronize {@link View} state and the screen. * @@ -1354,8 +1359,23 @@ public class BubbleStackView extends FrameLayout { public void onImeVisibilityChanged(boolean visible, int height) { mStackAnimationController.setImeHeight(visible ? height + mImeOffset : 0); - if (!mIsExpanded) { - mStackAnimationController.animateForImeVisibility(visible); + if (!mIsExpanded && getBubbleCount() > 0) { + final float stackDestinationY = + mStackAnimationController.animateForImeVisibility(visible); + + // How far the stack is animating due to IME, we'll just animate the flyout by that + // much too. + final float stackDy = + stackDestinationY - mStackAnimationController.getStackPosition().y; + + // If the flyout is visible, translate it along with the bubble stack. + if (mFlyout.getVisibility() == VISIBLE) { + PhysicsAnimator.getInstance(mFlyout) + .spring(DynamicAnimation.TRANSLATION_Y, + mFlyout.getTranslationY() + stackDy, + FLYOUT_IME_ANIMATION_SPRING_CONFIG) + .start(); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java index b81665cd186a1..e06e0ac68da60 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java @@ -68,9 +68,10 @@ public class StackAnimationController extends /** * Values to use for the default {@link SpringForce} provided to the physics animation layout. */ - private static final int DEFAULT_STIFFNESS = 12000; + public static final int DEFAULT_STIFFNESS = 12000; + public static final float IME_ANIMATION_STIFFNESS = SpringForce.STIFFNESS_LOW; private static final int FLING_FOLLOW_STIFFNESS = 20000; - private static final float DEFAULT_BOUNCINESS = 0.9f; + public static final float DEFAULT_BOUNCINESS = 0.9f; /** * Friction applied to fling animations. Since the stack must land on one of the sides of the @@ -501,8 +502,10 @@ public class StackAnimationController extends /** * Animates the stack either away from the newly visible IME, or back to its original position * due to the IME going away. + * + * @return The destination Y value of the stack due to the IME movement. */ - public void animateForImeVisibility(boolean imeVisible) { + public float animateForImeVisibility(boolean imeVisible) { final float maxBubbleY = getAllowableStackPositionRegion().bottom; float destinationY = Float.MIN_VALUE; @@ -523,12 +526,14 @@ public class StackAnimationController extends springFirstBubbleWithStackFollowing( DynamicAnimation.TRANSLATION_Y, getSpringForce(DynamicAnimation.TRANSLATION_Y, /* view */ null) - .setStiffness(SpringForce.STIFFNESS_LOW), + .setStiffness(IME_ANIMATION_STIFFNESS), /* startVel */ 0f, destinationY); notifyFloatingCoordinatorStackAnimatingTo(mStackPosition.x, destinationY); } + + return destinationY; } /** @@ -583,7 +588,7 @@ public class StackAnimationController extends - mBubblePaddingTop - (mImeHeight > Float.MIN_VALUE ? mImeHeight + mBubblePaddingTop : 0f) - Math.max( - insets.getSystemWindowInsetBottom(), + insets.getStableInsetBottom(), insets.getDisplayCutout() != null ? insets.getDisplayCutout().getSafeInsetBottom() : 0);