Merge "[Gesture Library Integration] Update the check for motion events on trackpad" into udc-dev

This commit is contained in:
TreeHugger Robot
2023-02-23 23:15:59 +00:00
committed by Android (Google) Code Review
7 changed files with 72 additions and 27 deletions
@@ -21,8 +21,8 @@ import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
import static com.android.launcher3.Utilities.isTrackpadMotionEvent;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN;
import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent;
import android.graphics.PointF;
import android.util.SparseArray;
@@ -91,10 +91,11 @@ public class StatusBarTouchController implements TouchController {
if (!mCanIntercept) {
return false;
}
mDownEvents.clear();
mDownEvents.put(pid, new PointF(ev.getX(), ev.getY()));
} else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
// Check!! should only set it only when threshold is not entered.
mDownEvents.put(pid, new PointF(ev.getX(idx), ev.getY(idx)));
// Check!! should only set it only when threshold is not entered.
mDownEvents.put(pid, new PointF(ev.getX(idx), ev.getY(idx)));
}
if (!mCanIntercept) {
return false;
@@ -369,7 +369,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
mIsTaskbarAllAppsOpen = controller != null && controller.isTaskbarAllAppsOpen();
mTaskbarAppWindowThreshold =
res.getDimensionPixelSize(R.dimen.taskbar_app_window_threshold);
boolean swipeWillNotShowTaskbar = mTaskbarAlreadyOpen;
boolean swipeWillNotShowTaskbar = mTaskbarAlreadyOpen || mGestureState.isTrackpadGesture();
mTaskbarHomeOverviewThreshold = swipeWillNotShowTaskbar
? 0
: res.getDimensionPixelSize(R.dimen.taskbar_home_overview_threshold);
@@ -2317,7 +2317,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
return displacement;
}
if (mTaskbarAlreadyOpen || mIsTaskbarAllAppsOpen) {
if (mTaskbarAlreadyOpen || mIsTaskbarAllAppsOpen || mGestureState.isTrackpadGesture()) {
return displacement;
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 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.CLASSIFICATION_TWO_FINGER_SWIPE;
import static com.android.launcher3.config.FeatureFlags.ENABLE_TRACKPAD_GESTURE;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.MotionEvent;
/** Handles motion events from trackpad. */
public class MotionEventsUtils {
/** {@link MotionEvent#CLASSIFICATION_MULTI_FINGER_SWIPE} is hidden. */
public static final int CLASSIFICATION_MULTI_FINGER_SWIPE = 4;
@TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public static boolean isTrackpadScroll(MotionEvent event) {
return ENABLE_TRACKPAD_GESTURE.get()
&& event.getClassification() == CLASSIFICATION_TWO_FINGER_SWIPE;
}
@TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public static boolean isTrackpadMultiFingerSwipe(MotionEvent event) {
return ENABLE_TRACKPAD_GESTURE.get()
&& event.getClassification() == CLASSIFICATION_MULTI_FINGER_SWIPE;
}
public static boolean isTrackpadMotionEvent(MotionEvent event) {
return isTrackpadScroll(event) || isTrackpadMultiFingerSwipe(event);
}
}
@@ -18,7 +18,6 @@ package com.android.quickstep;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Surface.ROTATION_0;
import static com.android.launcher3.Utilities.isTrackpadMotionEvent;
import static com.android.launcher3.util.DisplayController.CHANGE_ACTIVE_SCREEN;
import static com.android.launcher3.util.DisplayController.CHANGE_ALL;
import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
@@ -26,6 +25,8 @@ import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;
import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.NavigationMode.THREE_BUTTONS;
import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent;
import static com.android.quickstep.MotionEventsUtils.isTrackpadMultiFingerSwipe;
import android.content.Context;
import android.content.res.Resources;
@@ -233,10 +234,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
* @return whether the coordinates of the {@param event} is in the swipe up gesture region.
*/
public boolean isInSwipeUpTouchRegion(MotionEvent event, BaseActivityInterface activity) {
if (isTrackpadMotionEvent(event)) {
return !activity.isResumed();
}
return mOrientationTouchTransformer.touchInValidSwipeRegions(event.getX(), event.getY());
return isInSwipeUpTouchRegion(event, 0, activity);
}
/**
@@ -246,7 +244,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
public boolean isInSwipeUpTouchRegion(MotionEvent event, int pointerIndex,
BaseActivityInterface activity) {
if (isTrackpadMotionEvent(event)) {
return !activity.isResumed();
return isTrackpadMultiFingerSwipe(event) && !activity.isResumed();
}
return mOrientationTouchTransformer.touchInValidSwipeRegions(event.getX(pointerIndex),
event.getY(pointerIndex));
@@ -18,12 +18,14 @@ package com.android.quickstep;
import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
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.Utilities.isTrackpadMotionEvent;
import static com.android.launcher3.config.FeatureFlags.ASSISTANT_GIVES_LAUNCHER_FOCUS;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.quickstep.GestureState.DEFAULT_STATE;
import static com.android.quickstep.MotionEventsUtils.isTrackpadMultiFingerSwipe;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.FLAG_USING_OTHER_ACTIVITY_INPUT_CONSUMER;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_DOWN;
import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_UP;
@@ -628,7 +630,7 @@ public class TouchInteractionService extends Service
Object traceToken = TraceHelper.INSTANCE.beginFlagsOverride(
TraceHelper.FLAG_ALLOW_BINDER_TRACKING);
final int action = event.getAction();
final int action = event.getActionMasked();
if (action == ACTION_DOWN) {
mRotationTouchHelper.setOrientationTransformIfNeeded(event);
@@ -639,7 +641,7 @@ public class TouchInteractionService extends Service
// onConsumerInactive and wipe the previous gesture state
GestureState prevGestureState = new GestureState(mGestureState);
GestureState newGestureState = createGestureState(mGestureState,
isTrackpadMotionEvent(event));
isTrackpadMultiFingerSwipe(event));
newGestureState.setSwipeUpStartTimeMs(SystemClock.uptimeMillis());
mConsumer.onConsumerAboutToBeSwitched();
mGestureState = newGestureState;
@@ -647,7 +649,8 @@ public class TouchInteractionService extends Service
mUncheckedConsumer = mConsumer;
} else if (mDeviceState.isUserUnlocked() && mDeviceState.isFullyGesturalNavMode()
&& mDeviceState.canTriggerAssistantAction(event)) {
mGestureState = createGestureState(mGestureState, isTrackpadMotionEvent(event));
mGestureState = createGestureState(mGestureState,
isTrackpadMultiFingerSwipe(event));
// Do not change mConsumer as if there is an ongoing QuickSwitch gesture, we
// should not interrupt it. QuickSwitch assumes that interruption can only
// happen if the next gesture is also quick switch.
@@ -694,7 +697,12 @@ public class TouchInteractionService extends Service
if (cancelGesture) {
event.setAction(ACTION_CANCEL);
}
mUncheckedConsumer.onMotionEvent(event);
// Skip ACTION_POINTER_DOWN and ACTION_POINTER_UP events from trackpad.
if (!mGestureState.isTrackpadGesture() || (action != ACTION_POINTER_DOWN
&& action != ACTION_POINTER_UP)) {
mUncheckedConsumer.onMotionEvent(event);
}
if (cleanUpConsumer) {
reset();
@@ -17,9 +17,9 @@ package com.android.quickstep.inputconsumers;
import static android.view.MotionEvent.INVALID_POINTER_ID;
import static com.android.launcher3.Utilities.isTrackpadMotionEvent;
import static com.android.launcher3.Utilities.squaredHypot;
import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_TOUCHING;
import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent;
import android.content.Context;
import android.content.res.Resources;
-10
View File
@@ -16,9 +16,6 @@
package com.android.launcher3;
import static android.view.InputDevice.SOURCE_TOUCHSCREEN;
import static com.android.launcher3.config.FeatureFlags.ENABLE_TRACKPAD_GESTURE;
import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ICON_BADGED;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
@@ -725,13 +722,6 @@ public final class Utilities {
));
}
public static boolean isTrackpadMotionEvent(MotionEvent event) {
// TODO: ideally should use event.getClassification(), but currently only the move
// events get assigned the correct classification.
return ENABLE_TRACKPAD_GESTURE.get()
&& (event.getSource() & SOURCE_TOUCHSCREEN) != SOURCE_TOUCHSCREEN;
}
/** Logs the Scale and Translate properties of a matrix. Ignores skew and perspective. */
public static void logMatrix(String label, Matrix matrix) {
float[] matrixValues = new float[9];