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

Commit c2dbe49b authored by Mady Mellor's avatar Mady Mellor
Browse files

Don't commit snooze on horizontal swipes or when its in its expanded state

- Previously any touch outside of the snooze menu would commit the action
  (similar to how notification info gets reset) now only touches that
  aren't horizontal swipes will commit the action (if you snooze multiple
  in a row, it's jarring for the snooze item to disappear when you hit
  'down' on the next notification)
- Tracks expanded state of snooze menu
- Rather than commiting (i.e. snoozing) upon outside action when the
  menu is expanded it collapses the menu, upon next outside action snooze
  is commited

Test: manual / runtest systemui
Bug: 37253059
Change-Id: Ie0383fb8de49efe1b1bf0ed75d60cf75864f0210
parent 4d09adce
Loading
Loading
Loading
Loading
+35 −9
Original line number Diff line number Diff line
@@ -95,14 +95,25 @@ public class NotificationGuts extends FrameLayout {

        /**
         * Called when the guts view have been told to close, typically after an outside
         * interaction. Returning {@code true} here will prevent the guts view to close.
         * interaction.
         *
         * @param save whether the state should be saved.
         * @param force whether the guts view should be forced closed regardless of state.
         * @return if closing the view has been handled.
         */
        public boolean handleCloseControls(boolean save);
        public boolean handleCloseControls(boolean save, boolean force);

        /**
         * @return whether the notification associated with these guts is set to be removed.
         */
        public boolean willBeRemoved();

        /**
         * @return whether these guts are a leavebehind (e.g. {@link NotificationSnooze}).
         */
        public default boolean isLeavebehind() {
            return false;
        }
    }

    public interface OnGutsClosedListener {
@@ -125,7 +136,7 @@ public class NotificationGuts extends FrameLayout {
            @Override
            public void run() {
                if (mNeedsFalsingProtection && mExposed) {
                    closeControls(-1 /* x */, -1 /* y */, false /* save */);
                    closeControls(-1 /* x */, -1 /* y */, false /* save */, false /* force */);
                }
            }
        };
@@ -144,6 +155,10 @@ public class NotificationGuts extends FrameLayout {
        addView(mGutsContent.getContentView());
    }

    public GutsContent getGutsContent() {
        return mGutsContent;
    }

    public void resetFalsingCheck() {
        mHandler.removeCallbacks(mFalsingCheck);
        if (mNeedsFalsingProtection && mExposed) {
@@ -197,21 +212,32 @@ public class NotificationGuts extends FrameLayout {
        }
    }

    public void closeControls(int x, int y, boolean save) {
    public void closeControls(boolean leavebehinds, boolean controls, int x, int y, boolean force) {
        if (mGutsContent != null) {
            if (mGutsContent.isLeavebehind() && leavebehinds) {
                closeControls(x, y, true /* save */, force);
            } else if (!mGutsContent.isLeavebehind() && controls) {
                closeControls(x, y, true /* save */, force);
            }
        }
    }

    public void closeControls(int x, int y, boolean save, boolean force) {
        if (getWindowToken() == null) {
            if (mClosedListener != null) {
                mClosedListener.onGutsClosed(this);
            }
            return;
        }
        if (mGutsContent == null || !mGutsContent.handleCloseControls(save)) {

        if (mGutsContent == null || !mGutsContent.handleCloseControls(save, force)) {
            animateClose(x, y);
        }
            setExposed(false, mNeedsFalsingProtection);
            if (mClosedListener != null) {
                mClosedListener.onGutsClosed(this);
            }
        }
    }

    private void animateClose(int x, int y) {
        if (x == -1 || y == -1) {
+1 −1
Original line number Diff line number Diff line
@@ -393,7 +393,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    }

    @Override
    public boolean handleCloseControls(boolean save) {
    public boolean handleCloseControls(boolean save, boolean force) {
        if (save && hasImportanceChanged()) {
            if (mCheckSaveListener != null) {
                mCheckSaveListener.checkSave(() -> { saveImportance(); });
+29 −15
Original line number Diff line number Diff line
@@ -103,6 +103,18 @@ public class NotificationSnooze extends LinearLayout
        createOptionViews();
    }

    public boolean isExpanded() {
        return mExpanded;
    }

    public void setSnoozeListener(NotificationSwipeActionHelper listener) {
        mSnoozeListener = listener;
    }

    public void setStatusBarNotification(StatusBarNotification sbn) {
        mSbn = sbn;
    }

    private ArrayList<SnoozeOption> getDefaultSnoozeOptions() {
        ArrayList<SnoozeOption> options = new ArrayList<>();
        options.add(createOption(R.string.snooze_option_15_min, 15));
@@ -201,7 +213,7 @@ public class NotificationSnooze extends LinearLayout
            final int x = targetLoc[0] - parentLoc[0] + centerX;
            final int y = targetLoc[1] - parentLoc[1] + centerY;
            showSnoozeOptions(false);
            mGutsContainer.closeControls(x, y, false /* save */);
            mGutsContainer.closeControls(x, y, false /* save */, false /* force */);
        }
    }

@@ -222,29 +234,31 @@ public class NotificationSnooze extends LinearLayout
        return this;
    }

    public void setStatusBarNotification(StatusBarNotification sbn) {
        mSbn = sbn;
    }

    @Override
    public void setGutsParent(NotificationGuts guts) {
        mGutsContainer = guts;
    }

    public void setSnoozeListener(NotificationSwipeActionHelper listener) {
        mSnoozeListener = listener;
    }

    @Override
    public boolean handleCloseControls(boolean save) {
        // When snooze is closed (i.e. there was interaction outside of the notification)
        // then we commit the snooze action.
        if (mSnoozeListener != null && mSelectedOption != null) {
    public boolean handleCloseControls(boolean save, boolean force) {
        if (mExpanded && !force) {
            // Collapse expanded state on outside touch
            showSnoozeOptions(false);
            return true;
        } else if (mSnoozeListener != null && mSelectedOption != null) {
            // Snooze option selected so commit it
            mSnoozing = true;
            mSnoozeListener.snooze(mSbn, mSelectedOption);
            return true;
        } else {
            // The view should actually be closed
            setSelected(mSnoozeOptions.get(0));
            return false; // Return false here so that guts handles closing the view
        }
    }
        // The view should be closed
        return false;

    @Override
    public boolean isLeavebehind() {
        return true;
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -524,7 +524,8 @@ public class NotificationPanelView extends PanelView implements
            mLastCameraLaunchSource = KeyguardBottomAreaView.CAMERA_LAUNCH_SOURCE_AFFORDANCE;
        }
        closeQs();
        mStatusBar.dismissPopups();
        mStatusBar.closeAndSaveGuts(true /* leavebehind */, true /* force */,
                true /* controls */, -1 /* x */, -1 /* y */, true /* resetMenu */);
        mNotificationStackScroller.setOverScrollAmount(0f, true /* onTop */, false /* animate */,
                true /* cancelAnimators */);
        mNotificationStackScroller.resetScrollPosition();
@@ -1015,6 +1016,7 @@ public class NotificationPanelView extends PanelView implements
        float height = mQsExpansionHeight - overscrollAmount;
        setQsExpansion(height);
        requestPanelHeightUpdate();
        mNotificationStackScroller.checkSnoozeLeavebehind();
    }

    private void setQsExpanded(boolean expanded) {
@@ -1381,6 +1383,7 @@ public class NotificationPanelView extends PanelView implements
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mNotificationStackScroller.resetCheckSnoozeLeavebehind();
                mQsExpansionAnimator = null;
                if (onFinishRunnable != null) {
                    onFinishRunnable.run();
+36 −25
Original line number Diff line number Diff line
@@ -2996,8 +2996,9 @@ public class StatusBar extends SystemUI implements DemoMode,
        mStatusBarWindowManager.setPanelVisible(false);
        mStatusBarWindowManager.setForceStatusBarVisible(false);

        // Close any "App info" popups that might have snuck on-screen
        dismissPopups();
        // Close any guts that might be visible
        closeAndSaveGuts(true /* removeLeavebehind */, true /* force */, true /* removeControls */,
                -1 /* x */, -1 /* y */, true /* resetMenu */);

        runPostCollapseRunnables();
        setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
@@ -4617,6 +4618,7 @@ public class StatusBar extends SystemUI implements DemoMode,
    public void onDragDownReset() {
        mStackScroller.setDimmed(true /* dimmed */, true /* animated */);
        mStackScroller.resetScrollPosition();
        mStackScroller.resetCheckSnoozeLeavebehind();
    }

    @Override
@@ -4627,6 +4629,7 @@ public class StatusBar extends SystemUI implements DemoMode,
    @Override
    public void onTouchSlopExceeded() {
        mStackScroller.removeLongPressCallback();
        mStackScroller.checkSnoozeLeavebehind();
    }

    @Override
@@ -5800,8 +5803,10 @@ public class StatusBar extends SystemUI implements DemoMode,
            if (!g.willBeRemoved() && !row.isRemoved()) {
                mStackScroller.onHeightChanged(row, !isPanelFullyCollapsed() /* needsAnimation */);
            }
            if (mNotificationGutsExposed == g) {
                mNotificationGutsExposed = null;
                mGutsMenuItem = null;
            }
        });

        View gutsView = item.getGutsView();
@@ -5897,7 +5902,8 @@ public class StatusBar extends SystemUI implements DemoMode,
        final int centerY = done.getHeight() / 2;
        final int x = doneLocation[0] - rowLocation[0] + centerX;
        final int y = doneLocation[1] - rowLocation[1] + centerY;
        dismissPopups(x, y);
        closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
                true /* removeControls */, x, y, true /* resetMenu */);
    }

    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
@@ -5917,6 +5923,12 @@ public class StatusBar extends SystemUI implements DemoMode,
                if (row.isDark()) {
                    return false;
                }
                if (row.areGutsExposed()) {
                    closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
                            true /* removeControls */, -1 /* x */, -1 /* y */,
                            true /* resetMenu */);
                    return false;
                }
                bindGuts(row, item);
                NotificationGuts guts = row.getGuts();

@@ -5926,12 +5938,6 @@ public class StatusBar extends SystemUI implements DemoMode,
                    return false;
                }

                // Already showing?
                if (guts.getVisibility() == View.VISIBLE) {
                    dismissPopups(x, y);
                    return false;
                }

                mMetricsLogger.action(MetricsEvent.ACTION_NOTE_CONTROLS);

                // ensure that it's laid but not visible until actually laid out
@@ -5945,8 +5951,9 @@ public class StatusBar extends SystemUI implements DemoMode,
                                    + "window");
                            return;
                        }
                        dismissPopups(-1 /* x */, -1 /* y */, false /* resetMenu */,
                                false /* animate */);
                        closeAndSaveGuts(true /* removeLeavebehind */, true /* force */,
                                true /* removeControls */, -1 /* x */, -1 /* y */,
                                false /* resetMenu */);
                        guts.setVisibility(View.VISIBLE);
                        final double horz = Math.max(guts.getWidth() - x, x);
                        final double vert = Math.max(guts.getHeight() - y, y);
@@ -5986,20 +5993,23 @@ public class StatusBar extends SystemUI implements DemoMode,
        return mNotificationGutsExposed;
    }

    public void dismissPopups() {
        dismissPopups(-1 /* x */, -1 /* y */, true /* resetMenu */, false /* animate */);
    }

    private void dismissPopups(int x, int y) {
        dismissPopups(x, y, true /* resetMenu */, false /* animate */);
    }

    public void dismissPopups(int x, int y, boolean resetMenu, boolean animate) {
    /**
     * Closes guts or notification menus that might be visible and saves any changes.
     *
     * @param removeLeavebehinds true if leavebehinds (e.g. snooze) should be closed.
     * @param force true if guts should be closed regardless of state (used for snooze only).
     * @param removeControls true if controls (e.g. info) should be closed.
     * @param x if closed based on touch location, this is the x touch location.
     * @param y if closed based on touch location, this is the y touch location.
     * @param resetMenu if any notification menus that might be revealed should be closed.
     */
    public void closeAndSaveGuts(boolean removeLeavebehinds, boolean force, boolean removeControls,
            int x, int y, boolean resetMenu) {
        if (mNotificationGutsExposed != null) {
            mNotificationGutsExposed.closeControls(x, y, true /* save */);
            mNotificationGutsExposed.closeControls(removeLeavebehinds, removeControls, x, y, force);
        }
        if (resetMenu) {
            mStackScroller.resetExposedMenuView(animate, true /* force */);
            mStackScroller.resetExposedMenuView(false /* animate */, true /* force */);
        }
    }

@@ -6521,7 +6531,8 @@ public class StatusBar extends SystemUI implements DemoMode,
        if (mVisible != visible) {
            mVisible = visible;
            if (!visible) {
                dismissPopups();
                closeAndSaveGuts(true /* removeLeavebehind */, true /* force */,
                        true /* removeControls */, -1 /* x */, -1 /* y */, true /* resetMenu */);
            }
        }
        updateVisibleToUser();
Loading