Add app/src/main/java/space/bloggin/scribe/SettingsActivity.kt

This commit is contained in:
2026-11-11 17:59:35 +00:00
parent 398acf890d
commit 1d7fdabf3f
@@ -0,0 +1,88 @@
package space.bloggin.scribe
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.text.InputType
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Toast
class SettingsActivity : Activity() {
override fun onCreate(b: Bundle?) {
super.onCreate(b)
val root = LinearLayout(this)
root.orientation = LinearLayout.VERTICAL
val back = Ui.barButton(this, "Back")
back.setOnClickListener { finish() }
root.addView(Ui.topBar(this, "Settings", back))
val body = LinearLayout(this)
body.orientation = LinearLayout.VERTICAL
val pad = Ui.dp(this, 16)
body.setPadding(pad, pad, pad, pad)
body.addView(Ui.text(this, "Wake phrase", 16f, Ui.INK, true))
val wake = EditText(this)
wake.setText(Prefs.wake(this))
wake.inputType = InputType.TYPE_CLASS_TEXT
body.addView(wake)
body.addView(Ui.text(this, "Type it the way the speech model spells it, so “dumby” is “dummy” here. Longer phrases of ordinary words almost never trigger by accident. A word the model does not know will never trigger.", 13f, Ui.MUTED))
body.addView(Ui.text(this, "Seconds of silence before a note ends", 16f, Ui.INK, true).also { it.setPadding(0, pad, 0, 0) })
val sil = EditText(this)
sil.setText(Prefs.silence(this).toString())
sil.inputType = InputType.TYPE_CLASS_NUMBER
body.addView(sil)
val beep = CheckBox(this); beep.text = "Beep when a note starts and ends"; beep.isChecked = Prefs.beep(this)
val vib = CheckBox(this); vib.text = "Vibrate when a note starts and ends"; vib.isChecked = Prefs.vibrate(this)
val cpu = CheckBox(this); cpu.text = "Keep the processor awake while listening"; cpu.isChecked = Prefs.cpu(this)
for (c in listOf(beep, vib, cpu)) { c.setTextColor(Ui.INK); c.setPadding(0, Ui.dp(this, 10), 0, Ui.dp(this, 4)); body.addView(c) }
body.addView(Ui.text(this, "Keeping the processor awake is what lets it hear you with the screen off. It uses more battery.", 13f, Ui.MUTED))
val save = Ui.button(this, "Save")
save.setOnClickListener {
val w = wake.text.toString().trim().lowercase().replace(Regex("[^a-z' ]"), "").replace(Regex("\\s+"), " ")
if (w.isEmpty()) { Toast.makeText(this, "Enter a wake phrase", Toast.LENGTH_SHORT).show(); return@setOnClickListener }
Prefs.setWake(this, w)
Prefs.setSilence(this, sil.text.toString().toIntOrNull() ?: 6)
Prefs.setBeep(this, beep.isChecked)
Prefs.setVibrate(this, vib.isChecked)
Prefs.setCpu(this, cpu.isChecked)
if (Bus.running) {
ListenService.stop(this)
android.os.Handler(mainLooper).postDelayed({ ListenService.start(this) }, 900)
}
Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show()
finish()
}
val lp = LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
lp.topMargin = pad
body.addView(save, lp)
body.addView(Ui.text(this, "Export", 16f, Ui.INK, true).also { it.setPadding(0, pad, 0, 0) })
val ep = Ui.ghostButton(this, "Export all notes as PDF")
ep.setOnClickListener { val l = Store.all().sortedBy { it.created }; Export.share(this, l, Export.fileName(l), false) }
body.addView(ep)
val ew = Ui.ghostButton(this, "Export all notes as Word")
ew.setOnClickListener { val l = Store.all().sortedBy { it.created }; Export.share(this, l, Export.fileName(l), true) }
body.addView(ew)
val bat = Ui.ghostButton(this, "Open battery settings")
bat.setOnClickListener { startActivity(Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)) }
body.addView(bat, LinearLayout.LayoutParams(lp).also { it.topMargin = Ui.dp(this, 10) })
body.addView(Ui.text(this, "On Samsung phones, set Hey Dumby to Unrestricted in battery settings so the system does not stop it in the background.", 13f, Ui.MUTED))
body.addView(Ui.text(this, "Voice commands while a note is open: “end note”, “cancel note”, “scratch that”, “new line”, “new paragraph”, “period”, “comma”, “question mark”, “exclamation point”, “colon”.", 13f, Ui.MUTED).also { it.setPadding(0, pad, 0, 0) })
val sv = ScrollView(this)
sv.addView(body)
root.addView(sv, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
setContentView(root)
}
}