diff --git a/lawnchair/src/app/lawnchair/gestures/VerticalSwipeTouchController.kt b/lawnchair/src/app/lawnchair/gestures/VerticalSwipeTouchController.kt index ef4e709858..309df9d99d 100644 --- a/lawnchair/src/app/lawnchair/gestures/VerticalSwipeTouchController.kt +++ b/lawnchair/src/app/lawnchair/gestures/VerticalSwipeTouchController.kt @@ -37,6 +37,7 @@ class VerticalSwipeTouchController( private var currentDisplacement = 0f private var pointerCount = 0 + private var maxPointerCount = 0 private var triggered = false // LC: a touch that starts on a paged dock belongs to the pager while it is mostly horizontal. @@ -48,10 +49,10 @@ class VerticalSwipeTouchController( init { launcher.lifecycleScope.launch { prefs.swipeUpGestureHandler.get() - .onEach { overrideSwipeUp = it != prefs.swipeUpGestureHandler.defaultValue } + .onEach { overrideSwipeUp = it != prefs.swipeUpGestureHandler.defaultValue && it !is GestureHandlerConfig.OpenAppDrawer } .launchIn(this) prefs.swipeDownGestureHandler.get() - .onEach { overrideSwipeDown = it != prefs.swipeDownGestureHandler.defaultValue } + .onEach { overrideSwipeDown = it != prefs.swipeDownGestureHandler.defaultValue && it !is GestureHandlerConfig.OpenNotifications } .launchIn(this) // Override when a custom gesture handler is configured, as launcher does not handle these by default prefs.twoFingerSwipeUpGestureHandler.get() @@ -72,7 +73,7 @@ class VerticalSwipeTouchController( downOnPagedDock = isOnPagedDock(ev) downX = ev.x downY = ev.y - detector.setDetectableScrollConditions(getSwipeDirection(), false) + maxPointerCount = 1 } else if (downOnPagedDock && !noIntercept && HorizontalSwipeFilter.isHorizontalSwipe(ev.x - downX, ev.y - downY, touchSlop / 2f) ) { @@ -81,6 +82,10 @@ class VerticalSwipeTouchController( if (noIntercept) { return false } + pointerCount = ev.pointerCount + maxPointerCount = maxOf(maxPointerCount, pointerCount) + val effectivePointerCount = if (maxPointerCount >= 2) 2 else pointerCount + detector.setDetectableScrollConditions(getSwipeDirection(effectivePointerCount), false) onControllerTouchEvent(ev) return detector.isDraggingOrSettling } @@ -88,6 +93,7 @@ class VerticalSwipeTouchController( override fun onControllerTouchEvent(ev: MotionEvent): Boolean { // We don't need to check when the pointer count changes during a swipe pointerCount = ev.pointerCount + maxPointerCount = maxOf(maxPointerCount, pointerCount) return detector.onTouchEvent(ev) } @@ -122,16 +128,17 @@ class VerticalSwipeTouchController( val velocity = computeVelocity(displacement.y - currentDisplacement, motionEvent.eventTime) if (velocity.absoluteValue > TRIGGER_VELOCITY) { triggered = true + val effectivePointerCount = if (maxPointerCount >= 2) 2 else pointerCount if (velocity < 0) { - if (pointerCount == 1) { + if (effectivePointerCount == 1 && overrideSwipeUp) { gestureController.onSwipeUp() - } else if (pointerCount == 2) { + } else if (effectivePointerCount == 2 && overrideTwoFingerSwipeUp) { gestureController.onTwoFingerSwipeUp() } } else { - if (pointerCount == 1) { + if (effectivePointerCount == 1 && overrideSwipeDown) { gestureController.onSwipeDown() - } else if (pointerCount == 2) { + } else if (effectivePointerCount == 2 && overrideTwoFingerSwipeDown) { gestureController.onTwoFingerSwipeDown() } } @@ -141,15 +148,29 @@ class VerticalSwipeTouchController( override fun onDragEnd(velocity: PointF) { detector.finishedScrolling() + maxPointerCount = 0 } - private fun getSwipeDirection(): Int { + private fun getSwipeDirection(pointerCount: Int): Int { var directions = 0 - if (overrideSwipeUp || overrideTwoFingerSwipeUp) { - directions = directions or BothAxesSwipeDetector.DIRECTION_UP - } - if (overrideSwipeDown || overrideTwoFingerSwipeDown) { - directions = directions or BothAxesSwipeDetector.DIRECTION_DOWN + when (pointerCount) { + 1 -> { + if (overrideSwipeUp) { + directions = directions or BothAxesSwipeDetector.DIRECTION_UP + } + if (overrideSwipeDown) { + directions = directions or BothAxesSwipeDetector.DIRECTION_DOWN + } + } + + 2 -> { + if (overrideTwoFingerSwipeUp) { + directions = directions or BothAxesSwipeDetector.DIRECTION_UP + } + if (overrideTwoFingerSwipeDown) { + directions = directions or BothAxesSwipeDetector.DIRECTION_DOWN + } + } } return directions } diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index 790c728792..f556f979b7 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -843,6 +843,12 @@ class PreferenceManager2 @Inject constructor( defaultValue = GestureHandlerConfig.OpenAppDrawer, ) + /** Swipe down gesture handler + * + * Important: It is imperative swipe down gesture handler only passed over to or handled by the native touch controller at [com.android.launcher3.uioverrides.touchcontrollers.StatusBarTouchController] + * + * This is needed for ease of touch slop implementation and smooth notifications panel pulling for rooted device via SystemUI Proxy. + * */ val swipeDownGestureHandler = serializablePreference( key = stringPreferencesKey("swipe_down_gesture_handler"), defaultValue = GestureHandlerConfig.OpenNotifications, diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java index f9532b3711..1035d4ce0d 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java @@ -52,6 +52,8 @@ import java.util.function.Supplier; import java.lang.reflect.InvocationTargetException; import app.lawnchair.LawnchairAppKt; +import app.lawnchair.LawnchairLauncher; +import app.lawnchair.gestures.config.GestureHandlerConfig; import app.lawnchair.util.CompatibilityKt; /** @@ -95,10 +97,11 @@ public class StatusBarTouchController implements TouchController { private void dispatchTouchEvent(MotionEvent ev) { if (mSystemUiProxy.isActive()) { + // LC-Note: If a proxy is active, pass the motion over to the proxy mLastAction = ev.getActionMasked(); mSystemUiProxy.onStatusBarTouchEvent(ev); } else if (!mExpanded) { - // LC-Note: For pulling down on notification panel (default gesture config) + // LC-Note: If not, call the notification panel via reflection (no animations) mExpanded = true; expand(); } @@ -110,13 +113,18 @@ public class StatusBarTouchController implements TouchController { @SuppressLint({"WrongConstant", "PrivateApi"}) private void expand() { - // LC-Note: For pulling down on notification panel (default gesture config) - try { - Class.forName("android.app.StatusBarManager") - .getMethod("expandNotificationsPanel") - .invoke(mLauncher.getSystemService("statusbar")); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { - e.printStackTrace(); + // LC-Note: For pulling down on notification panel + if (mLauncher instanceof LawnchairLauncher launcher) { + launcher.getGestureController().handle(GestureHandlerConfig.OpenNotifications.INSTANCE); + } else { + // LC-Note: Fallback using older style for expanding the notifications panel + try { + Class.forName("android.app.StatusBarManager") + .getMethod("expandNotificationsPanel") + .invoke(mLauncher.getSystemService("statusbar")); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { + e.printStackTrace(); + } } } @@ -235,6 +243,7 @@ public class StatusBarTouchController implements TouchController { } } return true; - // LC-Ignored: return SystemUiProxy.INSTANCE.get(mLauncher).isActive(); + // LC-Ignored: Always intercept downward swipes on all devices regardless if a proxy is active or not. + // return SystemUiProxy.INSTANCE.get(mLauncher).isActive(); } }