Recently Written · git

assistkey

Hardware key remapper for the Viwoods AiPaper Reader: AI key, volume keys and power, with multi-tap, hold and chords

git clone https://github.com/equwal/assistkey

Log | Files | Refs


app/src/main/java/dev/equwal/assistkey/ui/DisplayActivity.kt (2094 bytes)

1 package dev.equwal.assistkey.ui
2 
3 import android.app.Activity
4 import android.content.Intent
5 import android.widget.Toast
6 import dev.equwal.assistkey.device.Device
7 import dev.equwal.assistkey.display.ExtraDim
8 import dev.equwal.assistkey.shell.Shell
9 import dev.equwal.assistkey.ui.Ui.header
10 import dev.equwal.assistkey.ui.Ui.note
11 import dev.equwal.assistkey.ui.Ui.row
12 
13 /** The frontlight, below where the system's own slider stops. */
14 class DisplayActivity : Activity() {
15 
16     private val redraw: () -> Unit = { if (!isFinishing) build() }
17 
18     override fun onResume() {
19         super.onResume()
20         Shell.onChange(redraw)
21         Shell.connect(this)
22         build()
23     }
24 
25     override fun onPause() {
26         super.onPause()
27         Shell.removeOnChange(redraw)
28     }
29 
30     private fun build() {
31         val col = Ui.page(this, "Extra-dim light")
32         col.note("Below the lowest the system allows.")
33 
34         if (!Shell.ready) {
35             col.row(
36                 "Shell access",
37                 "Needed for this",
38                 state = Shell.describe(this)
39             ) { startActivity(Intent(this, ShellActivity::class.java)) }
40             return
41         }
42 
43         val current = ExtraDim.level(this)
44         col.header("Level")
45         col.row(
46             "Off",
47             "The system is in charge",
48             state = if (current == 0) "In use" else null
49         ) { choose(0) }
50         ExtraDim.levels().forEach { v ->
51             col.row(v.toString() + " of 255", null, state = if (current == v) "In use" else null) {
52                 choose(v)
53             }
54         }
55         if (Device.brightnessFloor == null) {
56             col.note("These values are a guess on this device.")
57         }
58     }
59 
60     private fun choose(level: Int) {
61         ExtraDim.set(this, level) { ok ->
62             if (!ok) {
63                 Toast.makeText(
64                     this,
65                     "The light needs Shizuku started as root",
66                     Toast.LENGTH_LONG
67                 ).show()
68                 ExtraDim.set(this, 0) {}
69             }
70             build()
71         }
72     }
73 }