Merge remote-tracking branch 'org/main' into feat/start-without-steam

This commit is contained in:
The412Banner committed 2026-10-12 15:16:35 -04:00
commit c9152103bf
3 files changed
+168 -12

No files matched your search

@@ -0,0 +1,140 @@
package com.droiddeck.launcher.input
import android.graphics.RectF
import android.os.Looper
import android.view.MotionEvent
import java.time.Duration
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class TouchpadGesturesTest {
private val events = mutableListOf<String>()
private lateinit var touchpad: TouchpadGestures
private var time = 1000L
private var downTime = 0L
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"
events += "$name ${if (pressed) "down" else "up"}"
}
override fun onWheel(steps: Int) { events += "wheel $steps" }
override fun onLongPress() { events += "long press" }
}
@Before fun setUp() {
touchpad = TouchpadGestures(SLOP, listener)
touchpad.bounds = RectF(0f, 0f, 1920f, 1080f)
touchpad.place(960f, 540f)
}
@Test fun tapHoldsTheLeftButtonBeforeReleasingIt() {
tap()
assertEquals(listOf("left down"), events)
advance(40)
assertEquals(listOf("left down"), events)
advance(100)
assertEquals(listOf("left down", "left up"), events)
}
@Test fun twoFingerTapHoldsTheRightButtonBeforeReleasingIt() {
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(60)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
assertEquals(listOf("right down"), events)
advance(30)
assertEquals(listOf("right down"), events)
advance(100)
assertEquals(listOf("right down", "right up"), events)
}
@Test fun slowTwoFingerTapHoldsTheRightButtonBeforeReleasingIt() {
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(350)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(10)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
assertEquals(listOf("right down"), events)
advance(40)
assertEquals(listOf("right down"), events)
advance(100)
assertEquals(listOf("right down", "right up"), events)
}
@Test fun secondTapPressesOnlyAfterTheFirstClickIsReleased() {
tap()
advance(20)
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
assertEquals(listOf("left down", "left up", "left down"), events)
advance(80)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
advance(200)
assertEquals(listOf("left down", "left up", "left down", "left up"), events)
}
@Test fun secondFingerTappingAgainReleasesTheFirstRightClickFirst() {
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(60)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(10)
touch(MotionEvent.ACTION_POINTER_DOWN, 1, 1 to (400f to 300f), 2 to (600f to 310f))
advance(20)
touch(MotionEvent.ACTION_POINTER_UP, 1, 1 to (400f to 300f), 2 to (600f to 310f))
assertEquals(listOf("right down", "right up", "right down"), events)
advance(200)
assertEquals(listOf("right down", "right up", "right down", "right up"), events)
}
@Test fun cancelReleasesAClickThatIsStillHeld() {
tap()
touchpad.cancel()
assertEquals(listOf("left down", "left up"), events)
advance(200)
assertEquals(listOf("left down", "left up"), events)
}
private fun tap() {
touch(MotionEvent.ACTION_DOWN, 0, 1 to (400f to 300f))
advance(80)
touch(MotionEvent.ACTION_UP, 0, 1 to (400f to 300f))
}
private fun advance(ms: Long) {
time += ms
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
}
private fun touch(action: Int, index: Int, vararg pointers: Pair<Int, Pair<Float, Float>>) {
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)
touchpad.onTouch(event)
event.recycle()
}
private companion object {
const val SLOP = 8f
}
}