findfamily: real CARTO map tiles in metadata store screenshots
- Commit
e3f5e20807ed909e19b75e10bf5a525a448751b0- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 20:48 UTC (3 months ago)
- Parents
dced00c
Diff
findfamily/build.gradle.kts
diff --git a/findfamily/build.gradle.kts b/findfamily/build.gradle.ktsindex 6dbd79b81c..7164677668 100644--- a/findfamily/build.gradle.kts+++ b/findfamily/build.gradle.kts@@ -38,4 +38,25 @@ dependencies { // androidx.core.uwb because its only backend is GMS-mediated, which fails // on GrapheneOS (sandboxed Play Services can't talk to the platform UWB // service). All UWB code paths are gated on Build.VERSION.SDK_INT >= 35.+}++// The Compose screenshot renderer draws previews from the compiled `screenshotTest` classes+// directory (the renderer's screenshotProjectClassPath). JVM resources placed under+// src/screenshotTest/resources are NOT otherwise put on that classpath, so the metadata+// previews can't load the bundled CARTO map via getResourceAsStream. Stage those resources+// into the classes output so the previews can read them at render time. Because this asset+// lives only in the screenshotTest source set it ships in neither the dev nor the release APK.+val screenshotTestClasses = layout.buildDirectory.dir(+ "intermediates/built_in_kotlinc/devScreenshotTest/compileDevScreenshotTestKotlin/classes"+)+val stageDevScreenshotTestResources = tasks.register<Copy>("stageDevScreenshotTestResources") {+ from(layout.projectDirectory.dir("src/screenshotTest/resources"))+ into(screenshotTestClasses)+ mustRunAfter("compileDevScreenshotTestKotlin")+ outputs.upToDateWhen { false }+}+tasks.matching {+ it.name == "updateDevScreenshotTest" || it.name == "validateDevScreenshotTest"+}.configureEach {+ dependsOn(stageDevScreenshotTestResources) }\ No newline at end of file
findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt
diff --git a/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt b/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.ktindex 0c4436cb75..879a6e01a0 100644--- a/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt+++ b/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt@@ -1,14 +1,22 @@ package com.vayunmathur.findfamily.ui -import androidx.compose.foundation.Canvas+import android.graphics.BitmapFactory+import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.material3.Text import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier-import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp import com.android.tools.screenshot.PreviewTest import com.vayunmathur.findfamily.data.Coord import com.vayunmathur.findfamily.data.LocationValue@@ -25,7 +33,6 @@ import com.vayunmathur.findfamily.util.PersonUiState import com.vayunmathur.findfamily.util.UwbSessionManager import com.vayunmathur.findfamily.uwb.RangingSample import com.vayunmathur.library.ui.DynamicTheme-import com.vayunmathur.library.ui.MaterialTheme import kotlin.time.Clock import kotlin.time.Duration.Companion.minutes @@ -128,27 +135,44 @@ class MetadataPreviews { ) /**- * Stand-in for the live [MapView] in the `map` slot: a muted, map-ish neutral fill with a- * faint grid so the full page reads as "map behind chrome" without any tile rendering.+ * Stands in for the live [MapView] in the `map` slot. Layoutlib cannot fetch the network+ * raster tiles the real [MapView] draws, so instead of a synthetic grid we bundle a real+ * CARTO Voyager basemap mosaic (`preview_map_sf.png`, a screenshotTest-only classpath+ * resource centered on [mayaLocation]) and overlay the sample person marker exactly like+ * the app does. The mosaic is a JVM resource rather than an Android drawable so it never+ * ships in the app APK. The "© CARTO © OpenStreetMap" attribution is required by the+ * basemap terms and must stay visible. Image + static overlays only — no network or+ * effects — so it renders under Layoutlib. */ @Composable private fun StaticMapBackdrop() {- val gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.25f)- Box(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surfaceVariant)) {- Canvas(Modifier.fillMaxSize()) {- val step = 48.dp.toPx()- val stroke = 1.dp.toPx()- var x = step- while (x < size.width) {- drawLine(gridColor, Offset(x, 0f), Offset(x, size.height), stroke)- x += step- }- var y = step- while (y < size.height) {- drawLine(gridColor, Offset(0f, y), Offset(size.width, y), stroke)- y += step- }+ val mapImage = remember {+ val stream = MetadataPreviews::class.java.getResourceAsStream("/preview_map_sf.png")+ ?: error("preview_map_sf.png missing from screenshotTest resources")+ stream.use { BitmapFactory.decodeStream(it).asImageBitmap() }+ }+ Box(Modifier.fillMaxSize()) {+ Image(+ bitmap = mapImage,+ contentDescription = null,+ modifier = Modifier.fillMaxSize(),+ contentScale = ContentScale.Crop,+ )+ // Sample person marker over the map point the mosaic is centered on.+ Box(Modifier.align(Alignment.Center)) {+ UserPicture(maya, 64.dp) }+ Text(+ text = "© CARTO © OpenStreetMap",+ color = Color.Black.copy(alpha = 0.7f),+ fontSize = 9.sp,+ modifier = Modifier+ .align(Alignment.BottomStart)+ // Clear the 200.dp collapsed sheet peek so the required attribution stays visible.+ .padding(start = 8.dp, bottom = 208.dp)+ .background(Color.White.copy(alpha = 0.6f))+ .padding(horizontal = 4.dp, vertical = 2.dp),+ ) } }
findfamily/src/screenshotTest/resources/preview_map_sf.png
diff --git a/findfamily/src/screenshotTest/resources/preview_map_sf.png b/findfamily/src/screenshotTest/resources/preview_map_sf.pngnew file mode 100644index 0000000000..f2a135d4c5Binary files /dev/null and b/findfamily/src/screenshotTest/resources/preview_map_sf.png differ
metadata_data/photos/findfamily/1.png
diff --git a/metadata_data/photos/findfamily/1.png b/metadata_data/photos/findfamily/1.pngindex 12663958f0..8b616c10e1 100644Binary files a/metadata_data/photos/findfamily/1.png and b/metadata_data/photos/findfamily/1.png differ
metadata_data/photos/findfamily/2.png
diff --git a/metadata_data/photos/findfamily/2.png b/metadata_data/photos/findfamily/2.pngindex 2331991149..3b3529becc 100644Binary files a/metadata_data/photos/findfamily/2.png and b/metadata_data/photos/findfamily/2.png differ