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.

feat: update ScreenLensController and ScreenCropOverlayView to support dynamic theme colors

Durganshu Mishraaec853afaca2
diff --git a/app/src/main/java/com/gotcha/service/ScreenLensController.kt b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
index 12bac42..2d0a5e2 100644
--- a/app/src/main/java/com/gotcha/service/ScreenLensController.kt
+++ b/app/src/main/java/com/gotcha/service/ScreenLensController.kt
@@ -12,6 +12,10 @@ import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.gotcha.ui.ScreenCropOverlayView
+import com.gotcha.ui.applyOverlayCard
+import com.gotcha.ui.theme.OverlaySkin
+import com.gotcha.ui.theme.Skins
+import com.gotcha.ui.theme.overlaySkin
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -29,6 +33,17 @@ class ScreenLensController(
private val onCaptureChrome: (hide: Boolean) -> Unit = {}
) {
private val appContext = context.applicationContext
+
+ /**
+ * The active skin, re-read on every build rather than cached, so a theme
+ * change in Settings reaches Lens without the window being torn down.
+ */
+ private fun currentColors(): OverlaySkin = overlaySkin(
+ appContext,
+ runCatching { com.gotcha.data.SettingsRepository(appContext).load().skinId }
+ .getOrDefault(Skins.DEFAULT_ID)
+ )
+
private val windowManager = appContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
private val mainHandler = Handler(Looper.getMainLooper())
@@ -50,6 +65,7 @@ class ScreenLensController(
val overlay = ScreenCropOverlayView(
appContext,
+ colors = currentColors(),
onSelection = { rect -> onRegionSelected(rect) },
onCancel = { cancel() },
onReselectStart = {
@@ -189,28 +205,24 @@ class ScreenLensController(
val overlay = cropOverlay ?: return
val density = appContext.resources.displayMetrics.density
val cleanText = regionText?.replace(Regex("\\s+"), " ")?.trim()
+ val colors = currentColors()
val chipsLayout = android.widget.LinearLayout(appContext).apply {
orientation = android.widget.LinearLayout.HORIZONTAL
gravity = Gravity.CENTER
- setPadding((6 * density).toInt(), (4 * density).toInt(), (6 * density).toInt(), (4 * density).toInt())
- background = android.graphics.drawable.GradientDrawable().apply {
- cornerRadius = 14f * density
- setColor(android.graphics.Color.parseColor("#EE101018"))
- setStroke((1 * density).toInt(), android.graphics.Color.parseColor("#44568CD8"))
- }
+ applyOverlayCard(colors, horizontalDp = 6, verticalDp = 4)
}
if (!cleanText.isNullOrBlank()) {
chipsLayout.addView(
- chipButton("📝 Select") {
+ chipButton("📝 Select", colors) {
showSelectableTextCard(cleanText)
}
)
}
chipsLayout.addView(
- chipButton("📋 Copy") {
+ chipButton("📋 Copy", colors) {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -228,21 +240,17 @@ class ScreenLensController(
if (!isAlreadyInPreferredLang) {
chipsLayout.addView(
- chipButton("🌐 Translate") {
- val crop = pendingCrop
- if (crop != null && !crop.isRecycled) {
- val base64 = bitmapToBase64(crop)
- val prompt = "Extract text from this screenshot, translate it to $preferredLang, " +
- "and display both original and translated text."
- onImagePrompt(base64, prompt)
- }
+ chipButton("🌐 Translate", colors) {
+ val prompt = "Extract text from this screenshot, translate it to $preferredLang, " +
+ "and display both original and translated text."
+ encodePendingCrop { base64 -> onImagePrompt(base64, prompt) }
cancel()
}
)
}
chipsLayout.addView(
- chipButton("💾 Save") {
+ chipButton("💾 Save", colors) {
val crop = pendingCrop
if (crop != null && !crop.isRecycled) {
val cropCopy = runCatching { crop.copy(crop.config, false) }.getOrNull()
@@ -255,13 +263,9 @@ class ScreenLensController(
)
chipsLayout.addView(
- chipButton("❓ Ask") {
- val crop = pendingCrop
- if (crop != null && !crop.isRecycled) {
- val base64 = bitmapToBase64(crop)
- onAskAboutCrop(base64)
- cancel()
- }
+ chipButton("❓ Ask", colors) {
+ encodePendingCrop { base64 -> onAskAboutCrop(base64) }
+ cancel()
}
)
@@ -303,12 +307,13 @@ class ScreenLensController(
}
}
- private fun chipButton(label: String, onClick: () -> Unit): TextView {
+ private fun chipButton(label: String, colors: OverlaySkin, onClick: () -> Unit): TextView {
val density = appContext.resources.displayMetrics.density
return TextView(appContext).apply {
text = label
- textSize = 12f
- setTextColor(android.graphics.Color.WHITE)
+ textSize = colors.labelSp
+ typeface = colors.sans
+ setTextColor(colors.buttonText)
setPadding((10 * density).toInt(), (6 * density).toInt(), (10 * density).toInt(), (6 * density).toInt())
setOnClickListener { onClick() }
}
@@ -317,30 +322,27 @@ class ScreenLensController(
private fun showSelectableTextCard(text: String) {
removeActionMenu()
val density = appContext.resources.displayMetrics.density
+ val colors = currentColors()
val cardLayout = android.widget.LinearLayout(appContext).apply {
orientation = android.widget.LinearLayout.VERTICAL
- setPadding((16 * density).toInt(), (14 * density).toInt(), (16 * density).toInt(), (14 * density).toInt())
- background = android.graphics.drawable.GradientDrawable().apply {
- cornerRadius = 18f * density
- setColor(android.graphics.Color.parseColor("#F51E293B"))
- setStroke((1 * density).toInt(), android.graphics.Color.parseColor("#334155"))
- }
+ applyOverlayCard(colors, horizontalDp = 16, verticalDp = 14)
}
val titleView = TextView(appContext).apply {
this.text = "📝 Extracted Text"
- textSize = 14f
- setTypeface(null, android.graphics.Typeface.BOLD)
- setTextColor(android.graphics.Color.WHITE)
+ textSize = colors.titleSp
+ setTypeface(colors.sans, android.graphics.Typeface.BOLD)
+ setTextColor(colors.onSurface)
setPadding(0, 0, 0, (8 * density).toInt())
}
cardLayout.addView(titleView)
val textView = TextView(appContext).apply {
this.text = text
- textSize = 13f
- setTextColor(android.graphics.Color.parseColor("#E2E8F0"))
+ textSize = colors.bodySp
+ typeface = colors.sans
+ setTextColor(colors.onSurfaceVariant)
setTextIsSelectable(true)
}
@@ -359,7 +361,7 @@ class ScreenLensController(
}
btnRow.addView(
- chipButton("📋 Copy All") {
+ chipButton("📋 Copy All", colors) {
val clipService = Context.CLIPBOARD_SERVICE
val clipManager = appContext.getSystemService(clipService) as? android.content.ClipboardManager
clipManager?.setPrimaryClip(android.content.ClipData.newPlainText("Extracted Text", text))
@@ -373,7 +375,7 @@ class ScreenLensController(
)
btnRow.addView(
- chipButton("✕ Close") {
+ chipButton("✕ Close", colors) {
cancel()
}
)
@@ -402,25 +404,22 @@ class ScreenLensController(
if (actions.isEmpty()) return
val density = appContext.resources.displayMetrics.density
+ val colors = currentColors()
val menuLayout = android.widget.LinearLayout(appContext).apply {
orientation = android.widget.LinearLayout.VERTICAL
- setPadding((8 * density).toInt(), (8 * density).toInt(), (8 * density).toInt(), (8 * density).toInt())
- background = android.graphics.drawable.GradientDrawable().apply {
- cornerRadius = 16f * density
- setColor(android.graphics.Color.parseColor("#F51E293B"))
- setStroke((1 * density).toInt(), android.graphics.Color.parseColor("#334155"))
- }
+ applyOverlayCard(colors, horizontalDp = 8, verticalDp = 8)
}
for (action in actions) {
val btn = TextView(appContext).apply {
text = action.label
- textSize = 13f
- setTextColor(android.graphics.Color.parseColor("#E2E8F0"))
+ textSize = colors.bodySp
+ typeface = colors.sans
+ setTextColor(colors.buttonText)
setPadding((14 * density).toInt(), (8 * density).toInt(), (14 * density).toInt(), (8 * density).toInt())
background = android.graphics.drawable.GradientDrawable().apply {
- cornerRadius = 10f * density
- setColor(android.graphics.Color.parseColor("#334155"))
+ cornerRadius = colors.buttonRadiusDp * density
+ setColor(colors.buttonBg)
}
layoutParams = android.widget.LinearLayout.LayoutParams(
android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
@@ -508,6 +507,36 @@ class ScreenLensController(
} catch (_: Exception) {}
}
+ /**
+ * JPEG-encode the pending crop off the main thread and hand the result to
+ * [onEncoded] back on it.
+ *
+ * The caller is expected to `cancel()` immediately after calling this, which
+ * recycles [pendingCrop] — so this takes its own copy first rather than
+ * racing that. Encoding used to happen inline in the click listener, which
+ * meant compressing a screen-sized bitmap on the UI thread while the overlay
+ * was still up.
+ */
+ private fun encodePendingCrop(onEncoded: (String) -> Unit) {
+ val crop = pendingCrop
+ if (crop == null || crop.isRecycled) return
+ val copy = runCatching { crop.copy(crop.config, false) }.getOrNull() ?: return
+ scope.launch(Dispatchers.IO) {
+ val base64 = try {
+ bitmapToBase64(copy)
+ } catch (_: Exception) {
+ null
+ } finally {
+ if (!copy.isRecycled) copy.recycle()
+ }
+ if (base64 != null) {
+ withContext(Dispatchers.Main) { onEncoded(base64) }
+ } else {
+ withContext(Dispatchers.Main) { onError("Couldn't prepare the image") }
+ }
+ }
+ }
+
private fun bitmapToBase64(bitmap: Bitmap): String {
val baos = java.io.ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, baos)
diff --git a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
index 7846b92..2c40e88 100644
--- a/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
+++ b/app/src/main/java/com/gotcha/ui/ScreenCropOverlayView.kt
@@ -13,15 +13,35 @@ import android.graphics.RectF
import android.graphics.Shader
import android.view.MotionEvent
import android.view.View
+import androidx.core.graphics.ColorUtils
import com.gotcha.service.AnnotatedEntity
+import com.gotcha.ui.theme.OverlaySkin
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
+/**
+ * The full-screen Lens canvas.
+ *
+ * Two families of paint live here and they follow different rules:
+ *
+ * - **Decoration** — the dim, the edge glow, the particles and the pink→blue ink
+ * of the lasso itself — is deliberately *not* skinned. It is what makes Lens
+ * read as Lens rather than as a screenshot tool, and it is the same signature
+ * in every theme.
+ * - **Functional chrome** — the screen border, the selection box, the entity
+ * boxes and their chips — comes from [colors], like every other overlay.
+ *
+ * The one deliberate exception is the hint text, which is drawn straight onto
+ * the dim rather than onto a surface of ours. It stays white whatever the skin
+ * is, for the same reason the dim stays dark: on a light skin `onSurface` is
+ * near-black ink, and near-black ink on a 40% dark dim is unreadable.
+ */
@SuppressLint("ViewConstructor")
@Suppress("TooManyFunctions", "LargeClass", "MaxLineLength")
class ScreenCropOverlayView(
context: Context,
+ private val colors: OverlaySkin,
private val onSelection: (Rect) -> Unit,
private val onCancel: () -> Unit,
private val onReselectStart: () -> Unit = {},
@@ -55,47 +75,79 @@ class ScreenCropOverlayView(
private val screenBorderPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = 3f * density
- color = Color.parseColor("#B0568CD8")
+ color = ColorUtils.setAlphaComponent(colors.accent, BORDER_ALPHA)
}
private val screenBorderGlowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = 8f * density
- color = Color.parseColor("#55A0459E")
+ color = ColorUtils.setAlphaComponent(colors.accent, GLOW_ALPHA)
maskFilter = android.graphics.BlurMaskFilter(14f * density, android.graphics.BlurMaskFilter.Blur.NORMAL)
}
private val boxPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = 3f * density
- color = Color.parseColor("#D0B06FD0")
+ color = ColorUtils.setAlphaComponent(colors.accent, SELECTION_ALPHA)
pathEffect = android.graphics.DashPathEffect(floatArrayOf(14f * density, 8f * density), 0f)
}
private val boxGlowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = 7f * density
- color = Color.parseColor("#55568CD8")
+ color = ColorUtils.setAlphaComponent(colors.accent, GLOW_ALPHA)
maskFilter = android.graphics.BlurMaskFilter(12f * density, android.graphics.BlurMaskFilter.Blur.NORMAL)
}
private val entityBoxPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.STROKE
strokeWidth = 2.5f * density
- color = Color.parseColor("#FF00E5FF")
+ color = colors.accent
}
private val entityChipBgPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
- color = Color.parseColor("#EE1E293B")
+ // Opaque, not the old #EE: a chip sits over an app we do not control, so
+ // there is nothing behind it that showing through would help.
+ color = colors.surface
}
private val entityChipTextPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
- color = Color.WHITE
- textSize = 12f * density
+ color = colors.onSurface
+ textSize = colors.labelSp * density
+ typeface = colors.sans
textAlign = Paint.Align.LEFT
}
private val particlePaint = Paint(Paint.ANTI_ALIAS_FLAG)
+
+ /**
+ * One gradient per particle colour, built at unit radius around the origin and
+ * moved into place with [glowMatrix] for each draw.
+ *
+ * The obvious way to draw these is a fresh [RadialGradient] per particle per
+ * frame, which is what this used to do: 220 particles at refresh rate is well
+ * over ten thousand shader allocations a second, all of it garbage. The
+ * twinkle is applied through [Paint.setAlpha] instead of being baked into the
+ * gradient's colours, which is what makes a shared shader possible at all.
+ */
+ private val pinkGlowShader by lazy { unitGlowShader(PARTICLE_PINK) }
+ private val blueGlowShader by lazy { unitGlowShader(PARTICLE_BLUE) }
+ private val glowMatrix = android.graphics.Matrix()
+
+ /** Scratch, reused by [drawAnnotatedEntities] and [onTouchEvent]. */
+ private val scratchLocation = IntArray(2)
+ private val scratchRect = RectF()
+ private val scratchChipRect = RectF()
+
+ /** The bounds [pathPaint]'s gradient was last built for. */
+ private var gradientMinX = Float.NaN
+ private var gradientMinY = Float.NaN
+ private var gradientMaxX = Float.NaN
+ private var gradientMaxY = Float.NaN
+
+ // White on purpose — see the class comment. This text has no surface of ours
+ // under it, only the dim over somebody else's app.
private val hintPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE
textSize = 15f * density
+ typeface = colors.sans
textAlign = Paint.Align.CENTER
setShadowLayer(6f, 0f, 0f, Color.parseColor("#E081C0"))
}
@@ -108,6 +160,30 @@ class ScreenCropOverlayView(
setLayerType(LAYER_TYPE_SOFTWARE, null)
}
+ /**
+ * The functional chrome's colours, for tests. Every one of these must move
+ * when the skin moves — that is the whole point of stage B, and the last
+ * time nothing asserted it the overlay sat on a hardcoded cyan for five of
+ * the six skins without anyone noticing.
+ */
+ @androidx.annotation.VisibleForTesting
+ internal fun chromeColors(): IntArray = intArrayOf(
+ screenBorderPaint.color,
+ screenBorderGlowPaint.color,
+ boxPaint.color,
+ entityBoxPaint.color,
+ entityChipBgPaint.color,
+ entityChipTextPaint.color
+ )
+
+ /**
+ * The decorative colours, for tests. These must *not* move with the skin:
+ * the pink/blue signature is what makes Lens read as Lens, and the hint is
+ * white because it is drawn on the dim rather than on a surface of ours.
+ */
+ @androidx.annotation.VisibleForTesting
+ internal fun decorationColors(): IntArray = intArrayOf(dimPaint.color, hintPaint.color)
+
fun setAnnotatedEntities(entities: List<AnnotatedEntity>) {
this.annotatedEntities = entities
postInvalidateOnAnimation()
@@ -171,10 +247,12 @@ class ScreenCropOverlayView(
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
- if (captureMode) {
- postInvalidateOnAnimation()
- return
- }
+ // Nothing is drawn in capture mode, so nothing needs scheduling either.
+ // This used to keep the loop running at refresh rate while producing an
+ // empty frame each time — during the screenshot, which is the one moment
+ // the view should be getting out of the way. `setCaptureMode(false)`
+ // restarts the loop.
+ if (captureMode) return
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), dimPaint)
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), edgeGlowPaint)
@@ -189,13 +267,24 @@ class ScreenCropOverlayView(
val frozen = frozenRect
when {
drawing && moved -> {
- pathPaint.shader = LinearGradient(
- minX, minY, maxX, maxY,
- Color.parseColor("#FF6FC0"), Color.parseColor("#5B8CFF"),
- Shader.TileMode.CLAMP
- )
+ // The gradient only depends on the selection bounds, which change
+ // on a move event rather than on every frame.
+ if (minX != gradientMinX || minY != gradientMinY ||
+ maxX != gradientMaxX || maxY != gradientMaxY
+ ) {
+ gradientMinX = minX
+ gradientMinY = minY
+ gradientMaxX = maxX
+ gradientMaxY = maxY
+ pathPaint.shader = LinearGradient(
+ minX, minY, maxX, maxY,
+ STROKE_PINK, STROKE_BLUE,
+ Shader.TileMode.CLAMP
+ )
+ }
canvas.drawPath(path, pathPaint)
- drawSelectionBox(canvas, RectF(minX, minY, maxX, maxY))
+ scratchRect.set(minX, minY, maxX, maxY)
+ drawSelectionBox(canvas, scratchRect)
}
frozen != null -> drawSelectionBox(canvas, frozen)
else -> if (annotatedEntities.isEmpty()) {
@@ -211,14 +300,14 @@ class ScreenCropOverlayView(
}
private fun drawAnnotatedEntities(canvas: Canvas) {
- val location = IntArray(2)
- getLocationOnScreen(location)
- val viewOffsetX = location[0].toFloat()
- val viewOffsetY = location[1].toFloat()
+ getLocationOnScreen(scratchLocation)
+ val viewOffsetX = scratchLocation[0].toFloat()
+ val viewOffsetY = scratchLocation[1].toFloat()
for (item in annotatedEntities) {
val bounds = item.boundsOnScreen
- val rectF = RectF(
+ val rectF = scratchRect
+ rectF.set(
bounds.left.toFloat() - viewOffsetX,
bounds.top.toFloat() - viewOffsetY,
bounds.right.toFloat() - viewOffsetX,
@@ -226,7 +315,7 @@ class ScreenCropOverlayView(
)
// Draw bounding box
- val radius = 8f * density
+ val radius = colors.buttonRadiusDp * density
canvas.drawRoundRect(rectF, radius, radius, entityBoxPaint)
// Draw primary action chip pill anchored above the box
@@ -238,24 +327,30 @@ class ScreenCropOverlayView(
val chipLeft = (rectF.left).coerceIn(8f * density, width - chipW - 8f * density)
val chipTop = (rectF.top - chipH - 4f * density).coerceAtLeast(8f * density)
- val chipRect = RectF(chipLeft, chipTop, chipLeft + chipW, chipTop + chipH)
-
- canvas.drawRoundRect(chipRect, 12f * density, 12f * density, entityChipBgPaint)
- canvas.drawRoundRect(chipRect, 12f * density, 12f * density, entityBoxPaint)
- canvas.drawText(labelStr, chipLeft + 8f * density, chipTop + 16f * density, entityChipTextPaint)
+ val chipRect = scratchChipRect
+ chipRect.set(chipLeft, chipTop, chipLeft + chipW, chipTop + chipH)
+
+ canvas.drawRoundRect(chipRect, radius, radius, entityChipBgPaint)
+ canvas.drawRoundRect(chipRect, radius, radius, entityBoxPaint)
+ // Centred off the font's own metrics rather than a fixed baseline:
+ // the label size now comes from the skin's type scale, so a hardcoded
+ // offset would drift as soon as that scale moved.
+ val fm = entityChipTextPaint.fontMetrics
+ val baseline = chipRect.centerY() - (fm.ascent + fm.descent) / 2f
+ canvas.drawText(labelStr, chipLeft + 8f * density, baseline, entityChipTextPaint)
}
}
private fun drawScreenBorder(canvas: Canvas) {
val inset = screenBorderGlowPaint.strokeWidth / 2f + 1f
val r = RectF(inset, inset, width - inset, height - inset)
- val radius = 24f * density
+ val radius = colors.cardRadiusDp * density
canvas.drawRoundRect(r, radius, radius, screenBorderGlowPaint)
canvas.drawRoundRect(r, radius, radius, screenBorderPaint)
}
private fun drawSelectionBox(canvas: Canvas, rect: RectF) {
- val radius = 10f * density
+ val radius = colors.buttonRadiusDp * density
canvas.drawRoundRect(rect, radius, radius, boxGlowPaint)
canvas.drawRoundRect(rect, radius, radius, boxPaint)
}
@@ -287,47 +382,61 @@ class ScreenCropOverlayView(
if (p.y > h + p.radius) p.y = -p.radius
val glowAlpha = (0.35f + 0.65f * (0.5f + 0.5f * kotlin.math.sin(t * p.twinkle + p.phase)))
- val core = if (p.pink) 0xFF5FBF else 0x5B8CFF
val a = (glowAlpha * 255).toInt().coerceIn(0, 255)
- particlePaint.shader = RadialGradient(
- p.x, p.y, p.radius * 3.2f,
- Color.argb((a * 0.5f).toInt(), (core shr 16) and 0xFF, (core shr 8) and 0xFF, core and 0xFF),
- Color.TRANSPARENT,
- Shader.TileMode.CLAMP
- )
- canvas.drawCircle(p.x, p.y, p.radius * 3.2f, particlePaint)
+
+ val glowRadius = p.radius * GLOW_RADIUS_SCALE
+ glowMatrix.setScale(glowRadius, glowRadius)
+ glowMatrix.postTranslate(p.x, p.y)
+ val shader = if (p.pink) pinkGlowShader else blueGlowShader
+ shader.setLocalMatrix(glowMatrix)
+ particlePaint.shader = shader
+ // Modulates the shader rather than replacing its colours, which is
+ // what lets every particle of a colour share one gradient.
+ particlePaint.color = Color.WHITE
+ particlePaint.alpha = a
+ canvas.drawCircle(p.x, p.y, glowRadius, particlePaint)
+
particlePaint.shader = null
particlePaint.color = Color.argb(a, 255, 255, 255)
canvas.drawCircle(p.x, p.y, p.radius * 0.6f, particlePaint)
}
}
+ /**
+ * A glow gradient at unit radius around the origin, to be positioned by a
+ * local matrix. Half alpha at the centre, matching what the per-particle
+ * gradients used to bake in before [Paint.setAlpha] took over the twinkle.
+ */
+ private fun unitGlowShader(core: Int): RadialGradient {
+ val centre = Color.argb(
+ GLOW_CENTRE_ALPHA,
+ (core shr 16) and 0xFF,
+ (core shr 8) and 0xFF,
+ core and 0xFF
+ )
+ return RadialGradient(0f, 0f, 1f, centre, Color.TRANSPARENT, Shader.TileMode.CLAMP)
+ }
+
override fun onTouchEvent(event: MotionEvent): Boolean {
if (captureMode) return false
// Check if touch hits an annotated entity box/chip
if (event.action == MotionEvent.ACTION_UP && !moved) {
- val location = IntArray(2)
- getLocationOnScreen(location)
- val viewOffsetX = location[0].toFloat()
- val viewOffsetY = location[1].toFloat()
+ getLocationOnScreen(scratchLocation)
+ val viewOffsetX = scratchLocation[0].toFloat()
+ val viewOffsetY = scratchLocation[1].toFloat()
val touchX = event.x
val touchY = event.y
+ val chipH = 24f * density
+ val expandedBounds = scratchRect
for (item in annotatedEntities) {
val bounds = item.boundsOnScreen
- val rectF = RectF(
- bounds.left.toFloat() - viewOffsetX,
- bounds.top.toFloat() - viewOffsetY,
- bounds.right.toFloat() - viewOffsetX,
- bounds.bottom.toFloat() - viewOffsetY
- )
- val chipH = 24f * density
- val expandedBounds = RectF(
- rectF.left - 16f,
- rectF.top - chipH - 16f,
- rectF.right + 16f,
- rectF.bottom + 16f
+ expandedBounds.set(
+ bounds.left.toFloat() - viewOffsetX - 16f,
+ bounds.top.toFloat() - viewOffsetY - chipH - 16f,
+ bounds.right.toFloat() - viewOffsetX + 16f,
+ bounds.bottom.toFloat() - viewOffsetY + 16f
)
if (expandedBounds.contains(touchX, touchY)) {
val prompt = item.entity.primaryAction?.prompt
@@ -393,5 +502,16 @@ class ScreenCropOverlayView(
private companion object {
const val MIN_SIZE_PX = 24
+ const val PARTICLE_PINK = 0xFF5FBF
+ const val PARTICLE_BLUE = 0x5B8CFF
+ const val GLOW_RADIUS_SCALE = 3.2f
+ const val GLOW_CENTRE_ALPHA = 128
+ const val STROKE_PINK = 0xFFFF6FC0.toInt()
+ const val STROKE_BLUE = 0xFF5B8CFF.toInt()
+
+ /** Alphas the accent is drawn at, matching what the old fixed colours carried. */
+ const val BORDER_ALPHA = 0xB0
+ const val SELECTION_ALPHA = 0xD0
+ const val GLOW_ALPHA = 0x55
}
}
diff --git a/app/src/test/java/com/gotcha/ui/ScreenCropOverlayViewTest.kt b/app/src/test/java/com/gotcha/ui/ScreenCropOverlayViewTest.kt
new file mode 100644
index 0000000..35be9b6
--- /dev/null
+++ b/app/src/test/java/com/gotcha/ui/ScreenCropOverlayViewTest.kt
@@ -0,0 +1,64 @@
+package com.gotcha.ui
+
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import com.gotcha.ui.theme.Skins
+import com.gotcha.ui.theme.overlaySkin
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+/**
+ * The Lens overlay draws two families of paint under different rules: functional
+ * chrome follows the skin, decoration deliberately does not. Both halves need
+ * pinning — a regression in either direction is invisible on the default skin,
+ * which is exactly how the hardcoded `#FF00E5FF` survived. It happened to be
+ * Deep Space Dark's own accent.
+ */
+@RunWith(RobolectricTestRunner::class)
+class ScreenCropOverlayViewTest {
+
+ private val context = ApplicationProvider.getApplicationContext<Context>()
+
+ private fun viewFor(skinId: String) = ScreenCropOverlayView(
+ context,
+ colors = overlaySkin(context, skinId),
+ onSelection = {},
+ onCancel = {}
+ )
+
+ @Test
+ fun `every piece of chrome follows the skin`() {
+ val orchid = viewFor(Skins.Orchid.id).chromeColors()
+ val vellum = viewFor(Skins.Vellum.id).chromeColors()
+
+ assertEquals("the two views must expose the same chrome slots", orchid.size, vellum.size)
+ orchid.indices.forEach { i ->
+ assertTrue(
+ "chrome slot $i is the same colour in Orchid and Vellum, so it is hardcoded",
+ orchid[i] != vellum[i]
+ )
+ }
+ }
+
+ @Test
+ fun `the decoration is the same in every skin`() {
+ val reference = viewFor(Skins.DeepSpaceDark.id).decorationColors()
+ Skins.all.forEach { skin ->
+ assertTrue(
+ "${skin.id} changed the decoration, which is meant to be Lens's signature",
+ reference.contentEquals(viewFor(skin.id).decorationColors())
+ )
+ }
+ }
+
+ @Test
+ fun `the hint stays light on a light skin`() {
+ // It is drawn onto the dim over somebody else's app, not onto a surface
+ // of ours, so a light skin's near-black onSurface would be unreadable.
+ val vellum = viewFor(Skins.Vellum.id).decorationColors()
+ assertEquals(android.graphics.Color.WHITE, vellum[1])
+ }
+}