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、支持任意模型,记忆和密码绝不离开设备。
feat(ui): a day and a night palette, on the backdrop photograph
booboosuiebc91824e929
diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.ktindex 9ef5040..38e667f 100644--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt@@ -200,6 +200,16 @@ class BodyCoreService : Service() {// keeps this process alive when the accessibility service is taken// away, and it is the way back (see [postNotification]).startForegroundCompat()+ // The saved palette, and **before any view exists**: every colour the first card+ // draws is read from it, so a service that adopted it late would come up in the+ // other theme and only correct itself on the next change.+ net.kuafuai.andee.ui.Theme.load(this)+ // One hook rather than one per surface — [net.kuafuai.andee.ui.Theme.set] fires+ // it, and this service is the only owner of the live UI. Set before the window+ // is built and guarded, because a change landing in that gap must not crash.+ net.kuafuai.andee.ui.Theme.onChanged = {+ ui.post { if (::window.isInitialized) window.onThemeChanged() }+ }window = FloatingWindowUi(this, object : FloatingWindowUi.Listeners {override fun onTalkClick() {// Deliberately no unfold. Talking from the corner ball is thediff --git a/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt b/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.ktindex f99f070..e3d3463 100644--- a/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt+++ b/app/src/main/java/net/kuafuai/andee/config/VoiceConfig.kt@@ -143,6 +143,31 @@ data class VoiceConfig(/** Full TTS WebSocket URL for CodeFlying. */fun codeFlyingTtsEndpoint(): String = "${codeFlyingWsBaseUrl()}/voice/tts/bidirection"+ /**+ * Which palette the UI draws with. `true` = night, and false = day.+ *+ * **Night is the default.** A fresh install comes up dark, and so does a+ * device updating from a build that predates this setting — which is why the+ * test is "not day" rather than "is night". Inverted here on request; the+ * light palette is still one tap away in 设置 → 外观 and is remembered from+ * then on.+ *+ * Read straight off disk rather than out of [current], and that matters here:+ * [net.kuafuai.andee.ui.Theme] reads this once at process start and again on+ * every change, so the answer has to be the file's, not a snapshot of the+ * other rows that happens to be in memory.+ *+ * Only the two strings are meaningful; the "day" one is written by the picker+ * as [net.kuafuai.andee.ui.Theme.DAY].+ */+ fun nightTheme(context: Context): Boolean {+ val saved = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)+ .getString("theme", "").orEmpty().trim().lowercase()+ // Only an explicit "day" turns night off. Absent or unrecognised reads as+ // night, so the default cannot be lost by a build that never wrote it.+ return saved != "day"+ }+/** Whether to show the 云端 (hub) tab in the backend picker. Default off. */fun showHub(context: Context): Boolean =context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)@@ -602,6 +627,11 @@ data class VoiceConfig(// editable too, and is gone: the voice follows the ball's look, not a// row — see [lookSpeaker].)private val ALLOWED_KEYS = setOf(+ // Which palette the UI draws with — see [net.kuafuai.andee.ui.Theme].+ // In this list because [save] drops anything that is not: a key missing+ // here is a write that silently does nothing, which on a theme means the+ // picker moves, the card redraws and the setting is gone next launch.+ "theme","uid","api_key","asr_endpoint", "asr_resource_id",diff --git a/app/src/main/java/net/kuafuai/andee/ui/Backdrop.kt b/app/src/main/java/net/kuafuai/andee/ui/Backdrop.ktindex f0b40ab..653e454 100644--- a/app/src/main/java/net/kuafuai/andee/ui/Backdrop.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/Backdrop.kt@@ -55,9 +55,28 @@ import kotlin.math.roundToInt* look instead of a card with a transparent hole in it — the same trade* `backdropUp` was written for.*- * The image itself lives in `res/drawable-nodpi/backdrop.jpg`. Any photo will- * do: the scrim is derived from the image's own brightness rather than being a- * constant, so swapping the file is the whole procedure. See [scrim].+ * **One photograph serves both palettes, veiled in opposite directions.** The image is+ * the landscape this app shipped with, and it is the only texture in a UI that is+ * otherwise flat vector shapes. It is blurred once and then filmed over:+ *+ * * under the **night** palette it takes a black veil, 0.22 / 0.38 as it always was,+ * which is why the page reads `#243C49` — the original `backdrop.jpg` behaviour, kept+ * to the digit;+ * * under the **day** palette it takes a **white** one, to 0.70, so the same photograph+ * sits behind dark type at nearly half its own contrast: a landscape you can read as+ * sky and meadow rather than a texture you have to be told about, and still light+ * enough for the type. That target is the dial for how visible the image is — see+ * [DAY_TARGET_LUMA].+ *+ * That is the whole difference. Nothing about the file, the blur or the box changes+ * between the two — see [veilFor] for the arithmetic, and the constants under it for why+ * one direction needs a floor and the other a ceiling.+ *+ * It has been flat white in between, which lost because **a material needs something to+ * be made of**: glass over white is white, and the card stopped reading as a surface at+ * all. A veil over a photograph is what makes the pane a pane — and it is why the+ * bubbles and the input field read as frosted glass on this backdrop and only as pale+ * rectangles on a flat one.*/object Backdrop {@@ -83,24 +102,64 @@ object Backdrop {private const val BLUR_PASSES = 3/**- * What the backdrop's mean luminance should end up at, once the scrim is on.+ * How far the photograph is pushed, and which way.+ *+ * **One image, two palettes, two directions** — and the direction is the whole of+ * it. Night puts light type on the page, so the photo is pushed *down* under a black+ * veil until its mean luminance is somewhere dark: 0.22 was picked on a device+ * because 0.13 — what a 60%-black card composites to over a blurred desktop — read+ * as a black wall with a photo buried in it. The 0.38 floor is the other half of+ * that, a promise of *some* darkening so a bright image can never come back bright+ * enough to swallow the pale ball. Those two numbers are why the backdrop lands on+ * `#243C49`, which is what this app shipped with.+ *+ * Day puts dark type on the page, so the same photograph is pushed *up* under a+ * **white** veil instead. Nothing about the image differs between the two; only the+ * film over it does. See [veilFor] for the arithmetic.+ *+ * **[DAY_TARGET_LUMA] is the "how much do you want to see the photograph" dial** —+ * turn it down to let more of the image through, up to hide it. Walked down three+ * times on request: 0.88 → 0.82 → 0.70 → 0.62.+ *+ * The relation that makes this number tractable is*- * Started at 0.13 — what `CARD_FROSTED` (60% black over a blurred desktop)- * composites to on average — and was raised to 0.22 after use: on a card- * that stays up for minutes, 0.13 read as a black wall with a photo buried- * in it. 0.22 is about the ceiling: past it the pale ball and the- * `SECONDARY` text start to lose contrast against the image.+ * surviving contrast of the photograph = (1 − target) / (1 − luma)+ *+ * which at this image's luma of 0.364 runs 0.28, 0.44, 0.50, **0.60** across those+ * four values — so roughly two points of image per hundredth of target, and each step+ * is a large visible one.+ *+ * **How far down it can go is set by type contrast, not taste.** The page's mean+ * luminance *is* this number, and the fullscreen card has no fill of its own — the+ * photograph *is* the conversation's background, so its text sits directly on the+ * image. Meanwhile the bubbles are translucent films of 8–16% black, which is nothing+ * much to sit on when what is underneath varies. The numbers to keep in mind while+ * turning it: [SECONDARY] is a 0.36 grey, so it needs the ground under it to stay+ * above about 0.55, and the photograph's darker half lands near 0.45 at this target.+ * See [veilFor].+ */+ private const val NIGHT_TARGET_LUMA = 0.22f+ private const val NIGHT_VEIL_MIN = 0.38f+ private const val DAY_TARGET_LUMA = 0.62f++ /**+ * Night's other clamp: a near-black image must not be darkened into nothing.*/- private const val TARGET_LUMA = 0.22f+ private const val NIGHT_VEIL_MAX = 0.75f/**- * Bounds on the derived scrim, so a very dark or very bright photo cannot- * walk the card's base colour out of the range the palette assumes. The floor- * keeps text legible over a near-black image; the ceiling keeps the image- * from disappearing under a near-white one.+ * The ceiling on day's lift, and it is not the mirror of night's floor.+ *+ * A floor is needed in one direction and a ceiling in the other, because the two+ * have opposite failure modes. Under-darkening a bright image leaves dark type+ * fighting a photograph; under-*lightening* a dark one does exactly the same, so day+ * needs a guaranteed minimum lift — which the `(target − luma) / (1 − luma)` form+ * gives for free, since it climbs to 1 as the image darkens. What is left to guard+ * is the far end: without a cap, a near-black photo would be washed to a blank white+ * page, and "use the photograph in light mode too" would quietly have become "use a+ * white page". 0.90 keeps a tenth of the image's own contrast alive.*/- private const val SCRIM_MIN = 0.38f- private const val SCRIM_MAX = 0.75f+ private const val DAY_VEIL_MAX = 0.90fprivate val ui = Handler(Looper.getMainLooper())private val worker = Executors.newSingleThreadExecutor { r ->@@ -118,6 +177,21 @@ object Backdrop {/** Whether [bitmap] and [scrim] are worth reading yet. */fun ready(): Boolean = ready+ /**+ * Forget the decode, so the next [warm] redoes it against the current theme.+ *+ * Called on a theme change. [warm] is one-shot by design — "safe to call more than+ * once; only the first does work" — and the two palettes have two different files,+ * so without this the card would keep the day wash under the night palette. That is+ * the most visible way to get a theme switch wrong, and it is silent: the palette+ * around it would all be correct.+ */+ fun reset() {+ ready = false+ bitmap = null+ scrim = 0+ }+fun bitmap(): Bitmap? = bitmap/**@@ -159,15 +233,37 @@ object Backdrop {boxBlur(px, w, h)val luma = meanLuma(px)- val alpha = (1f - TARGET_LUMA / max(luma, 0.02f)).coerceIn(SCRIM_MIN, SCRIM_MAX)+ val veil = veilFor(luma)Log.i(TAG,- "backdrop %dx%d mean luma %.3f → scrim %.0f%% black".format(- w, h, luma, alpha * 100,+ "backdrop %dx%d mean luma %.3f → veil %.0f%% %s".format(+ w, h, luma, Color.alpha(veil) * 100f / 255f, if (Theme.night) "black" else "white",),)- return Bitmap.createBitmap(px, w, h, Bitmap.Config.ARGB_8888) to- Color.argb((alpha * 255).roundToInt(), 0, 0, 0)+ return Bitmap.createBitmap(px, w, h, Bitmap.Config.ARGB_8888) to veil+ }++ /**+ * The film that goes over the photograph, as ARGB, for the palette in force.+ *+ * Two formulas, because the two palettes fail in opposite directions. A black veil+ * leaves `luma × (1 − a)`, so the alpha falls straight out of the target. A white one+ * leaves `luma × (1 − a) + a`, which inverts to `(target − luma) / (1 − luma)` — and+ * that form is self-limiting in the useful direction: an image already brighter than+ * the target yields a negative alpha, i.e. no veil at all, which is the right answer+ * for a photograph pale enough for dark type to sit on unaided.+ *+ * Worker thread only.+ */+ private fun veilFor(luma: Float): Int {+ val l = max(luma, 0.02f)+ return if (Theme.night) {+ val a = (1f - NIGHT_TARGET_LUMA / l).coerceIn(NIGHT_VEIL_MIN, NIGHT_VEIL_MAX)+ Color.argb((a * 255).roundToInt(), 0, 0, 0)+ } else {+ val a = ((DAY_TARGET_LUMA - l) / (1f - l)).coerceIn(0f, DAY_VEIL_MAX)+ Color.argb((a * 255).roundToInt(), 255, 255, 255)+ }}/**@@ -180,6 +276,10 @@ object Backdrop {* that decides it is more code than the scaled copy it saves.*/private fun decode(context: Context): Bitmap {+ // One file, both palettes. What differs between day and night is the *veil*+ // over this image, not the image — see [veilFor] — so a second file would have+ // nothing of its own to say. This is the photograph the app shipped with, and+ // it is the only texture in a UI that is otherwise flat vector shapes.val id = net.kuafuai.andee.R.drawable.backdropval bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true }BitmapFactory.decodeResource(context.resources, id, bounds)diff --git a/app/src/main/java/net/kuafuai/andee/ui/CardUi.kt b/app/src/main/java/net/kuafuai/andee/ui/CardUi.ktindex e664c4e..fc1901e 100644--- a/app/src/main/java/net/kuafuai/andee/ui/CardUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/CardUi.kt@@ -582,6 +582,13 @@ object CardUi {private val density = resources.displayMetrics.density+ // The colours are re-read on every draw rather than only here, because a+ // theme change is not an event this view is told about — it holds its own+ // paint objects, so a colour baked in at construction is a colour it keeps.+ // [CardUi] is not wired into the theme broadcast (see [Theme.onChanged]: one+ // listener, the service) and this is what stands in for that: whichever card+ // is on screen is at most one repaint away from being right, instead of one+ // app restart.private val basePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = BASE }private val filmPaint = Paint(Paint.ANTI_ALIAS_FLAG)private val rimPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {@@ -626,6 +633,18 @@ object CardUi {}override fun dispatchDraw(canvas: Canvas) {+ // The fill and the rim are re-read on every draw, not only at construction.+ // A theme change is not an event this view is told about, so a colour baked+ // into a paint object is a colour it keeps — see [BASE]. Two assignments,+ // no allocation, and any repaint brings an open card back to the palette.+ //+ // The film's *gradient* is the one thing still built per size: it needs the+ // card's height, and rebuilding a shader every frame to catch a theme change+ // mid-card would be the wrong trade. A stale film on a changed card is a+ // faint wash in the old palette's direction, not a wrong colour — the fill,+ // the rim and every string inside are already correct by the lines below.+ basePaint.color = BASE+ rimPaint.color = RIMval shape = silhouette ?: buildSilhouette().also { silhouette = it }canvas.drawPath(shape, basePaint)canvas.drawPath(shape, filmPaint)@@ -672,21 +691,38 @@ object CardUi {const val OVERLAP = 2f/**- * Black, and nearly opaque. [Glass.CARD_SOLID] is the fill the- * settings card falls back to when the compositor refuses to blur- * behind it, which is permanently this card's situation — so it is- * the same value for the same reason, not a coincidence worth- * re-deciding. See the class KDoc on why not lower.+ * The card's base fill. [Glass.CARD_SOLID] is the fill the settings+ * card falls back to when the compositor refuses to blur behind it,+ * which is permanently this card's situation — so it is the same+ * value for the same reason, not a coincidence worth re-deciding.+ * See the class KDoc on why not lower.+ *+ * **A getter, and that is the fix for a real bug.** This was a plain+ * `val`, and a `val` in a `companion object` is evaluated exactly once,+ * when the class is first touched. So the card took whichever palette the+ * process happened to be in *then* and kept it for the life of the+ * process — through any number of theme changes and any number of new+ * cards. The symptom is one dark card sitting in the middle of a light+ * page, and it is worse than the "close it and open it again" limit the+ * other floating cards have: reopening could never fix this one, only+ * restarting the app could.*/- val BASE = Color.parseColor(Glass.CARD_SOLID)-- // Alpha in the low teens is the whole trick: high enough to lift- // the pane off what is behind it, low enough that the base colour- // still shows through, which is the only thing making it read as- // translucent rather than as grey paint.- val FILM_TOP = 0x2EFFFFFF- val FILM_BOTTOM = 0x0CFFFFFF- val RIM = 0x3DFFFFFF+ val BASE: Int get() = Color.parseColor(Glass.CARD_SOLID)++ // The glass. Alpha in the low teens is the whole trick: high enough to lift+ // the pane off what is behind it, low enough that the base colour still+ // shows through, which is the only thing making it read as translucent+ // rather than as grey paint.+ //+ // **White films on the dark card, black ones on the light card, and in the+ // same order** — because what a film means is *lifted*, and lifting a light+ // pane means nothing at the top and a shadow at the bottom. Inverting the+ // day values in place would shade the top of every card and light its+ // bottom, which is the one arrangement that reads as wrong at a glance.+ // Getters for the same reason [BASE] is one.+ val FILM_TOP: Int get() = if (Theme.night) 0x2EFFFFFF else 0x00FFFFFF+ val FILM_BOTTOM: Int get() = if (Theme.night) 0x0CFFFFFF else 0x24000000+ val RIM: Int get() = if (Theme.night) 0x3DFFFFFF else 0x24000000}}}diff --git a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.ktindex 73d7904..6663f01 100644--- a/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/FloatingWindowUi.kt@@ -278,6 +278,23 @@ class FloatingWindowUi(/** The ball's gesture vocabulary, pinned along the bottom of the full card. */private var tipsView: View? = null+ /**+ * The top bar's icon views, kept only so a theme change can re-tint them.+ *+ * `barButton` bakes its tint into a mutated drawable, so without this the bar+ * keeps whichever palette the *window* was built in — the whole chrome of the+ * card is built once and never again. That is how a light-mode grey ended up+ * sitting on a night-mode well: measured on the tablet as `#7D8592` glyphs on a+ * `#092E54` pill, which is a day value on a night ground.+ */+ private val barIcons = mutableListOf<ImageView>()++ /** The scene chip's ✕, for the same reason — its colour is set at build too. */+ private var sceneChipExit: TextView? = null++ /** The top bar's corner radius. One number: applied at build and on a theme change. */+ private val topBarRadius = dp(24)+// Folded into p.alpha / p.flags by [applyWindow]. Main thread only.private var captureHidden = falseprivate var compact = false@@ -908,6 +925,73 @@ class FloatingWindowUi(}}+ /**+ * The palette changed under us. See [Theme] for what sets it off and+ * [net.kuafuai.andee.BodyCoreService] for who calls this.+ *+ * A different job from [onLocaleChanged] in exactly one place: **the backdrop is a+ * decoded image rather than a colour read at build time.** [Backdrop.warm] is+ * one-shot by design, so the cached decode has to be dropped before the new+ * palette's file can be read at all — without that the card keeps the white wash+ * under the dark palette, which is the single most visible way to get a theme+ * switch wrong. Everything else is the same rebuild a language change is, so it is+ * the same calls.+ */+ fun onThemeChanged() {+ ui.post {+ Backdrop.reset()+ val bg = backdrop+ if (bg != null) {+ Backdrop.warm(context) { bmp ->+ bg.setImageBitmap(bmp)+ applyWindow()+ }+ }+ applyPaletteToChrome()+ historyView?.onThemeChanged()+ renderSceneChip()+ // The scrim is now the other palette's, and [paintCard] only pushes it when+ // it differs from what the image already carries.+ scrimShown = null+ applyWindow()+ }+ }++ /**+ * Re-colour the chrome that was built once and has no way of hearing about a theme+ * change on its own.+ *+ * **The cards rebuild; this bar does not.** [net.kuafuai.andee.ui.CardUi] and every+ * card are constructed on demand, so they pick up the new palette by existing.+ * The window's own chrome — built in [build] and never again — bakes its colours at+ * construction, which is a silent failure exactly once per control and shows up as+ * *one* unreadable element rather than as a broken screen. Both of the ones reported+ * from the tablet were this: a light-mode grey left on a night-mode well, and the+ * day ink left on the night photograph.+ *+ * The rule this is the last word on: **anything whose colour or fill is set at build+ * time in this class needs a line here.** The top bar's own `background` is the one+ * that proved it — it was missed twice, and what it looks like when it is missing is+ * a dark pill under correctly-tinted glyphs, which reads as a design choice rather+ * than as a stale value. If this list ever grows past a handful, the answer is to+ * rebuild the chrome rather than to keep enumerating it.+ */+ private fun applyPaletteToChrome() {+ val ink = Color.parseColor(Glass.PHOTO_INK)+ // The bar's own fill first, then the glyphs that sit on it. Both are colours+ // read at build; the fill is the one that has no way of looking wrong *and*+ // being noticed.+ topBarView?.background = Glass.well(context, topBarRadius)+ for (v in barIcons) v.setColorFilter(ink)+ // The tips sit on the photograph itself.+ (tipsView as? TextView)?.setTextColor(ink)+ // The scene chip is a well too, and its two labels are the card's greys.+ sceneChip?.background = Glass.well(context, dp(22))+ val soft = Color.parseColor(Glass.SECONDARY)+ sceneChipText?.setTextColor(soft)+ sceneChipExit?.setTextColor(soft)+ }+/*** The scene the assistant is in, by title, or null for none. Drawn only in* the full card — folded there is no room, and the corner ball is not where@@ -2260,7 +2344,10 @@ class FloatingWindowUi(val tips = TextView(context).apply {text = AppLocale.str(context, R.string.window_tips)textSize = Glass.Type.CAPTION- setTextColor(Color.parseColor(Glass.MUTED))+ // PHOTO_INK, not MUTED: this line sits on the photograph itself, and a+ // mid-grey has no contrast against a mid-tone ground — measured at roughly+ // 1:1, which is why it disappeared. See [Glass.PHOTO_INK].+ setTextColor(Color.parseColor(Glass.PHOTO_INK))gravity = Gravity.CENTER// The bottom padding clears the gesture bar, the same 30 dp the// scrollback's last row used to reserve for itself — this bar@@ -2320,6 +2407,9 @@ class FloatingWindowUi(Glass.pressable(this)setOnClickListener { listeners.onSceneExitClick() }layoutParams = LinearLayout.LayoutParams(dp(36), dp(36)).apply { leftMargin = dp(2) }+ // Kept for the same reason the bar's glyphs are: its colour is set right+ // here and nowhere else, so a theme change would otherwise leave it.+ sceneChipExit = this})}sceneChip = chip@@ -2375,8 +2465,11 @@ class FloatingWindowUi(* be managed by talking, but "what has it learned to do with me" is a* question a list answers better than a conversation. Five keys now.*- * All four keys are `Glass.LABEL` now rather than roughly half of them being- * dimmed: the dimmer ones were the drawer's contents and a folded `⋯`.+ * The glyphs take [Glass.PHOTO_INK], not one of the card's inks. They sit on+ * [Glass.well] over the photograph, which is the same ground the tips sit on, and a+ * colour chosen against a card has no contrast there: [Glass.MUTED] was what they+ * had, and on the light pill it came out around 1.4:1 — reported from the tablet as+ * "看不清", and it is arithmetic rather than taste.*/@SuppressLint("SetTextI18n")private fun buildTopBar(): View {@@ -2387,7 +2480,7 @@ class FloatingWindowUi(// A recessed well rather than a panel: this pill floats over a card// that is itself translucent, so its base has to be darker than// what it sits on or the glyphs read against the user's app.- background = Glass.well(context, dp(24))+ background = Glass.well(context, topBarRadius)}val keys = LinearLayout(context).apply {@@ -2396,21 +2489,21 @@ class FloatingWindowUi(}keys.addView(- barButton(R.drawable.ic_artifacts, Glass.MUTED, "产物") { listeners.onArtifactsClick() }+ barButton(R.drawable.ic_artifacts, Glass.PHOTO_INK, "产物") { listeners.onArtifactsClick() })- keys.addView(barButton(R.drawable.ic_scene, Glass.MUTED, "情景") { listeners.onScenesClick() })+ keys.addView(barButton(R.drawable.ic_scene, Glass.PHOTO_INK, "情景") { listeners.onScenesClick() })// ✓ and not ■: the stop button used to sit here, and stop is the one// action in this bar the ball can already perform — see onStopClick.- keys.addView(barButton(R.drawable.ic_check, Glass.MUTED, "自检") { listeners.onSelfCheckClick() })+ keys.addView(barButton(R.drawable.ic_check, Glass.PHOTO_INK, "自检") { listeners.onSelfCheckClick() })// No ⌨ here. Typing moved onto the ball's double-tap, and the bar is// the wrong place for it twice over: it only exists while the card is// unfolded (so the way to type vanished with the fold — the same fault// that made "点右上角的 ⌨" a lie in a failure message), and it put a// second meaning on the one control the user already had to learn.- keys.addView(barButton(R.drawable.ic_settings, Glass.MUTED, "设置") { listeners.onSettingsClick() })+ keys.addView(barButton(R.drawable.ic_settings, Glass.PHOTO_INK, "设置") { listeners.onSettingsClick() })// Reads as close, not as resize: the card is a thing you dismiss, and the// corner ball it folds into stays on screen either way.- keys.addView(barButton(R.drawable.ic_close, Glass.MUTED, "收起") { listeners.onMinimizeClick() })+ keys.addView(barButton(R.drawable.ic_close, Glass.PHOTO_INK, "收起") { listeners.onMinimizeClick() })bar.addView(keys)return bar@@ -2450,6 +2543,10 @@ class FloatingWindowUi(setTint(Color.parseColor(color))})+ // Kept so [applyPaletteToChrome] can re-tint it: the tint above is baked+ // into a mutated drawable at build time and nothing tells this view about a+ // theme change.+ barIcons += thisscaleType = ImageView.ScaleType.FIT_CENTERsetPadding(pad, pad, pad, pad)contentDescription = descriptiondiff --git a/app/src/main/java/net/kuafuai/andee/ui/Glass.kt b/app/src/main/java/net/kuafuai/andee/ui/Glass.ktindex ff9260a..167f0b5 100644--- a/app/src/main/java/net/kuafuai/andee/ui/Glass.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/Glass.kt@@ -84,78 +84,259 @@ import android.view.animation.PathInterpolatorobject Glass {// ---- Palette ----+ //+ // **Light.** The card is a white surface now, and every name below kept its+ // name through the change so the call sites did not have to move — what moved+ // is the direction each one leans.+ //+ // The old values were all "a white film over a near-black card": `#1FFFFFFF`+ // for a panel, `#2BFFFFFF` for an edge, `#FFFFFF` for a title. Not one of them+ // survives on white — a 6% white film over white *is* white. So each film is+ // now the same alpha in black, each text colour went from near-white to+ // near-black, and the three state colours were darkened until they carry on a+ // white field rather than glowing against a dark one.+ //+ // The exception is [TINT_START]/[TINT_END]: a saturated gradient reads on either+ // ground, and it is the one place colour is allowed to be loud.- /** The card's fill when [frost] got its blur: dark enough to read against. */- const val CARD_FROSTED = "#99000000"+ /**+ * The two palettes, behind one set of names.+ *+ * **Day is dark-on-light and night is light-on-dark, so most pairs are opposites**+ * — a film that is black at low alpha in one is white at low alpha in the other,+ * and near-black text becomes near-white. The night values are the ones this app+ * shipped with before the light card, name for name, so night is a look that was+ * already tuned on a tablet rather than a set of colours invented for a switch.+ *+ * **Three things are deliberately not a plain inversion**, because what they mean+ * is a position rather than a colour:+ * * [well] is *recessed* on both palettes — darker than what it sits on. A+ * mirrored day value would make every text field glow.+ * * [thumb] is *raised* on both — lighter than the well it slides in.+ * * [sheen] flips end for end rather than in place, because its job is a lit+ * edge and the direction the light comes from does not change with the theme.+ */+ private class Palette(+ val cardFrosted: String,+ val cardSolid: String,+ val hairline: String,+ val panel: String,+ val panelEdge: String,+ val glass: String,+ val glassEdge: String,+ val well: String,+ val wellEdge: String,+ val thumb: String,+ val thumbEdge: String,+ /** Gradient stops for [sheen], in the order the gradient runs: top to bottom. */+ val sheen: IntArray,+ val title: String,+ val label: String,+ val secondary: String,+ val muted: String,+ val photoInk: String,+ val accent: String,+ val danger: String,+ val ok: String,+ val warn: String,+ )- /** …and when it did not. Nearly opaque, because there is nothing to show. */- const val CARD_SOLID = "#F2060608"+ private fun stops(vararg hex: String): IntArray =+ IntArray(hex.size) { Color.parseColor(hex[it]) }++ private val DAY = Palette(+ cardFrosted = "#F2FFFFFF",+ cardSolid = "#FFFFFFFF",+ hairline = "#24000000",+ panel = "#0A000000",+ panelEdge = "#14000000",+ glass = "#0F000000",+ glassEdge = "#24000000",+ well = "#0D000000",+ wellEdge = "#1A000000",+ thumb = "#FFFFFFFF",+ thumbEdge = "#2E000000",+ sheen = stops("#1FFFFFFF", "#00FFFFFF", "#00FFFFFF", "#14000000"),+ title = "#0E1116",+ label = "#2B313B",+ secondary = "#5A6270",+ muted = "#7D8592",+ photoInk = "#252A33",+ accent = "#3B62E0",+ danger = "#DC2626",+ ok = "#16A34A",+ warn = "#D97706",+ )++ private val NIGHT = Palette(+ cardFrosted = "#99000000",+ cardSolid = "#F2060608",+ hairline = "#2BFFFFFF",+ panel = "#0FFFFFFF",+ panelEdge = "#17FFFFFF",+ glass = "#1FFFFFFF",+ glassEdge = "#38FFFFFF",+ well = "#59000000",+ wellEdge = "#1AFFFFFF",+ thumb = "#2EFFFFFF",+ thumbEdge = "#40FFFFFF",+ sheen = stops("#1FFFFFFF", "#00FFFFFF"),+ title = "#FFFFFF",+ label = "#DCE1EA",+ secondary = "#8F97A6",+ muted = "#5F6775",+ photoInk = "#98A0AE",+ accent = "#7FA5FF",+ danger = "#FF6B6B",+ ok = "#4ADE80",+ warn = "#FBBF24",+ )- /** The card's edge. The one place a bright hairline belongs. */- const val HAIRLINE = "#2BFFFFFF"+ /**+ * The palette in force, resolved on every access rather than cached — the theme+ * can change between two builds of what looks like the same view, which is the+ * entire reason [Theme.onChanged] exists.+ */+ private val active: Palette get() = if (Theme.night) NIGHT else DAY++ // ---- The names, as getters rather than constants ----+ //+ // Every call site still reads `Glass.TITLE`. What changed is *when* it is read:+ // a `const val` is inlined into its readers at compile time and therefore cannot+ // vary at runtime at all, which is the whole reason a theme switch could not be+ // added as a plain setting. Turning them into getters is what makes the switch+ // possible without touching forty call sites; the price is that the compiler no+ // longer folds them, which for a handful of `Color.parseColor` calls per card+ // build is nothing.+ //+ // ⚠️ The consequence to remember: **any `Glass.*` read is a read of whatever the+ // theme was when it ran**, so a view built before a change keeps the old colours+ // until it is rebuilt. Nothing may assume otherwise — every surface subscribes.++ /**+ * The card's fill when [frost] got its blur.+ *+ * Day is 95% rather than opaque, and the 5% is doing specific work: the card ends+ * up *lighter* than the page it sits on ([Backdrop]'s wash averages ~#F9FAFD), so+ * the pane reads as a raised surface and the wash underneath gives it something to+ * sit on. At 100% white the card and the page would be the same white and the card+ * would be a rectangle drawn in nothing. Night is the 60% black it always was,+ * over a photo.+ */+ val CARD_FROSTED: String get() = active.cardFrosted++ /** …and when it did not. Opaque, because there is nothing to show through it. */+ val CARD_SOLID: String get() = active.cardSolid++ /**+ * The card's edge. In day this is *the separation*, and the one piece of the iOS+ * material recipe that survives a white surface — see [sheen]. In night it is the+ * bright hairline the dark card was built around, which is the same job from the+ * other side.+ */+ val HAIRLINE: String get() = active.hairline/** A grouped surface sitting on the card. */- const val PANEL = "#0FFFFFFF"- const val PANEL_EDGE = "#17FFFFFF"+ val PANEL: String get() = active.panel+ val PANEL_EDGE: String get() = active.panelEdge/*** A card sitting on the blurred backdrop instead of on [PANEL].*- * [PANEL] cannot do this job: 6% white is the right film for a row group- * *inside* a 60%-black card and is invisible over the fullscreen backdrop,- * because those two surfaces have nothing in common — one is nearly opaque- * black, the other is a blurred photo at ~13% mean luma. This pair is the- * glassmorphism recipe proper, and the numbers are the balance that makes- * it read as a pane rather than as a hole: enough fill for [LABEL] and- * [SECONDARY] to sit on, enough edge and sheen to give the rectangle a lit- * top. See [glass].+ * [PANEL] cannot do this job: it is the right film for a row group *inside* a+ * card and too weak over the fullscreen backdrop, because those two surfaces have+ * nothing in common — one is a card, the other is whatever the backdrop is+ * painted with. This pair is the glassmorphism recipe proper, and the numbers are+ * the balance that makes it read as a pane rather than as a hole: enough fill for+ * [LABEL] and [SECONDARY] to sit on, enough edge and sheen to give the rectangle+ * a lit top. See [glass].*- * **Currently no caller.** It was written for the self-check page, which was- * a fullscreen surface on [net.kuafuai.andee.ui.Backdrop] with these rows on- * it for one day; that page is now a `Glass.card` opened from `✓` (see+ * **Currently no caller.** It was written for the self-check page, which was a+ * fullscreen surface on [net.kuafuai.andee.ui.Backdrop] with these rows on it for+ * one day; that page is now a `Glass.card` opened from `✓` (see* [net.kuafuai.andee.ui.SelfCheckUi]) and its rows are [PANEL], because a- * surface's fill is decided by what is directly underneath it and nothing- * else — 12% white on a 60%-black card is a grey box. The distinction is- * kept, rather than the two constants deleted, because the *fact* behind it- * has not gone anywhere: [Backdrop] is still what- * [net.kuafuai.andee.ui.TextInputActivity] and the launcher self-check host- * paint themselves with, and anything put on top of it needs this fill and- * not [PANEL].+ * surface's fill is decided by what is directly underneath it and nothing else.+ * The distinction is kept, rather than the two constants deleted, because the+ * *fact* behind it has not gone anywhere: [Backdrop] is still what+ * [net.kuafuai.andee.ui.TextInputActivity] and the launcher self-check host paint+ * themselves with, and anything put on top of it needs this fill and not [PANEL].*/- const val GLASS = "#1FFFFFFF"- const val GLASS_EDGE = "#38FFFFFF"-- /** Recessed: text fields and the track a segmented picker slides in. */- const val WELL = "#59000000"- const val WELL_EDGE = "#1AFFFFFF"+ val GLASS: String get() = active.glass+ val GLASS_EDGE: String get() = active.glassEdge- /** The pane that slides between segments. Lighter than what it sits on. */- const val THUMB = "#2EFFFFFF"- const val THUMB_EDGE = "#40FFFFFF"+ /**+ * Recessed: text fields and the track a segmented picker slides in.+ *+ * **Darker than what it sits on in both palettes** — 5% black on a white card, 35%+ * black on a dark one. Mirroring the day value instead would put a 35% *white*+ * film here and make every text field glow.+ */+ val WELL: String get() = active.well+ val WELL_EDGE: String get() = active.wellEdge- /** The highlight that makes a flat rectangle read as a pane of something. */- private const val SHEEN_TOP = "#1FFFFFFF"- private const val SHEEN_BOTTOM = "#00FFFFFF"+ /**+ * The pane that slides between segments: raised rather than recessed, so it is+ * *lighter* than the well it slides in on both palettes — pure white over day's+ * 5% black, 18% white over night's 35% black.+ */+ val THUMB: String get() = active.thumb+ val THUMB_EDGE: String get() = active.thumbEdge++ // The ramp. Day runs dark→light in this order, night runs light→dark. The two+ // light ends of day sit closer to the middle than an exact mirror of the night+ // values would put them: mirroring #5F6775 for contrast on white gives roughly+ // #98A0AD, a 2.2:1 grey — legible as a whisper of text and *not* legible as the+ // row of bar icons, which is what actually reads [MUTED] (`FloatingWindowUi.+ // barButton`). Light-on-dark forgives a low ratio; dark-on-light does not.+ val TITLE: String get() = active.title+ val LABEL: String get() = active.label+ val SECONDARY: String get() = active.secondary+ val MUTED: String get() = active.muted- const val TITLE = "#FFFFFF"- const val LABEL = "#DCE1EA"- const val SECONDARY = "#8F97A6"- const val MUTED = "#5F6775"+ /**+ * Ink for things that sit **on the backdrop photograph, or on a well over it** rather+ * than on a card: the gesture tips along the bottom of the full card, and the top+ * bar's five icons.+ *+ * **The value is bracketed by two measured failures, and both are worth knowing+ * before moving it.** [MUTED] is what these two had, and it is chosen against a+ * card — white in day, near-black at night — so on a photograph it has no ground to+ * stand on: measured **1.4:1**, reported from the tablet as 看不清. Moving to the+ * other end of the ramp fixed the legibility and overshot it: near-black on the light+ * page's mid-blue sky measured **6:1** and read as a lump, reported as 太突兀.+ *+ * So this is the middle of the ramp — about **3:1** against either ground, which is+ * the threshold for *graphics* rather than for body text, and these callers are large+ * solid glyphs and one small caption rather than prose. Both ends of the ramp fail on+ * an image, at opposite extremes, and there is no setting that is both quiet and+ * legible on a background whose brightness is somebody else's photograph.+ *+ * The rule to carry: **a colour chosen against a known ground has no guarantee once+ * the ground is an image.** Anything else landing directly on the photograph takes+ * this token and not one of the card's.+ */+ val PHOTO_INK: String get() = active.photoInk/** Section headings and anything tappable that is only text. */- const val ACCENT = "#7FA5FF"+ val ACCENT: String get() = active.accent- /** The primary button is a gradient, which is the one place colour is loud. */+ /**+ * The primary button is a gradient, which is the one place colour is loud.+ *+ * The only two colours here that are **not** theme-dependent: a saturated+ * blue-to-violet gradient with white text on it reads on a white card and on a+ * dark one, and it is what makes the button the loudest thing on either.+ */const val TINT_START = "#4C6FFF"const val TINT_END = "#8250FF"- const val DANGER = "#FF6B6B"+ val DANGER: String get() = active.danger/** Done, granted, reachable — the self-check's green and nothing else's. */- const val OK = "#4ADE80"+ val OK: String get() = active.ok/** Works, but degrades silently. */- const val WARN = "#FBBF24"+ val WARN: String get() = active.warn// ---- Type ----@@ -346,12 +527,24 @@ object Glass {LayerDrawable(arrayOf(base, sheen(radius)))/**- * A white gradient fading out downward. It is what separates "a rectangle- * filled with 6% white" from something that looks lit from above.+ * The shading that makes a flat rectangle read as a solid: `TOP_BOTTOM`, from+ * [Palette.sheen].+ *+ * **The one gradient whose direction belongs to the theme rather than to its+ * colour.** Light comes from above on both, so the *top* is the lit end on both —+ * but "lit" means opposite things: on the dark card it is a white film fading+ * downward to nothing, and on the white card it is a bright top that is mostly+ * invisible, followed by a shadow along the bottom. Inverting the day stops in+ * place instead of reversing them would shade the top of every surface and leave+ * its bottom lit, which is the one arrangement that reads as wrong at a glance+ * without being nameable.+ *+ * Day's empty middle is deliberate. A gradient tinted end to end turns the card+ * into a sheet of grey with a light top, which is what a light card must not be.*/private fun sheen(radius: Int): Drawable = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,- intArrayOf(Color.parseColor(SHEEN_TOP), Color.parseColor(SHEEN_BOTTOM)),+ active.sheen,).apply { cornerRadius = radius.toFloat() }// ---- Card motion ----diff --git a/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt b/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.ktindex e325b6f..ef82072 100644--- a/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/HistoryListView.kt@@ -345,6 +345,16 @@ class HistoryListView(private val context: Context) : ScrollView(context) {refresh()}+ /**+ * The palette changed.+ *+ * The same job as [onLocaleChanged], and aliased to it rather than renamed so+ * each caller reads for its own cause: every row here is built from [Glass] and+ * from resources at the moment it is added, so a change to either means the list+ * has to be thrown away and rebuilt rather than relabelled in place.+ */+ fun onThemeChanged() = onLocaleChanged()+/*** The empty state's offer: one line inviting the user in, then a pane per* ready-made scene, showing the scene's **title** over what it actually@@ -457,7 +467,7 @@ class HistoryListView(private val context: Context) : ScrollView(context) {setPadding(dp(16), dp(12), dp(16), dp(12))isClickable = truebackground = RippleDrawable(- ColorStateList.valueOf(RIPPLE),+ ColorStateList.valueOf(ripple()),Glass.well(context, dp(18)),null,)@@ -545,7 +555,7 @@ class HistoryListView(private val context: Context) : ScrollView(context) {if (e.role == ChatHistory.Role.PAGE && e.page != null) {bubble.isClickable = truebubble.background = RippleDrawable(- ColorStateList.valueOf(RIPPLE),+ ColorStateList.valueOf(ripple()),glass(false, false),null,)@@ -652,20 +662,19 @@ class HistoryListView(private val context: Context) : ScrollView(context) {private fun glass(mine: Boolean, bad: Boolean = false): GradientDrawable = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,when {- bad -> intArrayOf(TINT_TOP_BAD, TINT_BOTTOM_BAD)- mine -> intArrayOf(TINT_TOP_MINE, TINT_BOTTOM_MINE)- else -> intArrayOf(TINT_TOP, TINT_BOTTOM)+ bad -> intArrayOf(tintTopBad(), tintBottomBad())+ mine -> intArrayOf(tintTopMine(), tintBottomMine())+ else -> intArrayOf(tintTop(), tintBottom())},).apply {+ // No `setStroke`: bubbles have no border in either palette, and the note above+ // the tint functions is where that argument lives. One thing worth keeping from+ // the border's history — when there *was* one it had to be a whole dp. The half+ // it started as, `max(1, dp(1) / 2)`, resolves to ONE physical pixel at this+ // density, 0.44 dp, which is below the width at which an edge is visible at all:+ // the card spent a while with a border that existed in the source and nowhere on+ // the screen, and the same trap is waiting for whatever is drawn here next.cornerRadius = dp(18).toFloat()- setStroke(- Math.max(1, dp(1) / 2),- when {- bad -> EDGE_BAD- mine -> EDGE_MINE- else -> EDGE- },- )}private fun dp(v: Int): Int = (v * resources.displayMetrics.density).toInt()@@ -686,23 +695,65 @@ class HistoryListView(private val context: Context) : ScrollView(context) {fun film(hex: String, alpha: Int): Int =(alpha shl 24) or (Color.parseColor(hex) and 0x00FFFFFF)- // Alpha in the low teens is the whole trick: high enough to lift the- // pane off the card, low enough that the card's colour still shows- // through it, which is the only thing making it read as translucent.- // These three are the neutral pane and match Glass's panel family.- val TINT_TOP = Color.parseColor("#1FFFFFFF")- val TINT_BOTTOM = Color.parseColor("#0FFFFFFF")- val EDGE = Color.parseColor("#2EFFFFFF")-- val TINT_TOP_MINE = film(Glass.ACCENT, 0x2C)- val TINT_BOTTOM_MINE = film(Glass.ACCENT, 0x14)- val EDGE_MINE = film(Glass.ACCENT, 0x40)-- val TINT_TOP_BAD = film(Glass.DANGER, 0x2C)- val TINT_BOTTOM_BAD = film(Glass.DANGER, 0x14)- val EDGE_BAD = film(Glass.DANGER, 0x4D)+ // ---- Bubble material, per palette ----+ //+ // Functions rather than values, because a bubble takes its colours from+ // whatever the theme is *when its row is built*, and rows are rebuilt on a+ // theme change (see [onThemeChanged]). A cached pair would freeze whichever+ // palette the process happened to draw its first bubble in.+ //+ // **The rule that survives both palettes: the top of a bubble is the LIGHTER+ // end.** On the dark card the films were white, so "heavy at the top" *was*+ // lighter at the top; on the white card the films are black and the same pair+ // has to be written the other way round. Getting it backwards shades every+ // bubble from below, and a surface lit from below reads as a flat band however+ // carefully its fill is chosen — the one mistake here that is invisible in the+ // source and obvious on the screen.+ //+ // Day's numbers are also raised from the low teens: at 6–12% over a white+ // card, on a bubble that spans the full width (see [buildRow] for why it+ // does), there was not enough fill for it to read as a surface rather than as+ // a band of slightly-off white.+ private const val NEUTRAL_TOP_DAY = "#14000000"+ private const val NEUTRAL_BOTTOM_DAY = "#29000000"+ private const val NEUTRAL_TOP_NIGHT = "#1FFFFFFF"+ private const val NEUTRAL_BOTTOM_NIGHT = "#0FFFFFFF"++ private fun pick(day: String, night: String): Int =+ Color.parseColor(if (Theme.night) night else day)++ fun tintTop(): Int = pick(NEUTRAL_TOP_DAY, NEUTRAL_TOP_NIGHT)+ fun tintBottom(): Int = pick(NEUTRAL_BOTTOM_DAY, NEUTRAL_BOTTOM_NIGHT)++ // The accent and the danger colour need more of it than the neutral does: a+ // hue at an alpha is denser at the heavy end, so these run 10% → 20% by day+ // where the neutral runs 8% → 16%. Night is the pair this app shipped with.+ fun tintTopMine(): Int = film(Glass.ACCENT, if (Theme.night) 0x2C else 0x1A)+ fun tintBottomMine(): Int = film(Glass.ACCENT, if (Theme.night) 0x14 else 0x33)++ fun tintTopBad(): Int = film(Glass.DANGER, if (Theme.night) 0x2C else 0x1A)+ fun tintBottomBad(): Int = film(Glass.DANGER, if (Theme.night) 0x14 else 0x33)++ // ---- No borders, in either palette ----+ //+ // There used to be three here, one per row kind, and they were tried in both+ // directions: a dark 1 dp line on the light card, a white one on the dark card.+ // **Both read as a drawn box**, which is what "看着比较 low" was about — an+ // outline round every row makes a table cell out of a message, and once the page+ // became a photograph the light one looked like a rectangle drawn on the picture.+ //+ // A bubble is defined by its fill and its gradient alone, which is all an iOS+ // bubble relies on, and the fills do separate: the rows are 4–20% films over a+ // backdrop the palette already controls. Nothing here is waiting for a border to+ // come back — if one ever does, it belongs to the palette as a named constant+ // rather than to a per-row `when`./** The tap on a page row, in the accent it is labelled with. */- val RIPPLE = film(Glass.ACCENT, 0x33)+ /**+ * The press ripple, in the accent. A function for the same reason the tints+ * are: [Glass.ACCENT] is a different colour in each palette, and a value+ * computed at class-load would ripple in whichever one was in force then.+ */+ fun ripple(): Int = film(Glass.ACCENT, 0x33)}}diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.ktindex af26e81..94dee14 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt@@ -189,6 +189,12 @@ class SelfCheckActivity : StageActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)+ // The saved palette, before the first view this page draws. The service loads+ // it too, but this page is reachable from the launcher, so on a cold start+ // nothing guarantees the service's own [Theme.load] has run yet — and [Theme]+ // holds the *default* until then rather than the user's answer.+ Theme.load(this)+// The notification's 允许看屏幕 action lands here — see// [requestScreenCapture]. Asked before the branch below, because the// point of the action is that the page it opens is a means to an end.diff --git a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.ktindex 8f44587..ff7f1ce 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SettingsUi.kt@@ -360,7 +360,10 @@ class SettingsUi(// the credentials it can spend. 大脑 stays first because it is the one// setting that changes what the rest of the card means.brainSection(form)- expressionsSection(form)+ // 外观 is the only appearance setting left up here: 形象与表情 moved into 高级,+ // so the "these two are the same kind of setting" argument went with it. What is+ // left in 常用 is what a person opens settings to change.+ themeSection(form)wakeSection(form)notebookSection(form)notifySection(form)@@ -425,6 +428,10 @@ class SettingsUi(// 火山 (the voice section) used to live here. It is now a sub-panel// of 后端 → 本机, so a user looking for its rows finds them next to// the backend they belong to — see [brainSection].+ // 形象与表情, moved down here from 常用. It is a door rather than a setting —+ // see [expressionsSection] — and a door that most users never open belongs+ // behind the disclosure rather than in the column everyone scrolls.+ expressionsSection(body)showHubSection(body)typingSection(body)diagnosticsSection(body)@@ -692,11 +699,52 @@ class SettingsUi(applyThinking(thinking, false)}+ /**+ * 浅色 / 深色 — which of [Glass]'s two palettes the whole app draws with.+ *+ * **Eager, like the language picker and for the same reason**: the redraw *is* the+ * confirmation, and routing this through 保存 would mean the card you are looking+ * at is the one thing that does not change until you leave it.+ *+ * [Theme.set] is what does the work, and it reaches every live surface itself —+ * see its note on [Theme.onChanged]. All this has to do is move its own picker,+ * which [rebuild] handles.+ *+ * Not in [picks]: it is already on disk by the time [rebuild] runs, the same+ * arrangement [langPicker] has.+ */+ private fun themeSection(form: LinearLayout) {+ val panel = group(+ form,+ lctx.getString(R.string.settings_section_theme),+ lctx.getString(R.string.settings_theme_note),+ )+ val row = segments(+ options = listOf(+ Theme.DAY to lctx.getString(R.string.settings_theme_day),+ Theme.NIGHT to lctx.getString(R.string.settings_theme_night),+ ),+ picked = if (Theme.night) Theme.NIGHT else Theme.DAY,+ radius = dp(13),+ ) { v ->+ Theme.set(context, v == Theme.NIGHT)+ rebuild()+ }+ panel.addView(row, rowParams(dp(7)))+ }+/*** The door to [ExpressionsUi]. Nothing is edited here — the card it opens is* where a look is picked and where every expression can be tried — so the* section is a sentence and one button, like [vaultSection]'s door, and the* look picked inside is saved the moment it is picked rather than on 保存.+ *+ * Called from [advancedSection] rather than from the form's own list, which is+ * where it used to be. The argument for moving it is in the name: it is a door,+ * and what it opens is a card for *trying* looks rather than for setting+ * anything. 常用 is the column a person scrolls looking for a knob; a door they+ * open once should not be in it. Its body is unchanged — it takes its parent and+ * draws the same section — so the only thing that moved is who calls it.*/private fun expressionsSection(form: LinearLayout) {val panel = group(form, lctx.getString(R.string.settings_section_expr))diff --git a/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.ktindex 1597a44..f124fb4 100644--- a/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/TextInputActivity.kt@@ -129,6 +129,9 @@ class TextInputActivity : Activity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)+ // Before the first `Glass.*` read below: [Theme] holds the *default* palette+ // until something loads the saved one, and this page draws immediately.+ Theme.load(this)lctx = AppLocale.wrap(this)field = EditText(this).apply {@@ -182,24 +185,31 @@ class TextInputActivity : Activity() {strip = LinearLayout(this).apply {orientation = LinearLayout.VERTICAL- // The *card* fill, not `Glass.panel`.+ // **No fill, and that is the whole point.**//- // `Glass` is a two-layer stack: an almost-opaque black base, then- // white at low alpha on top of it. `panel` is the second layer —- // 6% white — and it is only ever correct *on top of a card*.- // Standing alone over somebody else's app it draws nothing at all,- // and the field's own background came out as whatever was behind- // it: measured over a white page, mean RGB 255,255,255 with- // `Glass.TITLE` white text on it. Contrast 0. That is the "输入框- // 是透明的" this replaces — not a matter of taste, arithmetic.+ // This strip used to paint `Glass.card(frosted = false)` — a near-opaque+ // slate — and the argument for it was real at the time. Read it, because+ // the argument still holds and what changed is underneath: the strip stands+ // over whatever app is behind, 6% white over a white document is nothing,+ // and there is no blur to lean on (`Glass.frost` blurs behind a *window*,+ // and this window is the whole screen). So the strip got the base fill and+ // the field's own translucency went to work on an opaque wall.//- // So this strip gets the base. It has to stay readable over *any*- // backdrop, a white document and a night-mode terminal alike, and- // there is no blur to lean on: `Glass.frost` blurs behind a window,- // and this window is the whole screen (only this strip is painted),- // so asking for it would defocus everything the user was looking- // at. A dark bar over the bottom edge is the honest answer.- background = Glass.card(this@TextInputActivity, dp(20), frosted = false)+ // **A translucent field on an opaque bar is a flat grey rectangle.** That+ // is what "the input box has no glass" was, and no alpha on the field could+ // have fixed it. What did change is that this window now paints [Backdrop]+ // itself (see below), so the surface behind this bar is *ours*: a known+ // blue wash rather than somebody's home screen. Nothing needs to be walled+ // off any more, so the strip gets out of the way and the field is left with+ // the thing it can actually be frosted against — the page. `Glass.well`'s+ // 5% / 35% now shows the wash's gradient through the box, which is the+ // effect this was asked for.+ //+ // The pre-warm window is still covered: the fill behind the backdrop image+ // is the same slate this line used to paint, so a field opened in the first+ // few hundred milliseconds gets a continuous surface rather than the+ // desktop. Same arrangement as before, one layer down.+ setPadding(dp(8), dp(8), dp(8), dp(8))setPadding(dp(8), dp(8), dp(8), dp(8))addView(thumbScroll, LinearLayout.LayoutParams(MATCH_PARENT, WRAP))addView(row, LinearLayout.LayoutParams(MATCH_PARENT, WRAP))diff --git a/app/src/main/java/net/kuafuai/andee/ui/Theme.kt b/app/src/main/java/net/kuafuai/andee/ui/Theme.ktnew file mode 100644index 0000000..c472632--- /dev/null+++ b/app/src/main/java/net/kuafuai/andee/ui/Theme.kt@@ -0,0 +1,92 @@+package net.kuafuai.andee.ui++import android.content.Context+import net.kuafuai.andee.config.VoiceConfig++/**+ * Which of [Glass]'s two palettes everything is drawing with, and how a change+ * reaches what is already on screen.+ *+ * **Why a process-global flag rather than a palette handed around with a Context.**+ * [Glass]'s colours are read as bare names from about forty call sites —+ * `Color.parseColor(Glass.LABEL)` inside view builders, most of them several frames+ * away from anything that has a Context to consult. Threading a Context (or a+ * palette) through all of them to answer a question whose answer is the same for the+ * whole process would be a change to every UI file to buy nothing. So the palette+ * resolves a flag, and the flag is set here.+ *+ * **The price of that choice is the thing to be careful about:** a `Glass.*` read is+ * a read of whatever the theme was *when it ran*. A view built before a change keeps+ * the old colours until it is rebuilt. That is why [set] fires [onChanged] rather+ * than leaving callers to remember — nobody flips this and hopes.+ *+ * Shaped after [net.kuafuai.andee.i18n.AppLocale], which solves the same problem for+ * the language and for the same reason: almost no UI here lives in an Activity, so no+ * system mechanism can reach it. `values-night/` resources and+ * `AppCompatDelegate.setDefaultNightMode` both rebuild Activities; the ball, the+ * card, the signboards and the settings sheet are `WindowManager` overlays owned by a+ * `Service` and would keep the old palette until something happened to rebuild them.+ * A theme is a setting here in exactly the way the language is, including that it+ * outranks the system.+ */+object Theme {++ /**+ * The two values the picker, the prefs and [set] agree on.+ *+ * [NIGHT] is the string that goes to disk; [DEVICE] is deliberately absent, because+ * following the system would need a reload on every configuration change in a+ * process whose UI is a Service overlay — see the class note. Light and dark are+ * the whole vocabulary.+ */+ const val DAY = "day"+ const val NIGHT = "night"++ /**+ * The state of the switch. Set by [load] and [set]; read by [Glass].+ *+ * **Initialised to night, because night is the default**+ * ([VoiceConfig.nightTheme]). [load] is what makes that true from the saved+ * preference, but this value is the one that must not be *wrong* in the window+ * between process start and the service's first line: a surface drawn there would+ * otherwise be light on a device whose answer is dark, and then flip.+ */+ @Volatile+ var night: Boolean = true+ private set++ /**+ * Told after every change, on the thread that made it.+ *+ * One listener rather than a list, because there is exactly one owner of the live+ * UI — [net.kuafuai.andee.BodyCoreService]; a list would be an invitation for a+ * card to register itself and never unregister.+ */+ @Volatile+ var onChanged: (() -> Unit)? = null++ /**+ * Adopt the saved preference.+ *+ * Call once and **before the first view is built** — this is the only thing that+ * decides what colour a surface created in the next frame will be, and a service+ * that reads it late is a service whose first card is in the other theme.+ */+ fun load(context: Context) {+ night = VoiceConfig.nightTheme(context)+ }++ /**+ * Save, adopt, and tell everyone.+ *+ * A no-op when the answer has not changed, so the picker can call it blindly on+ * every tap without writing the same value twice — the eager-write pattern+ * [VoiceConfig.uiLanguage] uses for exactly the same reason.+ */+ fun set(context: Context, wantNight: Boolean) {+ if (wantNight == night) return+ VoiceConfig.save(context, mapOf("theme" to if (wantNight) "night" else "day"))+ night = wantNight+ onChanged?.invoke()+ }+}diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xmlindex dc7ea29..bd7d43f 100644--- a/app/src/main/res/values-en/strings.xml+++ b/app/src/main/res/values-en/strings.xml@@ -523,6 +523,13 @@<string name="ball_look_imp">Imp</string><!-- The expressions screen: the entry in settings, and the card that shows them all -->+ <!-- Appearance: light / dark. The switch takes effect at once (see ui.Theme), so the+ note says what it reaches rather than what it is. -->+ <string name="settings_section_theme">Appearance</string>+ <string name="settings_theme_note">Light is a white card with dark text; dark is a dark card with light text. It switches at once — card, pages, bubbles and everything around the ball together.</string>+ <string name="settings_theme_day">Light</string>+ <string name="settings_theme_night">Dark</string>+<string name="settings_section_expr">Looks & expressions</string><string name="settings_expr_note">See every character and every expression; tap one to switch.</string><string name="settings_expr_open">Open</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex ef2a3db..2352431 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -603,6 +603,12 @@<string name="ball_look_imp">小恶魔</string><!-- 表情页:设置里"表情"一节的入口,以及那张看所有表情的卡片 -->+ <!-- 外观:浅色 / 深色。切换是立刻生效的(见 ui.Theme),所以说明里要讲清它管到哪儿 -->+ <string name="settings_section_theme">外观</string>+ <string name="settings_theme_note">浅色是白底深字,深色是深底浅字。点一下立刻换,卡片、页面、气泡和小球周围一起变。</string>+ <string name="settings_theme_day">浅色</string>+ <string name="settings_theme_night">深色</string>+<string name="settings_section_expr">形象与表情</string><string name="settings_expr_note">看看每个形象和每个表情,点一下就换。</string><string name="settings_expr_open">打开</string>