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

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

Recognize stylus touch + press button as a longpress in AbsListView

The gesture is: stylus touching screen + button pressed, the event
is recognized when the button is pressed, not when it's released.
It can be pressed during DOWN or MOVE.

Bug: 19620479
Change-Id: I4ce2cea4eb058e308ba88ef3dd3bed278bdca555
parent 7f9be1cb
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -3116,6 +3116,25 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

    private boolean performStylusButtonPressAction(MotionEvent ev) {
        if (ev.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
                && ev.isButtonPressed(MotionEvent.BUTTON_SECONDARY)
                && mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
            final View child = getChildAt(mMotionPosition - mFirstPosition);
            if (child != null) {
                final int longPressPosition = mMotionPosition;
                final long longPressId = mAdapter.getItemId(mMotionPosition);
                if (performLongPress(child, longPressPosition, longPressId)) {
                    mTouchMode = TOUCH_MODE_REST;
                    setPressed(false);
                    child.setPressed(false);
                    return true;
                }
            }
        }
        return false;
    }

    boolean performLongPress(final View child,
            final int longPressPosition, final long longPressId) {
        // CHOICE_MODE_MULTIPLE_MODAL takes over long press.
@@ -3757,7 +3776,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }

        if (mTouchMode == TOUCH_MODE_DOWN && mMotionPosition != INVALID_POSITION
                && performButtonActionOnTouchDown(ev)) {
                && (performButtonActionOnTouchDown(ev) || performStylusButtonPressAction(ev))) {
                removeCallbacks(mPendingCheckForTap);
        }
    }
@@ -3800,6 +3819,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    mTouchMode = TOUCH_MODE_DONE_WAITING;
                    updateSelectorState();
                } else if (motionView != null) {
                    if (performStylusButtonPressAction(ev)) {
                        removeCallbacks(mPendingCheckForTap);
                        removeCallbacks(mPendingCheckForLongPress);
                    }

                    // Still within bounds, update the hotspot.
                    final float[] point = mTmpPoint;
                    point[0] = x;