mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(input): Click a touch stick only on a fast double tap (#2173)
* fix(input): Click a touch stick only on a fast double tap * fix(input): Count the release position in stick tap travel * fix(input): Treat cancelled pointer-ups as cancelled stick touches
This commit is contained in:
1 parent
88acdbc3ab
commit
5f180d909b
2 files changed
+78
-3
No files matched your search
@@ -169,6 +169,59 @@ class OnScreenControlsTest {
|
||||
assertEquals(true, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun aCancelledSecondFingerDoesNotArmAStickClick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 7 to (660f to 400f))
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 7 to (660f to 400f), 9 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_POINTER_UP or (1 shl 8), 7 to (660f to 400f), 9 to (540f to 400f), flags = MotionEvent.FLAG_CANCELED)
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 7 to (660f to 400f), 9 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
touch(MotionEvent.ACTION_POINTER_UP or (1 shl 8), 7 to (660f to 400f), 9 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_POINTER_DOWN or (1 shl 8), 7 to (660f to 400f), 9 to (540f to 400f))
|
||||
assertEquals(true, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun movingTheStickAndTouchingItAgainDoesNotClickIt() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (600f to 400f))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (600f to 400f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun liftingFarFromTheTouchPointDoesNotArmAStickClick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (600f to 400f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun aLongHoldThenAQuickTouchDoesNotClickTheStick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
time += 600
|
||||
touch(MotionEvent.ACTION_UP, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun aFastDoubleTapClicksTheStickAndCanBeHeldWhileMoving() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_MOVE, 1 to (600f to 400f))
|
||||
assertEquals(true, field(control("ls"), "clicked"))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (600f to 400f))
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun aSlowSecondTapDoesNotClickTheStick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
touch(MotionEvent.ACTION_UP, 1 to (540f to 400f))
|
||||
time += 400
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (540f to 400f))
|
||||
assertEquals(false, field(control("ls"), "clicked"))
|
||||
}
|
||||
|
||||
@Test fun buttonsTakePriorityOverAdaptiveRegions() {
|
||||
val button = control("a")
|
||||
touch(MotionEvent.ACTION_DOWN, 3 to (value(button, "cx") to value(button, "cy")))
|
||||
@@ -461,10 +514,10 @@ class OnScreenControlsTest {
|
||||
return color
|
||||
}
|
||||
|
||||
private fun touch(action: Int, vararg pointers: Pair<Int, Pair<Float, Float>>): Boolean {
|
||||
private fun touch(action: Int, vararg pointers: Pair<Int, Pair<Float, Float>>, flags: Int = 0): Boolean {
|
||||
val properties = pointers.map { (id, _) -> MotionEvent.PointerProperties().apply { this.id = id; toolType = MotionEvent.TOOL_TYPE_FINGER } }.toTypedArray()
|
||||
val coords = pointers.map { (_, position) -> MotionEvent.PointerCoords().apply { x = position.first; y = position.second; pressure = 1f; size = 1f } }.toTypedArray()
|
||||
val event = MotionEvent.obtain(1000L, time++, action, pointers.size, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
|
||||
val event = MotionEvent.obtain(1000L, time++, action, pointers.size, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, flags)
|
||||
return try { view.onTouchEvent(event) } finally { event.recycle() }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user