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

Commit 4b04a3a1 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Clear all notifications improvements

- Fix a bug with visibility.
- Improve fling behavior such that the shade open animation still
  looks like that we are decelerating towards the last card.

Change-Id: I1ad167ce0001ff6850f49e819bab944943fa529d
parent 39ca3f5f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@
        android:id="@+id/date_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/clock_collapsed_bottom_margin"
        android:layout_alignParentBottom="true">
        <com.android.systemui.statusbar.policy.DateView android:id="@+id/date_collapsed"
            android:layout_width="wrap_content"
+27 −3
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ public class DismissView extends ExpandableView {

    private Button mClearAllText;
    private boolean mIsVisible;
    private boolean mAnimating;
    private boolean mWillBeGone;

    private final Interpolator mAppearInterpolator = new PathInterpolator(0f, 0.2f, 1f, 1f);
    private final Interpolator mDisappearInterpolator = new PathInterpolator(0f, 0f, 0.8f, 1f);

@@ -63,6 +66,10 @@ public class DismissView extends ExpandableView {
        animateText(nowVisible, onFinishedRunnable);
    }

    public boolean isVisible() {
        return mIsVisible || mAnimating;
    }

    /**
     * Animate the text to a new visibility.
     *
@@ -70,7 +77,7 @@ public class DismissView extends ExpandableView {
     * @param onFinishedRunnable A runnable which should be run when the animation is
     *        finished.
     */
    public void animateText(boolean nowVisible, Runnable onFinishedRunnable) {
    private void animateText(boolean nowVisible, final Runnable onFinishedRunnable) {
        if (nowVisible != mIsVisible) {
            // Animate text
            float endValue = nowVisible ? 1.0f : 0.0f;
@@ -80,12 +87,21 @@ public class DismissView extends ExpandableView {
            } else {
                interpolator = mDisappearInterpolator;
            }
            mAnimating = true;
            mClearAllText.animate()
                    .alpha(endValue)
                    .setInterpolator(interpolator)
                    .withEndAction(onFinishedRunnable)
                    .setDuration(260)
                    .withLayer();
                    .withLayer()
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            mAnimating = false;
                            if (onFinishedRunnable != null) {
                                onFinishedRunnable.run();
                            }
                        }
                    });
            mIsVisible = nowVisible;
        } else {
            if (onFinishedRunnable != null) {
@@ -126,4 +142,12 @@ public class DismissView extends ExpandableView {
    public void cancelAnimation() {
        mClearAllText.animate().cancel();
    }

    public boolean willBeGone() {
        return mWillBeGone;
    }

    public void setWillBeGone(boolean willBeGone) {
        mWillBeGone = willBeGone;
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -1288,6 +1288,22 @@ public class NotificationPanelView extends PanelView implements
        }
    }

    @Override
    protected boolean fullyExpandedClearAllVisible() {
        return mNotificationStackScroller.isDismissViewNotGone()
                && mNotificationStackScroller.isScrolledToBottom();
    }

    @Override
    protected boolean isClearAllVisible() {
        return mNotificationStackScroller.isDismissViewVisible();
    }

    @Override
    protected int getClearAllHeight() {
        return mNotificationStackScroller.getDismissViewHeight();
    }

    @Override
    protected boolean isTrackingBlocked() {
        return mConflictingQsExpansionGesture && mQsExpanded;
+48 −3
Original line number Diff line number Diff line
@@ -462,6 +462,16 @@ public abstract class PanelView extends FrameLayout {
    protected void fling(float vel, boolean expand) {
        cancelPeek();
        float target = expand ? getMaxPanelHeight() : 0.0f;

        // Hack to make the expand transition look nice when clear all button is visible - we make
        // the animation only to the last notification, and then jump to the maximum panel height so
        // clear all just fades in and the decelerating motion is towards the last notification.
        final boolean clearAllExpandHack = expand && fullyExpandedClearAllVisible()
                && mExpandedHeight < getMaxPanelHeight() - getClearAllHeight()
                && !isClearAllVisible();
        if (clearAllExpandHack) {
            target = getMaxPanelHeight() - getClearAllHeight();
        }
        if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
            notifyExpandingFinished();
            return;
@@ -490,11 +500,34 @@ public abstract class PanelView extends FrameLayout {

            @Override
            public void onAnimationEnd(Animator animation) {
                if (clearAllExpandHack && !mCancelled) {
                    mHeightAnimator = createHeightAnimator(getMaxPanelHeight());
                    mHeightAnimator.setInterpolator(mLinearOutSlowInInterpolator);
                    mHeightAnimator.setDuration(350);
                    mHeightAnimator.addListener(new AnimatorListenerAdapter() {
                        private boolean mCancelled;

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            mCancelled = true;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mHeightAnimator = null;
                            if (!mCancelled) {
                                notifyExpandingFinished();
                            }
                        }
                    });
                    mHeightAnimator.start();
                } else {
                    mHeightAnimator = null;
                    if (!mCancelled) {
                        notifyExpandingFinished();
                    }
                }
            }
        });
        mHeightAnimator = animator;
        animator.start();
@@ -878,4 +911,16 @@ public abstract class PanelView extends FrameLayout {
    protected abstract float getPeekHeight();

    protected abstract float getCannedFlingDurationFactor();

    /**
     * @return whether "Clear all" button will be visible when the panel is fully expanded
     */
    protected abstract boolean fullyExpandedClearAllVisible();

    protected abstract boolean isClearAllVisible();

    /**
     * @return the height of the clear all button, in pixels
     */
    protected abstract int getClearAllHeight();
}
+19 −6
Original line number Diff line number Diff line
@@ -175,7 +175,6 @@ public class NotificationStackScrollLayout extends ViewGroup
    private boolean mInterceptDelegateEnabled;
    private boolean mDelegateToScrollView;
    private boolean mDisallowScrollingInThisMotion;
    private boolean mDismissWillBeGone;

    private ViewTreeObserver.OnPreDrawListener mChildrenUpdater
            = new ViewTreeObserver.OnPreDrawListener() {
@@ -1978,24 +1977,26 @@ public class NotificationStackScrollLayout extends ViewGroup
    }

    public void updateDismissView(boolean visible) {
        int oldVisibility = mDismissWillBeGone ? GONE : mDismissView.getVisibility();
        int oldVisibility = mDismissView.willBeGone() ? GONE : mDismissView.getVisibility();
        int newVisibility = visible ? VISIBLE : GONE;
        if (oldVisibility != newVisibility) {
            if (oldVisibility == GONE) {
                if (mDismissWillBeGone) {
                if (mDismissView.willBeGone()) {
                    mDismissView.cancelAnimation();
                } else {
                    mDismissView.setInvisible();
                    mDismissView.setVisibility(newVisibility);
                }
                mDismissWillBeGone = false;
                mDismissView.setWillBeGone(false);
                updateContentHeight();
            } else {
                mDismissWillBeGone = true;
                mDismissView.setWillBeGone(true);
                mDismissView.performVisibilityAnimation(false, new Runnable() {
                    @Override
                    public void run() {
                        mDismissView.setVisibility(GONE);
                        mDismissWillBeGone = false;
                        mDismissView.setWillBeGone(false);
                        updateContentHeight();
                    }
                });
            }
@@ -2006,6 +2007,18 @@ public class NotificationStackScrollLayout extends ViewGroup
        mDismissAllInProgress = dismissAllInProgress;
    }

    public boolean isDismissViewNotGone() {
        return mDismissView.getVisibility() != View.GONE && !mDismissView.willBeGone();
    }

    public boolean isDismissViewVisible() {
        return mDismissView.isVisible();
    }

    public int getDismissViewHeight() {
        return mDismissView.getHeight() + mPaddingBetweenElementsNormal;
    }

    /**
     * A listener that is notified when some child locations might have changed.
     */
Loading