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

Commit 523a1289 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Fix bug 5051894 - drags/flings at the beginning/end of ListViews are often dropped"

parents 83e32904 044a46bd
Loading
Loading
Loading
Loading
+51 −43
Original line number Original line Diff line number Diff line
@@ -2817,9 +2817,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    mPositionScroller.stop();
                    mPositionScroller.stop();
                }
                }
                mTouchMode = TOUCH_MODE_OVERSCROLL;
                mTouchMode = TOUCH_MODE_OVERSCROLL;
                mMotionX = (int) ev.getX();
                mMotionY = mLastY = (int) ev.getY();
                mMotionY = mLastY = (int) ev.getY();
                mMotionCorrection = 0;
                mMotionCorrection = 0;
                mActivePointerId = ev.getPointerId(0);
                mActivePointerId = ev.getPointerId(0);
                mDirection = 0;
                break;
                break;
            }
            }


@@ -2994,56 +2996,57 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        mDirection = newDirection;
                        mDirection = newDirection;
                    }
                    }


                    if (mDirection != newDirection) {
                    int overScrollDistance = -incrementalDeltaY;
                        // Coming back to 'real' list scrolling
                    if ((newScroll < 0 && oldScroll >= 0) || (newScroll > 0 && oldScroll <= 0)) {
                        incrementalDeltaY = -newScroll;
                        overScrollDistance = -oldScroll;
                        mScrollY = 0;
                        incrementalDeltaY += overScrollDistance;
                        invalidateParentIfNeeded();
                    } else {

                        incrementalDeltaY = 0;
                        // No need to do all this work if we're not going to move anyway
                        if (incrementalDeltaY != 0) {
                            trackMotionScroll(incrementalDeltaY, incrementalDeltaY);
                    }
                    }


                        // Check to see if we are back in
                    if (overScrollDistance != 0) {
                        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
                        overScrollBy(0, overScrollDistance, 0, mScrollY, 0, 0,
                        if (motionView != null) {
                            mTouchMode = TOUCH_MODE_SCROLL;

                            // We did not scroll the full amount. Treat this essentially like the
                            // start of a new touch scroll
                            final int motionPosition = findClosestMotionRow(y);

                            mMotionCorrection = 0;
                            motionView = getChildAt(motionPosition - mFirstPosition);
                            mMotionViewOriginalTop = motionView.getTop();
                            mMotionY = y;
                            mMotionPosition = motionPosition;
                        }
                    } else {
                        overScrollBy(0, -incrementalDeltaY, 0, mScrollY, 0, 0,
                                0, mOverscrollDistance, true);
                                0, mOverscrollDistance, true);
                        final int overscrollMode = getOverScrollMode();
                        final int overscrollMode = getOverScrollMode();
                        if (overscrollMode == OVER_SCROLL_ALWAYS ||
                        if (overscrollMode == OVER_SCROLL_ALWAYS ||
                                (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS &&
                                (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS &&
                                        !contentFits())) {
                                        !contentFits())) {
                            if (rawDeltaY > 0) {
                            if (rawDeltaY > 0) {
                                mEdgeGlowTop.onPull((float) -incrementalDeltaY / getHeight());
                                mEdgeGlowTop.onPull((float) overScrollDistance / getHeight());
                                if (!mEdgeGlowBottom.isFinished()) {
                                if (!mEdgeGlowBottom.isFinished()) {
                                    mEdgeGlowBottom.onRelease();
                                    mEdgeGlowBottom.onRelease();
                                }
                                }
                            } else if (rawDeltaY < 0) {
                            } else if (rawDeltaY < 0) {
                                mEdgeGlowBottom.onPull((float) -incrementalDeltaY / getHeight());
                                mEdgeGlowBottom.onPull((float) overScrollDistance / getHeight());
                                if (!mEdgeGlowTop.isFinished()) {
                                if (!mEdgeGlowTop.isFinished()) {
                                    mEdgeGlowTop.onRelease();
                                    mEdgeGlowTop.onRelease();
                                }
                                }
                            }
                            }
                            invalidate();
                            invalidate();
                        }
                        }
                        if (Math.abs(mOverscrollDistance) == Math.abs(mScrollY)) {
                            // Don't allow overfling if we're at the edge.
                            mVelocityTracker.clear();
                    }
                    }

                    if (incrementalDeltaY != 0) {
                        // Coming back to 'real' list scrolling
                        mScrollY = 0;
                        invalidateParentIfNeeded();

                        // No need to do all this work if we're not going to move anyway
                        if (incrementalDeltaY != 0) {
                            trackMotionScroll(incrementalDeltaY, incrementalDeltaY);
                        }

                        mTouchMode = TOUCH_MODE_SCROLL;

                        // We did not scroll the full amount. Treat this essentially like the
                        // start of a new touch scroll
                        final int motionPosition = findClosestMotionRow(y);

                        mMotionCorrection = 0;
                        View motionView = getChildAt(motionPosition - mFirstPosition);
                        mMotionViewOriginalTop = motionView != null ? motionView.getTop() : 0;
                        mMotionY = y;
                        mMotionPosition = motionPosition;
                    }
                    }
                    mLastY = y;
                    mLastY = y;
                    mDirection = newDirection;
                    mDirection = newDirection;
@@ -3320,12 +3323,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mScrollY = scrollY;
            mScrollY = scrollY;
            invalidateParentIfNeeded();
            invalidateParentIfNeeded();


            if (clampedY) {
                // Velocity is broken by hitting the limit; don't start a fling off of this.
                if (mVelocityTracker != null) {
                    mVelocityTracker.clear();
                }
            }
            awakenScrollBars();
            awakenScrollBars();
        }
        }
    }
    }
@@ -3616,9 +3613,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
        }


        void startOverfling(int initialVelocity) {
        void startOverfling(int initialVelocity) {
            final int min = mScrollY > 0 ? Integer.MIN_VALUE : 0;
            mScroller.fling(0, mScrollY, 0, initialVelocity, 0, 0,
            final int max = mScrollY > 0 ? 0 : Integer.MAX_VALUE;
                    Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight());
            mScroller.fling(0, mScrollY, 0, initialVelocity, 0, 0, min, max, 0, getHeight());
            mTouchMode = TOUCH_MODE_OVERFLING;
            mTouchMode = TOUCH_MODE_OVERFLING;
            invalidate();
            invalidate();
            post(this);
            post(this);
@@ -3768,10 +3764,22 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                final OverScroller scroller = mScroller;
                final OverScroller scroller = mScroller;
                if (scroller.computeScrollOffset()) {
                if (scroller.computeScrollOffset()) {
                    final int scrollY = mScrollY;
                    final int scrollY = mScrollY;
                    final int deltaY = scroller.getCurrY() - scrollY;
                    final int currY = scroller.getCurrY();
                    final int deltaY = currY - scrollY;
                    if (overScrollBy(0, deltaY, 0, scrollY, 0, 0,
                    if (overScrollBy(0, deltaY, 0, scrollY, 0, 0,
                            0, mOverflingDistance, false)) {
                            0, mOverflingDistance, false)) {
                        final boolean crossDown = scrollY <= 0 && currY > 0;
                        final boolean crossUp = scrollY >= 0 && currY < 0;
                        if (crossDown || crossUp) {
                            int velocity = (int) scroller.getCurrVelocity();
                            if (crossUp) velocity = -velocity;

                            // Don't flywheel from this; we're just continuing things.
                            scroller.abortAnimation();
                            start(velocity);
                        } else {
                            startSpringback();
                            startSpringback();
                        }
                    } else {
                    } else {
                        invalidate();
                        invalidate();
                        post(this);
                        post(this);