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

Commit b981efa9 authored by Aaron Heuckroth's avatar Aaron Heuckroth Committed by Android (Google) Code Review
Browse files

Merge "Remove references to SwipeHelper from NotificationMenuRow."

parents 174a48b5 266cb348
Loading
Loading
Loading
Loading
+115 −11
Original line number Diff line number Diff line
@@ -38,11 +38,12 @@ import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem
public interface NotificationMenuRowPlugin extends Plugin {

    public static final String ACTION = "com.android.systemui.action.PLUGIN_NOTIFICATION_MENU_ROW";
    public static final int VERSION = 4;
    public static final int VERSION = 5;

    @ProvidesInterface(version = OnMenuEventListener.VERSION)
    public interface OnMenuEventListener {
        public static final int VERSION = 1;

        public void onMenuClicked(View row, int x, int y, MenuItem menu);

        public void onMenuReset(View row);
@@ -53,6 +54,7 @@ public interface NotificationMenuRowPlugin extends Plugin {
    @ProvidesInterface(version = MenuItem.VERSION)
    public interface MenuItem {
        public static final int VERSION = 1;

        public View getMenuView();

        public View getGutsView();
@@ -84,34 +86,136 @@ public interface NotificationMenuRowPlugin extends Plugin {

    public void setMenuClickListener(OnMenuEventListener listener);

    public void setSwipeActionHelper(NotificationSwipeActionHelper listener);

    public void setAppName(String appName);

    public void createMenu(ViewGroup parent, StatusBarNotification sbn);

    public void resetMenu();

    public View getMenuView();

    /**
     * Get the target position that a notification row should be snapped open to in order to reveal
     * the menu. This is generally determined by the number of icons in the notification menu and the
     * size of each icon. This method accounts for whether the menu appears on the left or ride side
     * of the parent notification row.
     *

     * @return an int representing the x-offset in pixels that the notification should snap open to.
     * Positive values imply that the notification should be offset to the right to reveal the menu,
     * and negative alues imply that the notification should be offset to the right.
     */
    public int getMenuSnapTarget();

    /**
     * Determines whether or not the menu should be shown in response to user input.
     * @return true if the menu should be shown, false otherwise.
     */
    public boolean shouldShowMenu();

    /**
     * Determines whether the menu is currently visible.
     * @return true if the menu is visible, false otherwise.
     */
    public boolean isMenuVisible();

    public void resetMenu();
    /**
     * Determines whether a given movement is towards or away from the current location of the menu.
     * @param movement
     * @return true if the movement is towards the menu, false otherwise.
     */
    public boolean isTowardsMenu(float movement);

    public void onTranslationUpdate(float translation);
    /**
     * Determines whether the menu should snap closed instead of dismissing the
     * parent notification, as a function of its current state.
     *
     * @return true if the menu should snap closed, false otherwise.
     */
    public boolean shouldSnapBack();

    public void onHeightUpdate();
    /**
     * Determines whether the menu was previously snapped open to the same side that it is currently
     * being shown on.
     * @return true if the menu is snapped open to the same side on which it currently appears,
     * false otherwise.
     */
    public boolean isSnappedAndOnSameSide();

    public void onNotificationUpdated(StatusBarNotification sbn);
    /**
     * Determines whether the notification the menu is attached to is able to be dismissed.
     * @return true if the menu's parent notification is dismissable, false otherwise.
     */
    public boolean canBeDismissed();

    public boolean onTouchEvent(View view, MotionEvent ev, float velocity);
    /**
     * Determines whether the menu should remain open given its current state, or snap closed.
     * @return true if the menu should remain open, false otherwise.
     */
    public boolean isWithinSnapMenuThreshold();

    /**
     * Determines whether the menu has been swiped far enough to snap open.
     * @return true if the menu has been swiped far enough to open, false otherwise.
     */
    public boolean isSwipedEnoughToShowMenu();

    public default boolean onInterceptTouchEvent(View view, MotionEvent ev) {
        return false;
    }

    public default boolean useDefaultMenuItems() {
    public default boolean shouldUseDefaultMenuItems() {
        return false;
    }

    public default void onConfigurationChanged() {
    }
    /**
     * Callback used to signal the menu that its parent's translation has changed.
     * @param translation The new x-translation of the menu as a position (not an offset).
     */
    public void onParentTranslationUpdate(float translation);

    /**
     * Callback used to signal the menu that its parent's height has changed.
     */
    public void onParentHeightUpdate();

    /**
     * Callback used to signal the menu that its parent notification has been updated.
     * @param sbn
     */
    public void onNotificationUpdated(StatusBarNotification sbn);

    /**
     * Callback used to signal the menu that a user is moving the parent notification.
     * @param delta The change in the parent notification's position.
     */
    public void onTouchMove(float delta);

    /**
     * Callback used to signal the menu that a user has begun touching its parent notification.
     */
    public void onTouchStart();

    /**
     * Callback used to signal the menu that a user has finished touching its parent notification.
     */
    public void onTouchEnd();

    /**
     * Callback used to signal the menu that it has been snapped closed.
     */
    public void onSnapClosed();

    /**
     * Callback used to signal the menu that it has been snapped open.
     */
    public void onSnapOpen();

    /**
     * Callback used to signal the menu that its parent notification has been dismissed.
     */
    public void onDismiss();

    public default void onConfigurationChanged() { }

}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public interface NotificationSwipeActionHelper {
    /**
     * Call this to snap a notification to provided {@code targetLeft}.
     */
    public void snap(View animView, float velocity, float targetLeft);
    public void snapOpen(View animView, int targetLeft, float velocity);

    /**
     * Call this to snooze a notification based on the provided {@link SnoozeOption}.
+4 −4
Original line number Diff line number Diff line
@@ -1037,7 +1037,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            removeView(mMenuRow.getMenuView());
        }
        mMenuRow = plugin;
        if (mMenuRow.useDefaultMenuItems()) {
        if (mMenuRow.shouldUseDefaultMenuItems()) {
            ArrayList<MenuItem> items = new ArrayList<>();
            items.add(NotificationMenuRow.createInfoItem(mContext));
            items.add(NotificationMenuRow.createSnoozeItem(mContext));
@@ -1787,7 +1787,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            getEntry().expandedIcon.setScrollX((int) -translationX);
        }
        if (mMenuRow.getMenuView() != null) {
            mMenuRow.onTranslationUpdate(translationX);
            mMenuRow.onParentTranslationUpdate(translationX);
        }
    }

@@ -2292,7 +2292,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            notifyHeightChanged(true  /* needsAnimation */);
        }
        if (mMenuRow.getMenuView() != null) {
            mMenuRow.onHeightUpdate();
            mMenuRow.onParentHeightUpdate();
        }
        updateContentShiftHeight();
        if (mLayoutListener != null) {
@@ -2543,7 +2543,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mGuts.setActualHeight(height);
        }
        if (mMenuRow.getMenuView() != null) {
            mMenuRow.onHeightUpdate();
            mMenuRow.onParentHeightUpdate();
        }
    }

+194 −175

File changed.

Preview size limit exceeded, changes collapsed.

+95 −16
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.animation.PropertyValuesHolder;
import android.animation.TimeAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.FloatRange;
import android.annotation.Nullable;
import android.app.WallpaperManager;
import android.content.Context;
@@ -5322,6 +5321,8 @@ public class NotificationStackScrollLayout extends ViewGroup
        private Runnable mFalsingCheck;
        private Handler mHandler;

        private static final long SWIPE_MENU_TIMING = 200;

        public NotificationSwipeHelper(int swipeDirection, Callback callback, Context context) {
            super(swipeDirection, callback, context);
            mHandler = new Handler();
@@ -5337,7 +5338,7 @@ public class NotificationStackScrollLayout extends ViewGroup
        public void onDownUpdate(View currView, MotionEvent ev) {
            mTranslatingParentView = currView;
            if (mCurrMenuRow != null) {
                mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
                mCurrMenuRow.onTouchStart();
            }
            mCurrMenuRow = null;
            mHandler.removeCallbacks(mFalsingCheck);
@@ -5350,18 +5351,21 @@ public class NotificationStackScrollLayout extends ViewGroup

                if (row.getEntry().hasFinishedInitialization()) {
                    mCurrMenuRow = row.createMenu();
                    mCurrMenuRow.setSwipeActionHelper(NotificationSwipeHelper.this);
                    mCurrMenuRow.setMenuClickListener(NotificationStackScrollLayout.this);
                    mCurrMenuRow.onTouchEvent(currView, ev, 0 /* velocity */);
                    mCurrMenuRow.onTouchStart();
                }
            }
        }

        private boolean swipedEnoughToShowMenu(NotificationMenuRowPlugin menuRow) {
            return !swipedFarEnough() && menuRow.isSwipedEnoughToShowMenu();
        }

        @Override
        public void onMoveUpdate(View view, MotionEvent ev, float translation, float delta) {
            mHandler.removeCallbacks(mFalsingCheck);
            if (mCurrMenuRow != null) {
                mCurrMenuRow.onTouchEvent(view, ev, 0 /* velocity */);
                mCurrMenuRow.onTouchMove(delta);
            }
        }

@@ -5369,11 +5373,91 @@ public class NotificationStackScrollLayout extends ViewGroup
        public boolean handleUpEvent(MotionEvent ev, View animView, float velocity,
                float translation) {
            if (mCurrMenuRow != null) {
                return mCurrMenuRow.onTouchEvent(animView, ev, velocity);
                mCurrMenuRow.onTouchEnd();
                handleMenuRowSwipe(ev, animView, velocity, mCurrMenuRow);
                return true;
            }
            return false;
        }

        @Override
        public boolean swipedFarEnough(float translation, float viewSize) {
            return swipedFarEnough();
        }

        private void handleMenuRowSwipe(MotionEvent ev, View animView, float velocity,
                NotificationMenuRowPlugin menuRow) {
            if (!menuRow.shouldShowMenu()) {
                // If the menu should not be shown, then there is no need to check if the a swipe
                // should result in a snapping to the menu. As a result, just check if the swipe
                // was enough to dismiss the notification.
                if (isDismissGesture(ev)) {
                    dismiss(animView, velocity);
                } else {
                    snapBack(animView, velocity);
                    menuRow.onSnapClosed();
                }
                return;
            }

            if (menuRow.isSnappedAndOnSameSide()) {
                // Menu was snapped to previously and we're on the same side
                handleSwipeFromSnap(ev, animView, velocity, menuRow);
            } else {
                // Menu has not been snapped, or was snapped previously but is now on
                // the opposite side.
                handleSwipeFromNonSnap(ev, animView, velocity, menuRow);
            }
        }

        private void handleSwipeFromNonSnap(MotionEvent ev, View animView, float velocity,
                NotificationMenuRowPlugin menuRow) {
            boolean isDismissGesture = isDismissGesture(ev);
            final boolean gestureTowardsMenu = menuRow.isTowardsMenu(velocity);
            final boolean gestureFastEnough =
                    mSwipeHelper.getMinDismissVelocity() <= Math.abs(velocity);

            final double timeForGesture = ev.getEventTime() - ev.getDownTime();
            final boolean showMenuForSlowOnGoing = !menuRow.canBeDismissed()
                    && timeForGesture >= SWIPE_MENU_TIMING;

            if (!isFalseGesture(ev)
                    && (swipedEnoughToShowMenu(menuRow)
                    && (!gestureFastEnough || showMenuForSlowOnGoing))
                    || (gestureTowardsMenu && !isDismissGesture)) {
                // Menu has not been snapped to previously and this is menu revealing gesture
                snapOpen(animView, menuRow.getMenuSnapTarget(), velocity);
                menuRow.onSnapOpen();
            } else if (isDismissGesture(ev) && !gestureTowardsMenu) {
                dismiss(animView, velocity);
                menuRow.onDismiss();
            } else {
                snapBack(animView, velocity);
                menuRow.onSnapClosed();
            }
        }

        private void handleSwipeFromSnap(MotionEvent ev, View animView, float velocity,
                NotificationMenuRowPlugin menuRow) {
            boolean isDismissGesture = isDismissGesture(ev);

            final boolean withinSnapMenuThreshold =
                    menuRow.isWithinSnapMenuThreshold();

            if (withinSnapMenuThreshold && !isDismissGesture) {
                // Haven't moved enough to unsnap from the menu
                menuRow.onSnapOpen();
                snapOpen(animView, menuRow.getMenuSnapTarget(), velocity);
            } else if (isDismissGesture && !menuRow.shouldSnapBack()) {
                // Only dismiss if we're not moving towards the menu
                dismiss(animView, velocity);
                menuRow.onDismiss();
            } else {
                snapBack(animView, velocity);
                menuRow.onSnapClosed();
            }
        }

        @Override
        public void dismissChild(final View view, float velocity,
                boolean useAccelerateInterpolator) {
@@ -5403,10 +5487,6 @@ public class NotificationStackScrollLayout extends ViewGroup
            mStatusBar.setNotificationSnoozed(sbn, snoozeOption);
        }

        public boolean isFalseGesture(MotionEvent ev) {
            return super.isFalseGesture(ev);
        }

        private void handleMenuCoveredOrDismissed() {
            if (mMenuExposedView != null && mMenuExposedView == mTranslatingParentView) {
                mMenuExposedView = null;
@@ -5440,13 +5520,12 @@ public class NotificationStackScrollLayout extends ViewGroup
        }

        @Override
        public void snap(View animView, float targetLeft, float velocity) {
        public void snapOpen(View animView, int targetLeft, float velocity) {
            snapChild(animView, targetLeft, velocity);
        }

        @Override
        public boolean swipedFarEnough(float translation, float viewSize) {
            return swipedFarEnough();
        private void snapBack(View animView, float velocity) {
            snapChild(animView, 0, velocity);
        }

        @Override
Loading