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

Commit 27ad267a authored by Jon Miranda's avatar Jon Miranda
Browse files

Fix bug where user gets stuck in overscroll.

By not intercepting touch when in overscroll, the user
can immediately exit by swiping the opposite direction.

Bug: 64094565
Change-Id: I0b4e3e7a38d90d4e6a336985d939d177a8f04c9b
parent 7f522a25
Loading
Loading
Loading
Loading
+14 −10
Original line number Original line Diff line number Diff line
@@ -109,12 +109,6 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine
        }
        }
    }
    }


    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
        mPullDetector.onTouchEvent(ev);
        return super.onInterceptTouchEvent(rv, ev) || mOverScrollHelper.isInOverScroll();
    }

    @Override
    @Override
    public boolean onTouchEvent(MotionEvent e) {
    public boolean onTouchEvent(MotionEvent e) {
        mPullDetector.onTouchEvent(e);
        mPullDetector.onTouchEvent(e);
@@ -281,7 +275,8 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine


    @Override
    @Override
    public boolean onInterceptTouchEvent(MotionEvent e) {
    public boolean onInterceptTouchEvent(MotionEvent e) {
        boolean result = super.onInterceptTouchEvent(e);
        mPullDetector.onTouchEvent(e);
        boolean result = super.onInterceptTouchEvent(e) || mOverScrollHelper.isInOverScroll();
        if (!result && e.getAction() == MotionEvent.ACTION_DOWN
        if (!result && e.getAction() == MotionEvent.ACTION_DOWN
                && mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) {
                && mEmptySearchBackground != null && mEmptySearchBackground.getAlpha() > 0) {
            mEmptySearchBackground.setHotspot(e.getX(), e.getY());
            mEmptySearchBackground.setHotspot(e.getX(), e.getY());
@@ -540,11 +535,16 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine
            // and if one of the following criteria are met:
            // and if one of the following criteria are met:
            // - User scrolls down when they're already at the bottom.
            // - User scrolls down when they're already at the bottom.
            // - User starts scrolling up, hits the top, and continues scrolling up.
            // - User starts scrolling up, hits the top, and continues scrolling up.
            boolean wasInOverScroll = mIsInOverScroll;
            mIsInOverScroll = !mScrollbar.isDraggingThumb() &&
            mIsInOverScroll = !mScrollbar.isDraggingThumb() &&
                    ((!canScrollVertically(1) && displacement < 0) ||
                    ((!canScrollVertically(1) && displacement < 0) ||
                    (!canScrollVertically(-1) && isScrollingUp && mFirstScrollYOnScrollUp != 0));
                    (!canScrollVertically(-1) && isScrollingUp && mFirstScrollYOnScrollUp != 0));


            if (mIsInOverScroll) {
            if (wasInOverScroll && !mIsInOverScroll) {
                // Exit overscroll. This can happen when the user is in overscroll and then
                // scrolls the opposite way.
                reset(false /* shouldSpring */);
            } else if (mIsInOverScroll) {
                if (Float.compare(mFirstDisplacement, 0) == 0) {
                if (Float.compare(mFirstDisplacement, 0) == 0) {
                    // Because users can scroll before entering overscroll, we need to
                    // Because users can scroll before entering overscroll, we need to
                    // subtract the amount where the user was not in overscroll.
                    // subtract the amount where the user was not in overscroll.
@@ -559,11 +559,15 @@ public class AllAppsRecyclerView extends BaseRecyclerView implements LogContaine


        @Override
        @Override
        public void onDragEnd(float velocity, boolean fling) {
        public void onDragEnd(float velocity, boolean fling) {
           reset(mIsInOverScroll  /* shouldSpring */);
        }

        private void reset(boolean shouldSpring) {
            float y = getContentTranslationY();
            float y = getContentTranslationY();
            if (Float.compare(y, 0) != 0) {
            if (Float.compare(y, 0) != 0) {
                if (FeatureFlags.LAUNCHER3_PHYSICS) {
                if (FeatureFlags.LAUNCHER3_PHYSICS && shouldSpring) {
                    // We calculate our own velocity to give the springs the desired effect.
                    // We calculate our own velocity to give the springs the desired effect.
                    velocity = y / getDampedOverScroll(getHeight()) * MAX_RELEASE_VELOCITY;
                    float velocity = y / getDampedOverScroll(getHeight()) * MAX_RELEASE_VELOCITY;
                    // We want to negate the velocity because we are moving to 0 from -1 due to the
                    // We want to negate the velocity because we are moving to 0 from -1 due to the
                    // downward motion. (y-axis -1 is above 0).
                    // downward motion. (y-axis -1 is above 0).
                    mSpringAnimationHandler.animateToPositionWithVelocity(0, -1, -velocity);
                    mSpringAnimationHandler.animateToPositionWithVelocity(0, -1, -velocity);