translate: give every route a screenshot capture
- Commit
52be330fa562fdc04dc446d4f215589b166756b6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 03:46 UTC (4 days ago)
- Parents
7fd9db0
RouteScreenshotCoverage flagged Text, Camera and Image: the existing previews were named 1-translated/2-listening/3-translating, which name no route key, and the camera and image routes had no capture at all. Rename the text previews to 1-text, 2-text-listening and 3-text-translating so they cover the Text route as its variants, and add 6-camera and 7-image previews rendering the shared CameraOverlay slice over a fixed dark stage with fixed detected lines and translations. Layoutlib cannot open a CameraX viewfinder or decode a picked image URI, but the overlay plates and language bar those routes draw over the feed or image render deterministically from literals; the image variant passes showCaptureControls = false as the image screen does. Update translate/AGENTS.md with the per-route capture inventory. No exemption markers are added. Verified: ./gradlew :translate:lint :translate:lintVitalRelease :translate:testDevUnitTest :translate:compileDevScreenshotTestKotlin all pass.
Diff
translate/AGENTS.md
diff --git a/translate/AGENTS.md b/translate/AGENTS.mdindex b27b39fcd7..f598a7983b 100644--- a/translate/AGENTS.md+++ b/translate/AGENTS.md@@ -56,6 +56,7 @@ _Install: ./install translate (dev by default)._ - com/vayunmathur/translate/ui/ImagePicker.kt - com/vayunmathur/translate/ui/LanguagePickerScreen.kt - com/vayunmathur/translate/ui/LanguagePickerPage.kt+- screenshotTest `ui/MetadataPreviews.kt` — one deterministic capture per `Route` leaf (`1-text`, `2-text-listening`, `3-text-translating`, `4-language-picker`, `5-history`, `6-camera`, `7-image`); `Camera`/`Image` render the shared `CameraOverlay` slice over a fixed stage (no CameraX viewfinder or URI decode in Layoutlib) ## Verify (this module only) ```
translate/src/screenshotTest/kotlin/com/vayunmathur/translate/ui/MetadataPreviews.kt
diff --git a/translate/src/screenshotTest/kotlin/com/vayunmathur/translate/ui/MetadataPreviews.kt b/translate/src/screenshotTest/kotlin/com/vayunmathur/translate/ui/MetadataPreviews.ktindex f12d1260cd..274c6adc03 100644--- a/translate/src/screenshotTest/kotlin/com/vayunmathur/translate/ui/MetadataPreviews.kt+++ b/translate/src/screenshotTest/kotlin/com/vayunmathur/translate/ui/MetadataPreviews.kt@@ -1,6 +1,12 @@ package com.vayunmathur.translate.ui +import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import com.android.tools.screenshot.PreviewTest import com.vayunmathur.library.ui.DynamicTheme@@ -35,14 +41,17 @@ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420" * - Everything is a literal. The translations below are written out rather than produced * by the NLLB-200 model, which is a ~620 MB runtime download that no preview can load. *- * Only the text screen is here. The camera screen is a live CameraX viewfinder, and- * Layoutlib cannot open a camera — a preview of it would be an empty rectangle, which is- * worse for the listing than leaving it out.+ * Coverage: every route has a capture. `Text` uses the text screen in its+ * translated/listening/translating variants, `LanguagePicker` and `History`+ * their screens, and `Camera`/`Image` the shared [CameraOverlay] slice over a+ * fixed dark stage: Layoutlib cannot open a CameraX viewfinder or decode a+ * picked image URI, but the overlay plates and language bar those routes draw+ * over the feed/image render from fixed literals. */ class MetadataPreviews { @PreviewTest- @Preview(name = "1-translated", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "1-text", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview1Translated() { DynamicTheme(darkTheme = true) {@@ -62,7 +71,7 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "2-listening", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "2-text-listening", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview2Listening() { DynamicTheme(darkTheme = true) {@@ -81,7 +90,7 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "3-translating", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "3-text-translating", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview3Translating() { DynamicTheme(darkTheme = true) {@@ -147,4 +156,53 @@ class MetadataPreviews { ) } }++ /** One detected line as the camera/image routes draw it: corners in frame pixels. */+ private fun overlayBox(text: String, top: Float) = OverlayBox(+ corners = listOf(+ Offset(90f, top), Offset(990f, top), Offset(990f, top + 130f), Offset(90f, top + 130f),+ ),+ text = text,+ )++ @PreviewTest+ @Preview(name = "6-camera", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview6Camera() {+ DynamicTheme(darkTheme = true) {+ Box(Modifier.fillMaxSize().background(Color(0xFF202124))) {+ CameraOverlay(+ overlays = listOf(overlayBox("Nearest station", 640f), overlayBox("Tickets", 840f)),+ translations = mapOf("Nearest station" to "Estación más cercana", "Tickets" to "Billetes"),+ translationAvailable = true,+ frameW = 1080, frameH = 2340, viewW = 1080, viewH = 2340,+ sourceLang = "en", targetLang = "es",+ paused = false, onTogglePaused = {},+ torchOn = false, onToggleTorch = {},+ onBack = {}, onOpenLanguagePicker = {},+ )+ }+ }+ }++ @PreviewTest+ @Preview(name = "7-image", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview7Image() {+ DynamicTheme(darkTheme = true) {+ Box(Modifier.fillMaxSize().background(Color(0xFF202124))) {+ CameraOverlay(+ overlays = listOf(overlayBox("Nearest station", 640f), overlayBox("Tickets", 840f)),+ translations = mapOf("Nearest station" to "Estación más cercana", "Tickets" to "Billetes"),+ translationAvailable = true,+ frameW = 1080, frameH = 2340, viewW = 1080, viewH = 2340,+ sourceLang = "en", targetLang = "es",+ paused = false, onTogglePaused = {},+ torchOn = false, onToggleTorch = {},+ onBack = {}, onOpenLanguagePicker = {},+ showCaptureControls = false,+ )+ }+ }+ } }