summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michał Brzeziński <brzezinski@google.com> 2024-10-23 10:22:56 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-23 10:22:56 +0000
commit05cea279f50c36c53435a3588bee500100a58d49 (patch)
tree2694798fd8d1319367f71feaf6627764f7be8822
parent1f632685ae3ad8bbacdd6183a229cd1969fb3942 (diff)
parent2c5c7d9bff7266528c5e183b90da37d989c36d52 (diff)
Merge "Adding optional gesture direction to gesture state" into main
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizerTest.kt41
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizer.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureState.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt4
6 files changed, 57 insertions, 14 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizerTest.kt
index 29e9ba752b36..d9d81692e2b6 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizerTest.kt
@@ -20,6 +20,8 @@ import android.view.MotionEvent
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureDirection.LEFT
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureDirection.RIGHT
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.Finished
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.NotStarted
@@ -61,23 +63,46 @@ class BackGestureRecognizerTest : SysuiTestCase() {
}
@Test
- fun triggersProgressRelativeToDistance() {
- assertProgressWhileMovingFingers(deltaX = -SWIPE_DISTANCE / 2, expectedProgress = 0.5f)
- assertProgressWhileMovingFingers(deltaX = SWIPE_DISTANCE / 2, expectedProgress = 0.5f)
- assertProgressWhileMovingFingers(deltaX = -SWIPE_DISTANCE, expectedProgress = 1f)
- assertProgressWhileMovingFingers(deltaX = SWIPE_DISTANCE, expectedProgress = 1f)
+ fun triggersProgressRelativeToDistanceWhenSwipingLeft() {
+ assertProgressWhileMovingFingers(
+ deltaX = -SWIPE_DISTANCE / 2,
+ expected = InProgress(progress = 0.5f, direction = LEFT),
+ )
+ assertProgressWhileMovingFingers(
+ deltaX = -SWIPE_DISTANCE,
+ expected = InProgress(progress = 1f, direction = LEFT),
+ )
}
- private fun assertProgressWhileMovingFingers(deltaX: Float, expectedProgress: Float) {
+ @Test
+ fun triggersProgressRelativeToDistanceWhenSwipingRight() {
+ assertProgressWhileMovingFingers(
+ deltaX = SWIPE_DISTANCE / 2,
+ expected = InProgress(progress = 0.5f, direction = RIGHT),
+ )
+ assertProgressWhileMovingFingers(
+ deltaX = SWIPE_DISTANCE,
+ expected = InProgress(progress = 1f, direction = RIGHT),
+ )
+ }
+
+ private fun assertProgressWhileMovingFingers(deltaX: Float, expected: InProgress) {
assertStateAfterEvents(
events = ThreeFingerGesture.eventsForGestureInProgress { move(deltaX = deltaX) },
- expectedState = InProgress(progress = expectedProgress),
+ expectedState = expected,
)
}
@Test
fun triggeredProgressIsNoBiggerThanOne() {
- assertProgressWhileMovingFingers(deltaX = SWIPE_DISTANCE * 2, expectedProgress = 1f)
+ assertProgressWhileMovingFingers(
+ deltaX = SWIPE_DISTANCE * 2,
+ expected = InProgress(progress = 1f, direction = RIGHT),
+ )
+ assertProgressWhileMovingFingers(
+ deltaX = -SWIPE_DISTANCE * 2,
+ expected = InProgress(progress = 1f, direction = LEFT),
+ )
}
@Test
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizer.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizer.kt
index 024048cbbb24..35ea0ea3e048 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizer.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/BackGestureRecognizer.kt
@@ -18,6 +18,9 @@ package com.android.systemui.touchpad.tutorial.ui.gesture
import android.util.MathUtils
import android.view.MotionEvent
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureDirection.LEFT
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureDirection.RIGHT
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
import kotlin.math.abs
/**
@@ -44,7 +47,13 @@ class BackGestureRecognizer(private val gestureDistanceThresholdPx: Int) : Gestu
gestureStateChangedCallback,
gestureState,
isFinished = { abs(it.deltaX) >= gestureDistanceThresholdPx },
- progress = { MathUtils.saturate(abs(it.deltaX / gestureDistanceThresholdPx)) },
+ progress = ::getProgress,
)
}
+
+ private fun getProgress(it: Moving): InProgress {
+ val direction = if (it.deltaX > 0) RIGHT else LEFT
+ val value = MathUtils.saturate(abs(it.deltaX / gestureDistanceThresholdPx))
+ return InProgress(value, direction)
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureState.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureState.kt
index b513c49371a4..f27ddb515c24 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureState.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureState.kt
@@ -21,5 +21,11 @@ sealed interface GestureState {
data object Finished : GestureState
- data class InProgress(val progress: Float = 0f) : GestureState
+ data class InProgress(val progress: Float = 0f, val direction: GestureDirection? = null) :
+ GestureState
+}
+
+enum class GestureDirection {
+ LEFT,
+ RIGHT,
}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt
index f19467726def..24f5d1f00794 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/GestureStateUpdates.kt
@@ -21,7 +21,7 @@ inline fun updateGestureState(
gestureStateChangedCallback: (GestureState) -> Unit,
gestureState: DistanceGestureState?,
isFinished: (Finished) -> Boolean,
- progress: (Moving) -> Float,
+ progress: (Moving) -> GestureState.InProgress,
) {
when (gestureState) {
is Finished -> {
@@ -32,7 +32,7 @@ inline fun updateGestureState(
}
}
is Moving -> {
- gestureStateChangedCallback(GestureState.InProgress(progress(gestureState)))
+ gestureStateChangedCallback(progress(gestureState))
}
is Started -> gestureStateChangedCallback(GestureState.InProgress())
else -> {}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt
index b804b9a0d4c7..e10b8253ebad 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt
@@ -18,6 +18,7 @@ package com.android.systemui.touchpad.tutorial.ui.gesture
import android.util.MathUtils
import android.view.MotionEvent
+import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
/** Recognizes touchpad home gesture, that is - using three fingers on touchpad - swiping up. */
class HomeGestureRecognizer(private val gestureDistanceThresholdPx: Int) : GestureRecognizer {
@@ -40,7 +41,7 @@ class HomeGestureRecognizer(private val gestureDistanceThresholdPx: Int) : Gestu
gestureStateChangedCallback,
gestureState,
isFinished = { -it.deltaY >= gestureDistanceThresholdPx },
- progress = { MathUtils.saturate(-it.deltaY / gestureDistanceThresholdPx) },
+ progress = { InProgress(MathUtils.saturate(-it.deltaY / gestureDistanceThresholdPx)) },
)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt
index 7d484ee85b7c..c47888609a61 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt
@@ -54,7 +54,9 @@ class RecentAppsGestureRecognizer(
-state.deltaY >= gestureDistanceThresholdPx &&
abs(velocityTracker.calculateVelocity().value) <= velocityThresholdPxPerMs
},
- progress = { MathUtils.saturate(-it.deltaY / gestureDistanceThresholdPx) },
+ progress = {
+ GestureState.InProgress(MathUtils.saturate(-it.deltaY / gestureDistanceThresholdPx))
+ },
)
}
}