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

Commit 234484a9 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

NumberPicker getting stuck if scroll wheel not wrapable.

1. If the number picker was not wrapping the selector wheel
   it was incorrectly initializing the fling scroller and
   the error was proportional to the difference of the
   current value and the max size. As a result if the number
   picker gets stuck for a very long time.

2. The alpha of the selector wheel paint was not reset on
   every subsequent fling so if the wheel was fading out
   and a new fling is performed the selector wheel is
   dimmed during the fling, rather bright.

bug:5728363

Change-Id: Ia90a6af86f162bda1b28f43f7ba7e4a9f5051b78
parent ca0a68cc
Loading
Loading
Loading
Loading
+4 −15
Original line number Diff line number Diff line
@@ -776,6 +776,7 @@ public class NumberPicker extends LinearLayout {
                mBeginEditOnUpEvent = false;
                mAdjustScrollerOnUpEvent = true;
                if (mSelectorWheelState == SELECTOR_WHEEL_STATE_LARGE) {
                    mSelectorWheelPaint.setAlpha(SELECTOR_WHEEL_BRIGHT_ALPHA);
                    boolean scrollersFinished = mFlingScroller.isFinished()
                            && mAdjustScroller.isFinished();
                    if (!scrollersFinished) {
@@ -1597,23 +1598,11 @@ public class NumberPicker extends LinearLayout {
     */
    private void fling(int velocityY) {
        mPreviousScrollerY = 0;
        Scroller flingScroller = mFlingScroller;

        if (mWrapSelectorWheel) {
        if (velocityY > 0) {
                flingScroller.fling(0, 0, 0, velocityY, 0, 0, 0, Integer.MAX_VALUE);
            } else {
                flingScroller.fling(0, Integer.MAX_VALUE, 0, velocityY, 0, 0, 0, Integer.MAX_VALUE);
            }
            mFlingScroller.fling(0, 0, 0, velocityY, 0, 0, 0, Integer.MAX_VALUE);
        } else {
            if (velocityY > 0) {
                int maxY = mTextSize * (mValue - mMinValue);
                flingScroller.fling(0, 0, 0, velocityY, 0, 0, 0, maxY);
            } else {
                int startY = mTextSize * (mMaxValue - mValue);
                int maxY = startY;
                flingScroller.fling(0, startY, 0, velocityY, 0, 0, 0, maxY);
            }
            mFlingScroller.fling(0, Integer.MAX_VALUE, 0, velocityY, 0, 0, 0, Integer.MAX_VALUE);
        }

        invalidate();