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

Commit aad3359e authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing unused touch handling in PagedView so that it is similar to various platform class

Bug: 109828536
Change-Id: Ibaba3fb4298f2dc055d125acea5f4c47403bbef0
parent 662f52b6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -415,7 +415,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
            case MotionEvent.ACTION_DOWN:
                // Touch down anywhere but the deadzone around the visible clear all button and
                // between the task views will start home on touch up
                if (mTouchState == TOUCH_STATE_REST) {
                if (!isHandlingTouch()) {
                    updateDeadZoneRects();
                    final boolean clearAllButtonDeadZoneConsumed = mClearAllButton.getAlpha() == 1
                            && mClearAllButtonDeadZoneRect.contains(x, y);
@@ -560,7 +560,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl
        boolean scrolling = super.computeScrollHelper();
        boolean isFlingingFast = false;
        updateCurveProperties();
        if (scrolling || (mTouchState == TOUCH_STATE_SCROLLING)) {
        if (scrolling || isHandlingTouch()) {
            if (scrolling) {
                // Check if we are flinging quickly to disable high res thumbnail loading
                isFlingingFast = mScroller.getCurrVelocity() > mFastFlingVelocity;
+1 −2
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
@@ -1247,7 +1246,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
                    mAppsView.reset(isStarted() /* animate */);
                }

                if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()) {
                if (shouldMoveToDefaultScreen && !mWorkspace.isHandlingTouch()) {
                    mWorkspace.post(mWorkspace::moveToDefaultScreen);
                }
            }
+16 −48
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
    protected static final ComputePageScrollsLogic SIMPLE_SCROLL_LOGIC = (v) -> v.getVisibility() != GONE;

    public static final int PAGE_SNAP_ANIMATION_DURATION = 750;
    public static final int SLOW_PAGE_SNAP_ANIMATION_DURATION = 950;

    // OverScroll constants
    private final static int OVERSCROLL_PAGE_SNAP_ANIMATION_DURATION = 270;
@@ -109,13 +108,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
    private float mTotalMotionX;

    protected int[] mPageScrolls;

    protected final static int TOUCH_STATE_REST = 0;
    protected final static int TOUCH_STATE_SCROLLING = 1;
    protected final static int TOUCH_STATE_PREV_PAGE = 2;
    protected final static int TOUCH_STATE_NEXT_PAGE = 3;

    protected int mTouchState = TOUCH_STATE_REST;
    private boolean mIsBeingDragged;

    protected int mTouchSlop;
    private int mMaximumVelocity;
@@ -451,7 +444,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou

            // We don't want to trigger a page end moving unless the page has settled
            // and the user has stopped scrolling
            if (mTouchState == TOUCH_STATE_REST) {
            if (!mIsBeingDragged) {
                pageEndTransition();
            }

@@ -812,9 +805,9 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
    }

    /** Returns whether x and y originated within the buffered viewport */
    private boolean isTouchPointInViewportWithBuffer(int x, int y) {
    private boolean isTouchPointInViewportWithBuffer(float x, float y) {
        sTmpRect.set(-getMeasuredWidth() / 2, 0, 3 * getMeasuredWidth() / 2, getMeasuredHeight());
        return sTmpRect.contains(x, y);
        return sTmpRect.contains((int) x, (int) y);
    }

    @Override
@@ -835,8 +828,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
         * motion.
         */
        final int action = ev.getAction();
        if ((action == MotionEvent.ACTION_MOVE) &&
                (mTouchState == TOUCH_STATE_SCROLLING)) {
        if ((action == MotionEvent.ACTION_MOVE) && mIsBeingDragged) {
            return true;
        }

@@ -877,17 +869,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
                final boolean finishedScrolling = (mScroller.isFinished() || xDist < mTouchSlop / 3);

                if (finishedScrolling) {
                    mTouchState = TOUCH_STATE_REST;
                    mIsBeingDragged = false;
                    if (!mScroller.isFinished() && !mFreeScroll) {
                        setCurrentPage(getNextPage());
                        pageEndTransition();
                    }
                } else {
                    if (isTouchPointInViewportWithBuffer((int) mDownMotionX, (int) mDownMotionY)) {
                        mTouchState = TOUCH_STATE_SCROLLING;
                    } else {
                        mTouchState = TOUCH_STATE_REST;
                    }
                    mIsBeingDragged = isTouchPointInViewportWithBuffer(mDownMotionX, mDownMotionY);
                }

                break;
@@ -908,11 +896,11 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
         * The only time we want to intercept motion events is if we are in the
         * drag mode.
         */
        return mTouchState != TOUCH_STATE_REST;
        return mIsBeingDragged;
    }

    public boolean isHandlingTouch() {
        return mTouchState != TOUCH_STATE_REST;
        return mIsBeingDragged;
    }

    protected void determineScrollingStart(MotionEvent ev) {
@@ -931,7 +919,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
        // Disallow scrolling if we started the gesture from outside the viewport
        final float x = ev.getX(pointerIndex);
        final float y = ev.getY(pointerIndex);
        if (!isTouchPointInViewportWithBuffer((int) x, (int) y)) return;
        if (!isTouchPointInViewportWithBuffer(x, y)) return;

        final int xDiff = (int) Math.abs(x - mLastMotionX);

@@ -940,7 +928,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou

        if (xMoved) {
            // Scroll if the user moved far enough along the X axis
            mTouchState = TOUCH_STATE_SCROLLING;
            mIsBeingDragged = true;
            mTotalMotionX += Math.abs(mLastMotionX - x);
            mLastMotionX = x;
            mLastMotionXRemainder = 0;
@@ -1077,14 +1065,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
            mTotalMotionX = 0;
            mActivePointerId = ev.getPointerId(0);

            if (mTouchState == TOUCH_STATE_SCROLLING) {
            if (mIsBeingDragged) {
                onScrollInteractionBegin();
                pageBeginTransition();
            }
            break;

        case MotionEvent.ACTION_MOVE:
            if (mTouchState == TOUCH_STATE_SCROLLING) {
            if (mIsBeingDragged) {
                // Scroll to follow the motion event
                final int pointerIndex = ev.findPointerIndex(mActivePointerId);

@@ -1111,7 +1099,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
            break;

        case MotionEvent.ACTION_UP:
            if (mTouchState == TOUCH_STATE_SCROLLING) {
            if (mIsBeingDragged) {
                final int activePointerId = mActivePointerId;
                final int pointerIndex = ev.findPointerIndex(activePointerId);
                final float x = ev.getX(pointerIndex);
@@ -1193,26 +1181,6 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
                    invalidate();
                }
                onScrollInteractionEnd();
            } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
                // at this point we have not moved beyond the touch slop
                // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                // we can just page
                int nextPage = Math.max(0, mCurrentPage - 1);
                if (nextPage != mCurrentPage) {
                    snapToPage(nextPage);
                } else {
                    snapToDestination();
                }
            } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
                // at this point we have not moved beyond the touch slop
                // (otherwise mTouchState would be TOUCH_STATE_SCROLLING), so
                // we can just page
                int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1);
                if (nextPage != mCurrentPage) {
                    snapToPage(nextPage);
                } else {
                    snapToDestination();
                }
            }

            // End any intermediate reordering states
@@ -1220,7 +1188,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
            break;

        case MotionEvent.ACTION_CANCEL:
            if (mTouchState == TOUCH_STATE_SCROLLING) {
            if (mIsBeingDragged) {
                snapToDestination();
                onScrollInteractionEnd();
            }
@@ -1242,7 +1210,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou

    private void resetTouchState() {
        releaseVelocityTracker();
        mTouchState = TOUCH_STATE_REST;
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
    }

+0 −4
Original line number Diff line number Diff line
@@ -474,10 +474,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        super.onViewAdded(child);
    }

    public boolean isTouchActive() {
        return mTouchState != TOUCH_STATE_REST;
    }

    /**
     * Initializes and binds the first page
     * @param qsb an existing qsb to recycle or null.
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public class WorkspaceTouchListener implements OnTouchListener, Runnable {
        }

        if (action == ACTION_UP || action == ACTION_POINTER_UP) {
            if (!mWorkspace.isTouchActive()) {
            if (!mWorkspace.isHandlingTouch()) {
                final CellLayout currentPage =
                        (CellLayout) mWorkspace.getChildAt(mWorkspace.getCurrentPage());
                if (currentPage != null) {