Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

refactor(onboarding): remove the first-run wizard

booboosui8dac568b17a4
diff --git a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
index f00e30f..944ab77 100644
--- a/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
+++ b/app/src/main/java/net/kuafuai/andee/ScreenBodyService.kt
@@ -63,17 +63,6 @@ class ScreenBodyService : AccessibilityService() {
*/
private var pendingArtifact: net.kuafuai.andee.ui.ChatHistory.Entry? = null
- /**
- * The first-run wizard, when it is up.
- *
- * Separate from [selfCheck] for the same reason [selfCheck] is separate from
- * [settings]: they can be on screen at once. The one route between them is
- * the self-check card's 重新设置 — see [openWizard] — and it closes the card
- * it came from, so two of them are never both visible; the field exists so a
- * second entry point could not leak a window.
- */
- private var wizard: net.kuafuai.andee.ui.FirstRunUi? = null
-
private lateinit var audio: AudioIO
private lateinit var asr: AsrController
private lateinit var tts: TtsController
@@ -499,10 +488,6 @@ class ScreenBodyService : AccessibilityService() {
startBrain(announce = false)
startWakeWord()
runStartupSelfCheck()
- // After the check, in both senses: it is scheduled after
- // [runStartupSelfCheck] has started, and it declines to run if that
- // thread won the race and put a card up. See [maybeOfferWizard].
- maybeOfferWizard()
}
/**
@@ -1261,14 +1246,6 @@ class ScreenBodyService : AccessibilityService() {
// in this service and have to be told the same way [openSettings]
// tells them.
onLocaleChanged = { window.onLocaleChanged() },
- // The manual door into the wizard. [SelfCheckUi.hide] runs first and
- // its onDismiss clears [selfCheck] from [Glass.exit]'s completion,
- // which is a fifth of a second later — so the wizard goes up while
- // this card is still fading out, deliberately: [maybeOfferWizard]'s
- // guards would otherwise have to wait out a fade they cannot see.
- // The two never overlap on screen for longer than that fade, and both
- // are counted by OwnCard.
- onRerunWizard = { openWizard() },
)
selfCheck = s
s.show()
@@ -1471,132 +1448,6 @@ class ScreenBodyService : AccessibilityService() {
}
}
- /**
- * The first-run wizard, in a window of its own.
- *
- * [net.kuafuai.andee.ui.FirstRunUi] draws it; this is only the wiring, and
- * it mirrors [openSelfCheck] deliberately — same host, same yield, same
- * language callback, because the two cards are reached from one another and
- * two ways of putting up a card is how they drift apart.
- *
- * **Three doors, and each one is a different errand:**
- * * [maybeOfferWizard], on the service's own start, when nothing has been
- * configured yet. That is the only automatic one, and it is a question
- * rather than a takeover.
- * * [openSelfCheck]'s card, for a device already in use: 重新设置. Reachable
- * from the list rather than from the bar, because re-running the wizard
- * on a configured device means redoing six steps.
- * * Nothing else. In particular the launcher Activity is *not* one: it is
- * the door for the state where no overlay exists, and the wizard needs
- * overlays to show the very permissions it is about to ask for.
- *
- * Each of the three callbacks hands over to a surface this service already
- * owns rather than reimplementing it: the wake recorder is
- * [net.kuafuai.andee.ui.WakeEnrollUi] (the same one ⚙ opens), the camera is
- * [net.kuafuai.andee.device.LookActivity] (the same one `device.look` opens,
- * so the shutter flash and the exposure ramp are the shared ones), and the
- * last step is [startTurn] — literally the ball's own tap.
- */
- private fun openWizard() {
- if (wizard?.isShowing() == true) return
- val w = net.kuafuai.andee.ui.FirstRunUi(
- context = this,
- onDismiss = { wizard = null },
- // Marked done so a device that has been through it is not offered it
- // again on the next start. Written on 开始使用 and not on 完成设置,
- // because the last step is a sentence the user may well say later —
- // the config is already complete by the time they see it, and a
- // wizard that will not stop asking is worse than one that stops one
- // screen early.
- onComplete = { markWizardDone() },
- onOpenSettings = { openSettings() },
- onOpenWakeEnroll = {
- // The wizard stays up underneath: that is the point of the card
- // being an overlay, and the user comes back to 下一步 with the
- // recorder's own 完成. Same relationship the settings sheet has
- // to this card.
- net.kuafuai.andee.ui.WakeEnrollUi(this) { }.show()
- },
- onOpenLook = {
- // Fold first: this card is a fullscreen overlay and an Activity
- // comes up *underneath* one. Same reason SelfCheckUi yields, and
- // the fold is the gesture the whole app already uses for "give
- // the screen back".
- dispatcher.compactForUser()
- net.kuafuai.andee.device.LookActivity.open(this, false)
- },
- // The last step is the ball's own tap, so the user learns the gesture
- // by using it rather than by reading about it. The wizard closes
- // first, or it would sit over the conversation it just started.
- onOpenMic = { hideWizard(); startTurn() },
- onLocaleChanged = { window.onLocaleChanged() },
- onYieldScreen = {
- dispatcher.compactForUser()
- wizard?.hide()
- },
- )
- wizard = w
- w.show()
- }
-
- /** [openWizard]'s bookkeeping, in one place so the two call sites agree. */
- private fun hideWizard() {
- wizard?.hide()
- wizard = null
- }
-
- /**
- * Whether the device has already been through the wizard.
- *
- * Its own preference, not a read of the config: "is anything configured" is
- * the wrong question — a user who deliberately runs with no 火山 key (the
- * brain, the screen tools and the notebook all work mute) would be offered
- * the wizard on every single start, and a card that comes back however many
- * times you decline it is nagware. What this records is that it was
- * *offered and taken*, which is a fact about the user rather than about the
- * config.
- */
- private fun wizardDone(): Boolean =
- getSharedPreferences(SELF_CHECK_PREFS, MODE_PRIVATE).getBoolean(WIZARD_DONE, false)
-
- private fun markWizardDone() {
- getSharedPreferences(SELF_CHECK_PREFS, MODE_PRIVATE)
- .edit().putBoolean(WIZARD_DONE, true).apply()
- }
-
- /**
- * Offer the wizard once, on a device that has never been through it.
- *
- * **A question, not a takeover.** The welcome card lists what is about to
- * happen and has 取消 beside 开始; nothing is written until the user taps
- * 开始使用 at the far end. A wizard that seized the screen on first start
- * with no way past it is the other half of the failure this app already has
- * — every failure here is silent, and the answer is not to make the working
- * case loud.
- *
- * **It waits for the self-check.** [runStartupSelfCheck] and this both want
- * to put a card up, and two cards arguing about the same missing permission
- * is exactly what `startBrain(announce = false)` exists to prevent. So it
- * yields to the check's card when there is one: a device with a broken
- * permission gets the list, and the wizard comes back on the next start
- * once that is dealt with. On a clean device there is no card and this runs
- * immediately — which is the out-of-box case, the only one it is for.
- */
- private fun maybeOfferWizard() {
- if (wizardDone()) return
- if (!::window.isInitialized || !window.isShown()) return
- if (selfCheck?.isShowing() == true) return
- // Long enough for the ball's own enter animation and for the self-check
- // thread to have decided. Not a race that matters — see the doc above:
- // losing to the check's card is a correct outcome, not a bug.
- ui.postDelayed({
- if (wizardDone() || wizard?.isShowing() == true) return@postDelayed
- if (selfCheck?.isShowing() == true) return@postDelayed
- if (!::window.isInitialized || !window.isShown()) return@postDelayed
- openWizard()
- }, 1200)
- }
-
/**
* 恢复出厂设置: wipe everything this app owns, then rebuild out of nothing.
*
@@ -2292,16 +2143,6 @@ class ScreenBodyService : AccessibilityService() {
* immediately, because the signature is compared, not the clock.
*/
private const val REPEAT_AFTER_MS = 6 * 60 * 60 * 1000L
-
- /**
- * Whether the first-run wizard has been taken to the end.
- *
- * Lives beside the self-check's own bookkeeping because it is the same
- * file for the same reason — both are "what has this device already been
- * told", neither is configuration the user edits. See [wizardDone] for
- * why this is not derived from the config.
- */
- private const val WIZARD_DONE = "wizard_done"
}
/**
diff --git a/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt b/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt
deleted file mode 100644
index 24d07c3..0000000
--- a/app/src/main/java/net/kuafuai/andee/ui/FirstRunUi.kt
+++ /dev/null
@@ -1,709 +0,0 @@
-package net.kuafuai.andee.ui
-
-import android.content.Context
-import android.content.Intent
-import android.graphics.Color
-import android.graphics.Typeface
-import android.net.Uri
-import android.os.Handler
-import android.os.Looper
-import android.util.Log
-import android.util.TypedValue
-import android.view.Gravity
-import android.view.View
-import android.view.WindowManager
-import android.widget.FrameLayout
-import android.widget.LinearLayout
-import android.widget.ScrollView
-import android.widget.TextView
-import android.widget.Toast
-import net.kuafuai.andee.R
-import net.kuafuai.andee.config.VoiceConfig
-import net.kuafuai.andee.device.PermissionRequestActivity
-import net.kuafuai.andee.device.SelfCheck
-import net.kuafuai.andee.i18n.AppLocale
-import java.util.concurrent.Executors
-
-/**
- * First-run onboarding wizard: a stepped flow that turns a blank device into
- * one ready to use.
- *
- * ### What this is not
- *
- * Not a second hand-written checklist. This reuses [SelfCheck.Finding] as its
- * only data source — [SelfCheck.kt]'s own KDoc warns that a second list would
- * drift from the first within a week, and the whole point of having one source
- * of truth is that nothing can contradict it. The wizard *filters* and
- * *reorders* the findings; it does not invent its own.
- *
- * ### The steps, and why they are in this order
- *
- * Six: accessibility → overlay → key → wake → look → first sentence. That is
- * dependency order — each uses the ones before it — and it is also the
- * ascending cost: the cheapest steps come first, so a user who bails out still
- * has the easier half done. The first three are [SelfCheck] rows; the last
- * three are instructions + a pill that opens something this service already
- * owns ([net.kuafuai.andee.wake.WakeEnrollUi], [net.kuafuai.andee.device.LookActivity],
- * and [net.kuafuai.andee.ui.FloatingWindowUi]'s mic).
- *
- * ### Two doors in
- *
- * - **Auto**, from [net.kuafuai.andee.ScreenBodyService.onServiceConnected]
- * when the config is blank: this is a device nobody has touched, so the
- * wizard is a better first screen than a mute ball with no explanation.
- * - **Manual**, from the existing self-check card (long-press ✓ on the card,
- * not the button — a second deliberate step, so a stray tap on the check
- * list does not blow the existing config away).
- *
- * Either way, it is only an *offer* — the first card asks whether to begin, and
- * 取消 lands you at the ball with no config lost. No auto-advancing; the user
- * taps 下一步 on each step once the Android permission screen they just came
- * back from is green or their settings field is filled.
- *
- * ### The two hosts
- *
- * Like [SelfCheckUi] and [SettingsUi], this is built for both: [host] null
- * means the service creates a window, non-null means the caller places it. The
- * hosted path is unreachable at the moment — the launcher Activity opens the
- * self-check list, not this — but the split is kept because the Activity is
- * where an interrupted wizard would land if service restarts ever resume it,
- * and because "cards match self-check" was the whole item 4 design.
- *
- * ### Yielding
- *
- * [onYieldScreen] is the same contract [SelfCheckUi] uses, and for the same
- * reason: the window host is an overlay, so Android Settings screens come up
- * behind the card unless we get out of the way. See [SelfCheckUi.apply].
- *
- * ### Language
- *
- * [LangToggle] in the header, same place the settings card and the self-check
- * card put theirs. [onLocaleChanged] announces the change to the service, and
- * [repaintForLanguage] is how the service tells this card to redraw itself
- * (because the scrollback and the ball are also on screen and need to follow).
- */
-class FirstRunUi(
- private val context: Context,
- private val onDismiss: () -> Unit,
- private val onComplete: () -> Unit,
- /**
- * The 大脑 / 语音密钥 rows open *our* settings sheet, which is an overlay the
- * service owns — exactly as [SelfCheckUi] does. Null when there is no sheet
- * to open, in which case those rows get no button rather than a dead one.
- */
- private val onOpenSettings: (() -> Unit)? = null,
- private val onOpenWakeEnroll: (() -> Unit)? = null,
- private val onOpenLook: (() -> Unit)? = null,
- private val onOpenMic: (() -> Unit)? = null,
- private val onLocaleChanged: () -> Unit = {},
- private val onYieldScreen: () -> Unit = {},
- private val host: FrameLayout? = null,
-) {
-
- private companion object {
- const val TAG = "Body"
- const val GUTTER_DP = 20
- const val CARD_RADIUS_DP = 28
-
- const val MATCH = LinearLayout.LayoutParams.MATCH_PARENT
- const val WRAP = LinearLayout.LayoutParams.WRAP_CONTENT
-
- /** The steps, in order. Only the first three are SelfCheck rows. */
- private val STEP_IDS = listOf(
- "accessibility",
- "overlay",
- "voice_key",
- "wake",
- "look",
- "first_sentence",
- )
- }
-
- private val wm: WindowManager? =
- if (host == null) context.getSystemService(Context.WINDOW_SERVICE) as WindowManager else null
-
- private val main = Handler(Looper.getMainLooper())
- private val prober = Executors.newSingleThreadExecutor { r ->
- Thread(r, "wizard-probe").apply { isDaemon = true }
- }
-
- private var root: View? = null
- private var closing: View? = null
- private var frosted = false
- private var lctx: Context = context
-
- private var stepIndex = -1 // -1 = welcome, 0..5 = steps, 6 = complete
- private var body: LinearLayout? = null
-
- /**
- * The last full list, kept so repaint can draw the current step from it.
- * See [SelfCheckUi.last] for why this is correct rather than a shortcut.
- */
- private var findings: List<SelfCheck.Finding>? = null
-
- fun isShowing(): Boolean = root != null
-
- // ---- Lifecycle ----
-
- fun show() {
- if (host == null) showInWindow() else showInHost()
- }
-
- private fun showInHost() {
- val stage = host ?: return
- if (root != null) return
- lctx = AppLocale.wrap(context)
- frosted = true
- val v = build()
- stage.addView(v, FrameLayout.LayoutParams(cardWidth(), cardHeight(), Gravity.CENTER))
- root = v
- OwnCard.shown()
- renderWelcome()
- }
-
- private fun showInWindow() {
- val wm = wm ?: return
- closing?.let { runCatching { wm.removeView(it) }; OwnCard.hidden() }
- closing = null
- if (root != null) return
-
- lctx = AppLocale.wrap(context)
- val p = WindowManager.LayoutParams(
- cardWidth(), cardHeight(),
- WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
- 0,
- android.graphics.PixelFormat.TRANSLUCENT,
- ).apply {
- gravity = Gravity.CENTER
- }
- frosted = Glass.frost(context, wm, p)
- val v = build()
- try {
- v.hideFromAccessibility()
- wm.addView(v, p)
- root = v
- OwnCard.shown()
- Glass.enter(v)
- renderWelcome()
- } catch (t: Throwable) {
- Log.w(TAG, "wizard refused", t)
- }
- }
-
- fun hide() {
- val v = root ?: return
- root = null
- val stage = host
- if (stage != null) {
- runCatching { stage.removeView(v) }
- OwnCard.hidden()
- onDismiss()
- return
- }
- val wm = wm ?: return
- closing = v
- Glass.exit(v) {
- if (closing === v) {
- runCatching { wm.removeView(v) }
- closing = null
- OwnCard.hidden()
- onDismiss()
- }
- }
- }
-
- fun destroy() {
- prober.shutdownNow()
- if (root != null) {
- root = null
- OwnCard.hidden()
- }
- }
-
- // ---- Navigation ----
-
- /** The welcome card: do you want to begin? */
- private fun renderWelcome() {
- stepIndex = -1
- body?.removeAllViews()
- body?.addView(heroText(
- lctx.getString(R.string.wizard_welcome_title),
- lctx.getString(R.string.wizard_welcome_body),
- ))
- }
-
- /** A step from the list. */
- private fun renderStep(index: Int) {
- if (index < 0 || index >= STEP_IDS.size) return
- stepIndex = index
- val id = STEP_IDS[index]
- body?.removeAllViews()
-
- when (id) {
- "accessibility", "overlay", "voice_key" -> {
- // SelfCheck rows: show the finding.
- val f = findings?.firstOrNull { it.id == id }
- if (f != null) {
- body?.addView(stepTitle(index))
- body?.addView(findingCard(f))
- }
- }
- "wake" -> {
- body?.addView(stepTitle(index))
- body?.addView(instructionCard(
- lctx.getString(R.string.wizard_wake_body),
- lctx.getString(R.string.wizard_wake_button),
- ) {
- onOpenWakeEnroll?.invoke()
- })
- }
- "look" -> {
- body?.addView(stepTitle(index))
- body?.addView(instructionCard(
- lctx.getString(R.string.wizard_look_body),
- lctx.getString(R.string.wizard_look_button),
- ) {
- onOpenLook?.invoke()
- })
- }
- "first_sentence" -> {
- body?.addView(stepTitle(index))
- body?.addView(instructionCard(
- lctx.getString(R.string.wizard_sentence_body),
- lctx.getString(R.string.wizard_sentence_button),
- ) {
- onOpenMic?.invoke()
- })
- }
- }
- }
-
- /** The final card: you're done. */
- private fun renderComplete() {
- stepIndex = STEP_IDS.size
- body?.removeAllViews()
- body?.addView(heroText(
- lctx.getString(R.string.wizard_complete_title),
- lctx.getString(R.string.wizard_complete_body),
- ))
- }
-
- private fun advance() {
- if (stepIndex == -1) {
- // Welcome → step 0: load findings first.
- probe { renderStep(0) }
- } else if (stepIndex < STEP_IDS.size - 1) {
- renderStep(stepIndex + 1)
- } else {
- renderComplete()
- }
- }
-
- private fun retreat() {
- if (stepIndex == 0) {
- renderWelcome()
- } else if (stepIndex > 0) {
- renderStep(stepIndex - 1)
- }
- }
-
- private fun probe(then: () -> Unit) {
- val app = context.applicationContext
- prober.execute {
- val found = runCatching { SelfCheck.run(app) }.getOrNull() ?: return@execute
- main.post {
- if (root == null) return@post
- findings = found
- then()
- }
- }
- }
-
- // ---- Language ----
-
- private fun onLanguageChanged() {
- repaintForLanguage()
- onLocaleChanged()
- }
-
- fun repaintForLanguage() {
- if (root == null) return
- lctx = AppLocale.wrap(context)
- rebuild()
- }
-
- private fun rebuild() {
- val old = root ?: return
- val stage = host
- if (stage != null) {
- val v = build()
- val i = stage.indexOfChild(old)
- runCatching { stage.removeView(old) }
- if (i >= 0) stage.addView(v, i, old.layoutParams) else stage.addView(v, old.layoutParams)
- root = v
- repaintCurrentStep()
- return
- }
- val wm = wm ?: return
- Glass.fadeOut(old) {
- if (root !== old) return@fadeOut
- val v = build()
- runCatching {
- v.hideFromAccessibility()
- val p = old.layoutParams as WindowManager.LayoutParams
- wm.removeView(old)
- wm.addView(v, p)
- root = v
- Glass.fadeIn(v)
- repaintCurrentStep()
- }
- }
- }
-
- private fun repaintCurrentStep() {
- when (stepIndex) {
- -1 -> renderWelcome()
- in 0 until STEP_IDS.size -> renderStep(stepIndex)
- else -> renderComplete()
- }
- }
-
- // ---- Build ----
-
- private fun build(): View {
- val card = LinearLayout(context).apply {
- orientation = LinearLayout.VERTICAL
- background = Glass.card(context, dp(CARD_RADIUS_DP), frosted)
- clipToOutline = true
- }
-
- card.addView(header(), matchWrap())
-
- val scroll = ScrollView(context).apply {
- isFillViewport = true
- isVerticalScrollBarEnabled = false
- }
- body = LinearLayout(context).apply {
- orientation = LinearLayout.VERTICAL
- setPadding(dp(24), dp(4), dp(24), dp(24))
- }
- scroll.addView(body, matchWrap())
- card.addView(scroll, LinearLayout.LayoutParams(MATCH, 0, 1f))
-
- card.addView(footer(), matchWrap())
- return card
- }
-
- private fun header(): View {
- val row = LinearLayout(context).apply {
- orientation = LinearLayout.HORIZONTAL
- gravity = Gravity.CENTER_VERTICAL
- setPadding(dp(28), dp(22), dp(18), dp(14))
- }
- val titles = LinearLayout(context).apply { orientation = LinearLayout.VERTICAL }
- titles.addView(TextView(context).apply {
- text = lctx.getString(R.string.wizard_title)
- textSize = Glass.Type.DISPLAY
- setTextColor(Color.parseColor(Glass.TITLE))
- letterSpacing = 0.01f
- })
- titles.addView(TextView(context).apply {
- text = progressLabel()
- textSize = Glass.Type.CAPTION
- setTextColor(Color.parseColor(Glass.MUTED))
- setPadding(0, dp(4), 0, 0)
- })
- row.addView(titles, LinearLayout.LayoutParams(0, WRAP, 1f))
- row.addView(
- LangToggle(context) { onLanguageChanged() },
- LinearLayout.LayoutParams(WRAP, WRAP).apply { marginEnd = dp(12) },
- )
- row.addView(closeButton(), LinearLayout.LayoutParams(dp(36), dp(36)))
- return row
- }
-
- private fun progressLabel(): String = when (stepIndex) {
- -1 -> lctx.getString(R.string.wizard_progress_welcome)
- in 0 until STEP_IDS.size -> lctx.getString(
- R.string.wizard_progress_step,
- stepIndex + 1,
- STEP_IDS.size,
- )
- else -> lctx.getString(R.string.wizard_progress_done)
- }
-
- private fun closeButton(): View = TextView(context).apply {
- text = "✕"
- textSize = Glass.Type.BODY
- setTextColor(Color.parseColor(Glass.SECONDARY))
- gravity = Gravity.CENTER
- background = Glass.panel(context, dp(18))
- isClickable = true
- isFocusable = true
- Glass.pressable(this)
- contentDescription = lctx.getString(R.string.wizard_cancel)
- setOnClickListener { hide() }
- }
-
- private fun footer(): View {
- val row = LinearLayout(context).apply {
- orientation = LinearLayout.HORIZONTAL
- gravity = Gravity.CENTER_VERTICAL
- setPadding(dp(18), dp(10), dp(18), dp(18))
- }
-
- val leftLabel = when (stepIndex) {
- -1 -> lctx.getString(R.string.wizard_cancel)
- in 0 until STEP_IDS.size -> lctx.getString(R.string.wizard_back)
- else -> null
- }
- if (leftLabel != null) {
- row.addView(
- textButton(leftLabel, Glass.SECONDARY) {
- if (stepIndex == -1) hide() else retreat()
- },
- LinearLayout.LayoutParams(0, WRAP, 1f),
- )
- } else {
- row.addView(View(context), LinearLayout.LayoutParams(0, WRAP, 1f))
- }
-
- val rightLabel = when (stepIndex) {
- -1 -> lctx.getString(R.string.wizard_begin)
- in 0 until STEP_IDS.size - 1 -> lctx.getString(R.string.wizard_next)
- STEP_IDS.size - 1 -> lctx.getString(R.string.wizard_finish)
- else -> lctx.getString(R.string.wizard_done)
- }
- row.addView(button(rightLabel, filled = true) {
- if (stepIndex == STEP_IDS.size) {
- onComplete()
- hide()
- } else {
- advance()
- }
- })
- return row
- }
-
- private fun textButton(label: String, tint: String, onClick: () -> Unit): TextView =
- TextView(context).apply {
- text = label
- textSize = Glass.Type.BODY
- setTextColor(Color.parseColor(tint))
- gravity = Gravity.START or Gravity.CENTER_VERTICAL
- setPadding(dp(4), dp(13), dp(4), dp(13))
- isClickable = true
- isFocusable = true
- Glass.pressable(this)
- setOnClickListener { onClick() }
- }
-
- private fun button(label: String, filled: Boolean, onClick: () -> Unit): TextView {
- val radius = dp(24)
- return TextView(context).apply {
- text = label
- textSize = Glass.Type.BODY
- setTextColor(Color.parseColor(if (filled) Glass.TITLE else Glass.LABEL))
- gravity = Gravity.CENTER
- background =
- if (filled) Glass.tinted(context, radius) else Glass.panel(context, radius)
- setPadding(dp(26), dp(13), dp(26), dp(13))
- isClickable = true
- isFocusable = true
- Glass.pressable(this)
- setOnClickListener { onClick() }
- }
- }
-
- // ---- Step parts ----
-
- private fun heroText(title: String, body: String): View {
- val card = LinearLayout(context).apply {
- orientation = LinearLayout.VERTICAL
- setPadding(0, dp(20), 0, 0)
- }
- card.addView(TextView(context).apply {
- text = title
- setTextSize(TypedValue.COMPLEX_UNIT_SP, Glass.Type.HEADLINE)
- setTypeface(typeface, Typeface.BOLD)
- setTextColor(Color.parseColor(Glass.TITLE))
- gravity = Gravity.CENTER
- })
- card.addView(TextView(context).apply {
- text = body
- setTextSize(TypedValue.COMPLEX_UNIT_SP, Glass.Type.BODY)
- setTextColor(Color.parseColor(Glass.SECONDARY))
- gravity = Gravity.CENTER
- setPadding(dp(12), dp(12), dp(12), 0)
- })
- return card
- }
-
- private fun stepTitle(index: Int): View = TextView(context).apply {
- val id = STEP_IDS.getOrNull(index) ?: ""
- text = when (id) {
- "accessibility" -> lctx.getString(R.string.check_title_accessibility)
- "overlay" -> lctx.getString(R.string.check_title_overlay)
- "voice_key" -> lctx.getString(R.string.check_title_voice_key)
- "wake" -> lctx.getString(R.string.wizard_wake_title)
- "look" -> lctx.getString(R.string.wizard_look_title)
- "first_sentence" -> lctx.getString(R.string.wizard_sentence_title)
- else -> ""
- }
- setTextSize(TypedValue.COMPLEX_UNIT_SP, Glass.Type.HEADLINE)
- setTypeface(typeface, Typeface.BOLD)
- setTextColor(Color.parseColor(Glass.TITLE))
- setPadding(0, dp(8), 0, dp(12))
- }
-
- private fun findingCard(f: SelfCheck.Finding): View {
- val card = LinearLayout(context).apply {
- orientation = LinearLayout.VERTICAL
- background = Glass.panel(context, dp(14))
- setPadding(dp(14), dp(14), dp(14), dp(14))
- }
- card.addView(TextView(context).apply {
- text = AppLocale.str(context, f.detail, *f.detailArgs.toTypedArray())
- setTextColor(Color.parseColor(Glass.SECONDARY))
- setTextSize(TypedValue.COMPLEX_UNIT_SP, Glass.Type.BODY)
- })
- fixButton(f)?.let {
- card.addView(it.apply {
- val lp = layoutParams as? LinearLayout.LayoutParams
- lp?.topMargin = dp(10)
- layoutParams = lp
- })
- }
- return card
- }
-
- private fun instructionCard(body: String, buttonLabel: String, onClick: () -> Unit): View {
- val card = LinearLayout(context).apply {
- orientation = LinearLayout.VERTICAL
- background = Glass.panel(context, dp(14))
- setPadding(dp(14), dp(14), dp(14), dp(14))
- }
- card.addView(TextView(context).apply {
- text = body
- setTextColor(Color.parseColor(Glass.SECONDARY))
- setTextSize(TypedValue.COMPLEX_UNIT_SP, Glass.Type.BODY)
- })
- card.addView(button(buttonLabel, filled = false, onClick).apply {
- val lp = LinearLayout.LayoutParams(WRAP, WRAP).apply { topMargin = dp(10) }
- layoutParams = lp
- })
- return card
- }
-
- /**
- * The way out for a step that is a [SelfCheck] row, or nothing when there is
- * not one.
- *
- * The [SelfCheck.Fix.OurSettings] guard is the same rule [SelfCheckUi] uses:
- * our sheet is an overlay the service owns, so with the service not there to
- * raise it the row must not offer a button that would do nothing. The wizard
- * is only ever raised by the service today, so this is currently unreachable
- * — it is here because the row and the button would otherwise be able to
- * disagree the day a host without overlays raises this card.
- */
- private fun fixButton(f: SelfCheck.Finding): View? {
- if (f.fix is SelfCheck.Fix.OurSettings && onOpenSettings == null) return null
- val label = when (val fix = f.fix) {
- is SelfCheck.Fix.Screen ->
- if (fix.label != 0) fix.label else R.string.check_fix_settings
- is SelfCheck.Fix.Link -> R.string.check_fix_download
- is SelfCheck.Fix.Grant -> R.string.check_fix_allow
- is SelfCheck.Fix.OurSettings -> R.string.check_fix_app_settings
- else -> return null
- }
- return button(lctx.getString(label), filled = false) { apply(f) }
- }
-
- // ---- Doors ----
-
- /**
- * Every fix is a `startActivity`, exactly as [SelfCheckUi.apply] — and the
- * yield matters here for the same reason it does there: this card is a
- * fullscreen `TYPE_APPLICATION_OVERLAY` in the window host, so the system
- * Settings page it opens comes up *behind* it unless we get out of the way.
- *
- * [SelfCheck.Fix.OurSettings] is the one exception: our own sheet is
- * supposed to come up over this card so the wizard is still behind it to
- * return to. And it is the one door that can be missing — see
- * [onOpenSettings] — in which case the row gets no button at all rather
- * than a button that does nothing.
- */
- private fun apply(f: SelfCheck.Finding) {
- val fix = f.fix
- if (fix !is SelfCheck.Fix.OurSettings) {
- if (!openable(fix)) {
- toastNoScreen()
- return
- }
- onYieldScreen()
- }
- when (fix) {
- is SelfCheck.Fix.Screen, is SelfCheck.Fix.Link -> launch(intentFor(fix))
- is SelfCheck.Fix.Grant -> launch(
- Intent(context, PermissionRequestActivity::class.java)
- .putExtra("permissions", fix.permissions.toTypedArray())
- )
- is SelfCheck.Fix.OurSettings -> onOpenSettings?.invoke()
- is SelfCheck.Fix.Adb, SelfCheck.Fix.Nothing -> Unit
- }
- }
-
- private fun openable(fix: SelfCheck.Fix): Boolean = when (fix) {
- is SelfCheck.Fix.Screen, is SelfCheck.Fix.Link ->
- runCatching {
- context.packageManager
- .queryIntentActivities(intentFor(fix), 0)
- .isNotEmpty()
- }.getOrDefault(true)
- else -> true
- }
-
- private fun intentFor(fix: SelfCheck.Fix): Intent = when (fix) {
- is SelfCheck.Fix.Screen -> Intent(fix.action).apply {
- fix.data?.let { data = Uri.parse(it) }
- fix.extras.forEach { (name, value) -> putExtra(name, value) }
- }
- is SelfCheck.Fix.Link -> Intent(Intent.ACTION_VIEW, Uri.parse(fix.url))
- else -> Intent()
- }
-
- private fun toastNoScreen() {
- runCatching {
- Toast.makeText(context, lctx.getString(R.string.check_fix_no_screen), Toast.LENGTH_LONG)
- .show()
- }
- }
-
- private fun launch(intent: Intent) {
- if (host == null) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- val ok = runCatching { context.startActivity(intent) }.onFailure {
- Log.w(TAG, "wizard: no activity for ${intent.action}", it)
- }.isSuccess
- if (!ok) toastNoScreen()
- }
-
- // ---- Helpers ----
-
- private fun matchWrap() = LinearLayout.LayoutParams(MATCH, WRAP)
-
- private fun dp(v: Int): Int = Glass.dp(context, v)
-
- private fun cardWidth(): Int {
- val screen = screenW()
- return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.98f).toInt())
- }
-
- private fun cardHeight(): Int {
- val screen = screenH()
- return minOf(screen - dp(2 * GUTTER_DP), (screen * 0.96f).toInt())
- }
-
- private fun screenW(): Int = Glass.usableSize(context).first
-
- private fun screenH(): Int = Glass.usableSize(context).second
-}
diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
index ef1a9cb..556d50e 100644
--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt
@@ -110,12 +110,6 @@ class SelfCheckUi(
* has anything to do, and it is the only host that passes this.
*/
private val onYieldScreen: () -> Unit = {},
- /**
- * Fired when the user taps 重新设置 — the manual entry point into the wizard.
- * Null ⇒ the button is not drawn. Default null, because `SelfCheckActivity`
- * has no service to ask and therefore cannot open it.
- */
- private val onRerunWizard: (() -> Unit)? = null,
/** Non-null ⇒ that host places the card and this class owns no window. */
private val host: FrameLayout? = null,
) {
@@ -563,20 +557,6 @@ class SelfCheckUi(
},
LinearLayout.LayoutParams(0, WRAP, 1f),
)
- // 重新设置 sits beside 重新检查 and not in a row of its own, because the
- // two are the same shape of thing — the one door here that is *not* a fix
- // for a listed failure has to look like the door that is. It is
- // deliberately not a filled button either: 完成 is the way out of this
- // card and must stay the only one that looks like a way out.
- if (onRerunWizard != null) {
- row.addView(
- textButton(lctx.getString(R.string.check_page_rerun_wizard), Glass.LABEL) {
- hide()
- onRerunWizard.invoke()
- },
- LinearLayout.LayoutParams(WRAP, WRAP).apply { marginEnd = dp(16) },
- )
- }
row.addView(button(lctx.getString(R.string.check_page_done), filled = true) { hide() })
return row
}
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
index ebf0037..b473d62 100644
--- a/app/src/main/res/values-en/strings.xml
+++ b/app/src/main/res/values-en/strings.xml
@@ -492,37 +492,4 @@
<string name="ball_look_bear">Bear</string>
<string name="ball_look_imp">Imp</string>
-
- <!-- First-run wizard -->
- <string name="wizard_title">First-run setup</string>
- <string name="wizard_progress_welcome">Welcome</string>
- <string name="wizard_progress_step">Step %1$d of %2$d</string>
- <string name="wizard_progress_done">Done</string>
- <string name="wizard_cancel">Cancel</string>
- <string name="wizard_back">Back</string>
- <string name="wizard_begin">Begin</string>
- <string name="wizard_next">Next</string>
- <string name="wizard_finish">Finish setup</string>
- <string name="wizard_done">Start using</string>
-
- <string name="wizard_welcome_title">Welcome</string>
- <string name="wizard_welcome_body">A few steps to get this device ready. Each one asks you to grant a permission or fill a setting. Tap Next when you\'re done.</string>
-
- <string name="wizard_wake_title">Wake phrase</string>
- <string name="wizard_wake_body">Pick a phrase and say it 3 times (e.g. “Hey Andee”) — you can then call me by voice when the screen is on. Works without one too; you\'d just tap the ball instead.</string>
- <string name="wizard_wake_button">Record</string>
-
- <string name="wizard_look_title">Take a look around</string>
- <string name="wizard_look_body">Let it see where you are now so it remembers this place. Later when you ask "where am I" it can answer.</string>
- <string name="wizard_look_button">Open camera</string>
-
- <string name="wizard_sentence_title">Say your first sentence</string>
- <string name="wizard_sentence_body">Tap the ball, say something — it\'ll answer, and setup is done.</string>
- <string name="wizard_sentence_button">Tap to talk</string>
-
- <string name="wizard_complete_title">All set</string>
- <string name="wizard_complete_body">Go tap the ball and talk. Long-press it to unfold the card, ⚙ opens settings.</string>
-
- <string name="check_page_rerun_wizard">Set up again</string>
-
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fa07360..d943b11 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -565,37 +565,4 @@
<string name="ball_look_bear">憨憨熊</string>
<string name="ball_look_imp">小恶魔</string>
-
- <!-- 首次引导向导 -->
- <string name="wizard_title">首次设置</string>
- <string name="wizard_progress_welcome">欢迎</string>
- <string name="wizard_progress_step">第 %1$d 步,共 %2$d 步</string>
- <string name="wizard_progress_done">完成</string>
- <string name="wizard_cancel">取消</string>
- <string name="wizard_back">上一步</string>
- <string name="wizard_begin">开始</string>
- <string name="wizard_next">下一步</string>
- <string name="wizard_finish">完成设置</string>
- <string name="wizard_done">开始使用</string>
-
- <string name="wizard_welcome_title">欢迎</string>
- <string name="wizard_welcome_body">接下来几步,把这台设备配好就能用了。每一步都需要你去开一个权限或填个设置,做完点「下一步」就行。</string>
-
- <string name="wizard_wake_title">唤醒词</string>
- <string name="wizard_wake_body">自己选个词录 3 遍(例如「嘿 Andee」),亮屏时喊得醒。不录也能用,只是得点球。</string>
- <string name="wizard_wake_button">去录</string>
-
- <string name="wizard_look_title">看一眼周围</string>
- <string name="wizard_look_body">让它看看你现在在哪儿,记住这个地方。之后问「我在哪」它就能答上来。</string>
- <string name="wizard_look_button">打开摄像头</string>
-
- <string name="wizard_sentence_title">说第一句话</string>
- <string name="wizard_sentence_body">点球,说点什么 — 它会答你,配置就算完成了。</string>
- <string name="wizard_sentence_button">点球说话</string>
-
- <string name="wizard_complete_title">都配好了</string>
- <string name="wizard_complete_body">去点球说话吧。长按球能回到全屏卡片,⚙ 里能改设置。</string>
-
- <string name="check_page_rerun_wizard">重新设置</string>
-
</resources>