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

Commit 5be6d9b8 authored by Danny Baumann's avatar Danny Baumann
Browse files

Improve notification shade collapse code.

- Collapse after dismissing the last notification
- Avoid duplicate code paths for collapsing
- Improve variable naming according to AOSP review suggestions

Change-Id: Ic6f26a61f263c5beebbcc9725fe8914d3858576f
parent 80d35e16
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,6 +19,6 @@
    <item type="id" name="expandable_tag" />
    <item type="id" name="user_expanded_tag" />
    <item type="id" name="user_lock_tag" />
    <item type="id" name="user_cleared_tag" />
    <item type="id" name="user_dismissed_tag" />
    <item type="id" name="status_bar_cling_stub" />
</resources>
+3 −7
Original line number Diff line number Diff line
@@ -270,10 +270,6 @@ public class SwipeHelper implements Gefingerpoken {
     * @param velocity The desired pixels/second speed at which the view should move
     */
    public void dismissChild(final View view, float velocity) {
        dismissChild(view, velocity, false);
    }

    private void dismissChild(final View view, float velocity, final boolean fromUser) {
        final View animView = mCallback.getChildContentView(view);
        final boolean canAnimViewBeDismissed = mCallback.canChildBeDismissed(view);
        float newPos;
@@ -301,7 +297,7 @@ public class SwipeHelper implements Gefingerpoken {
        anim.setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            public void onAnimationEnd(Animator animation) {
                mCallback.onChildDismissed(view, fromUser);
                mCallback.onChildDismissed(view);
                animView.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        });
@@ -388,7 +384,7 @@ public class SwipeHelper implements Gefingerpoken {

                    if (dismissChild) {
                        // flingadingy
                        dismissChild(mCurrView, childSwipedFastEnough ? velocity : 0f, true);
                        dismissChild(mCurrView, childSwipedFastEnough ? velocity : 0f);
                    } else {
                        // snappity
                        mCallback.onDragCancelled(mCurrView);
@@ -409,7 +405,7 @@ public class SwipeHelper implements Gefingerpoken {

        void onBeginDrag(View v);

        void onChildDismissed(View v, boolean fromUser);
        void onChildDismissed(View v);

        void onDragCancelled(View v);
    }
+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
        mSwipeHelper.dismissChild(v, 0);
    }

    public void onChildDismissed(View v, boolean fromUser) {
    public void onChildDismissed(View v) {
        addToRecycledViews(v);
        mLinearLayout.removeView(v);
        mCallback.handleSwipe(v);
+1 −1
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ public class RecentsVerticalScrollView extends ScrollView
        mSwipeHelper.dismissChild(v, 0);
    }

    public void onChildDismissed(View v, boolean fromUser) {
    public void onChildDismissed(View v) {
        addToRecycledViews(v);
        mLinearLayout.removeView(v);
        mCallback.handleSwipe(v);
+21 −8
Original line number Diff line number Diff line
@@ -109,6 +109,10 @@ public abstract class BaseStatusBar extends SystemUI implements
    public static final int EXPANDED_LEAVE_ALONE = -10000;
    public static final int EXPANDED_FULL_OPEN = -10001;

    private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true;
    private static final int COLLAPSE_AFTER_DISMISS_DELAY = 200;
    private static final int COLLAPSE_AFTER_REMOVE_DELAY = 400;

    protected CommandQueue mCommandQueue;
    protected IStatusBarService mBarService;
    protected H mHandler = createHandler();
@@ -131,6 +135,13 @@ public abstract class BaseStatusBar extends SystemUI implements

    protected FrameLayout mStatusBarContainer;

    private Runnable mPanelCollapseRunnable = new Runnable() {
        @Override
        public void run() {
            animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
        }
    };

    /**
     * An interface for navigation key bars to allow status bars to signal which keys are
     * currently of interest to the user.<br>
@@ -965,14 +976,14 @@ public abstract class BaseStatusBar extends SystemUI implements
        updateExpansionStates();
        updateNotificationIcons();

        if (entry.userCleared() && !mNotificationData.hasClearableItems()) {
            // wait a bit to make the user aware of what's happening
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
        if (CLOSE_PANEL_WHEN_EMPTIED && isNotificationPanelFullyVisible()) {
            if (entry.userDismissed() && !mNotificationData.hasClearableItems()) {
                mHandler.removeCallbacks(mPanelCollapseRunnable);
                mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_DISMISS_DELAY);
            } else if (mNotificationData.size() == 0) {
                mHandler.removeCallbacks(mPanelCollapseRunnable);
                mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_REMOVE_DELAY);
            }
            }, 225);
        }

        return entry.notification;
@@ -1014,6 +1025,7 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
        updateExpansionStates();
        updateNotificationIcons();
        mHandler.removeCallbacks(mPanelCollapseRunnable);

        return iconView;
    }
@@ -1061,6 +1073,7 @@ public abstract class BaseStatusBar extends SystemUI implements
    protected abstract void tick(IBinder key, StatusBarNotification n, boolean firstTime);
    protected abstract void updateExpandedViewPos(int expandedPosition);
    protected abstract int getExpandedViewMaxHeight();
    protected abstract boolean isNotificationPanelFullyVisible();
    protected abstract boolean shouldDisableNavbarGestures();

    protected boolean isTopNotification(ViewGroup parent, NotificationData.Entry entry) {
Loading