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

Commit a167a6e0 authored by Mario Bertschler's avatar Mario Bertschler Committed by Android (Google) Code Review
Browse files

Merge "Enables direct scrolling on the fastscroll bar." into ub-launcher3-master

parents b0d77fe3 ee4ee424
Loading
Loading
Loading
Loading
+44 −21
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.widget.TextView;

import com.android.launcher3.config.FeatureFlags;

/**
 * The track and scrollbar that shows when you scroll the list.
 */
@@ -198,6 +200,11 @@ public class BaseRecyclerViewFastScrollBar {
            case MotionEvent.ACTION_DOWN:
                if (isNearThumb(downX, downY)) {
                    mTouchOffsetY = downY - mThumbOffsetY;
                } else if (FeatureFlags.LAUNCHER3_DIRECT_SCROLL
                        && mRv.supportsFastScrolling()
                        && isNearScrollBar(downX)) {
                    calcTouchOffsetAndPrepToFastScroll(downY, lastY);
                    updateFastScrollSectionNameAndThumbOffset(lastY, y);
                }
                break;
            case MotionEvent.ACTION_MOVE:
@@ -207,6 +214,27 @@ public class BaseRecyclerViewFastScrollBar {
                if (!mIsDragging && !mIgnoreDragGesture && mRv.supportsFastScrolling() &&
                        isNearThumb(downX, lastY) &&
                        Math.abs(y - downY) > config.getScaledTouchSlop()) {
                    calcTouchOffsetAndPrepToFastScroll(downY, lastY);
                }
                if (mIsDragging) {
                    updateFastScrollSectionNameAndThumbOffset(lastY, y);
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mTouchOffsetY = 0;
                mLastTouchY = 0;
                mIgnoreDragGesture = false;
                if (mIsDragging) {
                    mIsDragging = false;
                    animatePopupVisibility(false);
                    showActiveScrollbar(false);
                }
                break;
        }
    }

    private void calcTouchOffsetAndPrepToFastScroll(int downY, int lastY) {
        mRv.getParent().requestDisallowInterceptTouchEvent(true);
        mIsDragging = true;
        if (mCanThumbDetach) {
@@ -216,7 +244,8 @@ public class BaseRecyclerViewFastScrollBar {
        animatePopupVisibility(true);
        showActiveScrollbar(true);
    }
                if (mIsDragging) {

    private void updateFastScrollSectionNameAndThumbOffset(int lastY, int y) {
        // Update the fastscroller section name at this touch position
        int bottom = mRv.getScrollbarTrackHeight() - mThumbHeight;
        float boundedY = (float) Math.max(0, Math.min(bottom, y - mTouchOffsetY));
@@ -230,20 +259,6 @@ public class BaseRecyclerViewFastScrollBar {
        mLastTouchY = boundedY;
        setThumbOffsetY((int) mLastTouchY);
    }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                mTouchOffsetY = 0;
                mLastTouchY = 0;
                mIgnoreDragGesture = false;
                if (mIsDragging) {
                    mIsDragging = false;
                    animatePopupVisibility(false);
                    showActiveScrollbar(false);
                }
                break;
        }
    }

    public void draw(Canvas canvas) {
        if (mThumbOffsetY < 0) {
@@ -277,7 +292,7 @@ public class BaseRecyclerViewFastScrollBar {
    }

    /**
     * Returns whether the specified points are near the scroll bar bounds.
     * Returns whether the specified point is inside the thumb bounds.
     */
    public boolean isNearThumb(int x, int y) {
        int left = getDrawLeft();
@@ -286,6 +301,14 @@ public class BaseRecyclerViewFastScrollBar {
        return mTmpRect.contains(x, y);
    }

    /**
     * Returns whether the specified x position is near the scroll bar.
     */
    public boolean isNearScrollBar(int x) {
        int left = getDrawLeft();
        return x >= left && x <= left + mMaxWidth;
    }

    private void animatePopupVisibility(boolean visible) {
        if (mPopupVisible != visible) {
            mPopupVisible = visible;
+2 −0
Original line number Diff line number Diff line
@@ -37,4 +37,6 @@ public final class FeatureFlags {
    public static final boolean PULLDOWN_SEARCH = false;
    // When enabled the status bar may show dark icons based on the top of the wallpaper.
    public static final boolean LIGHT_STATUS_BAR = false;
    // When enabled allows to use any point on the fast scrollbar to start dragging.
    public static final boolean LAUNCHER3_DIRECT_SCROLL = true;
}