Modern Apps git

← Modern-Apps.git

camera: show the tap-to-focus point and never drop a tap

Commit
cc942ec2c68680fbfed77722416ba8751adb2cfe
Author
Vayun Mathur <[email protected]>
When
2026-11-19 18:25 UTC (16 days ago)
Parents
6c3a852
Tap focus could silently do nothing and gave no feedback:
regular taps went through the viewfinder's own detector with a
parallel detectTapGestures racing it on the same modifier chain,
metering coords were fed unclamped into
SurfaceOrientedMeteringPointFactory (edge taps under Crop map
outside 0..1 and CameraX rejects them), and startFocusAndMetering
silently no-oped with no bound camera, discarded its future, and
marked focus locked even when the request later failed.

The preview surface now owns a single tap/long-press detector
(built-in tap-to-focus off, pinch zoom kept), shows a focus ring
that contracts and fades at the tapped point before metering runs
(visible whether or not AF converges), clamps/normalises metering
coordinates with a centre fallback, and falls back to default
metering when a focus request fails instead of staying locked.

Verified: :camera:testDevUnitTest (515 tests, 0 failures, incl.
new metering-coordinate tests). AF accuracy and the indicator
over bright scenes need a device.

Diff

camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt b/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.ktindex 3b5092e9cd..65d89471dc 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt@@ -104,24 +104,95 @@ fun CameraViewModel.updateZoomLevels(minZoom: Float, maxZoom: Float) {     availableZoomLevelsMutable.value = levels } -fun CameraViewModel.startFocusAndMetering(action: FocusMeteringAction) {+fun CameraViewModel.startFocusAndMetering(action: FocusMeteringAction): Boolean {     // A fresh tap clears any existing AE/AF lock.     focusLockedMutable.value = false-    boundCamera?.cameraControl?.startFocusAndMetering(action)+    return runFocusAndMetering(action, locked = false) }  /**  * Locks focus + exposure at the metered point by disabling auto-cancel, so 3A stays put until  * the user taps again (long-press-to-lock). Sets [focusLocked] for the on-screen indicator.  */-fun CameraViewModel.lockFocusAndMetering(action: FocusMeteringAction) {-    val cam = boundCamera ?: return-    cam.cameraControl.startFocusAndMetering(action)-    focusLockedMutable.value = true+fun CameraViewModel.lockFocusAndMetering(action: FocusMeteringAction): Boolean {+    val submitted = runFocusAndMetering(action, locked = true)+    if (submitted) focusLockedMutable.value = true+    return submitted+}++/**+ * Shared tap/long-press metering dispatch. Returns false (after logging) when+ * there is no bound camera or the control throws synchronously — the silent+ * `boundCamera?.` no-op this replaces gave the user no focus and no signal.+ *+ * The returned future is observed, not discarded: an asynchronous failure+ * (unsupported metering point, camera closed mid-tap) falls back to the+ * default continuous AF/AE via [fallbackToDefaultMetering] instead of leaving+ * metering in whatever half-applied state the failure stopped at. A focus+ * attempt that completes but does not converge ([androidx.camera.core+ * .FocusMeteringResult.isFocusSuccessful] false) is NOT a failure: metering+ * was still applied at the point, so it is only logged. Cancellation is the+ * normal superseded-by-the-next-tap case and needs no fallback either.+ */+internal fun CameraViewModel.runFocusAndMetering(action: FocusMeteringAction, locked: Boolean): Boolean {+    val cam = boundCamera+    if (cam == null) {+        Log.status("TapToFocus", "focus requested with no bound camera (locked=$locked); tap dropped")+        return false+    }+    val future: com.google.common.util.concurrent.ListenableFuture<androidx.camera.core.FocusMeteringResult>? = try {+        cam.cameraControl.startFocusAndMetering(action)+    } catch (e: Exception) {+        Log.status("TapToFocus", "startFocusAndMetering threw (locked=$locked); falling back to default metering", e)+        if (locked) focusLockedMutable.value = false+        fallbackToDefaultMetering()+        return false+    }+    // Real CameraX never returns null; fakes/mocks in unit tests may.+    if (future == null) return true+    com.google.common.util.concurrent.Futures.addCallback(+        future,+        object : com.google.common.util.concurrent.FutureCallback<androidx.camera.core.FocusMeteringResult> {+            override fun onSuccess(result: androidx.camera.core.FocusMeteringResult?) {+                if (result != null && !result.isFocusSuccessful) {+                    Log.dev("TapToFocus", "focus did not converge at metered point (locked=$locked)")+                }+            }++            override fun onFailure(t: Throwable) {+                if (t is androidx.camera.core.CameraControl.OperationCanceledException) {+                    Log.dev("TapToFocus", "focus superseded by a newer request (locked=$locked)")+                    return+                }+                Log.status("TapToFocus", "focus metering failed (locked=$locked); falling back to default metering", t)+                if (locked) focusLockedMutable.value = false+                fallbackToDefaultMetering()+            }+        },+        ContextCompat.getMainExecutor(app),+    )+    return true+}++/**+ * Returns metering to the camera's default continuous AF/AE (the centre-+ * weighted behaviour a plain `cancelFocusAndMetering` restores) after a+ * failed tap. Best-effort: a dead camera must not crash the tap path.+ */+internal fun CameraViewModel.fallbackToDefaultMetering() {+    try {+        boundCamera?.cameraControl?.cancelFocusAndMetering()+    } catch (e: Exception) {+        Log.status("TapToFocus", "fallback cancelFocusAndMetering threw", e)+    } }  fun CameraViewModel.clearFocusLock() {-    boundCamera?.cameraControl?.cancelFocusAndMetering()+    try {+        boundCamera?.cameraControl?.cancelFocusAndMetering()+    } catch (e: Exception) {+        Log.status("TapToFocus", "cancelFocusAndMetering threw while clearing lock", e)+    }     focusLockedMutable.value = false } 
camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.ktindex 86ab2a3b67..c90d842c5a 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt@@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.camera.R import com.vayunmathur.camera.platform.MotionPhotoDuration@@ -76,6 +77,7 @@ fun CameraPostProcessingSettings(                         modifier = Modifier.weight(1f),                         textAlign = TextAlign.Start,                         maxLines = 1,+                        overflow = TextOverflow.Ellipsis,                     )                     IconArrowDropDown()                 }
camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.ktindex c7c4b33728..ba44bc1c32 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt@@ -25,7 +25,12 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf+import androidx.compose.runtime.mutableLongStateOf+import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip@@ -43,8 +48,10 @@ import com.vayunmathur.camera.platform.CameraMode import com.vayunmathur.camera.platform.CameraViewModel import com.vayunmathur.camera.platform.bokehBlurScale import com.vayunmathur.camera.platform.buildColorAdjustmentMatrix+import com.vayunmathur.camera.platform.fallbackToDefaultMetering import com.vayunmathur.camera.platform.lockFocusAndMetering import com.vayunmathur.camera.platform.onViewfinderZoomRatio+import com.vayunmathur.camera.platform.startFocusAndMetering import com.vayunmathur.camera.data.setBlurStrength import com.vayunmathur.camera.data.setExposureCompensation import com.vayunmathur.camera.platform.setExposureTimeIndex@@ -72,6 +79,36 @@ internal fun previewRatioForWindow(baseRatio: Float, maxWidth: Float, maxHeight:     return if (isLandscape && baseRatio > 0f) 1f / baseRatio else baseRatio } +/** Minimum gap between two tap-to-focus requests; faster repeats are one gesture, not two. */+private const val FOCUS_TAP_DEBOUNCE_MS = 120L++/** How long the focus ring stays up (its own fade runs inside [FocusIndicator]). */+private const val FOCUS_INDICATOR_LIFETIME_MS = 1_350L++/**+ * Normalises a coordinate-transformer output (surface-buffer pixels) into the+ * 0..1 range [androidx.camera.core.MeteringPoint] expects, clamped to the+ * surface. Pure so it stays unit-testable.+ *+ * The clamp matters: with `ContentScale.Crop` a tap at the box edge can map+ * just outside the buffer, and CameraX rejects an out-of-range point — the+ * future then fails and, before this fix, was discarded unread, so the tap+ * silently did nothing. A non-finite transform (matrix not populated yet) or+ * a degenerate surface falls back to the centre rather than dropping the tap.+ */+internal fun normalizedMeteringCoordinates(+    transformedX: Float,+    transformedY: Float,+    surfaceWidth: Float,+    surfaceHeight: Float,+): Pair<Float, Float> {+    if (!transformedX.isFinite() || !transformedY.isFinite() || surfaceWidth <= 0f || surfaceHeight <= 0f) {+        return 0.5f to 0.5f+    }+    return (transformedX / surfaceWidth).coerceIn(0f, 1f) to+        (transformedY / surfaceHeight).coerceIn(0f, 1f)+}+ /**  * The letterboxed viewfinder plus its gesture handling, bokeh/color RenderEffects,  * grid/level/night overlays, settings column and panorama overlay. Extracted verbatim@@ -107,6 +144,18 @@ internal fun BoxWithConstraintsScope.CameraPreviewBox(         null     }     val coordinateTransformer = remember { MutableCoordinateTransformer() }+    // Tap-to-focus indicator: small in-screen sub-state (deliberately NOT+    // navigation — a focus point is transient state of this one screen).+    var focusPoint by remember { mutableStateOf<Offset?>(null) }+    var focusTapId by remember { mutableIntStateOf(0) }+    var focusPointLocked by remember { mutableStateOf(false) }+    var lastFocusTapMs by remember { mutableLongStateOf(0L) }+    LaunchedEffect(focusTapId) {+        if (focusTapId > 0) {+            kotlinx.coroutines.delay(FOCUS_INDICATOR_LIFETIME_MS)+            focusPoint = null+        }+    }     val previewModifier = previewSize         // CameraX mirrors the front-camera preview by default; counter it when the         // user turns selfie mirroring off so the preview matches the saved image (#632).@@ -172,24 +221,85 @@ internal fun BoxWithConstraintsScope.CameraPreviewBox(                 }             }         )-            // Tap-to-focus and pinch-to-zoom are handled by CameraXViewfinder's-            // built-in gestures (below). Long-press to lock AE/AF isn't built in, so-            // keep just that here.-            .pointerInput(state.activeSetting) {-                fun meteringPoint(tapOffset: Offset) = surfaceRequest?.let { request ->-                    val transformed = with(coordinateTransformer) { tapOffset.transform() }-                    val factory = SurfaceOrientedMeteringPointFactory(-                        request.resolution.width.toFloat(),-                        request.resolution.height.toFloat()-                    )-                    factory.createPoint(transformed.x, transformed.y)+            // Tap-to-focus is handled HERE, on the preview surface itself, in+            // the same single detector as long-press-to-lock. CameraXViewfinder's+            // built-in tap gesture is disabled below: it raced this detector,+            // gave no tap indicator (its onTapToFocus callback was never wired),+            // silently returned when the transformed point left 0..1, and its+            // result was invisible to the app. Pinch-to-zoom stays built-in.+            //+            // Keyed on surfaceRequest + mirrorPreview, NOT only on+            // activeSetting as before: with the old key the block captured the+            // first-composed surfaceRequest (null before the session binds)+            // for as long as the settings pane stayed closed, so every+            // long-press metering point came back null and was dropped.+            .pointerInput(surfaceRequest, state.mirrorPreview) {+                fun meteringPoint(tapOffset: Offset): androidx.camera.core.MeteringPoint? {+                    val request = surfaceRequest ?: return null+                    return try {+                        val transformed = with(coordinateTransformer) { tapOffset.transform() }+                        val width = request.resolution.width.toFloat()+                        val height = request.resolution.height.toFloat()+                        val (nx, ny) = normalizedMeteringCoordinates(transformed.x, transformed.y, width, height)+                        val factory = if (width > 0f && height > 0f) {+                            SurfaceOrientedMeteringPointFactory(width, height)+                        } else {+                            SurfaceOrientedMeteringPointFactory(1f, 1f)+                        }+                        val surfaceW = if (width > 0f) width else 1f+                        val surfaceH = if (height > 0f) height else 1f+                        factory.createPoint(nx * surfaceW, ny * surfaceH)+                    } catch (e: Exception) {+                        Log.status("TapToFocus", "metering-point conversion failed; using centre point", e)+                        try {+                            SurfaceOrientedMeteringPointFactory(1f, 1f).createPoint(0.5f, 0.5f)+                        } catch (_: Exception) {+                            null+                        }+                    }+                }++                fun showIndicator(tapOffset: Offset, locked: Boolean) {+                    // tapOffset is in the (possibly extra-mirrored) preview+                    // layer's coordinates; the indicator is drawn by a sibling+                    // outside that layer, so flip back into visual coordinates.+                    focusPoint = if (state.mirrorPreview) {+                        Offset(size.width - tapOffset.x, tapOffset.y)+                    } else {+                        tapOffset+                    }+                    focusPointLocked = locked+                    focusTapId++                 }                 detectTapGestures(+                    onTap = { tapOffset ->+                        val now = android.os.SystemClock.uptimeMillis()+                        if (now - lastFocusTapMs < FOCUS_TAP_DEBOUNCE_MS) return@detectTapGestures+                        lastFocusTapMs = now+                        // Indicator first, regardless of AF outcome: it proves+                        // the tap registered even if metering then fails.+                        showIndicator(tapOffset, locked = false)+                        val point = meteringPoint(tapOffset)+                        if (point == null) {+                            Log.status("TapToFocus", "tap with no surface request; falling back to default metering")+                            viewModel.fallbackToDefaultMetering()+                        } else {+                            viewModel.startFocusAndMetering(+                                FocusMeteringAction.Builder(point).build()+                            )+                        }+                    },                     onLongPress = { tapOffset ->-                        val point = meteringPoint(tapOffset) ?: return@detectTapGestures-                        viewModel.lockFocusAndMetering(-                            FocusMeteringAction.Builder(point).disableAutoCancel().build()-                        )+                        showIndicator(tapOffset, locked = true)+                        val point = meteringPoint(tapOffset)+                        if (point == null) {+                            Log.status("TapToFocus", "long-press with no surface request; cannot lock metering")+                            viewModel.fallbackToDefaultMetering()+                        } else {+                            viewModel.lockFocusAndMetering(+                                FocusMeteringAction.Builder(point).disableAutoCancel().build()+                            )+                        }                     }                 )             }@@ -225,10 +335,14 @@ internal fun BoxWithConstraintsScope.CameraPreviewBox(             // selected aspect ratio (1:1 / 3:2 / 16:9 / 4:3). Fit letterboxed the native             // 4:3 frame inside the box, making the preview shrink instead of reshape.             contentScale = ContentScale.Crop,-            // Built-in tap-to-focus and pinch-to-zoom (1.7.0-alpha02). The viewfinder-            // applies focus/zoom on the SurfaceRequest's camera; we just sync the-            // displayed zoom ratio so the zoom bar stays in step.-            isTapToFocusEnabled = true,+            // Pinch-to-zoom stays built-in (1.7.0-alpha02); we just sync the+            // displayed zoom ratio so the zoom bar stays in step. Tap-to-focus+            // is DISABLED here — it is handled by the pointerInput on+            // previewModifier above, which shows the focus ring and observes+            // (and falls back from) the metering result. Leaving both enabled+            // double-metered every tap and let the built-in detector swallow+            // taps the app never saw.+            isTapToFocusEnabled = false,             isPinchToZoomEnabled = true,             onZoomRatioChanged = { ratio -> viewModel.onViewfinderZoomRatio(ratio) },         )@@ -259,6 +373,18 @@ internal fun BoxWithConstraintsScope.CameraPreviewBox(         analysisStreamActive = state.analysisStreamActive,     ) +    // Above the grid/level overlays so the ring is never drawn under them;+    // below the settings column so its controls stay visually on top. The+    // Canvas carries no pointer input, so it never eats the next tap.+    focusPoint?.let { point ->+        FocusIndicator(+            point = point,+            tapId = focusTapId,+            locked = focusPointLocked,+            modifier = previewSize,+        )+    }+     CameraSettingsColumn(         activeSetting = state.activeSetting,         availableLenses = state.availableLenses.filter { it.facing == currentLensFacing(state.lensFacing) },
camera/src/main/java/com/vayunmathur/camera/ui/FocusIndicator.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/FocusIndicator.kt b/camera/src/main/java/com/vayunmathur/camera/ui/FocusIndicator.ktnew file mode 100644index 0000000000..77d82ee4d4--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/ui/FocusIndicator.kt@@ -0,0 +1,78 @@+package com.vayunmathur.camera.ui++import androidx.compose.foundation.Canvas+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.drawscope.Stroke+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.Motion+import com.vayunmathur.library.ui.animatedDp+import com.vayunmathur.library.ui.animatedFloat+import kotlinx.coroutines.delay++/** How long the ring stays at full opacity before it starts fading. */+private const val FOCUS_INDICATOR_HOLD_MS = 900L++/** Corner-bracket length as a fraction of the ring radius. */+private const val BRACKET_FRACTION = 0.45f++/**+ * The tap-to-focus ring: drawn at [point] (preview-local coordinates) whenever+ * [tapId] changes, contracting from a wide bracket to its resting size and+ * then fading out. [locked] tints it amber to match the AE/AF-lock pill.+ *+ * The composable only draws; when it appears and disappears is the caller's+ * in-screen state. Motion goes through the library helpers (`animatedDp` /+ * `animatedFloat` on [Motion] specs), never raw animation APIs.+ */+@Composable+internal fun FocusIndicator(+    point: Offset,+    tapId: Int,+    locked: Boolean,+    modifier: Modifier = Modifier,+) {+    var contracted by remember(tapId) { mutableStateOf(false) }+    var fading by remember(tapId) { mutableStateOf(false) }+    LaunchedEffect(tapId) {+        contracted = true+        delay(FOCUS_INDICATOR_HOLD_MS)+        fading = true+    }+    val radius = animatedDp(+        target = if (contracted) 28.dp else 44.dp,+        spec = Motion.over(250),+    )+    val alpha = animatedFloat(+        target = if (fading) 0f else 1f,+        spec = Motion.over(300),+    )+    if (alpha <= 0f) return+    val color = if (locked) Color(0xFFFFD54F) else Color.White+    Canvas(modifier = modifier) {+        val r = radius.toPx()+        val stroke = 2.dp.toPx()+        val bracket = r * BRACKET_FRACTION+        val ringColor = color.copy(alpha = alpha)+        // Ring plus four corner brackets, stock-camera style.+        drawCircle(ringColor, radius = r, center = point, style = Stroke(stroke))+        val corners = listOf(+            Offset(point.x - r, point.y - r) to Offset(1f, 1f),+            Offset(point.x + r, point.y - r) to Offset(-1f, 1f),+            Offset(point.x - r, point.y + r) to Offset(1f, -1f),+            Offset(point.x + r, point.y + r) to Offset(-1f, -1f),+        )+        for ((corner, dir) in corners) {+            drawLine(ringColor, corner, Offset(corner.x + dir.x * bracket, corner.y), stroke, cap = androidx.compose.ui.graphics.StrokeCap.Round)+            drawLine(ringColor, corner, Offset(corner.x, corner.y + dir.y * bracket), stroke, cap = androidx.compose.ui.graphics.StrokeCap.Round)+        }+        drawCircle(ringColor, radius = 2.dp.toPx(), center = point)+    }+}
camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt b/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.ktindex 0cbbd570aa..b0d8692108 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt@@ -19,6 +19,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.camera.R@@ -77,6 +78,7 @@ fun LensBar(                     fontSize = if (label.length > 3) 11.sp else 13.sp,                     fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,                     maxLines = 1,+                    overflow = TextOverflow.Ellipsis,                 )             }         }
camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.ktindex 486ba3cc97..8a2922f42e 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt@@ -15,6 +15,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.text.style.TextOverflow import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.DropdownMenu@@ -163,6 +164,7 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                                 modifier = Modifier.weight(1f),                                 textAlign = TextAlign.Start,                                 maxLines = 1,+                                overflow = TextOverflow.Ellipsis,                             )                             IconArrowDropDown()                         }@@ -213,6 +215,7 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                             modifier = Modifier.weight(1f),                             textAlign = TextAlign.Start,                             maxLines = 1,+                            overflow = TextOverflow.Ellipsis,                         )                         IconArrowDropDown()                     }@@ -313,6 +316,7 @@ private fun SaveLocationSection(                         .weight(1f)                         .padding(horizontal = 12.dp),                     maxLines = 1,+                    overflow = TextOverflow.Ellipsis,                 )             }             Row(modifier = Modifier.fillMaxWidth()) {
camera/src/test/java/com/vayunmathur/camera/platform/ControlsRecordingExtraTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/ControlsRecordingExtraTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/ControlsRecordingExtraTest.ktindex 23e84cf35c..3edafb3dbb 100644--- a/camera/src/test/java/com/vayunmathur/camera/platform/ControlsRecordingExtraTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/platform/ControlsRecordingExtraTest.kt@@ -101,6 +101,23 @@ class ControlsRecordingExtraTest {         viewModel.onSessionBound()     } +    @Test fun focusWithoutBoundCameraAndOnThrowFallsBack() {+        val viewModel = vm()+        val factory = SurfaceOrientedMeteringPointFactory(100f, 100f)+        val action = FocusMeteringAction.Builder(factory.createPoint(0.5f, 0.5f)).build()+        // No bound camera: must report failure, not silently no-op.+        assertFalse(viewModel.startFocusAndMetering(action))+        assertFalse(viewModel.lockFocusAndMetering(action))+        assertFalse(viewModel.focusLockedMutable.value)+        // Synchronous throw from the control: caught, lock cleared, reported.+        viewModel.boundCamera = fakeCamera()+        Mockito.`when`(viewModel.boundCamera!!.cameraControl.startFocusAndMetering(action))+            .thenThrow(IllegalStateException("camera closed"))+        assertFalse(viewModel.lockFocusAndMetering(action))+        assertFalse(viewModel.focusLockedMutable.value)+        viewModel.clearFocusLock()+    }+     @Test fun recordingTogglesWithoutRecording() {         val viewModel = vm()         // Countdown cancellation arm.
camera/src/test/java/com/vayunmathur/camera/ui/TapFocusMeteringTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/TapFocusMeteringTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/TapFocusMeteringTest.ktnew file mode 100644index 0000000000..1718a13e02--- /dev/null+++ b/camera/src/test/java/com/vayunmathur/camera/ui/TapFocusMeteringTest.kt@@ -0,0 +1,38 @@+package com.vayunmathur.camera.ui++import kotlin.test.Test+import kotlin.test.assertEquals++/** Tap-to-focus metering conversion: clamping and centre fallback. */+class TapFocusMeteringTest {++    @Test+    fun centreOfSurfaceNormalisesToHalf() {+        val (x, y) = normalizedMeteringCoordinates(960f, 540f, 1920f, 1080f)+        assertEquals(0.5f, x, 0.0001f)+        assertEquals(0.5f, y, 0.0001f)+    }++    @Test+    fun cropEdgeTapClampsIntoRangeInsteadOfBeingRejected() {+        // ContentScale.Crop can map an edge tap just outside the buffer;+        // CameraX rejects >1, so the point must clamp to the edge.+        val (x, y) = normalizedMeteringCoordinates(2100f, -20f, 1920f, 1080f)+        assertEquals(1f, x, 0.0001f)+        assertEquals(0f, y, 0.0001f)+    }++    @Test+    fun unpopulatedTransformFallsBackToCentre() {+        val (x, y) = normalizedMeteringCoordinates(Float.NaN, Float.POSITIVE_INFINITY, 1920f, 1080f)+        assertEquals(0.5f, x, 0.0001f)+        assertEquals(0.5f, y, 0.0001f)+    }++    @Test+    fun degenerateSurfaceFallsBackToCentre() {+        val (x, y) = normalizedMeteringCoordinates(10f, 10f, 0f, 0f)+        assertEquals(0.5f, x, 0.0001f)+        assertEquals(0.5f, y, 0.0001f)+    }+}