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: motion — messages arrive on a spring, skins cross-dissolve
Durganshu Mishra65a07547a36e
diff --git a/app/src/main/java/com/gotcha/ui/ChatComponents.kt b/app/src/main/java/com/gotcha/ui/ChatComponents.ktindex f1f21dc..b26bca7 100644--- a/app/src/main/java/com/gotcha/ui/ChatComponents.kt+++ b/app/src/main/java/com/gotcha/ui/ChatComponents.kt@@ -1,9 +1,12 @@package com.gotcha.ui+import androidx.compose.animation.core.Animatableimport androidx.compose.animation.core.RepeatMode+import androidx.compose.animation.core.Springimport androidx.compose.animation.core.animateFloatimport androidx.compose.animation.core.infiniteRepeatableimport androidx.compose.animation.core.rememberInfiniteTransition+import androidx.compose.animation.core.springimport androidx.compose.animation.core.tweenimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Arrangement@@ -17,11 +20,15 @@ import androidx.compose.foundation.shape.CircleShapeimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material3.MaterialThemeimport androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValue+import androidx.compose.runtime.rememberimport androidx.compose.ui.Modifierimport androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.graphicsLayerimport androidx.compose.ui.unit.dp+import com.gotcha.ui.theme.LocalAnimationsEnabledimport com.gotcha.ui.theme.WarningAmberimport kotlin.math.roundToInt@@ -73,6 +80,47 @@ fun ContextMeter(fraction: Float, modifier: Modifier = Modifier) {}}+/**+ * A message arriving.+ *+ * It rises a little and fades in on a spring, which is enough to say "this is+ * new" without making the reader wait. Only genuinely new messages animate:+ * anything already on screen when the chat opened appears instantly, and an+ * item that scrolls out of view and back does not replay — a list that+ * re-animates on scroll is a list that feels broken.+ *+ * There is no explicit stagger. A turn that emits a reply and four tool lines+ * emits them milliseconds apart already, so the offset arrives on its own and+ * stays honest about when things actually happened.+ */+@Composable+fun MessageArrival(animate: Boolean, content: @Composable () -> Unit) {+ val enabled = animate && LocalAnimationsEnabled.current+ val progress = remember { Animatable(if (enabled) 0f else 1f) }+ LaunchedEffect(Unit) {+ if (enabled) {+ progress.animateTo(+ targetValue = 1f,+ animationSpec = spring(+ dampingRatio = Spring.DampingRatioLowBouncy,+ stiffness = Spring.StiffnessMediumLow+ )+ )+ }+ }+ Box(+ Modifier.graphicsLayer {+ alpha = progress.value+ translationY = (1f - progress.value) * ARRIVAL_RISE.toPx()+ }+ ) {+ content()+ }+}++/** How far a new message travels on its way in. */+private val ARRIVAL_RISE = 14.dp+/*** The agent is working. A dot that breathes says so with one moving part, where* a spinner says "loading" — a different claim, and the wrong one for somethingdiff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.ktindex 56de5e4..3df9283 100644--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt@@ -112,6 +112,14 @@ fun ChatScreen(var pendingImageBase64 by rememberSaveable { mutableStateOf<String?>(null) }val listState = rememberLazyListState()+ // Everything already in the transcript when this chat opened is history, and+ // history should not animate itself in. Re-keyed per session so switching+ // chats does not replay someone else's conversation.+ val arrivalBaseline = remember(state.activeSessionId) {+ state.messages.lastOrNull()?.id ?: -1L+ }+ val animatedIds = remember(state.activeSessionId) { mutableSetOf<Long>() }+val imagePickerLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.GetContent()) { uri: Uri? ->@@ -268,12 +276,19 @@ fun ChatScreen(modifier = Modifier.weight(1f).fillMaxWidth().testTag("message_list")) {items(state.messages, key = { it.id }) { message ->- MessageBubble(- message = message,- onSpeak = onSpeak,- isSpeaking = state.isSpeaking,- onStopSpeaking = onStopSpeaking- )+ // Only what arrives after the chat is open animates, and+ // each id only ever animates once — `add` is false the+ // second time an item is composed, which is what stops a+ // scroll back up from replaying the whole thread.+ val firstShow = remember(message.id) { animatedIds.add(message.id) }+ MessageArrival(animate = firstShow && message.id > arrivalBaseline) {+ MessageBubble(+ message = message,+ onSpeak = onSpeak,+ isSpeaking = state.isSpeaking,+ onStopSpeaking = onStopSpeaking+ )+ }}}}diff --git a/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt b/app/src/main/java/com/gotcha/ui/theme/Backdrop.ktindex e034def..af37a5e 100644--- a/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt+++ b/app/src/main/java/com/gotcha/ui/theme/Backdrop.kt@@ -1,6 +1,7 @@package com.gotcha.ui.themeimport android.graphics.Bitmap+import androidx.compose.animation.Crossfadeimport androidx.compose.foundation.Canvasimport androidx.compose.foundation.backgroundimport androidx.compose.foundation.layout.Box@@ -46,10 +47,19 @@ fun SkinBackdrop(modifier: Modifier = Modifier) {// 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)- if (skin.grain > 0f) Grain(skin.grain)- Scrim(skin)+ // Crossfaded rather than colour-tweened: fog cannot become facets by+ // interpolation, so the two wallpapers are drawn at once and dissolved.+ Crossfade(+ targetState = skin,+ animationSpec = motionSpec(SKIN_TRANSITION_MS),+ label = "backdrop",+ modifier = modifier+ ) { shown ->+ Box(Modifier.fillMaxSize().background(shown.ground)) {+ Wallpaper(shown, live = tier == GlassTier.LIVE)+ if (shown.grain > 0f) Grain(shown.grain)+ Scrim(shown)+ }}}diff --git a/app/src/main/java/com/gotcha/ui/theme/Motion.kt b/app/src/main/java/com/gotcha/ui/theme/Motion.ktnew file mode 100644index 0000000..6ff6b1e--- /dev/null+++ b/app/src/main/java/com/gotcha/ui/theme/Motion.kt@@ -0,0 +1,96 @@+package com.gotcha.ui.theme++import android.provider.Settings+import androidx.compose.animation.animateColorAsState+import androidx.compose.animation.core.FiniteAnimationSpec+import androidx.compose.animation.core.snap+import androidx.compose.animation.core.tween+import androidx.compose.material3.ColorScheme+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.runtime.staticCompositionLocalOf+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.platform.LocalContext++/** How long a theme takes to become another theme. */+const val SKIN_TRANSITION_MS = 320++/**+ * Whether this device wants animation at all.+ *+ * Android exposes the accessibility "Remove animations" preference as an+ * animator duration scale of zero. Compose does not consult it for us, so every+ * animation we write has to ask — otherwise "remove animations" removes+ * everyone's animations except ours.+ */+val LocalAnimationsEnabled = staticCompositionLocalOf { true }++@Composable+fun rememberAnimationsEnabled(): Boolean {+ val context = LocalContext.current+ return remember(context) {+ val scale = Settings.Global.getFloat(+ context.contentResolver,+ Settings.Global.ANIMATOR_DURATION_SCALE,+ 1f+ )+ scale > 0f+ }+}++/** [tween] when animation is wanted, [snap] when it is not. */+@Composable+fun <T> motionSpec(durationMillis: Int): FiniteAnimationSpec<T> =+ if (LocalAnimationsEnabled.current) tween(durationMillis) else snap()++/**+ * The same scheme, with each role easing toward its new value.+ *+ * Switching skin used to be a single frame in which every colour on screen+ * changed at once, which reads as a glitch rather than as a choice. Tweening+ * the roles turns it into one movement — and because everything downstream+ * reads the scheme rather than the skin, the whole app comes along without+ * knowing anything happened.+ *+ * Only the roles that cover real estate are animated. Tweening all thirty would+ * cost more recompositions than the difference is worth on colours the eye never+ * catches mid-transition.+ */+@Composable+fun ColorScheme.animated(): ColorScheme {+ val spec = motionSpec<Color>(SKIN_TRANSITION_MS)+ val background by animateColorAsState(background, spec, label = "background")+ val surface by animateColorAsState(surface, spec, label = "surface")+ val surfaceVariant by animateColorAsState(surfaceVariant, spec, label = "surfaceVariant")+ val primary by animateColorAsState(primary, spec, label = "primary")+ val onSurface by animateColorAsState(onSurface, spec, label = "onSurface")+ val onSurfaceVariant by animateColorAsState(onSurfaceVariant, spec, label = "onSurfaceVariant")+ val primaryContainer by animateColorAsState(primaryContainer, spec, label = "primaryContainer")+ val onPrimaryContainer by animateColorAsState(+ targetValue = onPrimaryContainer,+ animationSpec = spec,+ label = "onPrimaryContainer"+ )+ val secondaryContainer by animateColorAsState(+ targetValue = secondaryContainer,+ animationSpec = spec,+ label = "secondaryContainer"+ )+ val surfaceContainer by animateColorAsState(surfaceContainer, spec, label = "surfaceContainer")+ val outlineVariant by animateColorAsState(outlineVariant, spec, label = "outlineVariant")++ return copy(+ background = background,+ surface = surface,+ surfaceVariant = surfaceVariant,+ primary = primary,+ onSurface = onSurface,+ onSurfaceVariant = onSurfaceVariant,+ primaryContainer = primaryContainer,+ onPrimaryContainer = onPrimaryContainer,+ secondaryContainer = secondaryContainer,+ surfaceContainer = surfaceContainer,+ outlineVariant = outlineVariant+ )+}diff --git a/app/src/main/java/com/gotcha/ui/theme/Theme.kt b/app/src/main/java/com/gotcha/ui/theme/Theme.ktindex 8b85f76..fecafcc 100644--- a/app/src/main/java/com/gotcha/ui/theme/Theme.kt+++ b/app/src/main/java/com/gotcha/ui/theme/Theme.kt@@ -57,10 +57,13 @@ fun GotchaTheme(CompositionLocalProvider(LocalSkin provides skin,- LocalGlassTier provides tier+ LocalGlassTier provides tier,+ LocalAnimationsEnabled provides rememberAnimationsEnabled()) {MaterialTheme(- colorScheme = skin.scheme,+ // Animated so changing skin is one movement rather than one frame in+ // which every colour on screen is suddenly different.+ colorScheme = skin.scheme.animated(),typography = Typography,content = content)