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.

ui+call: pulse an accent border after a screen read during calls

Durganshu Mishra2cdd40300170
diff --git a/app/src/main/java/com/gotcha/service/CallSessionController.kt b/app/src/main/java/com/gotcha/service/CallSessionController.kt
index 96fa278..a53f9ff 100644
--- a/app/src/main/java/com/gotcha/service/CallSessionController.kt
+++ b/app/src/main/java/com/gotcha/service/CallSessionController.kt
@@ -24,6 +24,7 @@ import com.gotcha.tools.AgentMode
import com.gotcha.tools.Category
import com.gotcha.tools.ToolCategories
import com.gotcha.ui.ConfirmationOverlay
+import com.gotcha.ui.ScreenReadFlashOverlay
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
@@ -63,6 +64,7 @@ class CallSessionController(
private val callsRepo = ChatHistoryRepository(appContext, "calls")
private val confirmationOverlay = ConfirmationOverlay(appContext)
+ private val screenReadFlash = ScreenReadFlashOverlay(appContext)
/** Survives service teardown so end-of-call deletion always completes. */
private val cleanupScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
@@ -178,6 +180,7 @@ class CallSessionController(
questionGate = null
pendingReply = null
onActionRingColor(null)
+ screenReadFlash.dismiss()
_state.value = CallState.READY
}
@@ -197,6 +200,7 @@ class CallSessionController(
questionGate?.complete("")
questionGate = null
confirmationOverlay.dismiss()
+ screenReadFlash.dismiss()
engine = null
val id = endingEngine.sessionId
@@ -412,6 +416,18 @@ class CallSessionController(
reportError("A permission is needed that can't be granted during a call — open Gotcha to grant it.")
}
+ override fun onScreenCaptureChrome(hide: Boolean) {
+ // Never capture the pulse: drop any stale window before a capture starts.
+ if (hide) screenReadFlash.dismiss()
+ onCaptureChrome(hide)
+ }
+
+ override fun onScreenReadDone() {
+ // Only flash during an active agent turn; the engine only runs in this
+ // host's THINKING state.
+ if (_state.value == CallState.THINKING) screenReadFlash.pulse()
+ }
+
/** The agent asked a question: speak it and wait for a PTT answer. */
override suspend fun awaitQuestionAnswer(question: PendingQuestion): String {
_state.value = CallState.WAITING_USER
diff --git a/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt b/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt
new file mode 100644
index 0000000..fd12f96
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/ScreenReadFlashOverlay.kt
@@ -0,0 +1,96 @@
+package com.gotcha.ui
+
+import android.animation.ValueAnimator
+import android.content.Context
+import android.graphics.PixelFormat
+import android.os.Handler
+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 ~400 ms, then
+ * removes it. No-op without the "Display over other apps" permission.
+ */
+class ScreenReadFlashOverlay(context: Context) {
+
+ private val appContext = context.applicationContext
+ private val mainHandler = Handler(Looper.getMainLooper())
+ private val windowManager: WindowManager
+ get() = appContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
+
+ @Volatile
+ private var view: ScreenReadFlashView? = null
+ private var animator: ValueAnimator? = null
+
+ fun pulse() {
+ mainHandler.post {
+ if (!Settings.canDrawOverlays(appContext)) return@post
+ removeView() // restart-safe: replace any stale instance
+ val colors = overlaySkin(
+ appContext,
+ runCatching { SettingsRepository(appContext).load().skinId }
+ .getOrDefault(Skins.DEFAULT_ID)
+ )
+ val flash = ScreenReadFlashView(appContext, colors)
+ try {
+ windowManager.addView(flash, windowParams())
+ 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(a: android.animation.Animator?) { removeView() }
+ })
+ start()
+ }
+ } catch (_: Exception) {
+ view = null
+ }
+ }
+ }
+
+ fun dismiss() {
+ mainHandler.post {
+ animator?.cancel()
+ animator = null
+ removeView()
+ }
+ }
+
+ private fun removeView() {
+ view?.let {
+ try {
+ windowManager.removeView(it)
+ } catch (_: Exception) {
+ // Already detached; ignore.
+ }
+ }
+ view = null
+ }
+
+ private fun windowParams(): WindowManager.LayoutParams {
+ val type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+ return WindowManager.LayoutParams(
+ WindowManager.LayoutParams.MATCH_PARENT,
+ WindowManager.LayoutParams.MATCH_PARENT,
+ type,
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
+ WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
+ WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
+ PixelFormat.TRANSLUCENT
+ ).apply { gravity = Gravity.TOP or Gravity.START }
+ }
+
+ private companion object {
+ const val PULSE_MS = 400L
+ }
+}
diff --git a/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt b/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt
new file mode 100644
index 0000000..bda02e3
--- /dev/null
+++ b/app/src/main/java/com/gotcha/ui/ScreenReadFlashView.kt
@@ -0,0 +1,74 @@
+package com.gotcha.ui
+
+import android.content.Context
+import android.graphics.BlurMaskFilter
+import android.graphics.Canvas
+import android.graphics.Paint
+import android.graphics.RectF
+import android.view.View
+import androidx.core.graphics.ColorUtils
+import com.gotcha.ui.theme.OverlaySkin
+
+/**
+ * One-shot "the screen was read" pulse: an accent rounded-rect border with a
+ * blurred glow that ramps in and out over ~400 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.
+ */
+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 borderRect = RectF()
+
+ /** 0..1 progress of the pulse; 0 invisible, mid peak, 1 finished. */
+ var pulse: Float = 0f
+ set(value) {
+ field = value
+ invalidate()
+ }
+
+ override fun onDraw(canvas: Canvas) {
+ 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 quickly, fall slowly (like a pulse), then vanish.
+ val alpha = (kotlin.math.sin(progress * kotlin.math.PI) * 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)
+ }
+
+ /** The accent-derived border stroke colour; tests pin it to the skin. */
+ internal fun borderColor(): Int = ColorUtils.setAlphaComponent(colors.accent, BORDER_ALPHA)
+
+ /** The accent-derived glow colour; tests pin it to the skin. */
+ internal fun glowColor(): Int = ColorUtils.setAlphaComponent(colors.accent, GLOW_ALPHA)
+
+ private companion object {
+ const val BORDER_DP = 3f
+ const val GLOW_DP = 10f
+ const val GLOW_BLUR_DP = 18f
+ const val BORDER_ALPHA = 0xB0
+ const val GLOW_ALPHA = 0x66
+ }
+}