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: Implement adaptive icon support and enhance UI background handling

Durganshu Mishraf2a1c153cfda
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index 2a7aa5f..30ddd2b 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -3,6 +3,8 @@ package com.gotcha
import android.app.admin.DevicePolicyManager
import android.content.Context
import android.content.Intent
+import android.content.res.Configuration
+import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.net.VpnService
import android.os.Build
@@ -29,6 +31,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.toArgb
import androidx.lifecycle.lifecycleScope
import com.gotcha.agent.ChatViewModel
import com.gotcha.audio.AudioApi
@@ -83,6 +86,29 @@ class MainActivity : ComponentActivity() {
val reduceTransparency: Boolean = false
)
+ /**
+ * Repaints the window behind Compose in the current skin's ground. themes.xml
+ * can only name one colour and has to guess Deep Space; once the setting has
+ * been read, an activity recreate should flash the skin the user actually
+ * chose rather than a slate blue they have never seen.
+ */
+ private fun applyLaunchBackground() {
+ val dark = when (appearance.themeMode) {
+ ThemeMode.LIGHT -> false
+ ThemeMode.DARK -> true
+ ThemeMode.SYSTEM -> {
+ val night = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
+ night == Configuration.UI_MODE_NIGHT_YES
+ }
+ }
+ val skin = Skins.resolve(
+ appearance.skinId,
+ appearance.matchSystemBrightness,
+ dark
+ )
+ window.setBackgroundDrawable(ColorDrawable(skin.launchGround(dark).toArgb()))
+ }
+
private fun Settings.appearance() = Appearance(
themeMode = themeMode,
skinId = skinId,
@@ -180,6 +206,7 @@ class MainActivity : ComponentActivity() {
}
appearance = settingsRepository.load().appearance()
+ applyLaunchBackground()
setContent {
val darkTheme = when (appearance.themeMode) {
@@ -473,7 +500,10 @@ class MainActivity : ComponentActivity() {
}
},
onBack = { currentRoute = Route.HOME },
- onAppearanceChange = { updated -> appearance = updated.appearance() },
+ onAppearanceChange = { updated ->
+ appearance = updated.appearance()
+ applyLaunchBackground()
+ },
onRefreshAudioModels = { s ->
withContext(Dispatchers.IO) {
val ttsBase = s.effectiveTtsBaseUrl
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 a99c0fd..555716e 100644
--- a/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt
@@ -45,6 +45,7 @@ fun SkinBackdrop(modifier: Modifier = Modifier) {
Box(modifier.background(skin.ground)) {
Wallpaper(skin, live = tier == GlassTier.LIVE)
if (skin.grain > 0f) Grain(skin.grain)
+ Scrim(skin)
}
}
@@ -72,9 +73,25 @@ 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)
}
}
+/**
+ * The contrast veil. Sits above the wallpaper and below every piece of UI, so
+ * text is always reading against a wallpaper whose range has been pulled in
+ * rather than against whatever the gradient happened to be doing there.
+ */
+@Composable
+private fun BoxScope.Scrim(skin: Skin) {
+ if (skin.scrim <= 0f) return
+ Box(
+ Modifier
+ .matchParentSize()
+ .background(skin.ground.copy(alpha = skin.scrim))
+ )
+}
+
/** 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,
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 9574d33..7e3fb9c 100644
--- a/app/src/main/java/com/gotcha/ui/theme/Skin.kt
+++ b/app/src/main/java/com/gotcha/ui/theme/Skin.kt
@@ -74,6 +74,13 @@ data class Skin(
val wallpaper: List<Color> = emptyList(),
val frost: Dp = 0.dp,
val grain: Float = 0f,
+ /**
+ * A veil of [ground] laid over the wallpaper, 0f–1f. Glass buys depth at the
+ * cost of contrast: body text ends up sitting on whatever the wallpaper is
+ * doing underneath it. The veil pulls the wallpaper's range in so the text
+ * always wins, and the louder the wallpaper the more of it there is.
+ */
+ val scrim: Float = 0f,
val corner: Dp = 20.dp,
val darkSystemBarIcons: Boolean = false,
val pairedWith: String? = null
@@ -89,6 +96,14 @@ data class Skin(
val isGlass: Boolean
get() = backdrop != Backdrop.NONE
+ /**
+ * What the window should be painted before Compose draws anything. A glass
+ * skin has a ground of its own; an opaque one is whatever its scheme says
+ * the background is, which depends on [dark].
+ */
+ fun launchGround(dark: Boolean): Color =
+ if (isGlass) ground else scheme(dark).background
+
/**
* 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
@@ -100,6 +115,7 @@ data class Skin(
return copy(
backdrop = Backdrop.NONE,
grain = 0f,
+ scrim = 0f,
schemeLight = schemeLight.flattenOnto(ground),
schemeDark = schemeDark.flattenOnto(ground)
)
@@ -285,6 +301,7 @@ object Skins {
),
frost = 26.dp,
grain = 0.05f,
+ scrim = 0.10f,
corner = 22.dp,
pairedWith = "vellum"
)
@@ -307,6 +324,7 @@ object Skins {
),
frost = 22.dp,
grain = 0.035f,
+ scrim = 0.12f,
corner = 22.dp,
darkSystemBarIcons = true,
pairedWith = "aura"
@@ -344,6 +362,8 @@ object Skins {
wallpaper = listOf(BrandViolet, BrandMagenta, BrandRose, BrandCoral, BrandSalmon),
frost = 34.dp,
grain = 0.05f,
+ // The facets are the loudest thing any skin puts behind text.
+ scrim = 0.30f,
corner = 20.dp
)
diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml
index 6c36ba3..004b6e1 100644
--- a/app/src/main/res/drawable/ic_launcher_background.xml
+++ b/app/src/main/res/drawable/ic_launcher_background.xml
@@ -4,7 +4,9 @@
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
+ <!-- The white field the mark sits on in the artwork. Was Android's template
+ green, which was never visible because no adaptive icon referenced it. -->
<path
- android:fillColor="#3DDC84"
+ android:fillColor="#FFFFFF"
android:pathData="M0,0h108v108H0z" />
</vector>
diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml
deleted file mode 100644
index 86d74f1..0000000
--- a/app/src/main/res/drawable/ic_launcher_foreground.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="108dp"
- android:height="108dp"
- android:viewportWidth="108"
- android:viewportHeight="108">
- <path
- android:fillColor="#FFFFFF"
- android:pathData="M36,54m-12,0a12,12 0,1 1,24 0a12,12 0,1 1,-24 0"
- android:strokeWidth="0" />
- <path
- android:pathData="M40,46L56,62L64,54"
- android:strokeWidth="4"
- android:strokeColor="#FFFFFF"
- android:fillColor="#00000000" />
-</vector>
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..d9ccbb8
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ The app had no adaptive icon at all: launchers on Android 8+ were letterboxing
+ the legacy PNG inside whatever mask shape they use. The foreground is the mark
+ drawn at 72dp inside the 108dp layer, which is the zone every mask is
+ guaranteed to keep, and the background is the white field the mark is drawn on
+ in the artwork itself.
+-->
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@drawable/ic_launcher_background" />
+ <foreground android:drawable="@mipmap/ic_launcher_foreground" />
+</adaptive-icon>
diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..3ba4e35
--- /dev/null
+++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@drawable/ic_launcher_background" />
+ <foreground android:drawable="@mipmap/ic_launcher_foreground" />
+</adaptive-icon>
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..dab11d5
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..6b47c53
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..68ad294
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..3889b7a
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
new file mode 100644
index 0000000..8cacd1b
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
new file mode 100644
index 0000000..9a0fe1c
--- /dev/null
+++ b/app/src/main/res/values-night/colors.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!-- Dark-mode Deep Space. See values/colors.xml. -->
+ <color name="launch_background">#0F172A</color>
+</resources>
diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml
index 5a1f5d8..0edef68 100644
--- a/app/src/main/res/values-v29/themes.xml
+++ b/app/src/main/res/values-v29/themes.xml
@@ -5,5 +5,7 @@
leaving white text on light surfaces. Opt out explicitly. -->
<style name="Theme.Gotcha" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:forceDarkAllowed">false</item>
+ <!-- Stops the white flash before Compose's first frame. See colors.xml. -->
+ <item name="android:windowBackground">@color/launch_background</item>
</style>
</resources>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..c4d1fd9
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <!--
+ Painted for the fraction of a second between the launcher tapping the
+ icon and Compose drawing its first frame. The platform default is white,
+ which flashes hard on the dark skins.
+
+ This is the light-mode Deep Space surface, because Deep Space is the
+ default skin and follows the system. MainActivity replaces it with the
+ actual skin's ground as soon as it can read the setting — see
+ applyLaunchBackground().
+ -->
+ <color name="launch_background">#FBFDF9</color>
+</resources>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 89fa3f9..ff8616d 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <style name="Theme.Gotcha" parent="android:Theme.Material.Light.NoActionBar" />
+ <style name="Theme.Gotcha" parent="android:Theme.Material.Light.NoActionBar">
+ <!-- Stops the white flash before Compose's first frame. See colors.xml. -->
+ <item name="android:windowBackground">@color/launch_background</item>
+ </style>
</resources>