summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizerTest.kt22
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizerTest.kt23
-rw-r--r--packages/SystemUI/res/values/dimens.xml6
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizer.kt13
-rw-r--r--packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizer.kt4
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/FakeVelocityTracker.kt36
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/VelocityTrackerKosmos.kt21
8 files changed, 107 insertions, 21 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizerTest.kt
index 7d3ed92cecc6..7aa389a1739f 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/HomeGestureRecognizerTest.kt
@@ -20,10 +20,12 @@ 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.testKosmos
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
import com.android.systemui.touchpad.tutorial.ui.gesture.MultiFingerGesture.Companion.SWIPE_DISTANCE
+import com.android.systemui.touchpad.ui.gesture.fakeVelocityTracker
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
@@ -33,12 +35,24 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class HomeGestureRecognizerTest : SysuiTestCase() {
+ companion object {
+ const val THRESHOLD_VELOCITY_PX_PER_MS = 1f
+ const val SLOW = THRESHOLD_VELOCITY_PX_PER_MS - 0.01f
+ const val FAST = THRESHOLD_VELOCITY_PX_PER_MS + 0.01f
+ }
+
private var gestureState: GestureState = GestureState.NotStarted
+ private var velocityTracker = testKosmos().fakeVelocityTracker
private val gestureRecognizer =
- HomeGestureRecognizer(gestureDistanceThresholdPx = SWIPE_DISTANCE.toInt())
+ HomeGestureRecognizer(
+ gestureDistanceThresholdPx = SWIPE_DISTANCE.toInt(),
+ velocityThresholdPxPerMs = THRESHOLD_VELOCITY_PX_PER_MS,
+ velocityTracker = velocityTracker,
+ )
@Before
fun before() {
+ velocityTracker.setVelocity(Velocity(FAST))
gestureRecognizer.addGestureStateCallback { gestureState = it }
}
@@ -48,6 +62,12 @@ class HomeGestureRecognizerTest : SysuiTestCase() {
}
@Test
+ fun doesntTriggerGestureFinished_onGestureSpeedTooSlow() {
+ velocityTracker.setVelocity(Velocity(SLOW))
+ assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = NotStarted)
+ }
+
+ @Test
fun triggersGestureProgressForThreeFingerGestureStarted() {
assertStateAfterEvents(
events = ThreeFingerGesture.startEvents(x = 0f, y = 0f),
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizerTest.kt
index c5c0d59ea48b..cb74e6569b3f 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/touchpad/tutorial/ui/gesture/RecentAppsGestureRecognizerTest.kt
@@ -17,21 +17,19 @@
package com.android.systemui.touchpad.tutorial.ui.gesture
import android.view.MotionEvent
-import androidx.compose.ui.input.pointer.util.VelocityTracker1D
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.testKosmos
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
import com.android.systemui.touchpad.tutorial.ui.gesture.MultiFingerGesture.Companion.SWIPE_DISTANCE
+import com.android.systemui.touchpad.ui.gesture.fakeVelocityTracker
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
-import org.mockito.kotlin.doReturn
-import org.mockito.kotlin.mock
-import org.mockito.kotlin.whenever
@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -39,26 +37,23 @@ class RecentAppsGestureRecognizerTest : SysuiTestCase() {
companion object {
const val THRESHOLD_VELOCITY_PX_PER_MS = 0.1f
- // multiply by 1000 to get px/ms instead of px/s which is unit used by velocity tracker
- const val SLOW = THRESHOLD_VELOCITY_PX_PER_MS * 1000 - 1
- const val FAST = THRESHOLD_VELOCITY_PX_PER_MS * 1000 + 1
+ const val SLOW = THRESHOLD_VELOCITY_PX_PER_MS - 0.01f
+ const val FAST = THRESHOLD_VELOCITY_PX_PER_MS + 0.01f
}
+ private var velocityTracker = testKosmos().fakeVelocityTracker
+
private var gestureState: GestureState = GestureState.NotStarted
- private val velocityTracker1D =
- mock<VelocityTracker1D> {
- // by default return correct speed for the gesture - as if pointer is slowing down
- on { calculateVelocity() } doReturn SLOW
- }
private val gestureRecognizer =
RecentAppsGestureRecognizer(
gestureDistanceThresholdPx = SWIPE_DISTANCE.toInt(),
velocityThresholdPxPerMs = THRESHOLD_VELOCITY_PX_PER_MS,
- velocityTracker = VerticalVelocityTracker(velocityTracker1D),
+ velocityTracker = velocityTracker,
)
@Before
fun before() {
+ velocityTracker.setVelocity(Velocity(SLOW))
gestureRecognizer.addGestureStateCallback { gestureState = it }
}
@@ -69,7 +64,7 @@ class RecentAppsGestureRecognizerTest : SysuiTestCase() {
@Test
fun doesntTriggerGestureFinished_onGestureSpeedTooHigh() {
- whenever(velocityTracker1D.calculateVelocity()).thenReturn(FAST)
+ velocityTracker.setVelocity(Velocity(FAST))
assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = NotStarted)
}
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 411f36b73802..2f821cfb9372 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1995,12 +1995,16 @@
<dimen name="backlight_indicator_step_large_radius">28dp</dimen>
<!-- Touchpad gestures tutorial-->
- <!-- This value is in unit of dp/ms
+ <!-- This value is in dp/ms.
TriggerSwipeUpTouchTracker (which is base for gesture tutorial implementation) uses value
of 0.5dp but from manual testing it's too high and doesn't really feel like it's forcing
slowing down. Also for tutorial it should be fine to lean to the side of being more strict
rather than not strict enough and not teaching user the proper gesture as a result.-->
<dimen name="touchpad_recent_apps_gesture_velocity_threshold">0.05dp</dimen>
+ <!-- This value is in dp/ms.
+ As above, it's not tied to system-wide value (defined in launcher's
+ quickstep_fling_threshold_speed) because for tutorial it's fine to be more strict. -->
+ <dimen name="touchpad_home_gesture_velocity_threshold">0.5dp</dimen>
<!-- Normal gesture threshold is system_gestures_distance_threshold but for tutorial we can
exaggerate gesture, which also works much better with live tracking -->
<dimen name="touchpad_tutorial_gestures_distance_threshold">48dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
index bcf4bad9991d..45fdd21e795e 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/composable/HomeGestureTutorialScreen.kt
@@ -63,7 +63,8 @@ fun HomeGestureTutorialScreen(onDoneButtonClicked: () -> Unit, onBack: () -> Uni
private fun rememberHomeGestureRecognizer(resources: Resources): GestureRecognizer {
val distance =
resources.getDimensionPixelSize(R.dimen.touchpad_tutorial_gestures_distance_threshold)
- return remember(distance) { HomeGestureRecognizer(distance) }
+ val velocity = resources.getDimension(R.dimen.touchpad_home_gesture_velocity_threshold)
+ return remember(distance) { HomeGestureRecognizer(distance, velocity) }
}
@Composable
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 e10b8253ebad..9801626dac8f 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
@@ -19,9 +19,14 @@ 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
+import kotlin.math.abs
/** Recognizes touchpad home gesture, that is - using three fingers on touchpad - swiping up. */
-class HomeGestureRecognizer(private val gestureDistanceThresholdPx: Int) : GestureRecognizer {
+class HomeGestureRecognizer(
+ private val gestureDistanceThresholdPx: Int,
+ private val velocityThresholdPxPerMs: Float,
+ private val velocityTracker: VelocityTracker = VerticalVelocityTracker(),
+) : GestureRecognizer {
private val distanceTracker = DistanceTracker()
private var gestureStateChangedCallback: (GestureState) -> Unit = {}
@@ -37,10 +42,14 @@ class HomeGestureRecognizer(private val gestureDistanceThresholdPx: Int) : Gestu
override fun accept(event: MotionEvent) {
if (!isThreeFingerTouchpadSwipe(event)) return
val gestureState = distanceTracker.processEvent(event)
+ velocityTracker.accept(event)
updateGestureState(
gestureStateChangedCallback,
gestureState,
- isFinished = { -it.deltaY >= gestureDistanceThresholdPx },
+ isFinished = {
+ -it.deltaY >= gestureDistanceThresholdPx &&
+ abs(velocityTracker.calculateVelocity().value) >= velocityThresholdPxPerMs
+ },
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 c47888609a61..5ff583a19ee9 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
@@ -28,10 +28,10 @@ import kotlin.math.abs
class RecentAppsGestureRecognizer(
private val gestureDistanceThresholdPx: Int,
private val velocityThresholdPxPerMs: Float,
- private val distanceTracker: DistanceTracker = DistanceTracker(),
- private val velocityTracker: VerticalVelocityTracker = VerticalVelocityTracker(),
+ private val velocityTracker: VelocityTracker = VerticalVelocityTracker(),
) : GestureRecognizer {
+ private val distanceTracker = DistanceTracker()
private var gestureStateChangedCallback: (GestureState) -> Unit = {}
override fun addGestureStateCallback(callback: (GestureState) -> Unit) {
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/FakeVelocityTracker.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/FakeVelocityTracker.kt
new file mode 100644
index 000000000000..f12089a08488
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/FakeVelocityTracker.kt
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2024 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.systemui.touchpad.ui.gesture
+
+import android.view.MotionEvent
+import com.android.systemui.touchpad.tutorial.ui.gesture.Velocity
+import com.android.systemui.touchpad.tutorial.ui.gesture.VelocityTracker
+
+class FakeVelocityTracker : VelocityTracker {
+
+ private var fakeVelocity = Velocity(0f)
+
+ override fun calculateVelocity(): Velocity {
+ return fakeVelocity
+ }
+
+ override fun accept(event: MotionEvent) {}
+
+ fun setVelocity(velocity: Velocity) {
+ fakeVelocity = velocity
+ }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/VelocityTrackerKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/VelocityTrackerKosmos.kt
new file mode 100644
index 000000000000..3b61e2191d8c
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/ui/gesture/VelocityTrackerKosmos.kt
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2024 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.systemui.touchpad.ui.gesture
+
+import com.android.systemui.kosmos.Kosmos
+
+var Kosmos.fakeVelocityTracker: FakeVelocityTracker by Kosmos.Fixture { FakeVelocityTracker() }