Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b98ddb45 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Cancel dark animation when new one arrives

Not doing so causes weird artifacts when power button is pressed
multiple times in a row and StackScroller would have the wrong
state if unlocked with fingerprint while animation is still running.

Test: lock from lock screen, fp before animation ends
Test: press power multiple times on lock screen, look at smooth animation
Change-Id: I381bf367533983595cd22ff080f51465f6c0f750
Fixes: 79747888
parent d8f3889b
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -388,6 +388,7 @@ public class NotificationStackScrollLayout extends ViewGroup
                    return object.getDarkAmount();
                }
            };
    private ObjectAnimator mDarkAmountAnimator;
    private boolean mUsingLightTheme;
    private boolean mQsExpanded;
    private boolean mForwardScrollable;
@@ -3401,7 +3402,7 @@ public class NotificationStackScrollLayout extends ViewGroup
                            .animateY(mShelf));
            ev.darkAnimationOriginIndex = mDarkAnimationOriginIndex;
            mAnimationEvents.add(ev);
            startBackgroundFade();
            startDarkAmountAnimation();
        }
        mDarkNeedsAnimation = false;
    }
@@ -3979,6 +3980,9 @@ public class NotificationStackScrollLayout extends ViewGroup
            mDarkAnimationOriginIndex = findDarkAnimationOriginIndex(touchWakeUpScreenLocation);
            mNeedsAnimation =  true;
        } else {
            if (mDarkAmountAnimator != null) {
                mDarkAmountAnimator.cancel();
            }
            setDarkAmount(dark ? 1f : 0f);
            updateBackground();
        }
@@ -4023,12 +4027,22 @@ public class NotificationStackScrollLayout extends ViewGroup
        return mDarkAmount;
    }

    private void startBackgroundFade() {
        ObjectAnimator fadeAnimator = ObjectAnimator.ofFloat(this, DARK_AMOUNT, mDarkAmount,
    private void startDarkAmountAnimation() {
        ObjectAnimator darkAnimator = ObjectAnimator.ofFloat(this, DARK_AMOUNT, mDarkAmount,
                mAmbientState.isDark() ? 1f : 0);
        fadeAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_WAKEUP);
        fadeAnimator.setInterpolator(Interpolators.ALPHA_IN);
        fadeAnimator.start();
        darkAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_WAKEUP);
        darkAnimator.setInterpolator(Interpolators.ALPHA_IN);
        darkAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mDarkAmountAnimator = null;
            }
        });
        if (mDarkAmountAnimator != null) {
            mDarkAmountAnimator.cancel();
        }
        mDarkAmountAnimator = darkAnimator;
        mDarkAmountAnimator.start();
    }

    private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) {