diff options
| author | Taran Singh <tarandeep@google.com> | 2020-06-10 13:42:49 -0700 |
|---|---|---|
| committer | Taran Singh <tarandeep@google.com> | 2020-06-20 03:51:00 +0000 |
| commit | 4291410118852cd6de6e4ce89a907fed1c33f92f (patch) | |
| tree | 4cf5f39e23399adaf7740078965266715e4e6f78 /core/java/android/view/InsetsController.java | |
| parent | 3987866cd7af2c2dda81592388dcc9c7b1d516a6 (diff) | |
Animate IME with zero insets
When IME has zero insets, it doesn't map to any side and doesn't have
can't be animated.
IME can have zero insets in following cases:
1. Floating IME
2. Fullscreen IME (in landscape)
3. IME doesn't overlap with IME target window.
In order to animate a type, it must have insets. We can animate IME
from negative insets to zero and vice-versa. This makes zero insets IME a
special case of ISIDE_BOTTOM.
Deprecate SIDE_FLOATING because it shouldn't logically map to a side.
Fix: 153909316
Test: atest WindowInsetsAnimationImeTests#testZeroInsetsImeAnimates
Change-Id: I6d1d3430888db4632cb2f93e9042f692b35ebaeb
Diffstat (limited to 'core/java/android/view/InsetsController.java')
| -rw-r--r-- | core/java/android/view/InsetsController.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index dd48d554f296..5f99bfe432a4 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -162,6 +162,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation */ @Nullable String getRootViewTitle(); + + /** @see ViewRootImpl#dipToPx */ + int dipToPx(int dips); } private static final String TAG = "InsetsController"; @@ -254,6 +257,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation public static class InternalAnimationControlListener implements WindowInsetsAnimationControlListener { + /** The amount IME will move up/down when animating in floating mode. */ + protected static final int FLOATING_IME_BOTTOM_INSET = -80; + private WindowInsetsAnimationController mController; private ValueAnimator mAnimator; private final boolean mShow; @@ -261,6 +267,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation private final @InsetsType int mRequestedTypes; private final long mDurationMs; private final boolean mDisable; + private final int mFloatingImeBottomInset; private ThreadLocal<AnimationHandler> mSfAnimationHandlerThreadLocal = new ThreadLocal<AnimationHandler>() { @@ -273,12 +280,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation }; public InternalAnimationControlListener(boolean show, boolean hasAnimationCallbacks, - int requestedTypes, boolean disable) { + int requestedTypes, boolean disable, int floatingImeBottomInset) { mShow = show; mHasAnimationCallbacks = hasAnimationCallbacks; mRequestedTypes = requestedTypes; mDurationMs = calculateDurationMs(); mDisable = disable; + mFloatingImeBottomInset = floatingImeBottomInset; } @Override @@ -293,12 +301,19 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation mAnimator = ValueAnimator.ofFloat(0f, 1f); mAnimator.setDuration(mDurationMs); mAnimator.setInterpolator(new LinearInterpolator()); + Insets hiddenInsets = controller.getHiddenStateInsets(); + // IME with zero insets is a special case: it will animate-in from offscreen and end + // with final insets of zero and vice-versa. + hiddenInsets = controller.hasZeroInsetsIme() + ? Insets.of(hiddenInsets.left, hiddenInsets.top, hiddenInsets.right, + mFloatingImeBottomInset) + : hiddenInsets; Insets start = mShow - ? controller.getHiddenStateInsets() + ? hiddenInsets : controller.getShownStateInsets(); Insets end = mShow ? controller.getShownStateInsets() - : controller.getHiddenStateInsets(); + : hiddenInsets; Interpolator insetsInterpolator = getInterpolator(); Interpolator alphaInterpolator = getAlphaInterpolator(); mAnimator.addUpdateListener(animation -> { @@ -1173,7 +1188,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation boolean hasAnimationCallbacks = mHost.hasAnimationCallbacks(); final InternalAnimationControlListener listener = new InternalAnimationControlListener( - show, hasAnimationCallbacks, types, mAnimationsDisabled); + show, hasAnimationCallbacks, types, mAnimationsDisabled, + mHost.dipToPx(InternalAnimationControlListener.FLOATING_IME_BOTTOM_INSET)); // Show/hide animations always need to be relative to the display frame, in order that shown // and hidden state insets are correct. |
