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

Commit cb776ca5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Preventing workspace scroll over QSB area" into sc-v2-dev

parents ff705eab bb030561
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1195,7 +1195,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
        // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
        // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
        // default state, otherwise we will update to the wrong offsets in RTL
        // default state, otherwise we will update to the wrong offsets in RTL
        mWorkspace.lockWallpaperToDefaultPage();
        mWorkspace.lockWallpaperToDefaultPage();
        mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
        mWorkspace.bindAndInitFirstWorkspaceScreen();
        mDragController.addDragListener(mWorkspace);
        mDragController.addDragListener(mWorkspace);


        // Get the search/delete/uninstall bar
        // Get the search/delete/uninstall bar
+1 −1
Original line number Original line Diff line number Diff line
@@ -1046,7 +1046,7 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
    /**
    /**
     * If being flinged and user touches the screen, initiate drag; otherwise don't.
     * If being flinged and user touches the screen, initiate drag; otherwise don't.
     */
     */
    private void updateIsBeingDraggedOnTouchDown(MotionEvent ev) {
    protected void updateIsBeingDraggedOnTouchDown(MotionEvent ev) {
        // mScroller.isFinished should be false when being flinged.
        // mScroller.isFinished should be false when being flinged.
        final int xDist = Math.abs(mScroller.getFinalX() - mScroller.getCurrX());
        final int xDist = Math.abs(mScroller.getFinalX() - mScroller.getCurrX());
        final boolean finishedScrolling = (mScroller.isFinished() || xDist < mPageSlop / 3);
        final boolean finishedScrolling = (mScroller.isFinished() || xDist < mPageSlop / 3);
+25 −15
Original line number Original line Diff line number Diff line
@@ -223,6 +223,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget)
    // Variables relating to touch disambiguation (scrolling workspace vs. scrolling a widget)
    private float mXDown;
    private float mXDown;
    private float mYDown;
    private float mYDown;
    private View mQsb;
    private boolean mIsEventOverQsb;

    final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
    final static float START_DAMPING_TOUCH_SLOP_ANGLE = (float) Math.PI / 6;
    final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
    final static float MAX_SWIPE_ANGLE = (float) Math.PI / 3;
    final static float TOUCH_SLOP_DAMPING_FACTOR = 4;
    final static float TOUCH_SLOP_DAMPING_FACTOR = 4;
@@ -548,9 +551,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>


    /**
    /**
     * Initializes and binds the first page
     * Initializes and binds the first page
     * @param qsb an existing qsb to recycle or null.
     */
     */
    public void bindAndInitFirstWorkspaceScreen(View qsb) {
    public void bindAndInitFirstWorkspaceScreen() {
        if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
        if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
            return;
            return;
        }
        }
@@ -558,10 +560,10 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        // Add the first page
        // Add the first page
        CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount());
        CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount());
        // Always add a QSB on the first screen.
        // Always add a QSB on the first screen.
        if (qsb == null) {
        if (mQsb == null) {
            // In transposed layout, we add the QSB in the Grid. As workspace does not touch the
            // In transposed layout, we add the QSB in the Grid. As workspace does not touch the
            // edges, we do not need a full width QSB.
            // edges, we do not need a full width QSB.
            qsb = LayoutInflater.from(getContext())
            mQsb = LayoutInflater.from(getContext())
                    .inflate(R.layout.search_container_workspace, firstPage, false);
                    .inflate(R.layout.search_container_workspace, firstPage, false);
        }
        }


@@ -570,8 +572,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(),
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(),
                cellVSpan);
                cellVSpan);
        lp.canReorder = false;
        lp.canReorder = false;
        if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) {
        if (!firstPage.addViewToCellLayout(mQsb, 0, R.id.search_container_workspace, lp, true)) {
            Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
            Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
            mQsb = null;
        }
        }
    }
    }


@@ -581,9 +584,8 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        disableLayoutTransitions();
        disableLayoutTransitions();


        // Recycle the QSB widget
        // Recycle the QSB widget
        View qsb = findViewById(R.id.search_container_workspace);
        if (mQsb != null) {
        if (qsb != null) {
            ((ViewGroup) mQsb.getParent()).removeView(mQsb);
            ((ViewGroup) qsb.getParent()).removeView(qsb);
        }
        }


        // Remove the pages and clear the screen models
        // Remove the pages and clear the screen models
@@ -596,7 +598,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
        mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);
        mLauncher.mHandler.removeCallbacksAndMessages(DeferredWidgetRefresh.class);


        // Ensure that the first page is always present
        // Ensure that the first page is always present
        bindAndInitFirstWorkspaceScreen(qsb);
        bindAndInitFirstWorkspaceScreen();


        // Re-enable the layout transitions
        // Re-enable the layout transitions
        enableLayoutTransitions();
        enableLayoutTransitions();
@@ -922,17 +924,25 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
    }
    }


    @Override
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
    protected void updateIsBeingDraggedOnTouchDown(MotionEvent ev) {
        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
        super.updateIsBeingDraggedOnTouchDown(ev);

        mXDown = ev.getX();
        mXDown = ev.getX();
        mYDown = ev.getY();
        mYDown = ev.getY();
        if (mQsb != null) {
            mTempFXY[0] = mXDown + getScrollX();
            mTempFXY[1] = mYDown + getScrollY();
            Utilities.mapCoordInSelfToDescendant(mQsb, this, mTempFXY);
            mIsEventOverQsb = mQsb.getLeft() <= mTempFXY[0] && mQsb.getRight() >= mTempFXY[0]
                    && mQsb.getTop() <= mTempFXY[1] && mQsb.getBottom() >= mTempFXY[1];
        } else {
            mIsEventOverQsb = false;
        }
        }
        return super.onInterceptTouchEvent(ev);
    }
    }


    @Override
    @Override
    protected void determineScrollingStart(MotionEvent ev) {
    protected void determineScrollingStart(MotionEvent ev) {
        if (!isFinishedSwitchingState()) return;
        if (!isFinishedSwitchingState() || mIsEventOverQsb) return;


        float deltaX = ev.getX() - mXDown;
        float deltaX = ev.getX() - mXDown;
        float absDeltaX = Math.abs(deltaX);
        float absDeltaX = Math.abs(deltaX);