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

Commit 2c80b0f4 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Reusing the existing handler when quickscrub starts

Bug: 72173796
Change-Id: I0517a09c10238f15e012f7edcab957aacef22444
parent 08af6b79
Loading
Loading
Loading
Loading
+49 −18
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@
 */
package com.android.quickstep;

import static com.android.quickstep.TouchInteractionService.INTERACTION_NORMAL;
import static com.android.quickstep.TouchInteractionService.INTERACTION_QUICK_SCRUB;
import static com.android.quickstep.TouchInteractionService.INTERACTION_QUICK_SWITCH;
import static com.android.quickstep.TouchInteractionService.isInteractionQuick;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.RectEvaluator;
@@ -44,8 +49,9 @@ import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.states.InternalStateHandler;
import com.android.launcher3.uioverrides.RecentsViewStateController;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.TraceHelper;
import com.android.quickstep.TouchInteractionService.InteractionType;
import com.android.systemui.shared.recents.model.RecentsTaskLoadPlan;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.Task.TaskKey;
@@ -93,20 +99,22 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
    private Launcher mLauncher;
    private SnapshotDragView mDragView;
    private RecentsView mRecentsView;
    private RecentsViewStateController mStateController;
    private QuickScrubController mQuickScrubController;
    private Hotseat mHotseat;

    private boolean mWasLauncherAlreadyVisible;

    private boolean mLauncherReady;
    private boolean mTouchEndHandled;
    private float mCurrentDisplacement;
    private @TouchInteractionService.InteractionType int mInteractionType;

    private @InteractionType int mInteractionType;
    private boolean mStartedQuickScrubFromHome;

    private Bitmap mTaskSnapshot;

    NavBarSwipeInteractionHandler(RunningTaskInfo runningTaskInfo, Context context,
            @TouchInteractionService.InteractionType int interactionType) {
            @InteractionType int interactionType) {
        // TODO: We need a better way for this
        TaskKey taskKey = new TaskKey(runningTaskInfo.id, 0, null, UserHandle.myUserId(), 0);
        mRunningTask = new Task(taskKey, null, null, "", "", Color.BLACK, Color.BLACK,
@@ -183,8 +191,8 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
        mLauncher = launcher;
        mRecentsView = launcher.getOverviewPanel();
        mRecentsView.showTask(mRunningTask);
        mStateController = mRecentsView.getStateController();
        mHotseat = mLauncher.getHotseat();
        mWasLauncherAlreadyVisible = alreadyOnHome;

        AbstractFloatingView.closeAllOpenViews(mLauncher, alreadyOnHome);
        mLauncher.getStateManager().goToState(LauncherState.OVERVIEW, alreadyOnHome);
@@ -194,17 +202,8 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
        mDragView.setPivotX(0);
        mDragView.setPivotY(0);

        boolean interactionIsQuick
                = mInteractionType == TouchInteractionService.INTERACTION_QUICK_SCRUB
                || mInteractionType == TouchInteractionService.INTERACTION_QUICK_SWITCH;
        mStartedQuickScrubFromHome = alreadyOnHome && interactionIsQuick;
        if (interactionIsQuick) {
            mQuickScrubController = mRecentsView.getQuickScrubController();
            mQuickScrubController.onQuickScrubStart(mStartedQuickScrubFromHome);
            animateToProgress(1f, MAX_SWIPE_DURATION);
            if (mStartedQuickScrubFromHome) {
                mDragView.setVisibility(View.INVISIBLE);
            }
        if (isInteractionQuick(mInteractionType)) {
            updateUiForQuickScrub();
        }

        // Optimization
@@ -215,6 +214,34 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
        TraceHelper.partitionSection("TouchInt", "Launcher on new intent");
    }


    public void updateInteractionType(@InteractionType int interactionType) {
        Preconditions.assertUIThread();
        if (mInteractionType != INTERACTION_NORMAL) {
            throw new IllegalArgumentException(
                    "Can't change interaction type from " + mInteractionType);
        }
        if (!isInteractionQuick(interactionType)) {
            throw new IllegalArgumentException(
                    "Can't change interaction type to " + interactionType);
        }
        mInteractionType = interactionType;

        if (mLauncher != null) {
            updateUiForQuickScrub();
        }
    }

    private void updateUiForQuickScrub() {
        mStartedQuickScrubFromHome = mWasLauncherAlreadyVisible;
        mQuickScrubController = mRecentsView.getQuickScrubController();
        mQuickScrubController.onQuickScrubStart(mStartedQuickScrubFromHome);
        animateToProgress(1f, MAX_SWIPE_DURATION);
        if (mStartedQuickScrubFromHome) {
            mDragView.setVisibility(View.INVISIBLE);
        }
    }

    @UiThread
    public void updateDisplacement(float displacement) {
        mCurrentDisplacement = displacement;
@@ -334,7 +361,7 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
        if (currentRecentsPage instanceof TaskView) {
            ((TaskView) currentRecentsPage).animateIconToScale(1f);
        }
        if (mInteractionType == TouchInteractionService.INTERACTION_QUICK_SWITCH) {
        if (mInteractionType == INTERACTION_QUICK_SWITCH) {
            for (int i = mRecentsView.getFirstTaskIndex(); i < mRecentsView.getPageCount(); i++) {
                TaskView taskView = (TaskView) mRecentsView.getPageAt(i);
                // TODO: Match the keys directly
@@ -345,7 +372,7 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
                    break;
                }
            }
        } else if (mInteractionType == TouchInteractionService.INTERACTION_QUICK_SCRUB) {
        } else if (mInteractionType == INTERACTION_QUICK_SCRUB) {
            if (mQuickScrubController != null) {
                mQuickScrubController.snapToPageForCurrentQuickScrubSection();
            }
@@ -355,12 +382,16 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler {
    public void onQuickScrubEnd() {
        if (mQuickScrubController != null) {
            mQuickScrubController.onQuickScrubEnd();
        } else {
            // TODO:
        }
    }

    public void onQuickScrubProgress(float progress) {
        if (mQuickScrubController != null) {
            mQuickScrubController.onQuickScrubProgress(progress);
        } else {
            // TODO:
        }
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.view.WindowManager;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.util.TraceHelper;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
@@ -99,6 +100,7 @@ public class TouchInteractionService extends Service {
        @Override
        public void onQuickSwitch() {
            startTouchTracking(INTERACTION_QUICK_SWITCH);
            mInteractionHandler = null;
        }

        @Override
@@ -110,6 +112,7 @@ public class TouchInteractionService extends Service {
        public void onQuickScrubEnd() {
            if (mInteractionHandler != null) {
                mInteractionHandler.onQuickScrubEnd();
                mInteractionHandler = null;
            }
        }

@@ -137,6 +140,7 @@ public class TouchInteractionService extends Service {
    private Intent mHomeIntent;
    private ComponentName mLauncher;
    private MotionEventQueue mEventQueue;
    private MainThreadExecutor mMainThreadExecutor;

    private final PointF mDownPos = new PointF();
    private final PointF mLastPos = new PointF();
@@ -156,6 +160,7 @@ public class TouchInteractionService extends Service {
        super.onCreate();
        mAM = ActivityManagerWrapper.getInstance();
        mRecentsModel = RecentsModel.getInstance(this);
        mMainThreadExecutor = new MainThreadExecutor();

        mHomeIntent = new Intent(Intent.ACTION_MAIN)
                .addCategory(Intent.CATEGORY_HOME)
@@ -284,7 +289,17 @@ public class TouchInteractionService extends Service {
        return mDisplayRotation == Surface.ROTATION_270 && mStableInsets.left > 0;
    }


    private void startTouchTracking(@InteractionType int interactionType) {
        if (isInteractionQuick(interactionType)) {
            // TODO: Send action cancel if its the Launcher consumer
        }
        if (mInteractionHandler != null) {
            final NavBarSwipeInteractionHandler handler = mInteractionHandler;
            mMainThreadExecutor.execute(() -> handler.updateInteractionType(interactionType));
            return;
        }

        // Create the shared handler
        final NavBarSwipeInteractionHandler handler =
                new NavBarSwipeInteractionHandler(mRunningTask, this, interactionType);
@@ -430,4 +445,9 @@ public class TouchInteractionService extends Service {
            ev.setEdgeFlags(flags);
        }
    }

    public static boolean isInteractionQuick(@InteractionType int interactionType) {
        return interactionType == INTERACTION_QUICK_SCRUB ||
                interactionType == INTERACTION_QUICK_SWITCH;
    }
}