Move the Linux runtime to Ubuntu 26.04 LTS with a separate Kubuntu desktop (#1733)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-29 09:05:20 -04:00
1 parent 5de690ef39
commit 29c83976d0
305 files changed
+9383 -462

No files matched your search

@@ -1,6 +1,7 @@
package com.droiddeck.launcher.input
import android.os.Looper
import android.view.InputDevice
import android.view.MotionEvent
import java.time.Duration
import org.junit.Assert.*
@@ -13,68 +14,171 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class DirectTouchHoldTest {
private val events = mutableListOf<String>()
private val touches = mutableListOf<String>()
private val buttons = mutableListOf<String>()
private val hold = DirectTouchHold(8f, object : PointerGestures.Listener {
override fun onMove(x: Float, y: Float) {}
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
assertEquals(PointerGestures.BTN_RIGHT, button)
events += "$pressed at $x,$y"
buttons += "$pressed at $x,$y"
}
override fun onWheel(steps: Int) {}
override fun onLongPress() {}
}) { events += "cancel touch" }.also { it.configure(TouchGestureConfig(longPressEnabled = true, longPressDelay = 500)) }
}, object : DirectTouchHold.Touch {
override fun down(pointerId: Int, x: Float, y: Float) { touches += "down $pointerId at $x,$y" }
override fun move(pointerId: Int, x: Float, y: Float) { touches += "move $pointerId at $x,$y" }
override fun up(pointerId: Int, x: Float, y: Float) { touches += "up $pointerId at $x,$y" }
override fun cancel() { touches += "cancel" }
}).also { it.configure(TouchGestureConfig(longPressEnabled = true, longPressDelay = 500)) }
@Test fun holdReleasesRawTouchBeforeClickAndConsumesTheLift() {
assertFalse(touch(MotionEvent.ACTION_DOWN))
advance(500)
assertEquals(listOf("cancel touch", "true at 40.0,30.0"), events)
assertTrue(touch(MotionEvent.ACTION_UP))
@Test fun holdClicksRightWithoutTouchingTheGame() {
touch(MotionEvent.ACTION_DOWN)
advance(400)
assertTrue(buttons.isEmpty())
advance(100)
assertEquals(listOf("true at 40.0,30.0"), buttons)
advance(50)
assertEquals("false at 40.0,30.0", events.last())
assertFalse(touch(MotionEvent.ACTION_DOWN))
hold.cancel()
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
touch(MotionEvent.ACTION_MOVE, 44f)
touch(MotionEvent.ACTION_UP)
assertTrue(touches.isEmpty())
}
@Test fun stillHoldKeepsTheTouchWhenLongPressIsOff() {
@Test fun tapForwardsTheTouchWhenItLifts() {
touch(MotionEvent.ACTION_DOWN)
advance(100)
touch(MotionEvent.ACTION_UP, 50f)
assertEquals(listOf("down 0 at 40.0,30.0"), touches)
advance(50)
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 50.0,30.0"), touches)
assertTrue(buttons.isEmpty())
}
@Test fun noneBehaviorForwardsTheTouchAtOnce() {
hold.configure(TouchGestureConfig(directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_NONE))
touch(MotionEvent.ACTION_DOWN)
assertEquals(listOf("down 0 at 40.0,30.0"), touches)
advance(600)
assertTrue(buttons.isEmpty())
touch(MotionEvent.ACTION_MOVE, 60f)
assertEquals("move 0 at 60.0,30.0", touches.last())
touch(MotionEvent.ACTION_UP, 60f)
advance(50)
assertEquals("up 0 at 60.0,30.0", touches.last())
}
@Test fun dragForwardsTheTouchOnceItMoves() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_MOVE, 60f)
assertEquals(listOf("down 0 at 40.0,30.0", "move 0 at 60.0,30.0"), touches)
advance(600)
assertTrue(buttons.isEmpty())
touch(MotionEvent.ACTION_UP, 60f)
advance(50)
assertEquals("up 0 at 60.0,30.0", touches.last())
}
@Test fun dragKeepsForwardingWithinTheSlop() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_MOVE, 44f)
assertTrue(touches.isEmpty())
touch(MotionEvent.ACTION_UP, 44f)
advance(50)
assertEquals(listOf("down 0 at 40.0,30.0", "up 0 at 44.0,30.0"), touches)
}
@Test fun stillHoldClicksRightWithTheDefaultConfig() {
hold.configure(TouchGestureConfig())
assertFalse(touch(MotionEvent.ACTION_DOWN))
touch(MotionEvent.ACTION_DOWN)
advance(2000)
assertFalse(touch(MotionEvent.ACTION_MOVE))
assertFalse(touch(MotionEvent.ACTION_UP))
assertTrue(events.isEmpty())
touch(MotionEvent.ACTION_MOVE)
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
touch(MotionEvent.ACTION_UP)
assertTrue(touches.isEmpty())
}
@Test fun longPressFollowsTheConfiguredDelay() {
hold.configure(TouchGestureConfig(longPressEnabled = true, longPressDelay = 800))
touch(MotionEvent.ACTION_DOWN)
advance(700)
assertTrue(events.isEmpty())
assertTrue(buttons.isEmpty())
advance(100)
assertEquals(listOf("cancel touch", "true at 40.0,30.0"), events)
assertEquals(listOf("true at 40.0,30.0"), buttons)
hold.cancel()
}
@Test fun tapDragSecondFingerAndCancellationDoNotRightClick() {
for (action in listOf(MotionEvent.ACTION_UP, MotionEvent.ACTION_MOVE,
MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_CANCEL)) {
touch(MotionEvent.ACTION_DOWN)
assertFalse(touch(action, 60f))
advance(600)
assertTrue(events.isEmpty())
hold.cancel()
}
@Test fun holdBehaviorKeepsTheButtonUntilTheLift() {
hold.configure(TouchGestureConfig(longPressDelay = 500,
directHoldBehavior = TouchGestureConfig.MOUSE_BEHAVIOR_HOLD))
touch(MotionEvent.ACTION_DOWN)
advance(500)
assertEquals(listOf("true at 40.0,30.0"), buttons)
advance(1000)
assertEquals(listOf("true at 40.0,30.0"), buttons)
touch(MotionEvent.ACTION_UP)
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
assertTrue(touches.isEmpty())
}
@Test fun secondFingerForwardsTheTouchAndDropsTheHold() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_POINTER_DOWN, 60f)
assertEquals(listOf("down 0 at 40.0,30.0", "down 0 at 60.0,30.0"), touches)
advance(600)
assertTrue(buttons.isEmpty())
touch(MotionEvent.ACTION_UP, 60f)
}
@Test fun modeChangeCancelsPendingHoldAndReleasesAnActiveClick() {
touch(MotionEvent.ACTION_DOWN)
hold.cancel()
advance(600)
assertTrue(events.isEmpty())
assertTrue(buttons.isEmpty())
assertTrue(touches.isEmpty())
touch(MotionEvent.ACTION_DOWN)
advance(500)
hold.cancel()
assertEquals(listOf("true at 40.0,30.0", "false at 40.0,30.0"), buttons)
}
@Test fun cancelForwardsACancelWhenTheTouchIsLive() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_MOVE, 60f)
hold.cancel()
assertEquals(listOf("down 0 at 40.0,30.0", "move 0 at 60.0,30.0", "cancel"), touches)
}
@Test fun cancelDropsAPendingLift() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_UP, 60f)
hold.cancel()
advance(100)
assertEquals(listOf("cancel touch", "true at 40.0,30.0", "false at 40.0,30.0"), events)
assertEquals(listOf("down 0 at 40.0,30.0", "cancel"), touches)
}
@Test fun aQuickSecondTapLiftsTheFirstInsteadOfCancellingIt() {
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_UP, 50f)
advance(20)
touch(MotionEvent.ACTION_DOWN, 60f)
touch(MotionEvent.ACTION_UP, 60f)
advance(50)
assertEquals(
listOf("down 0 at 40.0,30.0", "up 0 at 50.0,30.0", "down 0 at 60.0,30.0", "up 0 at 60.0,30.0"),
touches,
)
}
@Test fun theSecondFingerLiftsWithItsOwnId() {
multi(MotionEvent.ACTION_DOWN, 0, 0 to 40f)
multi(MotionEvent.ACTION_POINTER_DOWN, 1, 0 to 40f, 1 to 60f)
multi(MotionEvent.ACTION_POINTER_UP, 0, 0 to 40f, 1 to 60f)
multi(MotionEvent.ACTION_UP, 0, 1 to 60f)
advance(100)
assertEquals(
listOf("down 0 at 40.0,30.0", "down 1 at 60.0,30.0", "up 0 at 40.0,30.0", "up 1 at 60.0,30.0"),
touches,
)
}
private fun advance(ms: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
@@ -82,4 +186,23 @@ class DirectTouchHoldTest {
val event = MotionEvent.obtain(0, 0, action, x, 30f, 0)
return hold.onTouch(event).also { event.recycle() }
}
private fun multi(action: Int, index: Int, vararg points: Pair<Int, Float>): Boolean {
val properties = Array(points.size) {
MotionEvent.PointerProperties().apply {
id = points[it].first
toolType = MotionEvent.TOOL_TYPE_FINGER
}
}
val coords = Array(points.size) {
MotionEvent.PointerCoords().apply {
x = points[it].second
y = 30f
pressure = 1f
size = 1f
}
}
val event = MotionEvent.obtain(0, 0, action or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT),
points.size, properties, coords, 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0)
return hold.onTouch(event).also { event.recycle() }
}
}
@@ -220,7 +220,12 @@ class SessionGestureRoutingTest {
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) { directButtons += button to pressed }
override fun onWheel(steps: Int) {}
override fun onLongPress() {}
}) {}.also { it.configure(config) }
}, object : DirectTouchHold.Touch {
override fun down(pointerId: Int, x: Float, y: Float) {}
override fun move(pointerId: Int, x: Float, y: Float) {}
override fun up(pointerId: Int, x: Float, y: Float) {}
override fun cancel() {}
}).also { it.configure(config) }
setField("directTouchHold", directHold)
launcherScroll = ScrollTouchGestures(8f, 50f, object : ScrollTouchGestures.Listener {
override fun onMove(x: Float, y: Float) { scrollPositions += x to y }
@@ -25,11 +25,14 @@ class TouchpadGesturesTest {
private val listener = object : PointerGestures.Listener {
override fun onMove(x: Float, y: Float) { events += "move" }
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
val name = if (button == PointerGestures.BTN_RIGHT) "right" else "left"
val name = when (button) { PointerGestures.BTN_RIGHT -> "right"; PointerGestures.BTN_MIDDLE -> "middle"; else -> "left" }
events += "$name ${if (pressed) "down" else "up"}"
}
override fun onWheel(steps: Int) { events += "wheel $steps" }
override fun onLongPress() { events += "long press" }
override fun onScroll(dx: Float, dy: Float) { events += "scroll" }
override fun onScrollEnd() { events += "scroll end" }
override fun onZoom(steps: Int) { events += "zoom $steps" }
}
@Before fun setUp() {
@@ -41,12 +44,58 @@ class TouchpadGesturesTest {
@Test fun tapHoldsTheLeftButtonBeforeReleasingIt() {
tap()
assertEquals(listOf("left down"), events)
advance(40)
advance(TouchTiming.CLICK_MS - 10)
assertEquals(listOf("left down"), events)
advance(100)
assertEquals(listOf("left down", "left up"), events)
}
@Test fun threeFingerTapClicksTheMiddleButton() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 2, 1 to (400f to 300f), 2 to (600f to 310f), 3 to (800f to 320f))
advance(60)
touch(MotionEvent.ACTION_POINTER_UP, 2, 1 to (400f to 300f), 2 to (600f to 310f), 3 to (800f to 320f))
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(100)
assertEquals(listOf("middle down", "middle up"), events)
}
@Test fun desktopTwoFingerSlideScrollsSmoothlyAndStops() {
touchpad.desktop = true
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 300f))
for (step in 1..5) {
advance(16)
touch(MotionEvent.ACTION_MOVE, 0, 1 to (400f to 300f + step * 20f), 2 to (600f to 300f + step * 20f))
}
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 400f), 2 to (600f to 400f))
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 400f))
advance(100)
assertTrue(events.contains("scroll"))
assertEquals("scroll end", events.last())
assertFalse(events.any { it.startsWith("right") || it.startsWith("wheel") })
}
@Test fun desktopPinchZoomsWithoutScrolling() {
touchpad.desktop = true
touch(MotionEvent.ACTION_DOWN, 0, 1 to (500f to 300f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (500f to 300f), 2 to (600f to 300f))
for (step in 1..6) {
advance(16)
touch(MotionEvent.ACTION_MOVE, 0, 1 to (500f - step * 30f to 300f), 2 to (600f + step * 30f to 300f))
}
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (320f to 300f), 2 to (780f to 300f))
touch(MotionEvent.ACTION_UP, 0, 1 to (320f to 300f))
advance(100)
assertTrue(events.isNotEmpty() && events.all { it.startsWith("zoom -") })
}
@Test fun twoFingerTapHoldsTheRightButtonBeforeReleasingIt() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(10)
@@ -56,7 +105,7 @@ class TouchpadGesturesTest {
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
assertEquals(listOf("right down"), events)
advance(30)
advance(TouchTiming.CLICK_MS - 20)
assertEquals(listOf("right down"), events)
advance(100)
assertEquals(listOf("right down", "right up"), events)
@@ -71,7 +120,7 @@ class TouchpadGesturesTest {
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
assertEquals(listOf("right down"), events)
advance(40)
advance(TouchTiming.CLICK_MS - 10)
assertEquals(listOf("right down"), events)
advance(100)
assertEquals(listOf("right down", "right up"), events)
@@ -82,9 +82,9 @@ class TouchscreenGesturesTest {
@Test fun aVeryFastDoubleTapKeepsFullPressesAndAReleaseGap() {
tap(); tap(); advance(250)
assertEquals(4, leftClicks.size)
assertTrue(leftClicks[1].time - leftClicks[0].time >= 50)
assertTrue(leftClicks[2].time - leftClicks[1].time >= 50)
assertTrue(leftClicks[3].time - leftClicks[2].time >= 50)
assertTrue(leftClicks[1].time - leftClicks[0].time >= TouchTiming.CLICK_MS)
assertTrue(leftClicks[2].time - leftClicks[1].time >= TouchTiming.CLICK_MS)
assertTrue(leftClicks[3].time - leftClicks[2].time >= TouchTiming.CLICK_MS)
}
@Test fun doubleTapUsesTheFirstClickLocationDespiteNormalFingerDrift() {
@@ -121,7 +121,7 @@ class TouchscreenGesturesTest {
gestures.configure(TouchGestureConfig(tapEnabled = false))
tap(); tap(); advance(250)
assertEquals(4, leftClicks.size)
assertTrue(leftClicks[2].time - leftClicks[1].time >= 50)
assertTrue(leftClicks[2].time - leftClicks[1].time >= TouchTiming.CLICK_MS)
}
@Test fun aRapidThirdTapDoesNotDiscardThePendingSecondClick() {
@@ -285,11 +285,11 @@ class TouchscreenGesturesTest {
@Test fun twoFingerTapKeepsItsPressAfterTheLastFingerLifts() {
twoFingerTap()
assertEquals(listOf("button 273 true"), buttons())
advance(49)
advance(TouchTiming.CLICK_MS - 1)
assertEquals(1, rightClicks.size)
advance(1)
assertEquals(listOf(true, false), rightClicks.map { it.down })
assertEquals(50L, rightClicks[1].time - rightClicks[0].time)
assertEquals(TouchTiming.CLICK_MS, rightClicks[1].time - rightClicks[0].time)
}
@Test fun threeFingerKeyboardTapHasAnObservablePressAndReleases() {
@@ -298,14 +298,14 @@ class TouchscreenGesturesTest {
assertEquals(listOf("key 18 true"), events.filter { it.startsWith("key") })
advance(50)
assertEquals(listOf("key 18 true", "key 18 false"), events.filter { it.startsWith("key") })
assertEquals(50L, timedKeys.last().first - timedKeys.first().first)
assertEquals(TouchTiming.CLICK_MS, timedKeys.last().first - timedKeys.first().first)
}
@Test fun twoFingerKeyboardTapHasAnObservablePressAndReleases() {
gestures.configure(TouchGestureConfig(twoFingerTapAction = "key_E"))
twoFingerTap(); advance(50)
assertEquals(listOf(true, false), timedKeys.map { it.third })
assertEquals(50L, timedKeys.last().first - timedKeys.first().first)
assertEquals(TouchTiming.CLICK_MS, timedKeys.last().first - timedKeys.first().first)
}
@Test fun threeFingerMouseTapHasAnObservablePressAndReleases() {
@@ -314,7 +314,7 @@ class TouchscreenGesturesTest {
assertEquals(listOf("button 273 true"), buttons())
advance(50)
assertEquals(listOf(true, false), rightClicks.map { it.down })
assertEquals(50L, rightClicks[1].time - rightClicks[0].time)
assertEquals(TouchTiming.CLICK_MS, rightClicks[1].time - rightClicks[0].time)
}
@Test fun cancellingAMultiFingerTapReleasesItsButtonAndStopsCallbacks() {
@@ -338,7 +338,7 @@ class TouchscreenGesturesTest {
gestures.configure(TouchGestureConfig(tapAction = "right_click", doubleTapEnabled = false))
tap(); tap(); advance(250)
assertEquals(listOf(true, false, true, false), rightClicks.map { it.down })
assertTrue(rightClicks[2].time - rightClicks[1].time >= 50)
assertTrue(rightClicks[2].time - rightClicks[1].time >= TouchTiming.CLICK_MS)
}
@Test fun aFastTwoFingerSwipeDuringSettlingDoesNotClick() {
@@ -0,0 +1,121 @@
package com.droiddeck.launcher.input
import android.os.Looper
import android.view.MotionEvent
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import java.time.Duration
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class TwoFingerGesturesTest {
private val calls = mutableListOf<String>()
private val gestures = TwoFingerGestures(8f, object : TwoFingerGestures.Listener {
override fun cancelTouch() { calls += "cancel" }
override fun replay(event: MotionEvent) { calls += "replay ${event.actionMasked}" }
override fun rightClick(x: Float, y: Float) { calls += "right $x,$y" }
override fun scrollStart(x: Float, y: Float) { calls += "start $x,$y" }
override fun scroll(dx: Float, dy: Float) { calls += "scroll $dx,$dy" }
override fun scrollEnd() { calls += "end" }
})
private var time = 1000L
private var downTime = 0L
private val a = 1 to (400f to 300f)
private val b = 2 to (500f to 300f)
@Test fun tapRightClicksWhereTheFirstFingerLanded() {
assertTrue(touch(MotionEvent.ACTION_DOWN, 0, a))
time += 20
assertTrue(touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b))
time += 80
assertTrue(touch(MotionEvent.ACTION_POINTER_UP, 1, a, b))
assertTrue(touch(MotionEvent.ACTION_UP, 0, a))
assertEquals(listOf("cancel", "right 400.0,300.0"), calls)
}
@Test fun holdRightClicksOnce() {
touch(MotionEvent.ACTION_DOWN, 0, a)
time += 20
touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(TwoFingerGestures.HOLD_MS + 10))
time += 600
assertTrue(touch(MotionEvent.ACTION_POINTER_UP, 1, a, b))
assertTrue(touch(MotionEvent.ACTION_UP, 0, a))
assertEquals(listOf("cancel", "right 400.0,300.0"), calls)
}
@Test fun slidingTogetherScrollsLikeAWheel() {
touch(MotionEvent.ACTION_DOWN, 0, a)
time += 20
touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b)
time += 20
assertTrue(touch(MotionEvent.ACTION_MOVE, 0, 1 to (400f to 260f), 2 to (500f to 260f)))
assertTrue(touch(MotionEvent.ACTION_MOVE, 0, 1 to (400f to 200f), 2 to (500f to 200f)))
assertTrue(touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 200f), 2 to (500f to 200f)))
assertTrue(touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 200f)))
assertEquals(listOf("cancel", "start 450.0,260.0", "scroll 0.0,60.0", "end"), calls)
}
@Test fun pinchPassesThroughForZoom() {
touch(MotionEvent.ACTION_DOWN, 0, a)
time += 20
touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b)
assertTrue(touch(MotionEvent.ACTION_MOVE, 0, 1 to (350f to 300f), 2 to (550f to 300f)))
assertEquals(listOf("replay 0", "replay 5", "replay 2"), calls)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(TwoFingerGestures.HOLD_MS + 10))
assertFalse(touch(MotionEvent.ACTION_MOVE, 0, 1 to (340f to 300f), 2 to (560f to 300f)))
assertFalse(touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (340f to 300f), 2 to (560f to 300f)))
assertFalse(touch(MotionEvent.ACTION_UP, 0, 1 to (340f to 300f)))
assertEquals(3, calls.size)
}
@Test fun oneFingerTapIsReplayedOnRelease() {
assertTrue(touch(MotionEvent.ACTION_DOWN, 0, a))
assertTrue(calls.isEmpty())
time += 60
assertTrue(touch(MotionEvent.ACTION_UP, 0, a))
assertEquals(listOf("replay 0", "replay 1"), calls)
}
@Test fun oneFingerStillIsReplayedAfterTheLandingWindow() {
assertTrue(touch(MotionEvent.ACTION_DOWN, 0, a))
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(TwoFingerGestures.LAND_MS + 10))
assertEquals(listOf("replay 0"), calls)
time += 600
assertFalse(touch(MotionEvent.ACTION_POINTER_DOWN, 1, a, b))
assertFalse(touch(MotionEvent.ACTION_POINTER_UP, 1, a, b))
assertFalse(touch(MotionEvent.ACTION_UP, 0, a))
assertEquals(listOf("replay 0"), calls)
}
@Test fun oneFingerDragIsReplayedOnceItMoves() {
touch(MotionEvent.ACTION_DOWN, 0, a)
time += 16
assertTrue(touch(MotionEvent.ACTION_MOVE, 0, 1 to (402f to 300f)))
assertTrue(calls.isEmpty())
time += 16
assertTrue(touch(MotionEvent.ACTION_MOVE, 0, 1 to (440f to 300f)))
assertEquals(listOf("replay 0", "replay 2", "replay 2"), calls)
assertFalse(touch(MotionEvent.ACTION_MOVE, 0, 1 to (480f to 300f)))
assertFalse(touch(MotionEvent.ACTION_UP, 0, 1 to (480f to 300f)))
}
private fun touch(action: Int, index: Int, vararg pointers: Pair<Int, Pair<Float, Float>>): Boolean {
if (action == MotionEvent.ACTION_DOWN) downTime = time
val properties = pointers.map { (id, _) ->
MotionEvent.PointerProperties().apply { this.id = id; toolType = MotionEvent.TOOL_TYPE_FINGER }
}.toTypedArray()
val coords = pointers.map { (_, at) ->
MotionEvent.PointerCoords().apply { x = at.first; y = at.second; pressure = 1f; size = 1f }
}.toTypedArray()
val masked = action or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT)
val event = MotionEvent.obtain(downTime, time, masked, pointers.size, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
return gestures.onTouch(event).also { event.recycle() }
}
}