Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat: Enhance appearance settings with new action and update theme handling

Durganshu Mishra9fbd90231130
diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml
index 52f594a..fce2438 100644
--- a/app/src/debug/AndroidManifest.xml
+++ b/app/src/debug/AndroidManifest.xml
@@ -11,6 +11,7 @@
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.gotcha.debug.SEED_SETTINGS" />
+ <action android:name="com.gotcha.debug.SET_APPEARANCE" />
</intent-filter>
</receiver>
</application>
diff --git a/app/src/debug/java/com/gotcha/debug/TestHooksReceiver.kt b/app/src/debug/java/com/gotcha/debug/TestHooksReceiver.kt
index d9c493a..f22e265 100644
--- a/app/src/debug/java/com/gotcha/debug/TestHooksReceiver.kt
+++ b/app/src/debug/java/com/gotcha/debug/TestHooksReceiver.kt
@@ -3,6 +3,7 @@ package com.gotcha.debug
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
+import android.util.Log
import com.gotcha.MainActivity
import com.gotcha.data.LlmProvider
import com.gotcha.data.Settings
@@ -23,8 +24,41 @@ import com.gotcha.data.SettingsRepository
class TestHooksReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
- if (intent.action != ACTION_SEED_SETTINGS) return
+ when (intent.action) {
+ ACTION_SEED_SETTINGS -> seedSettings(context, intent)
+ ACTION_SET_APPEARANCE -> setAppearance(context, intent)
+ }
+ }
+
+ /**
+ * Sets the theme from adb, and logs what the app will actually paint.
+ *
+ * Appearance bugs are hard to tell apart from the outside: a skin whose
+ * wallpaper is missing and a skin the device has quietly downgraded to solid
+ * panels look identical in a screenshot. This makes the inputs settable and
+ * the resolved state readable without driving the UI.
+ */
+ private fun setAppearance(context: Context, intent: Intent) {
+ val repository = SettingsRepository(context)
+ val current = repository.load()
+ val updated = current.copy(
+ skinId = intent.getStringExtra(EXTRA_SKIN) ?: current.skinId,
+ reduceTransparency = intent.getBooleanExtra(
+ EXTRA_REDUCE_TRANSPARENCY,
+ current.reduceTransparency
+ ),
+ frostPercent = intent.getIntExtra(EXTRA_FROST, current.frostPercent)
+ )
+ repository.save(updated)
+ Log.i(
+ TAG,
+ "appearance: skin=${updated.skinId} " +
+ "reduceTransparency=${updated.reduceTransparency} " +
+ "frost=${updated.frostPercent}"
+ )
+ }
+ private fun seedSettings(context: Context, intent: Intent) {
val repository = SettingsRepository(context)
val current = repository.load()
repository.save(
@@ -47,7 +81,12 @@ class TestHooksReceiver : BroadcastReceiver() {
}
companion object {
+ private const val TAG = "GotchaTestHooks"
const val ACTION_SEED_SETTINGS = "com.gotcha.debug.SEED_SETTINGS"
+ const val ACTION_SET_APPEARANCE = "com.gotcha.debug.SET_APPEARANCE"
+ const val EXTRA_SKIN = "skin"
+ const val EXTRA_REDUCE_TRANSPARENCY = "reduce_transparency"
+ const val EXTRA_FROST = "frost"
const val EXTRA_BASE_URL = "base_url"
const val EXTRA_API_KEY = "api_key"
const val EXTRA_MODEL = "model"
diff --git a/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt b/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
index 831fe3a..0b12a66 100644
--- a/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/AppearanceScreen.kt
@@ -142,9 +142,9 @@ fun AppearanceScreen(
/** Says what this device is actually doing, rather than what the theme wishes it did. */
private fun tierExplanation(tier: GlassTier, reduceTransparency: Boolean): String = when {
- reduceTransparency -> "Panels are solid and no wallpaper is drawn. Colours are unchanged."
+ tier == GlassTier.SOLID -> "Battery saver is on, so the theme is drawn flat until it's off."
+ reduceTransparency -> "Panels are solid. The theme keeps its colour and texture."
tier == GlassTier.LIVE -> "Panels blur what's behind them."
- tier == GlassTier.SOLID -> "Battery saver is on, so panels are solid until it's off."
else -> "Live blur isn't available on this device, so panels use a fixed frost."
}
diff --git a/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt b/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt
index 5913bb8..69f9dde 100644
--- a/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt
@@ -4,13 +4,13 @@ import android.graphics.Bitmap
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.graphics.BlendMode
+import androidx.compose.ui.geometry.center
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
@@ -20,7 +20,10 @@ import androidx.compose.ui.graphics.ShaderBrush
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.drawscope.DrawScope
+import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.unit.dp
+import kotlin.math.abs
+import kotlin.math.hypot
import kotlin.random.Random
/**
@@ -39,8 +42,9 @@ fun SkinBackdrop(modifier: Modifier = Modifier) {
val skin = LocalSkin.current
val tier = LocalGlassTier.current
// An opaque skin paints its own background through the colour scheme; drawing
- // a second ground under it would only cost a full-screen fill.
- if (!skin.isGlass || tier == GlassTier.SOLID) return
+ // a second ground under it would only cost a full-screen fill. Whether the
+ // skin still has a wallpaper at this tier was already decided in GotchaTheme.
+ if (!skin.isGlass) return
Box(modifier.background(skin.ground)) {
Wallpaper(skin, live = tier == GlassTier.LIVE)
@@ -50,16 +54,16 @@ fun SkinBackdrop(modifier: Modifier = Modifier) {
}
@Composable
-private fun BoxScope.Wallpaper(skin: Skin, live: Boolean) {
+private fun Wallpaper(skin: Skin, live: Boolean) {
val canvas = Modifier
- .matchParentSize()
+ .fillMaxSize()
.let { if (live && skin.frost > 0.dp) it.blur(skin.frost) else it }
when (skin.backdrop) {
Backdrop.FOG -> Canvas(canvas) { drawFog(skin.wallpaper) }
Backdrop.FACETS -> Canvas(canvas) { drawFacets(skin.wallpaper) }
- // FLAT is the ground and the grain, nothing else — that is the point of it.
- Backdrop.FLAT, Backdrop.NONE -> Unit
+ Backdrop.FLAT -> Canvas(canvas) { drawTint() }
+ Backdrop.NONE -> Unit
}
}
@@ -70,10 +74,18 @@ private fun BoxScope.Wallpaper(skin: Skin, live: Boolean) {
*/
@Composable
fun SkinMiniature(skin: Skin, modifier: Modifier = Modifier) {
- Box(modifier.background(skin.ground)) {
- Wallpaper(skin, live = false)
- if (skin.grain > 0f) Grain(skin.grain)
- Scrim(skin)
+ // Shown as it will actually render on this device and at these settings. A
+ // preview that keeps its wallpaper while the app has dropped it is a picker
+ // promising something the app then does not do.
+ val shown = when (LocalGlassTier.current) {
+ GlassTier.SOLID -> skin.opaque()
+ GlassTier.OPAQUE -> skin.opaquePanels()
+ GlassTier.LIVE, GlassTier.STATIC -> skin
+ }
+ Box(modifier.background(shown.ground)) {
+ Wallpaper(shown, live = false)
+ if (shown.grain > 0f) Grain(shown.grain)
+ Scrim(shown)
}
}
@@ -83,15 +95,40 @@ fun SkinMiniature(skin: Skin, modifier: Modifier = Modifier) {
* rather than against whatever the gradient happened to be doing there.
*/
@Composable
-private fun BoxScope.Scrim(skin: Skin) {
+private fun Scrim(skin: Skin) {
if (skin.scrim <= 0f) return
Box(
Modifier
- .matchParentSize()
+ .fillMaxSize()
.background(skin.ground.copy(alpha = skin.scrim))
)
}
+/**
+ * A tinted ground with somewhere for the light to come from.
+ *
+ * One flat fill is not a tint, it is a wash — which is exactly what it looked
+ * like. The hue is untouched; a wide highlight off the top-left and a vignette
+ * into the corners give it a direction and an edge, and the grain on top gives
+ * it a surface.
+ */
+private fun DrawScope.drawTint() {
+ drawRect(
+ brush = Brush.radialGradient(
+ colors = listOf(Color.White.copy(alpha = 0.22f), Color.Transparent),
+ center = Offset(size.width * 0.16f, size.height * 0.08f),
+ radius = maxOf(size.width, size.height)
+ )
+ )
+ drawRect(
+ brush = Brush.radialGradient(
+ colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.38f)),
+ center = size.center,
+ radius = hypot(size.width, size.height) * 0.60f
+ )
+ )
+}
+
/** Where the fog sits, in fractions of the screen, and how far each one reaches. */
private val FogSpots = listOf(
Offset(0.22f, 0.14f) to 0.78f,
@@ -159,20 +196,43 @@ private fun DrawScope.drawFacets(stops: List<Color>) {
* a no-op — only the deviation shows, which is what keeps a flat ground from
* looking like an empty `<div>`.
*/
+/**
+ * Film grain.
+ *
+ * Two things were wrong with the first version. It was drawn at one device
+ * pixel per cell, which on a 3x screen averages out to nothing before it
+ * reaches the eye; and it was opaque mid-grey relying on an Overlay blend,
+ * which — where the blend is not honoured — lays a grey wash over the ground
+ * and desaturates it. Orchid's violet measured (126,31,136) and rendered
+ * (126,63,133): the same hue with the life drained out of it.
+ *
+ * So: the deviation lives in the alpha channel, which composites correctly
+ * everywhere, and each cell is scaled up to [GRAIN_CELL_PX] so there is
+ * something to see. White is capped lower than black because lifting a
+ * saturated colour toward white costs more saturation than dropping it
+ * toward black, which scales all three channels evenly and holds the hue.
+ */
@Composable
-private fun BoxScope.Grain(opacity: Float) {
+private fun Grain(opacity: Float) {
val noise = remember { noiseTile() }
val brush = remember(noise) {
ShaderBrush(ImageShader(noise, TileMode.Repeated, TileMode.Repeated))
}
- Canvas(Modifier.matchParentSize()) {
- drawRect(brush = brush, alpha = opacity, blendMode = BlendMode.Overlay)
+ Canvas(Modifier.fillMaxSize()) {
+ scale(GRAIN_CELL_PX, GRAIN_CELL_PX, pivot = Offset.Zero) {
+ drawRect(brush = brush, alpha = opacity)
+ }
}
}
private const val NOISE_TILE_PX = 128
-private const val NOISE_MID = 128
-private const val NOISE_SPREAD = 42
+
+/** Device pixels per grain cell. Below about 3 the texture stops being visible. */
+private const val GRAIN_CELL_PX = 4f
+
+/** Ceilings on how far one cell may push the ground, out of 255. */
+private const val NOISE_WHITE_MAX = 110
+private const val NOISE_BLACK_MAX = 200
/** Fixed seed: the grain is part of the design, so it should not re-roll per launch. */
private const val NOISE_SEED = 0x6074CA
@@ -180,8 +240,12 @@ private const val NOISE_SEED = 0x6074CA
private fun noiseTile(): ImageBitmap {
val random = Random(NOISE_SEED)
val pixels = IntArray(NOISE_TILE_PX * NOISE_TILE_PX) {
- val v = (NOISE_MID + random.nextInt(-NOISE_SPREAD, NOISE_SPREAD)).coerceIn(0, 255)
- (0xFF shl 24) or (v shl 16) or (v shl 8) or v
+ val deviation = random.nextInt(-100, 101)
+ val lifts = deviation >= 0
+ val ceiling = if (lifts) NOISE_WHITE_MAX else NOISE_BLACK_MAX
+ val alpha = abs(deviation) * ceiling / 100
+ val tone = if (lifts) 0xFF else 0x00
+ (alpha shl 24) or (tone shl 16) or (tone shl 8) or tone
}
return Bitmap.createBitmap(pixels, NOISE_TILE_PX, NOISE_TILE_PX, Bitmap.Config.ARGB_8888)
.asImageBitmap()
diff --git a/app/src/main/java/com/gotcha/ui/theme/GlassTier.kt b/app/src/main/java/com/gotcha/ui/theme/GlassTier.kt
index 5a11b61..06537ee 100644
--- a/app/src/main/java/com/gotcha/ui/theme/GlassTier.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/GlassTier.kt
@@ -37,7 +37,15 @@ enum class GlassTier {
*/
STATIC,
- /** Opaque panels, no wallpaper. Same palette, same layout — just not glass. */
+ /**
+ * Opaque panels, wallpaper kept. What "reduce transparency" should mean: the
+ * request is about seeing *through* chrome, not about the theme's colour and
+ * texture, and taking the wallpaper too makes the setting feel like it broke
+ * the app rather than adjusted it.
+ */
+ OPAQUE,
+
+ /** Nothing at all: opaque panels and no wallpaper. The cheapest we render. */
SOLID
}
@@ -86,7 +94,10 @@ fun rememberGlassTier(reduceTransparency: Boolean): GlassTier {
}
return when {
- reduceTransparency || powerSaving -> GlassTier.SOLID
+ // Battery saver is a cost signal, so it drops everything. Reduce
+ // transparency is a legibility signal, so it only drops the see-through.
+ powerSaving -> GlassTier.SOLID
+ reduceTransparency -> GlassTier.OPAQUE
blurAvailable && !lowRam -> GlassTier.LIVE
else -> GlassTier.STATIC
}
diff --git a/app/src/main/java/com/gotcha/ui/theme/Skin.kt b/app/src/main/java/com/gotcha/ui/theme/Skin.kt
index 95d894d..cbbe0eb 100644
--- a/app/src/main/java/com/gotcha/ui/theme/Skin.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/Skin.kt
@@ -91,6 +91,22 @@ data class Skin(
return copy(frost = frost * factor, scrim = scrim * factor)
}
+ /**
+ * Solid panels over the skin's own wallpaper. The ground keeps its tint,
+ * grain and vignette — those were never transparency — while everything you
+ * read from stops being see-through.
+ */
+ fun opaquePanels(): Skin {
+ if (!isGlass) return this
+ // `background` stays transparent on purpose. Scaffold paints its
+ // container from that role, so giving it a colour here would lay an
+ // opaque sheet straight over the wallpaper this function exists to keep.
+ return copy(
+ frost = 0.dp,
+ scheme = scheme.flattenOnto(ground, keepBackgroundTransparent = true)
+ )
+ }
+
/**
* The same skin with the glass taken out: panels composited down onto their
* own ground, no wallpaper, no grain. The palette and the layout are
@@ -112,9 +128,16 @@ data class Skin(
* Alpha-composites the translucent roles onto [ground]. The surfaceContainer*
* roles are already opaque in every skin — see Color.kt — so only the in-page
* chrome needs flattening here.
+ *
+ * [keepBackgroundTransparent] is the difference between "no glass" and "no
+ * wallpaper": Scaffold paints its container from the `background` role, so
+ * colouring it hides anything drawn behind the app.
*/
-private fun ColorScheme.flattenOnto(ground: Color): ColorScheme = copy(
- background = ground,
+private fun ColorScheme.flattenOnto(
+ ground: Color,
+ keepBackgroundTransparent: Boolean = false
+): ColorScheme = copy(
+ background = if (keepBackgroundTransparent) background else ground,
surface = surface.over(ground),
surfaceVariant = surfaceVariant.over(ground),
secondaryContainer = secondaryContainer.over(ground)
@@ -309,7 +332,7 @@ object Skins {
ground = OrchidGround,
scheme = OrchidScheme,
frost = 8.dp,
- grain = 0.34f,
+ grain = 0.30f,
corner = 22.dp
)
diff --git a/app/src/main/java/com/gotcha/ui/theme/Theme.kt b/app/src/main/java/com/gotcha/ui/theme/Theme.kt
index c6fe6c6..3444d31 100644
--- a/app/src/main/java/com/gotcha/ui/theme/Theme.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/Theme.kt
@@ -56,7 +56,11 @@ fun GotchaTheme(
val tier = rememberGlassTier(reduceTransparency)
val picked = Skins.byId(skinId).withFrost(frostPercent)
// The tier decides what the skin is made of, not whether the user gets it.
- val skin = if (tier == GlassTier.SOLID) picked.opaque() else picked
+ val skin = when (tier) {
+ GlassTier.SOLID -> picked.opaque()
+ GlassTier.OPAQUE -> picked.opaquePanels()
+ GlassTier.LIVE, GlassTier.STATIC -> picked
+ }
SystemBars(skin)