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

Commit db7f098b authored by Sihua Ma's avatar Sihua Ma
Browse files

Re-enable the fast scroll in widget picker

Fix: 258299457
Test: Manual
Change-Id: Ic069f5304827de40be88b80590f5c6c7d88b13b2
parent 2da05f36
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -169,6 +169,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    private View mSearchBarContainer;
    private WidgetsSearchBar mSearchBar;
    private TextView mHeaderTitle;
    private @Nullable WidgetsRecyclerView mCurrentTouchEventRecyclerView;

    public WidgetsFullSheet(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
@@ -642,6 +643,51 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        return sheet;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return isTouchOnScrollbar(ev) || super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return maybeHandleTouchEvent(ev) || super.onTouchEvent(ev);
    }

    private boolean maybeHandleTouchEvent(MotionEvent ev) {
        boolean isEventHandled = false;

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mCurrentTouchEventRecyclerView = isTouchOnScrollbar(ev) ? getRecyclerView() : null;
        }

        if (mCurrentTouchEventRecyclerView != null) {
            final float offsetX = mContent.getX();
            final float offsetY = mContent.getY();
            ev.offsetLocation(-offsetX, -offsetY);
            isEventHandled = mCurrentTouchEventRecyclerView.dispatchTouchEvent(ev);
            ev.offsetLocation(offsetX, offsetY);
        }

        if (ev.getAction() == MotionEvent.ACTION_UP
                || ev.getAction() == MotionEvent.ACTION_CANCEL) {
            mCurrentTouchEventRecyclerView = null;
        }

        return isEventHandled;
    }

    private boolean isTouchOnScrollbar(MotionEvent ev) {
        final float offsetX = mContent.getX();
        final float offsetY = mContent.getY();
        WidgetsRecyclerView rv = getRecyclerView();

        ev.offsetLocation(-offsetX, -offsetY);
        boolean isOnScrollBar = rv != null && rv.getScrollbar() != null && rv.isHitOnScrollBar(ev);
        ev.offsetLocation(offsetX, offsetY);

        return isOnScrollBar;
    }

    /** Gets the {@link WidgetsRecyclerView} which shows all widgets in {@link WidgetsFullSheet}. */
    @VisibleForTesting
    public static WidgetsRecyclerView getWidgetsView(Launcher launcher) {
+10 −2
Original line number Diff line number Diff line
@@ -127,8 +127,7 @@ public class WidgetsRecyclerView extends FastScrollRecyclerView implements OnIte
    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        if (e.getAction() == MotionEvent.ACTION_DOWN) {
            mTouchDownOnScroller =
                    mScrollbar.isHitInParent(e.getX(), e.getY(), mFastScrollerOffset);
            mTouchDownOnScroller = isHitOnScrollBar(e);
        }
        if (mTouchDownOnScroller) {
            final boolean result = mScrollbar.handleTouchEvent(e, mFastScrollerOffset);
@@ -144,6 +143,15 @@ public class WidgetsRecyclerView extends FastScrollRecyclerView implements OnIte
        }
    }

    /**
     * Detects whether a {@code MotionEvent} is on the scroll bar
     * @param e The {@code MotionEvent} on the screen
     * @return {@code true} if the motion is on the scroll bar
     */
    boolean isHitOnScrollBar(MotionEvent e) {
        return mScrollbar.isHitInParent(e.getX(), e.getY(), mFastScrollerOffset);
    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
    }