app/src/main/java/dev/equwal/assistkey/ui/TimingActivity.kt (2573 bytes)
1 package dev.equwal.assistkey.ui 2 3 import android.app.Activity 4 import android.widget.LinearLayout 5 import dev.equwal.assistkey.engine.GestureEngine 6 import dev.equwal.assistkey.route.ServiceHolder 7 import dev.equwal.assistkey.store.Store 8 import dev.equwal.assistkey.ui.Ui.header 9 import dev.equwal.assistkey.ui.Ui.row 10 11 /** 12 * The three windows the gesture engine runs on. Exposed because the right 13 * values are a matter of the user's hands, and because an e-ink device is slow 14 * enough that the defaults can feel wrong either way. 15 */ 16 class TimingActivity : Activity() { 17 18 override fun onResume() { 19 super.onResume() 20 build() 21 } 22 23 private fun build() { 24 val col = Ui.page(this, "Gesture timing") 25 val cfg = Store.timing(this) 26 27 section( 28 col, 29 "Multi-tap window", 30 cfg.multiTapMs, 31 listOf(180L, 220L, 280L, 350L, 450L), 32 "Longer is easier, but delays every tap" 33 ) { Store.setTiming(this, cfg.copy(multiTapMs = it)) } 34 35 section( 36 col, 37 "Hold threshold", 38 cfg.holdMs, 39 listOf(300L, 400L, 450L, 600L, 800L), 40 "How long a press counts as a hold" 41 ) { Store.setTiming(this, cfg.copy(holdMs = it)) } 42 43 section( 44 col, 45 "Combination window", 46 cfg.chordMs, 47 listOf(80L, 120L, 140L, 200L, 300L), 48 "How close together two presses count" 49 ) { Store.setTiming(this, cfg.copy(chordMs = it)) } 50 51 col.header("Defaults") 52 val d = GestureEngine.Config() 53 col.row( 54 "Restore " + d.multiTapMs + " / " + d.holdMs + " / " + d.chordMs + " ms", 55 null 56 ) { Store.setTiming(this, d); push(); build() } 57 } 58 59 private fun section( 60 col: LinearLayout, 61 title: String, 62 current: Long, 63 options: List<Long>, 64 hint: String, 65 onPick: (Long) -> Unit 66 ) { 67 col.row(title, hint, state = current.toString() + " ms") { 68 val labels = options.map { v -> 69 (if (v == current) "* " else " ") + v + " ms" 70 } 71 Ui.pick(this, title, labels) { i -> onPick(options[i]); push(); build() } 72 } 73 } 74 75 /** 76 * The accessibility service and this screen share a process, so the running 77 * engine can simply be handed the new numbers instead of being restarted. 78 */ 79 private fun push() { 80 (ServiceHolder.service as? dev.equwal.assistkey.engine.KeyFilterService) 81 ?.reloadTiming() 82 } 83 }