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: overlays get depth from an edge and a shadow (stage 2)
Durganshu Mishrac565b05383d0
diff --git a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.ktindex 2f5d8fa..a6b3de6 100644--- a/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/AssistiveBallOverlay.kt@@ -188,12 +188,7 @@ class AssistiveBallOverlay(context: Context) {val colors = palette()val container = LinearLayout(appContext).apply {orientation = LinearLayout.VERTICAL- setPadding(dp(20), dp(16), dp(20), dp(16))- background = GradientDrawable().apply {- cornerRadius = dp(colors.cardRadiusDp.toInt()).toFloat()- setColor(colors.surface)- setStroke(dp(1), colors.outline)- }+ applyOverlayCard(colors, horizontalDp = 20, verticalDp = 16)}val scroll = ScrollView(appContext).apply {addView(@@ -214,7 +209,7 @@ class AssistiveBallOverlay(context: Context) {container.addView(tapButton("Close", colors) { hideCard() })}try {- windowManager.addView(container, cardLayoutParams())+ windowManager.addView(container, cardLayoutParams(container))cardView = container} catch (_: Exception) {cardView = null@@ -231,14 +226,39 @@ class AssistiveBallOverlay(context: Context) {}}+ /**+ * The ball is a designed object, not a pasted icon.+ *+ * It used to be the bare mark on its own white disc — the adaptive-icon+ * asset, wearing the launcher's colours over whatever app happened to be+ * underneath. Now it is the skin's ground with the same edge highlight and+ * shadow the cards get, so it reads as one of our controls in the same+ * theme as everything else, and it keeps its shape over a photograph.+ *+ * The shadow is tighter than a card's: the window is a fixed 56dp and every+ * dock, peek and dismiss measurement in this class is written against that,+ * so the gutter is taken out of the disc rather than added to the window.+ */private fun buildBall(): View {val size = dp(BALL_SIZE_DP)+ val colors = palette()+ val density = appContext.resources.displayMetrics.density+ val disc = overlayCardBackground(+ density = density,+ colors = colors,+ radiusDp = BALL_SIZE_DP / 2f,+ fill = colors.ground,+ shadowRadiusDp = BALL_SHADOW_DP+ )return android.widget.ImageView(appContext).apply {contentDescription = ASSISTIVE_BALL_CONTENT_DESCRIPTION// The in-app mark. The launcher icon is adaptive now, so it would// draw at two-thirds size inside its own safe zone.setImageResource(R.drawable.gotcha_logo)- scaleType = android.widget.ImageView.ScaleType.CENTER_CROP+ scaleType = android.widget.ImageView.ScaleType.CENTER_INSIDE+ background = disc+ val inset = disc.shadowPadPx + dp(BALL_MARK_INSET_DP)+ setPadding(inset, inset, inset, inset)alpha = PEEK_ALPHAsetOnTouchListener(ballTouchListener())layoutParams = LinearLayout.LayoutParams(size, size)@@ -265,14 +285,10 @@ class AssistiveBallOverlay(context: Context) {val menuCard = LinearLayout(appContext).apply {orientation = LinearLayout.VERTICAL- setPadding(dp(10), dp(10), dp(10), dp(10))- background = GradientDrawable().apply {- cornerRadius = dp(colors.cardRadiusDp.toInt()).toFloat()- setColor(colors.surface)- setStroke(dp(1), colors.outline)- }+ applyOverlayCard(colors, horizontalDp = 10, verticalDp = 10)setOnClickListener { }}+ val menuShadowPad = (menuCard.background as? OverlayCardDrawable)?.shadowPadPx ?: 0buildProactiveMenuContent(menuCard, colors)@@ -302,7 +318,10 @@ class AssistiveBallOverlay(context: Context) {val metrics = appContext.resources.displayMetricsval screenHeight = metrics.heightPixelsval screenWidth = metrics.widthPixels- val menuWidth = dp(MENU_WIDTH_DP)+ // The view is the card plus its shadow gutter; the numbers below are all+ // about where the *card* lands, so the gutter is added to the width and+ // taken back off the margins.+ val menuWidth = dp(MENU_WIDTH_DP) + menuShadowPad * 2val maxCardHeight = (screenHeight - dp(48)).coerceAtLeast(dp(200))menuCard.measure(@@ -324,8 +343,8 @@ class AssistiveBallOverlay(context: Context) {val leftMargin = (ballParams.x).coerceIn(dp(8), (screenWidth - menuWidth - dp(8)).coerceAtLeast(dp(8)))val cardParams = FrameLayout.LayoutParams(menuWidth, FrameLayout.LayoutParams.WRAP_CONTENT).apply {- this.leftMargin = leftMargin- this.topMargin = topMargin+ this.leftMargin = leftMargin - menuShadowPad+ this.topMargin = topMargin - menuShadowPad}rootLayout.addView(menuCard, cardParams)@@ -470,9 +489,10 @@ class AssistiveBallOverlay(context: Context) {val density = appContext.resources.displayMetrics.densityval viewSize = (BALL_SIZE_DP * 3.2f * density).toInt()val ballPx = dp(BALL_SIZE_DP)+ val accent = accentColor()val drawable = RingDrawable().apply {fillColor = Color.TRANSPARENT- strokeColor = accentColor()+ strokeColor = accentstrokeWidth = 2.5f * density}val view = View(appContext).apply { background = drawable }@@ -502,7 +522,9 @@ class AssistiveBallOverlay(context: Context) {addUpdateListener { anim ->val p = anim.animatedValue as Floatdrawable.ringRadius = minRadius + (maxRadius - minRadius) * p- drawable.strokeColor = ColorUtils.setAlphaComponent(Color.WHITE, ((1f - p * 0.6f) * 255).toInt())+ // Accent, not white: the ring was set from the skin at+ // construction and then painted over on the first frame.+ drawable.strokeColor = ColorUtils.setAlphaComponent(accent, ((1f - p * 0.6f) * 255).toInt())}start()}@@ -692,15 +714,19 @@ class AssistiveBallOverlay(context: Context) {private fun showDismissTarget() {if (dismissTargetView != null) return+ val colors = palette()val target = TextView(appContext).apply {text = "✕"textSize = 22f- setTextColor(Color.WHITE)+ typeface = colors.sans+ setTextColor(colors.onSurface)gravity = Gravity.CENTER+ // Was #CC222222 with a white rim, which is a fifth theme nobody+ // chose. The rim is the same lit edge the cards wear.background = GradientDrawable().apply {shape = GradientDrawable.OVAL- setColor(Color.parseColor("#CC222222"))- setStroke(dp(2), Color.parseColor("#66FFFFFF"))+ setColor(colors.surface)+ setStroke(dp(2), colors.edgeHighlight)}}val params = WindowManager.LayoutParams(@@ -778,9 +804,10 @@ class AssistiveBallOverlay(context: Context) {gravity = Gravity.TOP or Gravity.START}- private fun cardLayoutParams(): WindowManager.LayoutParams =+ /** Wide enough for [card] plus the room its shadow needs on either side. */+ private fun cardLayoutParams(card: View): WindowManager.LayoutParams =WindowManager.LayoutParams(- dp(320),+ dp(320) + ((card.background as? OverlayCardDrawable)?.shadowPadPx ?: 0) * 2,WindowManager.LayoutParams.WRAP_CONTENT,overlayType(),WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,@@ -806,6 +833,13 @@ class AssistiveBallOverlay(context: Context) {private companion object {const val BALL_SIZE_DP = 56++ /** Taken out of the disc, not added to the window — see [buildBall]. */+ const val BALL_SHADOW_DP = 4f++ /** How far the mark sits inside the disc. */+ const val BALL_MARK_INSET_DP = 9+const val MENU_WIDTH_DP = 290const val LONG_PRESS_START_MS = 2000Lconst val LONG_PRESS_END_MS = 2000Ldiff --git a/app/src/main/java/com/gotcha/ui/ConfirmationOverlay.kt b/app/src/main/java/com/gotcha/ui/ConfirmationOverlay.ktindex 2f557f6..6188f23 100644--- a/app/src/main/java/com/gotcha/ui/ConfirmationOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/ConfirmationOverlay.kt@@ -9,10 +9,10 @@ import android.provider.Settingsimport android.view.Gravityimport android.view.Viewimport android.view.WindowManager-import android.widget.Buttonimport android.widget.LinearLayoutimport android.widget.TextViewimport com.gotcha.data.SettingsRepository+import com.gotcha.ui.theme.OverlaySkinimport com.gotcha.ui.theme.Skinsimport com.gotcha.ui.theme.overlaySkin@@ -43,7 +43,7 @@ class ConfirmationOverlay(context: Context) {removeView()val card = buildCard(summary, onAllow, onDeny)try {- windowManager.addView(card, layoutParams())+ windowManager.addView(card, layoutParams(card))view = card} catch (_: Exception) {view = null@@ -74,12 +74,7 @@ class ConfirmationOverlay(context: Context) {)val container = LinearLayout(appContext).apply {orientation = LinearLayout.VERTICAL- setPadding(dp(20), dp(20), dp(20), dp(20))- background = GradientDrawable().apply {- cornerRadius = dp(colors.cardRadiusDp.toInt()).toFloat()- setColor(colors.surface)- setStroke(dp(1), colors.outline)- }+ applyOverlayCard(colors, horizontalDp = 20, verticalDp = 20)}val title = TextView(appContext).apply {@@ -102,16 +97,11 @@ class ConfirmationOverlay(context: Context) {gravity = Gravity.ENDsetPadding(0, dp(16), 0, 0)}- val deny = Button(appContext).apply {- text = "Deny"- setOnClickListener { onDeny() }- }- val allow = Button(appContext).apply {- text = "Allow"- setOnClickListener { onAllow() }- }- buttonRow.addView(deny)- buttonRow.addView(allow)+ // Platform [Button]s until now, which meant the one card that asks the+ // user to approve something was the one card drawn in someone else's+ // design. Allow is the accented one: it is the answer that does work.+ buttonRow.addView(choice("Deny", colors, filled = false, onClick = onDeny))+ buttonRow.addView(choice("Allow", colors, filled = true, onClick = onAllow))container.addView(title)container.addView(body)@@ -119,12 +109,44 @@ class ConfirmationOverlay(context: Context) {return container}- private fun layoutParams(): WindowManager.LayoutParams {+ private fun choice(+ label: String,+ colors: OverlaySkin,+ filled: Boolean,+ onClick: () -> Unit+ ): TextView = TextView(appContext).apply {+ text = label+ typeface = colors.sans+ textSize = colors.bodySp+ gravity = Gravity.CENTER+ isClickable = true+ isFocusable = true+ setTextColor(if (filled) colors.onAccent else colors.onSurfaceVariant)+ setPadding(dp(20), dp(10), dp(20), dp(10))+ background = GradientDrawable().apply {+ cornerRadius = dp(colors.buttonRadiusDp.toInt()).toFloat()+ setColor(if (filled) colors.accent else colors.surface)+ if (!filled) setStroke(dp(1), colors.outline)+ }+ layoutParams = LinearLayout.LayoutParams(+ LinearLayout.LayoutParams.WRAP_CONTENT,+ LinearLayout.LayoutParams.WRAP_CONTENT+ ).apply { setMargins(dp(8), 0, 0, 0) }+ setOnClickListener { onClick() }+ }++ /**+ * [card]'s width is the card plus the room its shadow needs on either side.+ * Sizing the window to the card alone would clip the shadow to a hard+ * square edge — the exact artefact the shadow is there to avoid.+ */+ private fun layoutParams(card: View): WindowManager.LayoutParams {val type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY+ val shadowPad = (card.background as? OverlayCardDrawable)?.shadowPadPx ?: 0// FLAG_NOT_FOCUSABLE keeps us from stealing the keyboard, but the window still// receives touch events, so the Allow/Deny buttons remain tappable.return WindowManager.LayoutParams(- dp(320),+ dp(320) + shadowPad * 2,WindowManager.LayoutParams.WRAP_CONTENT,type,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,diff --git a/app/src/main/java/com/gotcha/ui/OverlayCardDrawable.kt b/app/src/main/java/com/gotcha/ui/OverlayCardDrawable.ktnew file mode 100644index 0000000..d9c9abc--- /dev/null+++ b/app/src/main/java/com/gotcha/ui/OverlayCardDrawable.kt@@ -0,0 +1,197 @@+package com.gotcha.ui++import android.graphics.Canvas+import android.graphics.ColorFilter+import android.graphics.Paint+import android.graphics.PixelFormat+import android.graphics.Rect+import android.graphics.RectF+import android.graphics.drawable.Drawable+import android.view.View+import androidx.core.graphics.ColorUtils+import com.gotcha.ui.theme.OverlaySkin++/**+ * The background every overlay surface is drawn on: a soft drop shadow, an+ * opaque fill, a hairline outline, and a lit top edge.+ *+ * An overlay floats over somebody else's app. There is nothing of ours behind+ * it, so the app's glass — blur, scrim, translucency — has nothing to show+ * through and would only make the surface unreadable over an unknown screen.+ * Depth here has to be carried by the edge and the shadow instead, which is a+ * technique that works over a white document and a photograph alike.+ *+ * The shadow is stacked rounded rects rather than [Paint.setShadowLayer] or a+ * [android.graphics.BlurMaskFilter]: both of those are ignored on a+ * hardware-accelerated canvas for anything but text, and forcing the view into+ * a software layer to get them back would cost more than this does — a handful+ * of alpha-blended rects, each cheap, drawn once and then cached with the rest+ * of the view.+ */+class OverlayCardDrawable(+ private val fillColor: Int,+ private val strokeColor: Int,+ private val highlightColor: Int,+ private val shadowColor: Int,+ private val cornerRadiusPx: Float,+ private val shadowRadiusPx: Float,+ private val hairlinePx: Float+) : Drawable() {++ private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }+ private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }+ private val shadowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }++ private val rect = RectF()+ private val scratch = RectF()++ /** How much room the shadow needs outside the card, in whole pixels. */+ val shadowPadPx: Int = kotlin.math.ceil(shadowRadiusPx).toInt()++ /**+ * The shadow reads as cast from above, so it sits slightly low. Kept well+ * under the blur radius: any further and the card looks like it is peeling+ * off the screen rather than resting a few millimetres above it.+ */+ private val shadowOffsetPx: Float = shadowRadiusPx * SHADOW_DROP++ override fun getPadding(padding: Rect): Boolean {+ padding.set(shadowPadPx, shadowPadPx, shadowPadPx, shadowPadPx)+ return shadowPadPx > 0+ }++ override fun draw(canvas: Canvas) {+ if (bounds.isEmpty) return+ rect.set(+ bounds.left + shadowPadPx.toFloat(),+ bounds.top + shadowPadPx.toFloat(),+ bounds.right - shadowPadPx.toFloat(),+ bounds.bottom - shadowPadPx.toFloat()+ )+ if (rect.width() <= 0f || rect.height() <= 0f) return++ drawShadow(canvas)++ fillPaint.color = fillColor+ canvas.drawRoundRect(rect, cornerRadiusPx, cornerRadiusPx, fillPaint)++ strokePaint.strokeWidth = hairlinePx+ strokePaint.color = strokeColor+ val half = hairlinePx / 2f+ scratch.set(rect.left + half, rect.top + half, rect.right - half, rect.bottom - half)+ canvas.drawRoundRect(scratch, cornerRadiusPx, cornerRadiusPx, strokePaint)++ drawTopEdge(canvas)+ }++ /**+ * Each layer is faint; it is the overlap that builds the density, so the+ * result falls off smoothly from the card's edge outward without any layer+ * being visible as a band on its own.+ */+ private fun drawShadow(canvas: Canvas) {+ if (shadowRadiusPx <= 0f) return+ val layerAlpha = android.graphics.Color.alpha(shadowColor).toFloat() / SHADOW_STEPS+ for (step in SHADOW_STEPS downTo 1) {+ val spread = shadowRadiusPx * step / SHADOW_STEPS+ scratch.set(+ rect.left - spread,+ rect.top - spread + shadowOffsetPx,+ rect.right + spread,+ rect.bottom + spread + shadowOffsetPx+ )+ shadowPaint.color = ColorUtils.setAlphaComponent(shadowColor, layerAlpha.toInt())+ canvas.drawRoundRect(+ scratch,+ cornerRadiusPx + spread,+ cornerRadiusPx + spread,+ shadowPaint+ )+ }+ }++ /**+ * The highlight is the same rounded rect as the outline, clipped to the top+ * of the card, so it follows the corners round and stops where the light+ * would. Drawn last, over the outline it replaces along that edge.+ */+ private fun drawTopEdge(canvas: Canvas) {+ val strip = cornerRadiusPx.coerceAtLeast(hairlinePx * 2f)+ canvas.save()+ canvas.clipRect(rect.left, rect.top, rect.right, rect.top + strip)+ strokePaint.color = highlightColor+ strokePaint.strokeWidth = hairlinePx+ val half = hairlinePx / 2f+ scratch.set(rect.left + half, rect.top + half, rect.right - half, rect.bottom - half)+ canvas.drawRoundRect(scratch, cornerRadiusPx, cornerRadiusPx, strokePaint)+ canvas.restore()+ }++ override fun setAlpha(alpha: Int) {+ fillPaint.alpha = alpha+ strokePaint.alpha = alpha+ shadowPaint.alpha = alpha+ }++ override fun setColorFilter(colorFilter: ColorFilter?) {+ fillPaint.colorFilter = colorFilter+ strokePaint.colorFilter = colorFilter+ shadowPaint.colorFilter = colorFilter+ }++ @Suppress("Deprecated")+ override fun getOpacity(): Int = PixelFormat.TRANSLUCENT++ private companion object {+ const val SHADOW_STEPS = 8+ const val SHADOW_DROP = 0.3f+ }+}++/**+ * The raised surface for [colors], at [radiusDp] (the card radius unless the+ * caller wants the button radius, or half a ball).+ */+fun overlayCardBackground(+ density: Float,+ colors: OverlaySkin,+ radiusDp: Float = colors.cardRadiusDp,+ fill: Int = colors.surface,+ shadowRadiusDp: Float = colors.shadowRadiusDp+): OverlayCardDrawable = OverlayCardDrawable(+ fillColor = fill,+ strokeColor = colors.outline,+ highlightColor = colors.edgeHighlight,+ shadowColor = colors.shadowColor,+ cornerRadiusPx = radiusDp * density,+ shadowRadiusPx = shadowRadiusDp * density,+ hairlinePx = density.coerceAtLeast(1f)+)++/**+ * Give [this] the raised overlay surface, with [horizontalDp]/[verticalDp] of+ * content padding *inside* it.+ *+ * Padding is set here rather than left to the caller because the shadow lives+ * outside the card and needs its own room in the view: a `setPadding` call+ * after `setBackground` silently discards the drawable's own padding, which is+ * exactly how a shadow ends up clipped to a hard square edge.+ */+fun View.applyOverlayCard(+ colors: OverlaySkin,+ horizontalDp: Int,+ verticalDp: Int,+ radiusDp: Float = colors.cardRadiusDp,+ fill: Int = colors.surface+) {+ val density = resources.displayMetrics.density+ val card = overlayCardBackground(density, colors, radiusDp, fill)+ background = card+ val pad = card.shadowPadPx+ setPadding(+ pad + (horizontalDp * density).toInt(),+ pad + (verticalDp * density).toInt(),+ pad + (horizontalDp * density).toInt(),+ pad + (verticalDp * density).toInt()+ )+}diff --git a/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt b/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.ktindex dd1a094..71b7155 100644--- a/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt+++ b/app/src/main/java/com/gotcha/ui/ScreenCompanionPanelOverlay.kt@@ -50,6 +50,13 @@ class ScreenCompanionPanelOverlay(private val context: Context) {private var isListening = falseprivate var isSpeaking = false+ /**+ * The skin the visible panel was built with. [setListening] and+ * [setSpeaking] fire long after [show] and need the same palette the rest+ * of the panel is wearing.+ */+ private var currentColors: OverlaySkin? = null+private fun dp(value: Int): Int = (value * appContext.resources.displayMetrics.density).toInt()/**@@ -80,15 +87,12 @@ class ScreenCompanionPanelOverlay(private val context: Context) {}val colors = skin()+ currentColors = colorsval container = LinearLayout(appContext).apply {orientation = LinearLayout.VERTICAL- setPadding(dp(16), dp(16), dp(16), dp(16))- background = GradientDrawable().apply {- cornerRadius = dp(colors.cardRadiusDp.toInt()).toFloat()- setColor(colors.surface)- setStroke(dp(1), colors.outline)- }+ applyOverlayCard(colors, horizontalDp = 16, verticalDp = 16)}+ val shadowPad = (container.background as? OverlayCardDrawable)?.shadowPadPx ?: 0val headerLayout = LinearLayout(appContext).apply {orientation = LinearLayout.HORIZONTAL@@ -104,6 +108,7 @@ class ScreenCompanionPanelOverlay(private val context: Context) {}val speakerBtn = TextView(appContext).apply {text = "🔊"+ setTextColor(colors.onSurfaceVariant)textSize = colors.titleSpsetPadding(dp(8), dp(8), dp(8), dp(8))setOnClickListener {@@ -147,6 +152,7 @@ class ScreenCompanionPanelOverlay(private val context: Context) {text = initialPromptsetTextColor(colors.onSurfaceVariant)textSize = colors.labelSp+ typeface = colors.sanssetPadding(0, 0, 0, dp(8))}chatContainer.addView(promptView)@@ -155,6 +161,7 @@ class ScreenCompanionPanelOverlay(private val context: Context) {text = resultText ?: "Thinking..."setTextColor(colors.onSurface)textSize = colors.bodySp+ typeface = colors.sanssetPadding(0, dp(8), 0, dp(16))// Ensure links are clickablemovementMethod = android.text.method.LinkMovementMethod.getInstance()@@ -208,8 +215,9 @@ class ScreenCompanionPanelOverlay(private val context: Context) {val editText = EditText(appContext).apply {hint = "Ask a follow-up..."- setHintTextColor(Color.GRAY)+ setHintTextColor(colors.onSurfaceVariant)setTextColor(colors.onSurface)+ typeface = colors.sansbackground = nulllayoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)textSize = colors.labelSp@@ -219,6 +227,7 @@ class ScreenCompanionPanelOverlay(private val context: Context) {val micBtn = TextView(appContext).apply {text = "🎤"+ setTextColor(colors.onSurfaceVariant)textSize = colors.titleSpsetPadding(dp(8), dp(8), dp(8), dp(8))setOnClickListener {@@ -235,7 +244,9 @@ class ScreenCompanionPanelOverlay(private val context: Context) {val sendButton = Button(appContext).apply {text = "Send"- setTextColor(Color.CYAN)+ // Was Color.CYAN — Deep Space, from before there was a second theme.+ setTextColor(colors.accent)+ typeface = colors.sansbackground = nullsetOnClickListener {val input = editText.text.toString()@@ -250,9 +261,11 @@ class ScreenCompanionPanelOverlay(private val context: Context) {inputLayout.addView(sendButton)container.addView(inputLayout)+ // Sized to the card plus the room its shadow needs, so the shadow is not+ // clipped to the window's square edge.val params = WindowManager.LayoutParams(- dp(320),- dp(400),+ dp(320) + shadowPad * 2,+ dp(400) + shadowPad * 2,WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE orWindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,@@ -300,7 +313,7 @@ class ScreenCompanionPanelOverlay(private val context: Context) {}private fun createChip(label: String): TextView {- val colors = skin()+ val colors = currentColors ?: skin()return TextView(appContext).apply {text = labelsetTextColor(colors.buttonText)@@ -342,13 +355,19 @@ class ScreenCompanionPanelOverlay(private val context: Context) {}}- /** Reflect STT listening state on the mic icon (tinted while active). */+ /**+ * Reflect STT listening state on the mic icon (tinted while active).+ *+ * Recording stays red in every skin, the way the call window's amber and+ * coral do: a colour that tells the user a microphone is open has to mean+ * the same thing whichever theme they picked.+ */fun setListening(listening: Boolean) {isListening = listeningmainHandler.post {micButton?.apply {text = if (listening) "⏺" else "🎤"- setTextColor(if (listening) Color.RED else Color.WHITE)+ setTextColor(if (listening) RECORDING_RED else currentColors?.onSurfaceVariant ?: Color.WHITE)}}}@@ -359,7 +378,8 @@ class ScreenCompanionPanelOverlay(private val context: Context) {mainHandler.post {speakerButton?.apply {text = if (speaking) "⏹" else "🔊"- setTextColor(if (speaking) Color.CYAN else Color.WHITE)+ val resting = currentColors?.onSurfaceVariant ?: Color.WHITE+ setTextColor(if (speaking) currentColors?.accent ?: Color.WHITE else resting)}}}@@ -377,7 +397,13 @@ class ScreenCompanionPanelOverlay(private val context: Context) {speakerButton = nullisListening = falseisSpeaking = false+ currentColors = nullonDismiss()}}++ private companion object {+ /** Semantic, not thematic: an open microphone is red in every skin. */+ val RECORDING_RED = Color.parseColor("#E23B3B")+ }}diff --git a/app/src/main/java/com/gotcha/ui/theme/OverlaySkin.kt b/app/src/main/java/com/gotcha/ui/theme/OverlaySkin.ktindex 4eee390..6a69cb4 100644--- a/app/src/main/java/com/gotcha/ui/theme/OverlaySkin.kt+++ b/app/src/main/java/com/gotcha/ui/theme/OverlaySkin.kt@@ -1,11 +1,27 @@package com.gotcha.ui.themeimport android.content.Context+import android.graphics.Colorimport android.graphics.Typefaceimport androidx.compose.ui.graphics.toArgbimport androidx.core.content.res.ResourcesCompat+import androidx.core.graphics.ColorUtilsimport com.gotcha.R+/** How far the top edge is lifted off a dark surface. */+private const val EDGE_LIGHTEN = 0.14f++/**+ * How far it is sunk into a light one. Lower than it looks like it should be:+ * on a near-white panel a little ink goes a very long way, and 22% — the+ * mirror of the dark figure — reads as a second border rather than an edge.+ */+private const val EDGE_DARKEN = 0.12f++private const val SHADOW_ALPHA_DARK = 0x66+private const val SHADOW_ALPHA_LIGHT = 0x4D+private const val SHADOW_RADIUS_DP = 12f+/*** The active skin, in the form View code can use.*@@ -22,6 +38,12 @@ import com.gotcha.R*/data class OverlaySkin(val surface: Int,+ /**+ * What the skin paints under everything else. The ball is drawn on this+ * rather than on [surface]: it is not a panel, it is the app itself made+ * small, so it wears the app's floor.+ */+ val ground: Int,val onSurface: Int,val onSurfaceVariant: Int,val outline: Int,@@ -34,6 +56,19 @@ data class OverlaySkin(val cardRadiusDp: Float,/** Radius for buttons and rows, in dp, from [Skin.cornerSmall]. */val buttonRadiusDp: Float,+ /**+ * The lit top edge of a raised surface, already composited onto [surface].+ *+ * Lighter than the surface on a dark skin, darker on a light one. That+ * asymmetry is the point: a white hairline on Vellum's near-white panel is+ * invisible, so what sells the raise there is a fine dark rule against the+ * app underneath, the same way a printed card sits on paper.+ */+ val edgeHighlight: Int,+ /** Colour of the drop shadow, alpha included. */+ val shadowColor: Int,+ /** How far the shadow spreads beyond the card, in dp. */+ val shadowRadiusDp: Float,val sans: Typeface,val mono: Typeface,val titleSp: Float,@@ -69,8 +104,11 @@ private fun figtree(context: Context): Typeface {fun overlaySkin(context: Context, skinId: String): OverlaySkin {val skin = Skins.byId(skinId).opaque()val scheme = skin.scheme+ val surface = scheme.surface.toArgb()+ val dark = skin.brightness == Brightness.DARKreturn OverlaySkin(- surface = scheme.surface.toArgb(),+ surface = surface,+ ground = scheme.background.toArgb(),onSurface = scheme.onSurface.toArgb(),onSurfaceVariant = scheme.onSurfaceVariant.toArgb(),outline = scheme.outline.toArgb(),@@ -81,6 +119,18 @@ fun overlaySkin(context: Context, skinId: String): OverlaySkin {error = scheme.error.toArgb(),cardRadiusDp = skin.corner.value,buttonRadiusDp = skin.cornerSmall.value,+ edgeHighlight = ColorUtils.blendARGB(+ surface,+ if (dark) Color.WHITE else Color.BLACK,+ if (dark) EDGE_LIGHTEN else EDGE_DARKEN+ ),+ // Deeper under a light skin, where there is less contrast between the+ // card and a bright host app to do the separating on its own.+ shadowColor = ColorUtils.setAlphaComponent(+ Color.BLACK,+ if (dark) SHADOW_ALPHA_DARK else SHADOW_ALPHA_LIGHT+ ),+ shadowRadiusDp = SHADOW_RADIUS_DP,sans = figtree(context),mono = Typeface.MONOSPACE,titleSp = Typography.titleMedium.fontSize.value,diff --git a/app/src/test/java/com/gotcha/ui/theme/OverlaySkinTest.kt b/app/src/test/java/com/gotcha/ui/theme/OverlaySkinTest.ktindex f2854ec..c14daa6 100644--- a/app/src/test/java/com/gotcha/ui/theme/OverlaySkinTest.kt+++ b/app/src/test/java/com/gotcha/ui/theme/OverlaySkinTest.kt@@ -2,6 +2,7 @@ package com.gotcha.ui.themeimport android.graphics.Colorimport androidx.compose.ui.graphics.toArgb+import androidx.core.graphics.ColorUtilsimport androidx.test.core.app.ApplicationProviderimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrue@@ -71,6 +72,55 @@ class OverlaySkinTest {assertEquals(overlaySkin(context, Skins.DEFAULT_ID).accent, fallback.accent)}+ /**+ * Depth over another app's screen comes from the edge, not from blur — so+ * the edge has to actually be visible against the surface it sits on. Which+ * direction that is depends on the skin: a white hairline on Vellum's+ * near-white panel would be nothing at all.+ */+ @Test+ fun `the top edge is lit against the surface, whichever way the skin runs`() {+ Skins.all.forEach { skin ->+ val tokens = overlaySkin(context, skin.id)+ val surface = luminance(tokens.surface)+ val edge = luminance(tokens.edgeHighlight)+ if (skin.brightness == Brightness.DARK) {+ assertTrue(+ "${skin.id}: the edge must be lighter than the surface ($edge vs $surface)",+ edge > surface+ )+ } else {+ assertTrue(+ "${skin.id}: the edge must be darker than the surface ($edge vs $surface)",+ edge < surface+ )+ }+ }+ }++ /** Far enough to read, close enough not to look like a second border. */+ @Test+ fun `the edge stays a hairline rather than becoming a band of its own`() {+ Skins.all.forEach { skin ->+ val tokens = overlaySkin(context, skin.id)+ val delta = kotlin.math.abs(luminance(tokens.edgeHighlight) - luminance(tokens.surface))+ assertTrue("${skin.id}: edge is invisible ($delta)", delta > 0.01)+ assertTrue("${skin.id}: edge is shouting ($delta)", delta < 0.35)+ }+ }++ @Test+ fun `the shadow is translucent black and has somewhere to fall`() {+ Skins.all.forEach { skin ->+ val tokens = overlaySkin(context, skin.id)+ val alpha = Color.alpha(tokens.shadowColor)+ assertTrue("${skin.id}: an opaque shadow is a black box", alpha in 1..254)+ assertTrue("${skin.id}: a shadow needs room to spread", tokens.shadowRadiusDp > 0f)+ }+ }++ private fun luminance(argb: Int): Double = ColorUtils.calculateLuminance(argb)+/** Type sizes track the app's scale rather than being chosen per overlay. */@Testfun `type sizes come from the app typography`() {