From a002c6c19d2e7e1c3fc010ffdcbb2138586b5553 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 12 Feb 2019 16:20:10 -0800 Subject: [PATCH] Removing use of onQuickstep event and determining the touchSlopPassed in Launcher Bug: 124255113 Change-Id: If6fe77c7086a30775f78ec2a86251cb6bcd3c4c4 --- .../uioverrides/RecentsUiFactory.java | 12 +- .../android/quickstep/MotionEventQueue.java | 10 - .../quickstep/OtherActivityTouchConsumer.java | 85 +++--- .../quickstep/OverviewInteractionState.java | 11 - .../quickstep/OverviewTouchConsumer.java | 247 ++++++++++++++++++ .../com/android/quickstep/TouchConsumer.java | 2 - .../quickstep/TouchInteractionService.java | 230 +--------------- .../WindowTransformSwipeHandler.java | 1 - src/com/android/launcher3/Launcher.java | 11 +- 9 files changed, 310 insertions(+), 299 deletions(-) create mode 100644 quickstep/src/com/android/quickstep/OverviewTouchConsumer.java diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java index 51e9495994..027fd910c0 100644 --- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java +++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/RecentsUiFactory.java @@ -120,13 +120,11 @@ public abstract class RecentsUiFactory { */ public static void onLauncherStateOrResumeChanged(Launcher launcher) { LauncherState state = launcher.getStateManager().getState(); - if (!OverviewInteractionState.INSTANCE.get(launcher).swipeGestureInitializing()) { - DeviceProfile profile = launcher.getDeviceProfile(); - boolean visible = (state == NORMAL || state == OVERVIEW) && launcher.isUserActive() - && !profile.isVerticalBarLayout(); - UiThreadHelper.runAsyncCommand(launcher, SET_SHELF_HEIGHT_CMD, - visible ? 1 : 0, profile.hotseatBarSizePx); - } + DeviceProfile profile = launcher.getDeviceProfile(); + boolean visible = (state == NORMAL || state == OVERVIEW) && launcher.isUserActive() + && !profile.isVerticalBarLayout(); + UiThreadHelper.runAsyncCommand(launcher, SET_SHELF_HEIGHT_CMD, + visible ? 1 : 0, profile.hotseatBarSizePx); if (state == NORMAL) { launcher.getOverviewPanel().setSwipeDownShouldLaunchApp(false); diff --git a/quickstep/src/com/android/quickstep/MotionEventQueue.java b/quickstep/src/com/android/quickstep/MotionEventQueue.java index 3664c97ff0..3e2e9a6a8d 100644 --- a/quickstep/src/com/android/quickstep/MotionEventQueue.java +++ b/quickstep/src/com/android/quickstep/MotionEventQueue.java @@ -52,8 +52,6 @@ public class MotionEventQueue { ACTION_VIRTUAL | (4 << ACTION_POINTER_INDEX_SHIFT); private static final int ACTION_SHOW_OVERVIEW_FROM_ALT_TAB = ACTION_VIRTUAL | (5 << ACTION_POINTER_INDEX_SHIFT); - private static final int ACTION_QUICK_STEP = - ACTION_VIRTUAL | (6 << ACTION_POINTER_INDEX_SHIFT); private final InputEventDispatcher mDispatcher; private final InputEventReceiver mReceiver; @@ -98,9 +96,6 @@ public class MotionEventQueue { mConsumer.onShowOverviewFromAltTab(); mConsumer.onQuickScrubStart(); break; - case ACTION_QUICK_STEP: - mConsumer.onQuickStep(event); - break; default: Log.e(TAG, "Invalid virtual event: " + event.getAction()); } @@ -139,11 +134,6 @@ public class MotionEventQueue { queueVirtualAction(ACTION_QUICK_SCRUB_END, 0); } - public void onQuickStep(MotionEvent event) { - event.setAction(ACTION_QUICK_STEP); - queue(event); - } - public void onNewGesture(@HitTarget int downHitTarget) { queueVirtualAction(ACTION_NEW_GESTURE, downHitTarget); } diff --git a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java index 84f16cb258..fa8eceba1f 100644 --- a/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java +++ b/quickstep/src/com/android/quickstep/OtherActivityTouchConsumer.java @@ -80,21 +80,30 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC private final InputConsumerController mInputConsumer; private final SwipeSharedState mSwipeSharedState; + private final int mDisplayRotation; + private final Rect mStableInsets = new Rect(); + private final MotionEventQueue mEventQueue; private final MotionPauseDetector mMotionPauseDetector; private VelocityTracker mVelocityTracker; + private WindowTransformSwipeHandler mInteractionHandler; + private final boolean mIsDeferredDownTarget; private final PointF mDownPos = new PointF(); private final PointF mLastPos = new PointF(); private int mActivePointerId = INVALID_POINTER_ID; - private boolean mPassedInitialSlop; - // Used for non-deferred gestures to determine when to start dragging - private int mQuickStepDragSlop; + + private final float mDragSlop; + private final float mTouchSlop; + + // Slop used to check when we start moving window. + private boolean mPassedDragSlop; + // Slop used to determine when we say that the gesture has started. + private boolean mPassedTouchSlop; + + // TODO: Start displacement should have both x and y private float mStartDisplacement; - private WindowTransformSwipeHandler mInteractionHandler; - private int mDisplayRotation; - private Rect mStableInsets = new Rect(); public OtherActivityTouchConsumer(Context base, RunningTaskInfo runningTaskInfo, RecentsModel recentsModel, Intent homeIntent, ActivityControlHelper activityControl, @@ -120,6 +129,15 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC mTouchInteractionLog.setTouchConsumer(this); mInputConsumer = inputConsumer; mSwipeSharedState = swipeSharedState; + + Display display = getSystemService(WindowManager.class).getDefaultDisplay(); + mDisplayRotation = display.getRotation(); + WindowManagerWrapper.getInstance().getStableInsets(mStableInsets); + + mDragSlop = NavigationBarCompat.getQuickStepDragSlopPx(); + mTouchSlop = NavigationBarCompat.getQuickStepTouchSlopPx(); + // If active listener isn't null, we are continuing the previous gesture. + mPassedTouchSlop = mPassedDragSlop = mSwipeSharedState.getActiveListener() != null; } @Override @@ -146,9 +164,6 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC mActivePointerId = ev.getPointerId(0); mDownPos.set(ev.getX(), ev.getY()); mLastPos.set(mDownPos); - // If active listener isn't null, we are continuing the previous gesture. - mPassedInitialSlop = mSwipeSharedState.getActiveListener() != null; - mQuickStepDragSlop = NavigationBarCompat.getQuickStepDragSlopPx(); // Start the window animation on down to give more time for launcher to draw if the // user didn't start the gesture over the back button @@ -156,9 +171,6 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC startTouchTrackingForWindowAnimation(ev.getEventTime()); } - Display display = getSystemService(WindowManager.class).getDefaultDisplay(); - mDisplayRotation = display.getRotation(); - WindowManagerWrapper.getInstance().getStableInsets(mStableInsets); RaceConditionTracker.onEvent(DOWN_EVT, EXIT); break; } @@ -182,18 +194,38 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC } mLastPos.set(ev.getX(pointerIndex), ev.getY(pointerIndex)); float displacement = getDisplacement(ev); - if (!mPassedInitialSlop) { + + if (!mPassedDragSlop) { if (!mIsDeferredDownTarget) { // Normal gesture, ensure we pass the drag slop before we start tracking // the gesture - if (Math.abs(displacement) > mQuickStepDragSlop) { - mPassedInitialSlop = true; + if (Math.abs(displacement) > mDragSlop) { + mPassedDragSlop = true; mStartDisplacement = displacement; } } } - if (mPassedInitialSlop && mInteractionHandler != null) { + if (!mPassedTouchSlop) { + if (Math.hypot(mLastPos.x - mDownPos.x, mLastPos.y - mDownPos.y) >= + mTouchSlop) { + mPassedTouchSlop = true; + + mTouchInteractionLog.startQuickStep(); + if (mIsDeferredDownTarget) { + // Deferred gesture, start the animation and gesture tracking once + // we pass the actual touch slop + startTouchTrackingForWindowAnimation(ev.getEventTime()); + } + if (!mPassedDragSlop) { + mPassedDragSlop = true; + mStartDisplacement = displacement; + } + notifyGestureStarted(); + } + } + + if (mPassedDragSlop && mInteractionHandler != null) { // Move dispatchMotion(ev, displacement - mStartDisplacement, null); @@ -298,7 +330,7 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC * the animation can still be running. */ private void finishTouchTracking(MotionEvent ev) { - if (mPassedInitialSlop && mInteractionHandler != null) { + if (mPassedDragSlop && mInteractionHandler != null) { mVelocityTracker.computeCurrentVelocity(1000, ViewConfiguration.get(this).getScaledMaximumFlingVelocity()); @@ -360,11 +392,11 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC @Override public void onQuickScrubStart() { - if (!mPassedInitialSlop && mIsDeferredDownTarget && mInteractionHandler == null) { + if (!mPassedDragSlop && mIsDeferredDownTarget && mInteractionHandler == null) { // If we deferred starting the window animation on touch down, then // start tracking now startTouchTrackingForWindowAnimation(SystemClock.uptimeMillis()); - mPassedInitialSlop = true; + mPassedDragSlop = true; } mTouchInteractionLog.startQuickScrub(); @@ -390,21 +422,6 @@ public class OtherActivityTouchConsumer extends ContextWrapper implements TouchC } } - @Override - public void onQuickStep(MotionEvent ev) { - mTouchInteractionLog.startQuickStep(); - if (mIsDeferredDownTarget) { - // Deferred gesture, start the animation and gesture tracking once we pass the actual - // touch slop - startTouchTrackingForWindowAnimation(ev.getEventTime()); - } - if (!mPassedInitialSlop) { - mPassedInitialSlop = true; - mStartDisplacement = getDisplacement(ev); - } - notifyGestureStarted(); - } - private float getDisplacement(MotionEvent ev) { float eventX = ev.getX(); float eventY = ev.getY(); diff --git a/quickstep/src/com/android/quickstep/OverviewInteractionState.java b/quickstep/src/com/android/quickstep/OverviewInteractionState.java index 27f1399ffc..eaa3ad48ad 100644 --- a/quickstep/src/com/android/quickstep/OverviewInteractionState.java +++ b/quickstep/src/com/android/quickstep/OverviewInteractionState.java @@ -64,8 +64,6 @@ public class OverviewInteractionState { private final Handler mUiHandler; private final Handler mBgHandler; - private boolean mSwipeGestureInitializing = false; - // These are updated on the background thread private ISystemUiProxy mISystemUiProxy; private boolean mSwipeUpEnabled = true; @@ -177,15 +175,6 @@ public class OverviewInteractionState { } } - @WorkerThread - public void setSwipeGestureInitializing(boolean swipeGestureInitializing) { - mSwipeGestureInitializing = swipeGestureInitializing; - } - - public boolean swipeGestureInitializing() { - return mSwipeGestureInitializing; - } - public void notifySwipeUpSettingChanged(boolean swipeUpEnabled) { mUiHandler.removeMessages(MSG_SET_SWIPE_UP_ENABLED); mUiHandler.obtainMessage(MSG_SET_SWIPE_UP_ENABLED, swipeUpEnabled ? 1 : 0, 0). diff --git a/quickstep/src/com/android/quickstep/OverviewTouchConsumer.java b/quickstep/src/com/android/quickstep/OverviewTouchConsumer.java new file mode 100644 index 0000000000..2638f2391d --- /dev/null +++ b/quickstep/src/com/android/quickstep/OverviewTouchConsumer.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.quickstep; + +import static android.view.MotionEvent.ACTION_CANCEL; +import static android.view.MotionEvent.ACTION_DOWN; +import static android.view.MotionEvent.ACTION_MOVE; +import static android.view.MotionEvent.ACTION_POINTER_DOWN; +import static android.view.MotionEvent.ACTION_POINTER_INDEX_SHIFT; +import static android.view.MotionEvent.ACTION_UP; + +import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS; + +import android.graphics.PointF; +import android.view.MotionEvent; +import android.view.ViewConfiguration; + +import com.android.launcher3.BaseDraggingActivity; +import com.android.launcher3.views.BaseDragLayer; +import com.android.quickstep.views.RecentsView; +import com.android.systemui.shared.system.ActivityManagerWrapper; + +/** + * Touch consumer for handling touch on the recents/Launcher activity. + */ +public class OverviewTouchConsumer + implements TouchConsumer { + + private static final String TAG = "OverviewTouchConsumer"; + + private final ActivityControlHelper mActivityHelper; + private final T mActivity; + private final BaseDragLayer mTarget; + private final int[] mLocationOnScreen = new int[2]; + private final PointF mDownPos = new PointF(); + private final int mTouchSlop; + private final QuickScrubController mQuickScrubController; + private final TouchInteractionLog mTouchInteractionLog; + + private final boolean mStartingInActivityBounds; + + private boolean mTrackingStarted = false; + private boolean mInvalidated = false; + + private float mLastProgress = 0; + private boolean mStartPending = false; + private boolean mEndPending = false; + private boolean mWaitForWindowAvailable; + + OverviewTouchConsumer(ActivityControlHelper activityHelper, T activity, + boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog, + boolean waitForWindowAvailable) { + mActivityHelper = activityHelper; + mActivity = activity; + mTarget = activity.getDragLayer(); + mTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + mStartingInActivityBounds = startingInActivityBounds; + + mQuickScrubController = mActivity.getOverviewPanel() + .getQuickScrubController(); + mTouchInteractionLog = touchInteractionLog; + mTouchInteractionLog.setTouchConsumer(this); + + mWaitForWindowAvailable = waitForWindowAvailable; + } + + @Override + public void accept(MotionEvent ev) { + if (mInvalidated) { + return; + } + mTouchInteractionLog.addMotionEvent(ev); + int action = ev.getActionMasked(); + if (action == ACTION_DOWN) { + if (mStartingInActivityBounds) { + startTouchTracking(ev, false /* updateLocationOffset */, + false /* closeActiveWindows */); + return; + } + mTrackingStarted = false; + mDownPos.set(ev.getX(), ev.getY()); + } else if (!mTrackingStarted) { + switch (action) { + case ACTION_CANCEL: + case ACTION_UP: + startTouchTracking(ev, true /* updateLocationOffset */, + false /* closeActiveWindows */); + break; + case ACTION_MOVE: { + float displacement = mActivity.getDeviceProfile().isLandscape ? + ev.getX() - mDownPos.x : ev.getY() - mDownPos.y; + if (Math.abs(displacement) >= mTouchSlop) { + // Start tracking only when mTouchSlop is crossed. + startTouchTracking(ev, true /* updateLocationOffset */, + true /* closeActiveWindows */); + } + } + } + } + + if (mTrackingStarted) { + sendEvent(ev); + } + + if (action == ACTION_UP || action == ACTION_CANCEL) { + mInvalidated = true; + } + } + + private void startTouchTracking(MotionEvent ev, boolean updateLocationOffset, + boolean closeActiveWindows) { + if (updateLocationOffset) { + mTarget.getLocationOnScreen(mLocationOnScreen); + } + + // Send down touch event + MotionEvent down = MotionEvent.obtainNoHistory(ev); + down.setAction(ACTION_DOWN); + sendEvent(down); + + mTrackingStarted = true; + // Send pointer down for remaining pointers. + int pointerCount = ev.getPointerCount(); + for (int i = 1; i < pointerCount; i++) { + down.setAction(ACTION_POINTER_DOWN | (i << ACTION_POINTER_INDEX_SHIFT)); + sendEvent(down); + } + + down.recycle(); + + if (closeActiveWindows) { + OverviewCallbacks.get(mActivity).closeAllWindows(); + ActivityManagerWrapper.getInstance() + .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS); + mTouchInteractionLog.startQuickStep(); + } + } + + private void sendEvent(MotionEvent ev) { + if (!mTarget.verifyTouchDispatch(this, ev)) { + mInvalidated = true; + return; + } + int flags = ev.getEdgeFlags(); + ev.setEdgeFlags(flags | TouchInteractionService.EDGE_NAV_BAR); + ev.offsetLocation(-mLocationOnScreen[0], -mLocationOnScreen[1]); + if (!mTrackingStarted) { + mTarget.onInterceptTouchEvent(ev); + } + mTarget.onTouchEvent(ev); + ev.offsetLocation(mLocationOnScreen[0], mLocationOnScreen[1]); + ev.setEdgeFlags(flags); + } + + @Override + public void onQuickScrubStart() { + if (mInvalidated) { + return; + } + mTouchInteractionLog.startQuickScrub(); + if (!mQuickScrubController.prepareQuickScrub(TAG)) { + mInvalidated = true; + mTouchInteractionLog.endQuickScrub("onQuickScrubStart"); + return; + } + OverviewCallbacks.get(mActivity).closeAllWindows(); + ActivityManagerWrapper.getInstance() + .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS); + + mStartPending = true; + Runnable action = () -> { + if (!mQuickScrubController.prepareQuickScrub(TAG)) { + mInvalidated = true; + mTouchInteractionLog.endQuickScrub("onQuickScrubStart"); + return; + } + mActivityHelper.onQuickInteractionStart(mActivity, null, true, + mTouchInteractionLog); + mQuickScrubController.onQuickScrubProgress(mLastProgress); + mStartPending = false; + + if (mEndPending) { + mQuickScrubController.onQuickScrubEnd(); + mEndPending = false; + } + }; + + if (mWaitForWindowAvailable) { + mActivityHelper.executeOnWindowAvailable(mActivity, action); + } else { + action.run(); + } + } + + @Override + public void onQuickScrubEnd() { + mTouchInteractionLog.endQuickScrub("onQuickScrubEnd"); + if (mInvalidated) { + return; + } + if (mStartPending) { + mEndPending = true; + } else { + mQuickScrubController.onQuickScrubEnd(); + } + } + + @Override + public void onQuickScrubProgress(float progress) { + mTouchInteractionLog.setQuickScrubProgress(progress); + mLastProgress = progress; + if (mInvalidated || mStartPending) { + return; + } + mQuickScrubController.onQuickScrubProgress(progress); + } + + public static TouchConsumer newInstance(ActivityControlHelper activityHelper, + boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog) { + return newInstance(activityHelper, startingInActivityBounds, touchInteractionLog, + true /* waitForWindowAvailable */); + } + + public static TouchConsumer newInstance(ActivityControlHelper activityHelper, + boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog, + boolean waitForWindowAvailable) { + BaseDraggingActivity activity = activityHelper.getCreatedActivity(); + if (activity == null) { + return TouchConsumer.NO_OP; + } + return new OverviewTouchConsumer(activityHelper, activity, startingInActivityBounds, + touchInteractionLog, waitForWindowAvailable); + } +} \ No newline at end of file diff --git a/quickstep/src/com/android/quickstep/TouchConsumer.java b/quickstep/src/com/android/quickstep/TouchConsumer.java index 026f715851..d9b1fcf850 100644 --- a/quickstep/src/com/android/quickstep/TouchConsumer.java +++ b/quickstep/src/com/android/quickstep/TouchConsumer.java @@ -46,8 +46,6 @@ public interface TouchConsumer extends Consumer { default void onQuickScrubProgress(float progress) { } - default void onQuickStep(MotionEvent ev) { } - default void onShowOverviewFromAltTab() {} default boolean isActive() { diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 951ba4fc57..276ba05099 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -17,20 +17,15 @@ package com.android.quickstep; import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_DOWN; -import static android.view.MotionEvent.ACTION_MOVE; -import static android.view.MotionEvent.ACTION_POINTER_DOWN; -import static android.view.MotionEvent.ACTION_POINTER_INDEX_SHIFT; import static android.view.MotionEvent.ACTION_UP; import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE; -import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS; import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE; import android.annotation.TargetApi; import android.app.ActivityManager.RunningTaskInfo; import android.app.Service; import android.content.Intent; -import android.graphics.PointF; import android.graphics.Region; import android.os.Build; import android.os.Bundle; @@ -40,13 +35,9 @@ import android.util.Log; import android.util.SparseArray; import android.view.Choreographer; import android.view.MotionEvent; -import android.view.ViewConfiguration; -import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.util.TraceHelper; -import com.android.launcher3.views.BaseDragLayer; -import com.android.quickstep.views.RecentsView; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; import com.android.systemui.shared.system.ActivityManagerWrapper; @@ -95,12 +86,6 @@ public class TouchInteractionService extends Service { mEventQueue.queue(ev); int action = ev.getActionMasked(); - if (action == ACTION_DOWN) { - mOverviewInteractionState.setSwipeGestureInitializing(true); - } else if (action == ACTION_UP || action == ACTION_CANCEL) { - mOverviewInteractionState.setSwipeGestureInitializing(false); - } - String name = sMotionEventNames.get(action); if (name != null){ TraceHelper.partitionSection("SysUiBinder", name); @@ -115,7 +100,6 @@ public class TouchInteractionService extends Service { public void onQuickScrubStart() { mEventQueue.onQuickScrubStart(); - mOverviewInteractionState.setSwipeGestureInitializing(false); TraceHelper.partitionSection("SysUiBinder", "onQuickScrubStart"); } @@ -151,11 +135,7 @@ public class TouchInteractionService extends Service { } } - public void onQuickStep(MotionEvent motionEvent) { - mEventQueue.onQuickStep(motionEvent); - mOverviewInteractionState.setSwipeGestureInitializing(false); - TraceHelper.endSection("SysUiBinder", "onQuickStep"); - } + public void onQuickStep(MotionEvent motionEvent) { } @Override public void onTip(int actionType, int viewType) { @@ -252,212 +232,4 @@ public class TouchInteractionService extends Service { protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { mTouchInteractionLog.dump(pw); } - - public static class OverviewTouchConsumer - implements TouchConsumer { - - private final ActivityControlHelper mActivityHelper; - private final T mActivity; - private final BaseDragLayer mTarget; - private final int[] mLocationOnScreen = new int[2]; - private final PointF mDownPos = new PointF(); - private final int mTouchSlop; - private final QuickScrubController mQuickScrubController; - private final TouchInteractionLog mTouchInteractionLog; - - private final boolean mStartingInActivityBounds; - - private boolean mTrackingStarted = false; - private boolean mInvalidated = false; - - private float mLastProgress = 0; - private boolean mStartPending = false; - private boolean mEndPending = false; - private boolean mWaitForWindowAvailable; - - OverviewTouchConsumer(ActivityControlHelper activityHelper, T activity, - boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog, - boolean waitForWindowAvailable) { - mActivityHelper = activityHelper; - mActivity = activity; - mTarget = activity.getDragLayer(); - mTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); - mStartingInActivityBounds = startingInActivityBounds; - - mQuickScrubController = mActivity.getOverviewPanel() - .getQuickScrubController(); - mTouchInteractionLog = touchInteractionLog; - mTouchInteractionLog.setTouchConsumer(this); - - mWaitForWindowAvailable = waitForWindowAvailable; - } - - @Override - public void accept(MotionEvent ev) { - if (mInvalidated) { - return; - } - mTouchInteractionLog.addMotionEvent(ev); - int action = ev.getActionMasked(); - if (action == ACTION_DOWN) { - if (mStartingInActivityBounds) { - startTouchTracking(ev, false /* updateLocationOffset */); - return; - } - mTrackingStarted = false; - mDownPos.set(ev.getX(), ev.getY()); - } else if (!mTrackingStarted) { - switch (action) { - case ACTION_CANCEL: - case ACTION_UP: - startTouchTracking(ev, true /* updateLocationOffset */); - break; - case ACTION_MOVE: { - float displacement = mActivity.getDeviceProfile().isLandscape ? - ev.getX() - mDownPos.x : ev.getY() - mDownPos.y; - if (Math.abs(displacement) >= mTouchSlop) { - // Start tracking only when mTouchSlop is crossed. - startTouchTracking(ev, true /* updateLocationOffset */); - } - } - } - } - - if (mTrackingStarted) { - sendEvent(ev); - } - - if (action == ACTION_UP || action == ACTION_CANCEL) { - mInvalidated = true; - } - } - - private void startTouchTracking(MotionEvent ev, boolean updateLocationOffset) { - if (updateLocationOffset) { - mTarget.getLocationOnScreen(mLocationOnScreen); - } - - // Send down touch event - MotionEvent down = MotionEvent.obtainNoHistory(ev); - down.setAction(ACTION_DOWN); - sendEvent(down); - - mTrackingStarted = true; - // Send pointer down for remaining pointers. - int pointerCount = ev.getPointerCount(); - for (int i = 1; i < pointerCount; i++) { - down.setAction(ACTION_POINTER_DOWN | (i << ACTION_POINTER_INDEX_SHIFT)); - sendEvent(down); - } - - down.recycle(); - } - - private void sendEvent(MotionEvent ev) { - if (!mTarget.verifyTouchDispatch(this, ev)) { - mInvalidated = true; - return; - } - int flags = ev.getEdgeFlags(); - ev.setEdgeFlags(flags | TouchInteractionService.EDGE_NAV_BAR); - ev.offsetLocation(-mLocationOnScreen[0], -mLocationOnScreen[1]); - if (!mTrackingStarted) { - mTarget.onInterceptTouchEvent(ev); - } - mTarget.onTouchEvent(ev); - ev.offsetLocation(mLocationOnScreen[0], mLocationOnScreen[1]); - ev.setEdgeFlags(flags); - } - - @Override - public void onQuickStep(MotionEvent ev) { - if (mInvalidated) { - return; - } - OverviewCallbacks.get(mActivity).closeAllWindows(); - ActivityManagerWrapper.getInstance() - .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS); - mTouchInteractionLog.startQuickStep(); - } - - @Override - public void onQuickScrubStart() { - if (mInvalidated) { - return; - } - mTouchInteractionLog.startQuickScrub(); - if (!mQuickScrubController.prepareQuickScrub(TAG)) { - mInvalidated = true; - mTouchInteractionLog.endQuickScrub("onQuickScrubStart"); - return; - } - OverviewCallbacks.get(mActivity).closeAllWindows(); - ActivityManagerWrapper.getInstance() - .closeSystemWindows(CLOSE_SYSTEM_WINDOWS_REASON_RECENTS); - - mStartPending = true; - Runnable action = () -> { - if (!mQuickScrubController.prepareQuickScrub(TAG)) { - mInvalidated = true; - mTouchInteractionLog.endQuickScrub("onQuickScrubStart"); - return; - } - mActivityHelper.onQuickInteractionStart(mActivity, null, true, - mTouchInteractionLog); - mQuickScrubController.onQuickScrubProgress(mLastProgress); - mStartPending = false; - - if (mEndPending) { - mQuickScrubController.onQuickScrubEnd(); - mEndPending = false; - } - }; - - if (mWaitForWindowAvailable) { - mActivityHelper.executeOnWindowAvailable(mActivity, action); - } else { - action.run(); - } - } - - @Override - public void onQuickScrubEnd() { - mTouchInteractionLog.endQuickScrub("onQuickScrubEnd"); - if (mInvalidated) { - return; - } - if (mStartPending) { - mEndPending = true; - } else { - mQuickScrubController.onQuickScrubEnd(); - } - } - - @Override - public void onQuickScrubProgress(float progress) { - mTouchInteractionLog.setQuickScrubProgress(progress); - mLastProgress = progress; - if (mInvalidated || mStartPending) { - return; - } - mQuickScrubController.onQuickScrubProgress(progress); - } - - public static TouchConsumer newInstance(ActivityControlHelper activityHelper, - boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog) { - return newInstance(activityHelper, startingInActivityBounds, touchInteractionLog, - true /* waitForWindowAvailable */); - } - - public static TouchConsumer newInstance(ActivityControlHelper activityHelper, - boolean startingInActivityBounds, TouchInteractionLog touchInteractionLog, - boolean waitForWindowAvailable) { - BaseDraggingActivity activity = activityHelper.getCreatedActivity(); - if (activity == null) { - return TouchConsumer.NO_OP; - } - return new OverviewTouchConsumer(activityHelper, activity, startingInActivityBounds, - touchInteractionLog, waitForWindowAvailable); - } - } } diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index bc4e094296..4a329d218a 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -95,7 +95,6 @@ import com.android.quickstep.ActivityControlHelper.AnimationFactory; import com.android.quickstep.ActivityControlHelper.AnimationFactory.ShelfAnimState; import com.android.quickstep.ActivityControlHelper.LayoutListener; import com.android.quickstep.TouchConsumer.InteractionType; -import com.android.quickstep.TouchInteractionService.OverviewTouchConsumer; import com.android.quickstep.util.ClipAnimationHelper; import com.android.quickstep.util.RemoteAnimationTargetSet; import com.android.quickstep.util.SwipeAnimationTargetSet; diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 245e4708c3..cf16759e54 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -259,7 +259,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, private final Handler mHandler = new Handler(); - private final Runnable mLogOnDelayedResume = this::logOnDelayedResume; + private final Runnable mHandleDeferredResume = this::handleDeferredResume; @Override protected void onCreate(Bundle savedInstanceState) { @@ -782,11 +782,13 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, RaceConditionTracker.onEvent(ON_START_EVT, EXIT); } - private void logOnDelayedResume() { + private void handleDeferredResume() { if (hasBeenResumed()) { getUserEventDispatcher().logActionCommand(Action.Command.RESUME, mStateManager.getState().containerType, -1); getUserEventDispatcher().startSession(); + + UiFactory.onLauncherStateOrResumeChanged(this); } } @@ -797,8 +799,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, super.onResume(); TraceHelper.partitionSection("ON_RESUME", "superCall"); - mHandler.removeCallbacks(mLogOnDelayedResume); - Utilities.postAsyncCallback(mHandler, mLogOnDelayedResume); + mHandler.removeCallbacks(mHandleDeferredResume); + Utilities.postAsyncCallback(mHandler, mHandleDeferredResume); setOnResumeCallback(null); // Process any items that were added while Launcher was away. @@ -812,7 +814,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, if (mLauncherCallbacks != null) { mLauncherCallbacks.onResume(); } - UiFactory.onLauncherStateOrResumeChanged(this); TraceHelper.endSection("ON_RESUME"); RaceConditionTracker.onEvent(ON_RESUME_EVT, EXIT);