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

Commit 74ded29b authored by Alan Viverette's avatar Alan Viverette
Browse files

Clear pressed state when moving outside list bounds.

Bug: 8724943
Change-Id: Ife40ad672c161fef76e62dfd3c7f7fb3b08c3648
parent c930c4e1
Loading
Loading
Loading
Loading
+75 −76
Original line number Diff line number Diff line
@@ -2428,7 +2428,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
     * @return True if the selector should be shown
     */
    boolean shouldShowSelector() {
        return (!isInTouchMode()) || touchModeDrawsInPressedState();
        return (!isInTouchMode()) || (touchModeDrawsInPressedState() && isPressed());
    }

    private void drawSelector(Canvas canvas) {
@@ -3055,15 +3055,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                mTouchMode = TOUCH_MODE_SCROLL;
                mMotionCorrection = deltaY > 0 ? mTouchSlop : -mTouchSlop;
            }
            final Handler handler = getHandler();
            // Handler should not be null unless the AbsListView is not attached to a
            // window, which would make it very hard to scroll it... but the monkeys
            // say it's possible.
            if (handler != null) {
                handler.removeCallbacks(mPendingCheckForLongPress);
            }
            removeCallbacks(mPendingCheckForLongPress);
            setPressed(false);
            View motionView = getChildAt(mMotionPosition - mFirstPosition);
            final View motionView = getChildAt(mMotionPosition - mFirstPosition);
            if (motionView != null) {
                motionView.setPressed(false);
            }
@@ -3457,8 +3451,26 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            case TOUCH_MODE_TAP:
            case TOUCH_MODE_DONE_WAITING:
                // Check if we have moved far enough that it looks more like a
                // scroll than a tap
                startScrollIfNeeded(y);
                // scroll than a tap. If so, we'll enter scrolling mode.
                if (startScrollIfNeeded(y)) {
                    break;
                }
                // Otherwise, check containment within list bounds. If we're
                // outside bounds, cancel any active presses.
                final float x = ev.getX();
                final boolean inList = (x > mListPadding.left)
                        && (x < getWidth() - mListPadding.right);
                if (!inList) {
                    setPressed(false);
                    final View motionView = getChildAt(mMotionPosition - mFirstPosition);
                    if (motionView != null) {
                        motionView.setPressed(false);
                    }
                    removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ?
                            mPendingCheckForTap : mPendingCheckForLongPress);
                    mTouchMode = TOUCH_MODE_DONE_WAITING;
                    updateSelectorState();
                }
                break;
            case TOUCH_MODE_SCROLL:
            case TOUCH_MODE_OVERSCROLL:
@@ -3474,15 +3486,14 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        case TOUCH_MODE_DONE_WAITING:
            final int motionPosition = mMotionPosition;
            final View child = getChildAt(motionPosition - mFirstPosition);

            final float x = ev.getX();
            final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;

            if (child != null && !child.hasFocusable() && inList) {
            if (child != null) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                final float x = ev.getX();
                final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
                if (inList && !child.hasFocusable()) {
                    if (mPerformClick == null) {
                        mPerformClick = new PerformClick();
                    }
@@ -3494,11 +3505,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    mResurrectToPosition = motionPosition;

                    if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handler = getHandler();
                    if (handler != null) {
                        handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ?
                        removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ?
                                mPendingCheckForTap : mPendingCheckForLongPress);
                    }
                        mLayoutMode = LAYOUT_NORMAL;
                        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                            mTouchMode = TOUCH_MODE_TAP;
@@ -3539,6 +3547,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        performClick.run();
                    }
                }
            }
            mTouchMode = TOUCH_MODE_REST;
            updateSelectorState();
            break;
@@ -3619,12 +3628,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

        // Need to redraw since we probably aren't drawing the selector anymore
        invalidate();

        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        removeCallbacks(mPendingCheckForLongPress);
        recycleVelocityTracker();

        mActivePointerId = INVALID_POINTER;
@@ -3658,17 +3662,12 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        default:
            mTouchMode = TOUCH_MODE_REST;
            setPressed(false);
            View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
            final View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
            if (motionView != null) {
                motionView.setPressed(false);
            }
            clearScrollingCache();

            final Handler handler = getHandler();
            if (handler != null) {
                handler.removeCallbacks(mPendingCheckForLongPress);
            }

            removeCallbacks(mPendingCheckForLongPress);
            recycleVelocityTracker();
        }