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

Commit 90de2246 authored by Geoffrey Pitsch's avatar Geoffrey Pitsch Committed by android-build-merger
Browse files

Merge "Support keyboard long-press on notifications" into oc-mr1-dev am: e7c9d8f9

am: fd7be277

Change-Id: Ia2a0d536e3f1cfe6af682071f91f810bfb84da21
parents 69332c48 fd7be277
Loading
Loading
Loading
Loading
+29 −44
Original line number Original line Diff line number Diff line
@@ -83,7 +83,6 @@ public class SwipeHelper implements Gefingerpoken {


    private boolean mMenuRowIntercepting;
    private boolean mMenuRowIntercepting;
    private boolean mLongPressSent;
    private boolean mLongPressSent;
    private LongPressListener mLongPressListener;
    private Runnable mWatchLongPress;
    private Runnable mWatchLongPress;
    private final long mLongPressTimeout;
    private final long mLongPressTimeout;


@@ -115,10 +114,6 @@ public class SwipeHelper implements Gefingerpoken {
        mFlingAnimationUtils = new FlingAnimationUtils(context, getMaxEscapeAnimDuration() / 1000f);
        mFlingAnimationUtils = new FlingAnimationUtils(context, getMaxEscapeAnimDuration() / 1000f);
    }
    }


    public void setLongPressListener(LongPressListener listener) {
        mLongPressListener = listener;
    }

    public void setDensityScale(float densityScale) {
    public void setDensityScale(float densityScale) {
        mDensityScale = densityScale;
        mDensityScale = densityScale;
    }
    }
@@ -257,7 +252,7 @@ public class SwipeHelper implements Gefingerpoken {
        }
        }
    }
    }


    public void removeLongPressCallback() {
    public void cancelLongPress() {
        if (mWatchLongPress != null) {
        if (mWatchLongPress != null) {
            mHandler.removeCallbacks(mWatchLongPress);
            mHandler.removeCallbacks(mWatchLongPress);
            mWatchLongPress = null;
            mWatchLongPress = null;
@@ -281,6 +276,14 @@ public class SwipeHelper implements Gefingerpoken {
                mVelocityTracker.clear();
                mVelocityTracker.clear();
                mCurrView = mCallback.getChildAtPosition(ev);
                mCurrView = mCallback.getChildAtPosition(ev);


                // The SwipeHelper sends its own long-press, don't let the view send a dupe.
                // Queue up a cancelLongPress on the view a few ms after we see a down event.
                mHandler.post(() -> {
                    if (mCurrView != null) {
                        mCurrView.cancelLongPress();
                    }
                });

                if (mCurrView != null) {
                if (mCurrView != null) {
                    onDownUpdate(mCurrView, ev);
                    onDownUpdate(mCurrView, ev);
                    mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
                    mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
@@ -288,26 +291,20 @@ public class SwipeHelper implements Gefingerpoken {
                    mInitialTouchPos = getPos(ev);
                    mInitialTouchPos = getPos(ev);
                    mPerpendicularInitialTouchPos = getPerpendicularPos(ev);
                    mPerpendicularInitialTouchPos = getPerpendicularPos(ev);
                    mTranslation = getTranslation(mCurrView);
                    mTranslation = getTranslation(mCurrView);
                    if (mLongPressListener != null) {
                    if (mWatchLongPress == null) {
                    if (mWatchLongPress == null) {
                        mWatchLongPress = new Runnable() {
                        mWatchLongPress = new Runnable() {
                            @Override
                            @Override
                            public void run() {
                            public void run() {
                                if (mCurrView != null && !mLongPressSent) {
                                if (mCurrView != null && !mLongPressSent) {
                                    mLongPressSent = true;
                                    mLongPressSent = true;
                                        mCurrView.sendAccessibilityEvent(
                                                AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
                                    mCurrView.getLocationOnScreen(mTmpPos);
                                    mCurrView.getLocationOnScreen(mTmpPos);
                                    final int x = (int) ev.getRawX() - mTmpPos[0];
                                    final int x = (int) ev.getRawX() - mTmpPos[0];
                                    final int y = (int) ev.getRawY() - mTmpPos[1];
                                    final int y = (int) ev.getRawY() - mTmpPos[1];
                                        MenuItem menuItem = null;
                                    if (mCurrView instanceof ExpandableNotificationRow) {
                                    if (mCurrView instanceof ExpandableNotificationRow) {
                                            menuItem = ((ExpandableNotificationRow) mCurrView)
                                        ExpandableNotificationRow currRow =
                                                    .getProvider().getLongpressMenuItem(mContext);
                                                (ExpandableNotificationRow) mCurrView;
                                        }
                                        currRow.setLongPressPosition(x, y);
                                        if (menuItem != null) {
                                        currRow.performLongClick(x, y);
                                            mLongPressListener.onLongPress(mCurrView, x, y,
                                                    menuItem);
                                    }
                                    }
                                }
                                }
                            }
                            }
@@ -315,7 +312,6 @@ public class SwipeHelper implements Gefingerpoken {
                    }
                    }
                    mHandler.postDelayed(mWatchLongPress, mLongPressTimeout);
                    mHandler.postDelayed(mWatchLongPress, mLongPressTimeout);
                }
                }
                }
                break;
                break;


            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_MOVE:
@@ -331,7 +327,7 @@ public class SwipeHelper implements Gefingerpoken {
                        mDragging = true;
                        mDragging = true;
                        mInitialTouchPos = getPos(ev);
                        mInitialTouchPos = getPos(ev);
                        mTranslation = getTranslation(mCurrView);
                        mTranslation = getTranslation(mCurrView);
                        removeLongPressCallback();
                        cancelLongPress();
                    }
                    }
                }
                }
                break;
                break;
@@ -343,7 +339,7 @@ public class SwipeHelper implements Gefingerpoken {
                mCurrView = null;
                mCurrView = null;
                mLongPressSent = false;
                mLongPressSent = false;
                mMenuRowIntercepting = false;
                mMenuRowIntercepting = false;
                removeLongPressCallback();
                cancelLongPress();
                if (captured) return true;
                if (captured) return true;
                break;
                break;
        }
        }
@@ -586,7 +582,7 @@ public class SwipeHelper implements Gefingerpoken {


                // We are not doing anything, make sure the long press callback
                // We are not doing anything, make sure the long press callback
                // is not still ticking like a bomb waiting to go off.
                // is not still ticking like a bomb waiting to go off.
                removeLongPressCallback();
                cancelLongPress();
                return false;
                return false;
            }
            }
        }
        }
@@ -734,15 +730,4 @@ public class SwipeHelper implements Gefingerpoken {
         */
         */
        float getFalsingThresholdFactor();
        float getFalsingThresholdFactor();
    }
    }

    /**
     * Equivalent to View.OnLongClickListener with coordinates
     */
    public interface LongPressListener {
        /**
         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
         * @return whether the longpress was handled
         */
        boolean onLongPress(View v, int x, int y, MenuItem item);
    }
}
}
+48 −0
Original line number Original line Diff line number Diff line
@@ -172,6 +172,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private boolean mShowNoBackground;
    private boolean mShowNoBackground;
    private ExpandableNotificationRow mNotificationParent;
    private ExpandableNotificationRow mNotificationParent;
    private OnExpandClickListener mOnExpandClickListener;
    private OnExpandClickListener mOnExpandClickListener;

    // Listener will be called when receiving a long click event.
    // Use #setLongPressPosition to optionally assign positional data with the long press.
    private LongPressListener mLongPressListener;
    private boolean mLongPressPositionSet = false;
    private int mLongPressX = 0;
    private int mLongPressY = 0;

    private boolean mGroupExpansionChanging;
    private boolean mGroupExpansionChanging;


    /**
    /**
@@ -773,6 +781,16 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mOnExpandClickListener = onExpandClickListener;
        mOnExpandClickListener = onExpandClickListener;
    }
    }


    public void setLongPressListener(LongPressListener longPressListener) {
        mLongPressListener = longPressListener;
    }

    public void setLongPressPosition(int x, int y) {
        mLongPressPositionSet = true;
        mLongPressX = x;
        mLongPressY = y;
    }

    @Override
    @Override
    public void setOnClickListener(@Nullable OnClickListener l) {
    public void setOnClickListener(@Nullable OnClickListener l) {
        super.setOnClickListener(l);
        super.setOnClickListener(l);
@@ -1321,6 +1339,25 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mTranslateableViews.remove(mChildrenContainerStub);
            mTranslateableViews.remove(mChildrenContainerStub);
            mTranslateableViews.remove(mGutsStub);
            mTranslateableViews.remove(mGutsStub);
        }
        }

        setOnLongClickListener((View v) -> {
            createMenu();
            MenuItem menuItem = getProvider().getLongpressMenuItem(mContext);
            if (mLongPressListener != null && menuItem != null) {
                int x, y;
                if (mLongPressPositionSet) {
                    x = mLongPressX;
                    y = mLongPressY;
                } else {
                    // No position assigned - use the center of the View
                    x = getWidth() / 2;
                    y = getHeight() / 2;
                }
                mLongPressPositionSet = false;
                return mLongPressListener.onLongPress(this, x, y, menuItem);
            }
            return false;
        });
    }
    }


    public void resetTranslation() {
    public void resetTranslation() {
@@ -2304,4 +2341,15 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
    protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
        mChildrenContainer = childrenContainer;
        mChildrenContainer = childrenContainer;
    }
    }

    /**
     * Equivalent to View.OnLongClickListener with coordinates
     */
    public interface LongPressListener {
        /**
         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
         * @return whether the longpress was handled
         */
        boolean onLongPress(View v, int x, int y, MenuItem item);
    }
}
}
+5 −3
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.fragments.FragmentHostManager;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.NotificationData;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment;
import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment;
@@ -247,11 +248,12 @@ public class CarStatusBar extends StatusBar implements
    }
    }


    /**
    /**
     * Returns the {@link com.android.systemui.SwipeHelper.LongPressListener} that will be
     * Returns the
     * triggered when a notification card is long-pressed.
     * {@link com.android.systemui.statusbar.ExpandableNotificationRow.LongPressListener} that will
     * be triggered when a notification card is long-pressed.
     */
     */
    @Override
    @Override
    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
    protected ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
        // For the automative use case, we do not want to the user to be able to interact with
        // For the automative use case, we do not want to the user to be able to interact with
        // a notification other than a regular click. As a result, just return null for the
        // a notification other than a regular click. As a result, just return null for the
        // long click listener.
        // long click listener.
+2 −2
Original line number Original line Diff line number Diff line
@@ -700,7 +700,7 @@ public class NotificationPanelView extends PanelView implements
                    mInitialHeightOnTouch = mQsExpansionHeight;
                    mInitialHeightOnTouch = mQsExpansionHeight;
                    mQsTracking = true;
                    mQsTracking = true;
                    mIntercepting = false;
                    mIntercepting = false;
                    mNotificationStackScroller.removeLongPressCallback();
                    mNotificationStackScroller.cancelLongPress();
                }
                }
                break;
                break;
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_POINTER_UP:
@@ -736,7 +736,7 @@ public class NotificationPanelView extends PanelView implements
                    mInitialTouchY = y;
                    mInitialTouchY = y;
                    mInitialTouchX = x;
                    mInitialTouchX = x;
                    mIntercepting = false;
                    mIntercepting = false;
                    mNotificationStackScroller.removeLongPressCallback();
                    mNotificationStackScroller.cancelLongPress();
                    return true;
                    return true;
                }
                }
                break;
                break;
+7 −6
Original line number Original line Diff line number Diff line
@@ -167,7 +167,6 @@ import com.android.systemui.Interpolators;
import com.android.systemui.Prefs;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.RecentsComponent;
import com.android.systemui.RecentsComponent;
import com.android.systemui.SwipeHelper;
import com.android.systemui.SystemUI;
import com.android.systemui.SystemUI;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.UiOffloadThread;
@@ -4940,7 +4939,7 @@ public class StatusBar extends SystemUI implements DemoMode,


    @Override
    @Override
    public void onTouchSlopExceeded() {
    public void onTouchSlopExceeded() {
        mStackScroller.removeLongPressCallback();
        mStackScroller.cancelLongPress();
        mStackScroller.checkSnoozeLeavebehind();
        mStackScroller.checkSnoozeLeavebehind();
    }
    }


@@ -6427,14 +6426,15 @@ public class StatusBar extends SystemUI implements DemoMode,
                true /* removeControls */, x, y, true /* resetMenu */);
                true /* removeControls */, x, y, true /* resetMenu */);
    }
    }


    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
    protected ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
        return new SwipeHelper.LongPressListener() {
        return new ExpandableNotificationRow.LongPressListener() {
            @Override
            @Override
            public boolean onLongPress(View v, final int x, final int y,
            public boolean onLongPress(View v, final int x, final int y,
                    MenuItem item) {
                    MenuItem item) {
                if (!(v instanceof ExpandableNotificationRow)) {
                if (!(v instanceof ExpandableNotificationRow)) {
                    return false;
                    return false;
                }
                }

                if (v.getWindowToken() == null) {
                if (v.getWindowToken() == null) {
                    Log.e(TAG, "Trying to show notification guts, but not attached to window");
                    Log.e(TAG, "Trying to show notification guts, but not attached to window");
                    return false;
                    return false;
@@ -6449,7 +6449,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                    closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
                    closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
                            true /* removeControls */, -1 /* x */, -1 /* y */,
                            true /* removeControls */, -1 /* x */, -1 /* y */,
                            true /* resetMenu */);
                            true /* resetMenu */);
                    return false;
                    return true;
                }
                }
                bindGuts(row, item);
                bindGuts(row, item);
                NotificationGuts guts = row.getGuts();
                NotificationGuts guts = row.getGuts();
@@ -6735,6 +6735,7 @@ public class StatusBar extends SystemUI implements DemoMode,
        row.setOnExpandClickListener(this);
        row.setOnExpandClickListener(this);
        row.setRemoteViewClickHandler(mOnClickHandler);
        row.setRemoteViewClickHandler(mOnClickHandler);
        row.setInflationCallback(this);
        row.setInflationCallback(this);
        row.setLongPressListener(getNotificationLongClicker());


        // Get the app name.
        // Get the app name.
        // Note that Notification.Builder#bindHeaderAppName has similar logic
        // Note that Notification.Builder#bindHeaderAppName has similar logic
Loading