From 439bd449d879ee35f3e487f871e59cab59ffc1a2 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Tue, 12 Jun 2018 15:05:28 -0700 Subject: [PATCH] Smoother wake-up animation Removed overlapping interpolators and made the "screen off" animation slower when more than 1 notifications are visible. Fixes: 110081253 Bug: 109809484 Test: visual Change-Id: I355ac94d4e6a880f37ce1d68c15c693b6f09f7f8 --- .../stack/NotificationStackScrollLayout.java | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java index 9c26c69045d55..126e6fb687a99 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -140,7 +140,6 @@ public class NotificationStackScrollLayout extends ViewGroup private boolean mSwipingInProgress; private int mCurrentStackHeight = Integer.MAX_VALUE; private final Paint mBackgroundPaint = new Paint(); - private final Path mBackgroundPath = new Path(); private final boolean mShouldDrawNotificationBackground; private float mExpandedHeight; @@ -376,6 +375,11 @@ public class NotificationStackScrollLayout extends ViewGroup private View mForcedScroll; private View mNeedingPulseAnimation; private float mDarkAmount = 0f; + + /** + * How fast the background scales in the X direction as a factor of the Y expansion. + */ + private float mBackgroundXFactor = 1f; private static final Property DARK_AMOUNT = new FloatProperty("darkAmount") { @Override @@ -548,7 +552,7 @@ public class NotificationStackScrollLayout extends ViewGroup float inverseDark = 1 - mDarkAmount; float yProgress = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(inverseDark); float xProgress = Interpolators.FAST_OUT_SLOW_IN - .getInterpolation(inverseDark * 2f); + .getInterpolation(inverseDark * mBackgroundXFactor); mBackgroundAnimationRect.set( (int) MathUtils.lerp(darkLeft, lockScreenLeft, xProgress), @@ -4028,21 +4032,37 @@ public class NotificationStackScrollLayout extends ViewGroup return mDarkAmount; } + /** + * Cancel any previous dark animations - to avoid race conditions - and creates a new one. + * This function also sets {@code mBackgroundXFactor} based on the current {@code mDarkAmount}. + */ private void startDarkAmountAnimation() { - ObjectAnimator darkAnimator = ObjectAnimator.ofFloat(this, DARK_AMOUNT, mDarkAmount, - mAmbientState.isDark() ? 1f : 0); - darkAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_WAKEUP); - darkAnimator.setInterpolator(Interpolators.ALPHA_IN); - darkAnimator.addListener(new AnimatorListenerAdapter() { + boolean dark = mAmbientState.isDark(); + if (mDarkAmountAnimator != null) { + mDarkAmountAnimator.cancel(); + } + + long duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP; + // Longer animation when sleeping with more than 1 notification + if (dark && getNotGoneChildCount() > 2) { + duration *= 1.2f; + } + + mDarkAmountAnimator = ObjectAnimator.ofFloat(this, DARK_AMOUNT, mDarkAmount, + dark ? 1f : 0); + // We only swap the scaling factor if we're fully dark or fully awake to avoid + // interpolation issues when playing with the power button. + if (mDarkAmount == 0 || mDarkAmount == 1) { + mBackgroundXFactor = dark ? 2.5f : 1.5f; + } + mDarkAmountAnimator.setDuration(duration); + mDarkAmountAnimator.setInterpolator(Interpolators.LINEAR); + mDarkAmountAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDarkAmountAnimator = null; } }); - if (mDarkAmountAnimator != null) { - mDarkAmountAnimator.cancel(); - } - mDarkAmountAnimator = darkAnimator; mDarkAmountAnimator.start(); }