mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix(steam): preserve Back taps and recover QAM controls
This commit is contained in:
1 parent
dde1a55d00
commit
fa5506df35
13 files changed
+395
-56
No files matched your search
@@ -1,28 +1,76 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Looper
|
||||
import android.view.KeyEvent
|
||||
import java.time.Duration
|
||||
import org.junit.Assert.*
|
||||
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 = [34], manifest = Config.NONE)
|
||||
class BackQamInputTest {
|
||||
private val changes = mutableListOf<Boolean>()
|
||||
private val input = BackQamInput(changes::add)
|
||||
private val taps = mutableListOf<Boolean>()
|
||||
private val input = BackQamInput(changes::add, taps::add)
|
||||
|
||||
@Test fun aHoldAndItsRepeatsProduceOnePressAndOneRelease() {
|
||||
@Test fun singleTapWaitsForTheDoubleTapWindowWithoutPressingQam() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(499)
|
||||
assertTrue(taps.isEmpty())
|
||||
advance(1)
|
||||
assertEquals(listOf(false), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun doubleTapProducesOnlyTheDoubleAction() {
|
||||
repeat(2) {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(100)
|
||||
}
|
||||
advance(1000)
|
||||
assertEquals(listOf(true), taps)
|
||||
assertTrue(changes.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun aHoldStartsAt500msAndNeverProducesATap() {
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN))
|
||||
advance(499)
|
||||
assertTrue(changes.isEmpty())
|
||||
advance(1)
|
||||
for (repeat in 1..10) assertTrue(send(KeyEvent.ACTION_DOWN, repeat = repeat))
|
||||
advance(4000)
|
||||
assertEquals(listOf(true), changes)
|
||||
assertTrue(send(KeyEvent.ACTION_UP))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun holdingTheSecondPressCancelsTheFirstTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(400)
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(499)
|
||||
assertTrue(taps.isEmpty())
|
||||
advance(1)
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun otherButtonsAndSelectPassThroughWhileBackIsHeld() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(500)
|
||||
for (code in listOf(KeyEvent.KEYCODE_BUTTON_X, KeyEvent.KEYCODE_BUTTON_SELECT)) {
|
||||
for (action in listOf(KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP)) {
|
||||
assertFalse(input.onKeyEvent(KeyEvent(action, code), true))
|
||||
@@ -37,20 +85,42 @@ class BackQamInputTest {
|
||||
assertFalse(send(KeyEvent.ACTION_DOWN, enabled = false))
|
||||
assertFalse(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun losingFocusReleasesQamAndConsumesTheLateRelease() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(500)
|
||||
input.cancel()
|
||||
input.cancel()
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN, repeat = 1, enabled = false))
|
||||
assertTrue(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertFalse(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cancellationBeforeTheThresholdPreventsBothHoldAndTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(100)
|
||||
input.cancel()
|
||||
send(KeyEvent.ACTION_UP)
|
||||
advance(1000)
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun cancellationAlsoDiscardsAPendingSingleTap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
send(KeyEvent.ACTION_UP)
|
||||
input.cancel()
|
||||
advance(1000)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun openingAnOverlayReleasesQamBeforeRoutingItsNextKey() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(500)
|
||||
assertFalse(input.onKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_B), false))
|
||||
assertTrue(send(KeyEvent.ACTION_UP, enabled = false))
|
||||
assertEquals(listOf(true, false), changes)
|
||||
@@ -58,33 +128,39 @@ class BackQamInputTest {
|
||||
|
||||
@Test fun repeatsAfterCancellationCannotReassertQam() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
advance(500)
|
||||
input.cancel()
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN, repeat = 1))
|
||||
advance(1000)
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(send(KeyEvent.ACTION_DOWN))
|
||||
advance(500)
|
||||
assertTrue(send(KeyEvent.ACTION_UP))
|
||||
assertEquals(listOf(true, false, true, false), changes)
|
||||
}
|
||||
|
||||
@Test fun cancelledReleaseStillReleasesQam() {
|
||||
@Test fun cancelledReleaseNeverProducesATap() {
|
||||
send(KeyEvent.ACTION_DOWN)
|
||||
assertTrue(input.onKeyEvent(KeyEvent(0, 100, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK,
|
||||
0, 0, 4, 0, KeyEvent.FLAG_CANCELED), true))
|
||||
assertEquals(listOf(true, false), changes)
|
||||
advance(1000)
|
||||
assertTrue(changes.isEmpty())
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
@Test fun removingOneDeviceDoesNotReleaseAnotherDevicesHold() {
|
||||
send(KeyEvent.ACTION_DOWN, device = 4)
|
||||
send(KeyEvent.ACTION_DOWN, device = 5)
|
||||
advance(500)
|
||||
input.onDeviceRemoved(4)
|
||||
assertTrue(changes.last())
|
||||
assertEquals(listOf(true), changes)
|
||||
send(KeyEvent.ACTION_UP, device = 5)
|
||||
assertFalse(changes.last())
|
||||
send(KeyEvent.ACTION_DOWN, device = 4)
|
||||
input.onDeviceRemoved(4)
|
||||
assertFalse(changes.last())
|
||||
assertEquals(listOf(true, false), changes)
|
||||
assertTrue(taps.isEmpty())
|
||||
}
|
||||
|
||||
private fun advance(millis: Long) = shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(millis))
|
||||
|
||||
private fun send(action: Int, repeat: Int = 0, device: Int = 4, enabled: Boolean = true) =
|
||||
input.onKeyEvent(KeyEvent(0, 100, action, KeyEvent.KEYCODE_BACK, repeat, 0, device, 0), enabled)
|
||||
}
|
||||
Reference in new issue
Block a user