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.

Play the launch video on cold start

Rishabh Bajpaia9ac84bf0953
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.kt
index 1060f21..8f2c584 100644
--- a/app/src/main/java/com/gotcha/MainActivity.kt
+++ b/app/src/main/java/com/gotcha/MainActivity.kt
@@ -95,6 +95,7 @@ import com.gotcha.ui.SettingsPage
import com.gotcha.ui.SettingsScreen
import com.gotcha.ui.SharePosterSheet
import com.gotcha.ui.SharePosterState
+import com.gotcha.ui.SplashVideoOverlay
import com.gotcha.ui.StarPromptDialog
import com.gotcha.ui.rememberChatTransfer
import com.gotcha.ui.runtimePermissionAsk
@@ -197,6 +198,25 @@ class MainActivity : ComponentActivity() {
/** The one setting that decides what the app looks like. */
private data class Appearance(val skinId: String = Skins.DEFAULT_ID)
+ /**
+ * The launch video plays once per process: a warm start that reuses this
+ * activity (singleTask) must not replay it. Set when playback starts, not
+ * when it ends, so a rotation mid-video still lands in the app.
+ */
+ private object SplashGate {
+ var played = false
+ }
+
+ /** Whether the launch video is still up. Field, so it survives composition. */
+ private var showSplash by mutableStateOf(!SplashGate.played)
+
+ /**
+ * True once the app shell has drawn behind the launch video. Posted to the
+ * decor view after setContent, so it flips after the first traversal
+ * rather than during composition.
+ */
+ private var splashContentReady by mutableStateOf(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
@@ -458,8 +478,22 @@ class MainActivity : ComponentActivity() {
TourOverlay(controller = tour.controller)
}
}
+ // The launch video over everything, content initializing
+ // underneath it. Back is held while it plays: two seconds of
+ // branding must not read as a way to quit the app.
+ if (showSplash) {
+ BackHandler {}
+ SplashVideoOverlay(
+ contentReady = splashContentReady,
+ onFinished = { showSplash = false },
+ // Playback has started, so a rotation from here opens
+ // straight into the app instead of replaying the video.
+ onStarted = { SplashGate.played = true }
+ )
+ }
}
}
+ window.decorView.post { splashContentReady = true }
}
/**
diff --git a/app/src/main/java/com/gotcha/ui/SplashOverlay.kt b/app/src/main/java/com/gotcha/ui/SplashOverlay.kt
new file mode 100644
index 0000000..52f8354
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/SplashOverlay.kt
@@ -0,0 +1,159 @@
+package com.gotcha.ui
+
+import android.net.Uri
+import android.widget.VideoView
+import androidx.compose.animation.core.animateFloatAsState
+import androidx.compose.animation.core.tween
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.size
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.viewinterop.AndroidView
+import com.gotcha.R
+import kotlinx.coroutines.delay
+
+/** Failsafe: a wedged decoder must never hold the launch hostage. */
+private const val SPLASH_TIMEOUT_MS = 12_000L
+
+/** The fade from the video's last frame into the app. */
+private const val SPLASH_FADE_MS = 300
+
+/**
+ * Whether the overlay may go away. The video is the minimum: it is two seconds
+ * long and cannot finish earlier, so a fast device still watches the whole
+ * launch. Past it, dismissal waits for the app shell ([contentReady]) — on a
+ * slow start the last frame holds as the logo. The timeout releases either
+ * wait on its own, so a decoder that never calls back cannot hold the launch
+ * hostage.
+ */
+fun shouldDismissSplash(videoEnded: Boolean, contentReady: Boolean, timedOut: Boolean): Boolean =
+ (videoEnded && contentReady) || timedOut
+
+/**
+ * The cold-start launch video, played once per process while the app
+ * initializes underneath it.
+ *
+ * One activity, not two: the content composes behind this overlay from the
+ * first frame, so startup work overlaps the video instead of following it,
+ * and notifications, the ball and deep links keep landing on the one
+ * activity they already address. The overlay is opaque, so nothing behind it
+ * needs to hold back — no permission or consent surface can peek through.
+ *
+ * @param contentReady true once the app shell has drawn its first frame.
+ * @param onFinished called after the fade, when the player is released.
+ */
+@Composable
+fun SplashVideoOverlay(
+ contentReady: Boolean,
+ onFinished: () -> Unit,
+ /** Fires once the overlay commits to showing, even if the video restarts. */
+ onStarted: () -> Unit = {},
+ timeoutMs: Long = SPLASH_TIMEOUT_MS
+) {
+ var videoEnded by remember { mutableStateOf(false) }
+ var videoFailed by remember { mutableStateOf(false) }
+ var timedOut by remember { mutableStateOf(false) }
+ var fading by remember { mutableStateOf(false) }
+ LaunchedEffect(Unit) {
+ onStarted()
+ delay(timeoutMs)
+ timedOut = true
+ }
+ LaunchedEffect(videoEnded, videoFailed, contentReady, timedOut) {
+ if (shouldDismissSplash(videoEnded || videoFailed, contentReady, timedOut)) {
+ fading = true
+ }
+ }
+ val alpha by animateFloatAsState(
+ targetValue = if (fading) 0f else 1f,
+ animationSpec = tween(SPLASH_FADE_MS),
+ label = "splashFade"
+ )
+ LaunchedEffect(fading) {
+ if (fading) {
+ delay(SPLASH_FADE_MS.toLong())
+ onFinished()
+ }
+ }
+
+ // The video's own near-white ground, matching the window behind it: the
+ // square footage around the footage must not read as a panel. Clicks are
+ // swallowed whole: the app is live underneath, and a tap aimed at the logo
+ // must not land on a control nobody can see yet.
+ Box(
+ modifier = Modifier
+ .fillMaxSize()
+ .background(colorResource(R.color.splash_background))
+ .clickable(
+ interactionSource = remember { MutableInteractionSource() },
+ indication = null,
+ onClick = {}
+ )
+ .alpha(alpha)
+ ) {
+ BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
+ val size = minOf(maxWidth, 440.dp)
+ if (videoFailed) {
+ Image(
+ painter = painterResource(R.drawable.splash_logo),
+ contentDescription = stringResource(R.string.chat_gotcha_logo),
+ modifier = Modifier
+ .align(Alignment.Center)
+ .size(size)
+ )
+ } else {
+ var player by remember { mutableStateOf<VideoView?>(null) }
+ AndroidView(
+ factory = { ctx ->
+ VideoView(ctx).apply {
+ // Listeners first: a local resource can prepare
+ // before the next line runs.
+ setOnPreparedListener { mp ->
+ mp.setVolume(0f, 0f)
+ start()
+ }
+ setOnCompletionListener {
+ videoEnded = true
+ }
+ setOnErrorListener { _, what, extra ->
+ android.util.Log.w("SplashVideo", "error what=$what extra=$extra")
+ videoFailed = true
+ true
+ }
+ setVideoURI(
+ Uri.parse(
+ "android.resource://${ctx.packageName}/${R.raw.gotcha_splash}"
+ )
+ )
+ player = this
+ }
+ },
+ modifier = Modifier
+ .align(Alignment.Center)
+ .size(size)
+ )
+ DisposableEffect(Unit) {
+ onDispose { player?.stopPlayback() }
+ }
+ }
+ }
+ }
+}
diff --git a/app/src/main/res/drawable-xxxhdpi/splash_logo.png b/app/src/main/res/drawable-xxxhdpi/splash_logo.png
new file mode 100644
index 0000000..05d132c
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/splash_logo.png differ
diff --git a/app/src/main/res/raw/gotcha_splash.mp4 b/app/src/main/res/raw/gotcha_splash.mp4
new file mode 100644
index 0000000..a0616c3
Binary files /dev/null and b/app/src/main/res/raw/gotcha_splash.mp4 differ
diff --git a/app/src/main/res/values-night-v31/themes.xml b/app/src/main/res/values-night-v31/themes.xml
new file mode 100644
index 0000000..8060d6f
--- /dev/null
+++ b/app/src/main/res/values-night-v31/themes.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Night-mode twin of values-v31/themes.xml. The window still follows the
+ night ground, but the splash keeps the video's own light shade: the
+ footage is light either way, and a dark splash behind a light logo and
+ a light video would flash twice.
+-->
+<resources>
+ <style name="Theme.Gotcha" parent="android:Theme.Material.Light.NoActionBar">
+ <item name="android:windowBackground">@color/launch_background</item>
+ <item name="android:windowSplashScreenBackground">@color/splash_background</item>
+ <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_logo</item>
+ <item name="android:windowSplashScreenAnimationDuration">1000</item>
+ </style>
+</resources>
diff --git a/app/src/main/res/values-v31/themes.xml b/app/src/main/res/values-v31/themes.xml
new file mode 100644
index 0000000..2ccbad5
--- /dev/null
+++ b/app/src/main/res/values-v31/themes.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Startup on Android 12 and later. Without this the OS shows the launcher
+ icon as the launch animation, blown up to splash size from a 432px
+ adaptive foreground — which is where the blurry logo came from. The
+ still below is cut from the launch video at full resolution on the same
+ near-white ground, so the system splash hands over to the video
+ seamlessly.
+-->
+<resources>
+ <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>
+ <item name="android:windowSplashScreenBackground">@color/splash_background</item>
+ <item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_logo</item>
+ <item name="android:windowSplashScreenAnimationDuration">1000</item>
+ </style>
+</resources>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index c4d1fd9..bb3689b 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -11,4 +11,11 @@
applyLaunchBackground().
-->
<color name="launch_background">#FBFDF9</color>
+ <!--
+ The launch video's own ground, sampled off its first frame. The system
+ splash and the video overlay both paint this instead of following night
+ mode: the footage is light either way, so the whole chain stays one
+ shade from tap to app.
+ -->
+ <color name="splash_background">#FBFDFA</color>
</resources>
diff --git a/app/src/test/java/com/gotcha/ui/SplashDismissTest.kt b/app/src/test/java/com/gotcha/ui/SplashDismissTest.kt
new file mode 100644
index 0000000..749889c
--- /dev/null
+++ b/app/src/test/java/com/gotcha/ui/SplashDismissTest.kt
@@ -0,0 +1,31 @@
+package com.gotcha.ui
+
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/**
+ * The launch overlay's dismissal rule: the two-second video is the minimum,
+ * the app shell gates the rest, and the timeout is the back stop.
+ */
+class SplashDismissTest {
+
+ @Test
+ fun `the video alone never dismisses before it ends`() {
+ assertFalse(shouldDismissSplash(videoEnded = false, contentReady = true, timedOut = false))
+ assertFalse(shouldDismissSplash(videoEnded = false, contentReady = false, timedOut = false))
+ }
+
+ @Test
+ fun `after the video, dismissal waits for the app shell`() {
+ assertFalse(shouldDismissSplash(videoEnded = true, contentReady = false, timedOut = false))
+ assertTrue(shouldDismissSplash(videoEnded = true, contentReady = true, timedOut = false))
+ }
+
+ @Test
+ fun `the timeout releases a stuck launch even if the video never ends`() {
+ assertTrue(shouldDismissSplash(videoEnded = true, contentReady = false, timedOut = true))
+ assertTrue(shouldDismissSplash(videoEnded = false, contentReady = false, timedOut = true))
+ assertTrue(shouldDismissSplash(videoEnded = false, contentReady = true, timedOut = true))
+ }
+}