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.

refactor: replace border-and-blur pulse with edge-anchored gradient animation using a smooth raised cosine envelope

Rishabh Bajpaia0dd2c53be2a
diff --git a/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt b/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt
index 4182f1b..919596f 100644
--- a/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt
+++ b/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt
@@ -8,14 +8,13 @@ import android.os.Looper
import android.provider.Settings
import android.view.Gravity
import android.view.WindowManager
-import android.view.animation.DecelerateInterpolator
import com.gotcha.data.SettingsRepository
import com.gotcha.ui.theme.Skins
import com.gotcha.ui.theme.overlaySkin
/**
* Flashes a brief accent border around the screen after an agent screen read.
- * Fire-and-forget: [pulse] adds a non-touchable window, animates ~650 ms, then
+ * Fire-and-forget: [pulse] adds a non-touchable window, animates ~1 s, then
* removes it. No-op without the "Display over other apps" permission.
*/
class ScreenReadFlashOverlay(context: Context) {
@@ -43,7 +42,6 @@ class ScreenReadFlashOverlay(context: Context) {
view = flash
animator = ValueAnimator.ofFloat(0f, 1f).apply {
duration = PULSE_MS
- interpolator = DecelerateInterpolator()
addUpdateListener { a -> flash.pulse = a.animatedValue as Float }
addListener(object : android.animation.AnimatorListenerAdapter() {
override fun onAnimationEnd(
@@ -95,6 +93,6 @@ class ScreenReadFlashOverlay(context: Context) {
}
private companion object {
- const val PULSE_MS = 650L
+ const val PULSE_MS = 1_000L
}
}
diff --git a/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt b/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt
index b5af5ef..882079c 100644
--- a/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt
+++ b/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt
@@ -1,41 +1,43 @@
package com.gotcha.ui
import android.content.Context
-import android.graphics.BlurMaskFilter
import android.graphics.Canvas
+import android.graphics.LinearGradient
import android.graphics.Paint
-import android.graphics.RectF
+import android.graphics.Shader
import android.view.View
import androidx.core.graphics.ColorUtils
import com.gotcha.ui.theme.OverlaySkin
-import kotlin.math.pow
+import kotlin.math.PI
+import kotlin.math.cos
/**
- * One-shot "the screen was read" pulse: an accent rounded-rect border with a
- * blurred glow that ramps in and out over ~650 ms. The owning controller removes
- * the window on animation end — this view only draws. Deliberately drawn only
- * AFTER a capture has finished so it never appears in a screenshot.
+ * One-shot "the screen was read" pulse: an accent frame that glows from the
+ * physical screen edges inward and fades back out over ~1 s. The owning
+ * controller removes the window on animation end — this view only draws.
+ * Deliberately drawn only AFTER a capture has finished so it never appears in
+ * a screenshot.
+ *
+ * Rendering is an edge-anchored gradient, not a blurred stroke: each edge band
+ * runs from full accent at the exact screen boundary to transparent ~48 dp
+ * inward. Because the window is MATCH_PARENT and full-screen, the frame hugs
+ * the real display perimeter (the device rounds the corners itself) and the
+ * brightness is maximal on the edges and falls off toward the center — a clean
+ * frame, not a floating box with a glow that reduces on both sides.
*/
class ScreenReadFlashView(
context: Context,
private val colors: OverlaySkin
) : View(context) {
- private val borderPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
- style = Paint.Style.STROKE
- strokeWidth = BORDER_DP * resources.displayMetrics.density
- color = ColorUtils.setAlphaComponent(colors.accent, BORDER_ALPHA)
- }
- private val glowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
- style = Paint.Style.STROKE
- strokeWidth = GLOW_DP * resources.displayMetrics.density
- color = ColorUtils.setAlphaComponent(colors.accent, GLOW_ALPHA)
- maskFilter = BlurMaskFilter(
- GLOW_BLUR_DP * resources.displayMetrics.density,
- BlurMaskFilter.Blur.NORMAL
- )
+ private val density = resources.displayMetrics.density
+
+ /** Edge colour at its full (pre-envelope) alpha, from the skin accent. */
+ private val edgeColor = ColorUtils.setAlphaComponent(colors.accent, EDGE_ALPHA)
+
+ private val edgePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
+ color = edgeColor
}
- private val borderRect = RectF()
/** 0..1 progress of the pulse; 0 invisible, mid peak, 1 finished. */
var pulse: Float = 0f
@@ -48,32 +50,54 @@ class ScreenReadFlashView(
super.onDraw(canvas)
val progress = pulse
if (progress <= 0f || progress >= 1f) return
- val inset = glowPaint.strokeWidth / 2f + 1f
- borderRect.set(inset, inset, width - inset, height - inset)
- // Rise fast and hold near peak so the pulse reads as a clear flash rather
- // than a flicker: the sin wave alone only sits at full brightness for a
- // fraction of the duration. Raising it to ^0.4 keeps it bright across
- // most of the middle of the animation.
- val wave = kotlin.math.sin(progress * kotlin.math.PI)
- val alpha = (wave.pow(0.4) * 255).toInt().coerceIn(0, 255)
- borderPaint.alpha = alpha
- glowPaint.alpha = alpha
- val radius = colors.cardRadiusDp * resources.displayMetrics.density
- canvas.drawRoundRect(borderRect, radius, radius, glowPaint)
- canvas.drawRoundRect(borderRect, radius, radius, borderPaint)
+ val alpha = (pulseAlpha(progress) * EDGE_ALPHA).toInt().coerceIn(0, 255)
+ val glowW = EDGE_GLOW_WIDTH_DP * density
+ // Left / right bands.
+ edgePaint.alpha = alpha
+ edgePaint.shader = gradient(0f, 0f, glowW, 0f)
+ canvas.drawRect(0f, 0f, glowW, height.toFloat(), edgePaint)
+ edgePaint.shader = gradient(width.toFloat(), 0f, width.toFloat() - glowW, 0f)
+ canvas.drawRect(width.toFloat() - glowW, 0f, width.toFloat(), height.toFloat(), edgePaint)
+ // Top / bottom bands.
+ edgePaint.shader = gradient(0f, 0f, 0f, glowW)
+ canvas.drawRect(0f, 0f, width.toFloat(), glowW, edgePaint)
+ edgePaint.shader = gradient(0f, height.toFloat(), 0f, height.toFloat() - glowW)
+ canvas.drawRect(0f, height.toFloat() - glowW, width.toFloat(), height.toFloat(), edgePaint)
}
- /** The accent-derived border stroke colour; tests pin it to the skin. */
- internal fun borderColor(): Int = ColorUtils.setAlphaComponent(colors.accent, BORDER_ALPHA)
+ /**
+ * A linear shader from full [edgeColor] at the anchor to transparent at the
+ * fade point. Per-edge coordinates are passed in by [onDraw] so the falloff
+ * always runs from the physical edge inward.
+ */
+ private fun gradient(x0: Float, y0: Float, x1: Float, y1: Float): Shader =
+ LinearGradient(
+ x0,
+ y0,
+ x1,
+ y1,
+ edgeColor,
+ ColorUtils.setAlphaComponent(colors.accent, 0),
+ Shader.TileMode.CLAMP
+ )
+
+ /** The accent-derived edge colour; tests pin it to the skin. */
+ internal fun edgeColor(): Int = edgeColor
- /** The accent-derived glow colour; tests pin it to the skin. */
- internal fun glowColor(): Int = ColorUtils.setAlphaComponent(colors.accent, GLOW_ALPHA)
+ /**
+ * The pulse's alpha envelope for [progress] in 0..1, mapping to 0..1.
+ *
+ * Raised cosine: zero slope at both ends, a single smooth peak mid-pulse,
+ * and 0 exactly at progress 0 and 1. No hard on/off snap and no strobing —
+ * deliberately kept gentle for photosensitivity.
+ */
+ internal fun pulseAlpha(progress: Float): Float {
+ if (progress <= 0f || progress >= 1f) return 0f
+ return ((1f - cos(progress * 2f * PI)) / 2f).toFloat()
+ }
private companion object {
- const val BORDER_DP = 6f
- const val GLOW_DP = 14f
- const val GLOW_BLUR_DP = 26f
- const val BORDER_ALPHA = 0xB0
- const val GLOW_ALPHA = 0x66
+ const val EDGE_GLOW_WIDTH_DP = 48f
+ const val EDGE_ALPHA = 0xA0
}
}
diff --git a/app/src/test/java/com/gotcha/ui/ScreenReadFlashViewTest.kt b/app/src/test/java/com/gotcha/ui/ScreenReadFlashViewTest.kt
index 862dad1..fa565e8 100644
--- a/app/src/test/java/com/gotcha/ui/ScreenReadFlashViewTest.kt
+++ b/app/src/test/java/com/gotcha/ui/ScreenReadFlashViewTest.kt
@@ -36,15 +36,30 @@ class ScreenReadFlashViewTest {
)
@Test
- fun `border and glow follow the skin accent`() {
+ fun `edge glow follows the skin accent`() {
val orchid = viewFor(Skins.Orchid.id)
val vellum = viewFor(Skins.Vellum.id)
- assertNotEquals("border is hardcoded across skins", orchid.borderColor(), vellum.borderColor())
- assertNotEquals("glow is hardcoded across skins", orchid.glowColor(), vellum.glowColor())
- // Both derive from the accent, at their fixed alphas.
- assertEquals(0xB0, Color.alpha(orchid.borderColor()))
- assertEquals(0x66, Color.alpha(orchid.glowColor()))
+ assertNotEquals("edge glow is hardcoded across skins", orchid.edgeColor(), vellum.edgeColor())
+ // The edge colour derives from the accent at its fixed pre-envelope alpha.
+ assertEquals(0xA0, Color.alpha(orchid.edgeColor()))
+ }
+
+ @Test
+ fun `pulseAlpha is a smooth raised cosine with no hard on or off`() {
+ val view = viewFor(Skins.DEFAULT_ID)
+ // Invisible exactly at the endpoints — no on/off snap.
+ assertEquals(0f, view.pulseAlpha(0f))
+ assertEquals(0f, view.pulseAlpha(1f))
+ // Single smooth peak mid-pulse, never above 1.
+ val mid = view.pulseAlpha(0.5f)
+ assertTrue("peak must be positive", mid > 0f)
+ assertTrue("peak must never exceed 1", mid <= 1f)
+ // Monotonic rise then fall (no flicker/strobe): each half is monotonic.
+ val rising = listOf(0.1f, 0.2f, 0.3f, 0.4f, 0.5f).map(view::pulseAlpha)
+ val falling = listOf(0.5f, 0.6f, 0.7f, 0.8f, 0.9f).map(view::pulseAlpha)
+ assertEquals("rise must be monotonic", rising.sorted(), rising)
+ assertEquals("fall must be monotonic", falling.sortedDescending(), falling)
}
@Test