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

Commit 1fa179ef authored by Adam Powell's avatar Adam Powell
Browse files

Fix some smooth scrolling bugs in lists and update on the animation

timer.

Change-Id: I0cb03c6da204a34c9e942c3953b87287c3d4763d
parent a131f4ef
Loading
Loading
Loading
Loading
+41 −33
Original line number Original line Diff line number Diff line
@@ -403,7 +403,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    /**
    /**
     * Handles scrolling between positions within the list.
     * Handles scrolling between positions within the list.
     */
     */
    private PositionScroller mPositionScroller;
    PositionScroller mPositionScroller;


    /**
    /**
     * The offset in pixels form the top of the AdapterView to the top
     * The offset in pixels form the top of the AdapterView to the top
@@ -3080,6 +3080,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            return isClickable() || isLongClickable();
            return isClickable() || isLongClickable();
        }
        }


        if (mPositionScroller != null) {
            mPositionScroller.stop();
        }

        if (mFastScroller != null) {
        if (mFastScroller != null) {
            boolean intercepted = mFastScroller.onTouchEvent(ev);
            boolean intercepted = mFastScroller.onTouchEvent(ev);
            if (intercepted) {
            if (intercepted) {
@@ -3564,6 +3568,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        int action = ev.getAction();
        int action = ev.getAction();
        View v;
        View v;


        if (mPositionScroller != null) {
            mPositionScroller.stop();
        }

        if (mFastScroller != null) {
        if (mFastScroller != null) {
            boolean intercepted = mFastScroller.onInterceptTouchEvent(ev);
            boolean intercepted = mFastScroller.onInterceptTouchEvent(ev);
            if (intercepted) {
            if (intercepted) {
@@ -3748,7 +3756,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mScroller.fling(0, initialY, 0, initialVelocity,
            mScroller.fling(0, initialY, 0, initialVelocity,
                    0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
                    0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
            mTouchMode = TOUCH_MODE_FLING;
            mTouchMode = TOUCH_MODE_FLING;
            post(this);
            postOnAnimation(this);


            if (PROFILE_FLINGING) {
            if (PROFILE_FLINGING) {
                if (!mFlingProfilingStarted) {
                if (!mFlingProfilingStarted) {
@@ -3766,7 +3774,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            if (mScroller.springBack(0, mScrollY, 0, 0, 0, 0)) {
            if (mScroller.springBack(0, mScrollY, 0, 0, 0, 0)) {
                mTouchMode = TOUCH_MODE_OVERFLING;
                mTouchMode = TOUCH_MODE_OVERFLING;
                invalidate();
                invalidate();
                post(this);
                postOnAnimation(this);
            } else {
            } else {
                mTouchMode = TOUCH_MODE_REST;
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
@@ -3778,7 +3786,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight());
                    Integer.MIN_VALUE, Integer.MAX_VALUE, 0, getHeight());
            mTouchMode = TOUCH_MODE_OVERFLING;
            mTouchMode = TOUCH_MODE_OVERFLING;
            invalidate();
            invalidate();
            post(this);
            postOnAnimation(this);
        }
        }


        void edgeReached(int delta) {
        void edgeReached(int delta) {
@@ -3800,7 +3808,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                }
                }
            }
            }
            invalidate();
            invalidate();
            post(this);
            postOnAnimation(this);
        }
        }


        void startScroll(int distance, int duration) {
        void startScroll(int distance, int duration) {
@@ -3808,7 +3816,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mLastFlingY = initialY;
            mLastFlingY = initialY;
            mScroller.startScroll(0, initialY, 0, distance, duration);
            mScroller.startScroll(0, initialY, 0, distance, duration);
            mTouchMode = TOUCH_MODE_FLING;
            mTouchMode = TOUCH_MODE_FLING;
            post(this);
            postOnAnimation(this);
        }
        }


        void endFling() {
        void endFling() {
@@ -3907,7 +3915,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                if (more && !atEnd) {
                if (more && !atEnd) {
                    if (atEdge) invalidate();
                    if (atEdge) invalidate();
                    mLastFlingY = y;
                    mLastFlingY = y;
                    post(this);
                    postOnAnimation(this);
                } else {
                } else {
                    endFling();
                    endFling();


@@ -3948,7 +3956,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                        }
                        }
                    } else {
                    } else {
                        invalidate();
                        invalidate();
                        post(this);
                        postOnAnimation(this);
                    }
                    }
                } else {
                } else {
                    endFling();
                    endFling();
@@ -3959,7 +3967,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
        }
    }
    }



    class PositionScroller implements Runnable {
    class PositionScroller implements Runnable {
        private static final int SCROLL_DURATION = 400;
        private static final int SCROLL_DURATION = 400;


@@ -4009,7 +4016,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mBoundPos = INVALID_POSITION;
            mBoundPos = INVALID_POSITION;
            mLastSeenPos = INVALID_POSITION;
            mLastSeenPos = INVALID_POSITION;


            post(this);
            postOnAnimation(this);
        }
        }


        void start(int position, int boundPosition) {
        void start(int position, int boundPosition) {
@@ -4070,7 +4077,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            mBoundPos = boundPosition;
            mBoundPos = boundPosition;
            mLastSeenPos = INVALID_POSITION;
            mLastSeenPos = INVALID_POSITION;


            post(this);
            postOnAnimation(this);
        }
        }


        void startWithOffset(int position, int offset) {
        void startWithOffset(int position, int offset) {
@@ -4080,6 +4087,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        void startWithOffset(int position, int offset, int duration) {
        void startWithOffset(int position, int offset, int duration) {
            stop();
            stop();


            offset += getPaddingTop();

            mTargetPos = position;
            mTargetPos = position;
            mOffsetFromTop = offset;
            mOffsetFromTop = offset;
            mBoundPos = INVALID_POSITION;
            mBoundPos = INVALID_POSITION;
@@ -4108,7 +4117,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    (int) (duration / screenTravelCount);
                    (int) (duration / screenTravelCount);
            mLastSeenPos = INVALID_POSITION;
            mLastSeenPos = INVALID_POSITION;


            post(this);
            postOnAnimation(this);
        }
        }


        void stop() {
        void stop() {
@@ -4116,10 +4125,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
        }


        public void run() {
        public void run() {
            if (mTouchMode != TOUCH_MODE_FLING && mLastSeenPos != INVALID_POSITION) {
                return;
            }

            final int listHeight = getHeight();
            final int listHeight = getHeight();
            final int firstPos = mFirstPosition;
            final int firstPos = mFirstPosition;


@@ -4134,7 +4139,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te


                if (lastPos == mLastSeenPos) {
                if (lastPos == mLastSeenPos) {
                    // No new views, let things keep going.
                    // No new views, let things keep going.
                    post(this);
                    postOnAnimation(this);
                    return;
                    return;
                }
                }


@@ -4142,14 +4147,15 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                final int lastViewHeight = lastView.getHeight();
                final int lastViewHeight = lastView.getHeight();
                final int lastViewTop = lastView.getTop();
                final int lastViewTop = lastView.getTop();
                final int lastViewPixelsShowing = listHeight - lastViewTop;
                final int lastViewPixelsShowing = listHeight - lastViewTop;
                final int extraScroll = lastPos < mItemCount - 1 ? mExtraScroll : mListPadding.bottom;
                final int extraScroll = lastPos < mItemCount - 1 ?
                        Math.max(mListPadding.bottom, mExtraScroll) : mListPadding.bottom;


                smoothScrollBy(lastViewHeight - lastViewPixelsShowing + extraScroll,
                final int scrollBy = lastViewHeight - lastViewPixelsShowing + extraScroll;
                        mScrollDuration);
                smoothScrollBy(scrollBy, mScrollDuration);


                mLastSeenPos = lastPos;
                mLastSeenPos = lastPos;
                if (lastPos < mTargetPos) {
                if (lastPos < mTargetPos) {
                    post(this);
                    postOnAnimation(this);
                }
                }
                break;
                break;
            }
            }
@@ -4166,21 +4172,21 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te


                if (nextPos == mLastSeenPos) {
                if (nextPos == mLastSeenPos) {
                    // No new views, let things keep going.
                    // No new views, let things keep going.
                    post(this);
                    postOnAnimation(this);
                    return;
                    return;
                }
                }


                final View nextView = getChildAt(nextViewIndex);
                final View nextView = getChildAt(nextViewIndex);
                final int nextViewHeight = nextView.getHeight();
                final int nextViewHeight = nextView.getHeight();
                final int nextViewTop = nextView.getTop();
                final int nextViewTop = nextView.getTop();
                final int extraScroll = mExtraScroll;
                final int extraScroll = Math.max(mListPadding.bottom, mExtraScroll);
                if (nextPos < mBoundPos) {
                if (nextPos < mBoundPos) {
                    smoothScrollBy(Math.max(0, nextViewHeight + nextViewTop - extraScroll),
                    smoothScrollBy(Math.max(0, nextViewHeight + nextViewTop - extraScroll),
                            mScrollDuration);
                            mScrollDuration);


                    mLastSeenPos = nextPos;
                    mLastSeenPos = nextPos;


                    post(this);
                    postOnAnimation(this);
                } else  {
                } else  {
                    if (nextViewTop > extraScroll) {
                    if (nextViewTop > extraScroll) {
                        smoothScrollBy(nextViewTop - extraScroll, mScrollDuration);
                        smoothScrollBy(nextViewTop - extraScroll, mScrollDuration);
@@ -4192,7 +4198,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            case MOVE_UP_POS: {
            case MOVE_UP_POS: {
                if (firstPos == mLastSeenPos) {
                if (firstPos == mLastSeenPos) {
                    // No new views, let things keep going.
                    // No new views, let things keep going.
                    post(this);
                    postOnAnimation(this);
                    return;
                    return;
                }
                }


@@ -4201,14 +4207,15 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    return;
                    return;
                }
                }
                final int firstViewTop = firstView.getTop();
                final int firstViewTop = firstView.getTop();
                final int extraScroll = firstPos > 0 ? mExtraScroll : mListPadding.top;
                final int extraScroll = firstPos > 0 ?
                        Math.max(mExtraScroll, mListPadding.top) : mListPadding.top;


                smoothScrollBy(firstViewTop - extraScroll, mScrollDuration);
                smoothScrollBy(firstViewTop - extraScroll, mScrollDuration);


                mLastSeenPos = firstPos;
                mLastSeenPos = firstPos;


                if (firstPos > mTargetPos) {
                if (firstPos > mTargetPos) {
                    post(this);
                    postOnAnimation(this);
                }
                }
                break;
                break;
            }
            }
@@ -4230,12 +4237,13 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                final int lastViewHeight = lastView.getHeight();
                final int lastViewHeight = lastView.getHeight();
                final int lastViewTop = lastView.getTop();
                final int lastViewTop = lastView.getTop();
                final int lastViewPixelsShowing = listHeight - lastViewTop;
                final int lastViewPixelsShowing = listHeight - lastViewTop;
                final int extraScroll = Math.max(mListPadding.top, mExtraScroll);
                mLastSeenPos = lastPos;
                mLastSeenPos = lastPos;
                if (lastPos > mBoundPos) {
                if (lastPos > mBoundPos) {
                    smoothScrollBy(-(lastViewPixelsShowing - mExtraScroll), mScrollDuration);
                    smoothScrollBy(-(lastViewPixelsShowing - extraScroll), mScrollDuration);
                    post(this);
                    postOnAnimation(this);
                } else {
                } else {
                    final int bottom = listHeight - mExtraScroll;
                    final int bottom = listHeight - extraScroll;
                    final int lastViewBottom = lastViewTop + lastViewHeight;
                    final int lastViewBottom = lastViewTop + lastViewHeight;
                    if (bottom > lastViewBottom) {
                    if (bottom > lastViewBottom) {
                        smoothScrollBy(-(bottom - lastViewBottom), mScrollDuration);
                        smoothScrollBy(-(bottom - lastViewBottom), mScrollDuration);
@@ -4270,10 +4278,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                final float modifier = Math.min(Math.abs(screenTravelCount), 1.f);
                final float modifier = Math.min(Math.abs(screenTravelCount), 1.f);
                if (position < firstPos) {
                if (position < firstPos) {
                    smoothScrollBy((int) (-getHeight() * modifier), mScrollDuration);
                    smoothScrollBy((int) (-getHeight() * modifier), mScrollDuration);
                    post(this);
                    postOnAnimation(this);
                } else if (position > lastPos) {
                } else if (position > lastPos) {
                    smoothScrollBy((int) (getHeight() * modifier), mScrollDuration);
                    smoothScrollBy((int) (getHeight() * modifier), mScrollDuration);
                    post(this);
                    postOnAnimation(this);
                } else {
                } else {
                    // On-screen, just scroll.
                    // On-screen, just scroll.
                    final int targetTop = getChildAt(position - firstPos).getTop();
                    final int targetTop = getChildAt(position - firstPos).getTop();
+7 −0
Original line number Original line Diff line number Diff line
@@ -1463,6 +1463,9 @@ public class GridView extends AbsListView {
            mResurrectToPosition = position;
            mResurrectToPosition = position;
        }
        }
        mLayoutMode = LAYOUT_SET_SELECTION;
        mLayoutMode = LAYOUT_SET_SELECTION;
        if (mPositionScroller != null) {
            mPositionScroller.stop();
        }
        requestLayout();
        requestLayout();
    }
    }


@@ -1475,6 +1478,10 @@ public class GridView extends AbsListView {
    void setSelectionInt(int position) {
    void setSelectionInt(int position) {
        int previousSelectedPosition = mNextSelectedPosition;
        int previousSelectedPosition = mNextSelectedPosition;


        if (mPositionScroller != null) {
            mPositionScroller.stop();
        }

        setNextSelectedPositionInt(position);
        setNextSelectedPositionInt(position);
        layoutChildren();
        layoutChildren();
        
        
+7 −0
Original line number Original line Diff line number Diff line
@@ -1926,6 +1926,9 @@ public class ListView extends AbsListView {
                mSyncRowId = mAdapter.getItemId(position);
                mSyncRowId = mAdapter.getItemId(position);
            }
            }


            if (mPositionScroller != null) {
                mPositionScroller.stop();
            }
            requestLayout();
            requestLayout();
        }
        }
    }
    }
@@ -1950,6 +1953,10 @@ public class ListView extends AbsListView {
            }
            }
        }
        }


        if (mPositionScroller != null) {
            mPositionScroller.stop();
        }

        layoutChildren();
        layoutChildren();


        if (awakeScrollbars) {
        if (awakeScrollbars) {