From df336cf685c9d85e1e5ce5c8a5048e71322b22f3 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 9 Apr 2018 10:05:04 -0700 Subject: [PATCH] Making QuickScrub work, when the fallback activity is on top Bug: 75979063 Change-Id: If8029901ad1f99551b3eba74620616edf6f993ef --- .../quickstep/ActivityControlHelper.java | 48 ++++++++++--- .../quickstep/TouchInteractionService.java | 69 +++++++++++-------- 2 files changed, 81 insertions(+), 36 deletions(-) diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java index d82b8f437c..97930f898a 100644 --- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java +++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java @@ -35,7 +35,6 @@ import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherAppTransitionManagerImpl; import com.android.launcher3.LauncherInitListener; import com.android.launcher3.LauncherState; import com.android.launcher3.allapps.AllAppsTransitionController; @@ -61,7 +60,13 @@ public interface ActivityControlHelper { void onQuickstepGestureStarted(T activity, boolean activityVisible); - void onQuickInteractionStart(T activity, boolean activityVisible); + /** + * Updates the UI to indicate quick interaction. + * @return true if there any any UI change as a result of this + */ + boolean onQuickInteractionStart(T activity, boolean activityVisible); + + void executeOnWindowAvailable(T activity, Runnable action); void executeOnNextDraw(T activity, TaskView targetView, Runnable action); @@ -82,6 +87,9 @@ public interface ActivityControlHelper { void startRecentsFromSwipe(Intent intent, AssistDataReceiver assistDataReceiver, final RecentsAnimationListener remoteAnimationListener); + @Nullable + T getCreatedActivity(); + @UiThread @Nullable RecentsView getVisibleRecentsView(); @@ -102,8 +110,18 @@ public interface ActivityControlHelper { } @Override - public void onQuickInteractionStart(Launcher activity, boolean activityVisible) { + public boolean onQuickInteractionStart(Launcher activity, boolean activityVisible) { + LauncherState fromState = activity.getStateManager().getState(); activity.getStateManager().goToState(FAST_OVERVIEW, activityVisible); + return !fromState.overviewUi; + } + + @Override + public void executeOnWindowAvailable(Launcher activity, Runnable action) { + if (activity.getWorkspace().runOnOverlayHidden(action)) { + // Notify the activity that qiuckscrub has started + onQuickstepGestureStarted(activity, true); + } } @Override @@ -209,8 +227,8 @@ public interface ActivityControlHelper { } @Nullable - @UiThread - private Launcher getLauncher() { + @Override + public Launcher getCreatedActivity() { LauncherAppState app = LauncherAppState.getInstanceNoCreate(); if (app == null) { return null; @@ -221,7 +239,7 @@ public interface ActivityControlHelper { @Nullable @UiThread private Launcher getVisibleLaucher() { - Launcher launcher = getLauncher(); + Launcher launcher = getCreatedActivity(); return (launcher != null) && launcher.isStarted() && launcher.hasWindowFocus() ? launcher : null; } @@ -253,8 +271,14 @@ public interface ActivityControlHelper { } @Override - public void onQuickInteractionStart(RecentsActivity activity, boolean activityVisible) { - // TODO: + public boolean onQuickInteractionStart(RecentsActivity activity, boolean activityVisible) { + // Activity does not need any UI change for quickscrub. + return false; + } + + @Override + public void executeOnWindowAvailable(RecentsActivity activity, Runnable action) { + action.run(); } @Override @@ -336,10 +360,16 @@ public interface ActivityControlHelper { intent, assistDataReceiver, remoteAnimationListener, null, null); } + @Nullable + @Override + public RecentsActivity getCreatedActivity() { + return RecentsActivityTracker.getCurrentActivity(); + } + @Nullable @Override public RecentsView getVisibleRecentsView() { - RecentsActivity activity = RecentsActivityTracker.getCurrentActivity(); + RecentsActivity activity = getCreatedActivity(); if (activity != null && activity.hasWindowFocus()) { return activity.getOverviewPanel(); } diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index b610f4d424..84d8983e03 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -21,8 +21,7 @@ import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; -import static com.android.launcher3.LauncherState.FAST_OVERVIEW; -import static com.android.launcher3.LauncherState.NORMAL; + import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE; import android.annotation.TargetApi; @@ -43,9 +42,7 @@ import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherState; +import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.R; import com.android.launcher3.util.TraceHelper; @@ -220,13 +217,13 @@ public class TouchInteractionService extends Service { private TouchConsumer getCurrentTouchConsumer( @HitTarget int downHitTarget, boolean forceToLauncher, VelocityTracker tracker) { - RunningTaskInfo runningTaskInfo = mAM.getRunningTask(); + RunningTaskInfo runningTaskInfo = mAM.getRunningTask(0); if (runningTaskInfo == null && !forceToLauncher) { return mNoOpTouchConsumer; } else if (forceToLauncher || runningTaskInfo.topActivity.equals(mOverviewCommandHelper.launcher)) { - return getLauncherConsumer(); + return getOverviewConsumer(); } else { if (tracker == null) { tracker = VelocityTracker.obtain(); @@ -238,18 +235,20 @@ public class TouchInteractionService extends Service { } } - private TouchConsumer getLauncherConsumer() { - Launcher launcher = (Launcher) LauncherAppState.getInstance(this).getModel().getCallback(); - if (launcher == null) { + private TouchConsumer getOverviewConsumer() { + ActivityControlHelper activityHelper = mOverviewCommandHelper.getActivityControlHelper(); + BaseDraggingActivity activity = activityHelper.getCreatedActivity(); + if (activity == null) { return mNoOpTouchConsumer; } - View target = launcher.getDragLayer(); - return new LauncherTouchConsumer(launcher, target); + return new OverviewTouchConsumer(activityHelper, activity); } - private static class LauncherTouchConsumer implements TouchConsumer { + private static class OverviewTouchConsumer + implements TouchConsumer { - private final Launcher mLauncher; + private final ActivityControlHelper mActivityHelper; + private final T mActivity; private final View mTarget; private final int[] mLocationOnScreen = new int[2]; private final PointF mDownPos = new PointF(); @@ -260,12 +259,17 @@ public class TouchInteractionService extends Service { private boolean mInvalidated = false; private boolean mHadWindowFocusOnDown; - LauncherTouchConsumer(Launcher launcher, View target) { - mLauncher = launcher; - mTarget = target; + private float mLastProgress = 0; + private boolean mStartPending = false; + private boolean mEndPending = false; + + OverviewTouchConsumer(ActivityControlHelper activityHelper, T activity) { + mActivityHelper = activityHelper; + mActivity = activity; + mTarget = activity.getDragLayer(); mTouchSlop = ViewConfiguration.get(mTarget.getContext()).getScaledTouchSlop(); - mQuickScrubController = mLauncher.getOverviewPanel() + mQuickScrubController = mActivity.getOverviewPanel() .getQuickScrubController(); } @@ -327,16 +331,22 @@ public class TouchInteractionService extends Service { return; } if (interactionType == INTERACTION_QUICK_SCRUB) { + mStartPending = true; + Runnable action = () -> { - LauncherState fromState = mLauncher.getStateManager().getState(); - mLauncher.getStateManager().goToState(FAST_OVERVIEW, true); - mQuickScrubController.onQuickScrubStart(fromState == NORMAL); + mQuickScrubController.onQuickScrubStart( + mActivityHelper.onQuickInteractionStart(mActivity, true)); + mQuickScrubController.onQuickScrubProgress(mLastProgress); + mStartPending = false; + + if (mEndPending) { + mQuickScrubController.onQuickScrubEnd(); + mEndPending = false; + } + }; - if (mLauncher.getWorkspace().runOnOverlayHidden(action)) { - // Hide the minus one overlay so launcher can get window focus. - mLauncher.onQuickstepGestureStarted(true); - } + mActivityHelper.executeOnWindowAvailable(mActivity, action); } } @@ -345,12 +355,17 @@ public class TouchInteractionService extends Service { if (mInvalidated) { return; } - mQuickScrubController.onQuickScrubEnd(); + if (mStartPending) { + mEndPending = true; + } else { + mQuickScrubController.onQuickScrubEnd(); + } } @Override public void onQuickScrubProgress(float progress) { - if (mInvalidated) { + mLastProgress = progress; + if (mInvalidated || mEndPending) { return; } mQuickScrubController.onQuickScrubProgress(progress);