camera: remove the lens pills row; zoom stops keep lens state in sync
- Commit
9146042b030f534bd4ed8904004d5c9f02690579- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-30 22:03 UTC (5 days ago)
- Parents
d4b3efa
Owner-directed UI simplification: the discrete LensBar pills duplicated the continuous ZoomBar (every lens stop is a zoom ratio), so the row is gone and LensBar.kt is deleted. ZoomBar chips, scrub and pinch are the one zoom surface; panorama and photosphere still hide it at the 1x lock. Zoom-path equivalence was verified: sessions resolve their id from facing only, and selectLens itself took effect through setZoomRatio, so zooming to a stop reaches the same ratio and framing. The one real gap — side effects keyed on selectedLens (panorama focal seeding, night refresh, fallback-latch bind keys, startup-lens persistence) — is closed: the committed-zoom path (setZoomRatio and onViewfinderZoomRatio) now syncs the selected lens when the ratio lands on a stop within 0.01 (persisting camera_last_lens_id/facing and resetting night detection, exactly what selectLens committed), without recursion and never in zoom-locked modes or while recording; between stops the selection is left alone. Tests: ZoomBar lens-stop tests replace the LensBar tests, plus four ZoomStopLensSyncTest cases (stop sync + persist, between-stop no-op, panorama lock, selectLens non-recursion). Verified: :camera:testDevUnitTest 637 tests and :camera:lint BUILD SUCCESSFUL.
Diff
camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex 55dce0954d..9c0e6c2dac 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -19,7 +19,7 @@ _Install: ./install camera (dev by default)._ - Portrait mode with on-device segmentation (MediaPipe selfie + MODNet matting on a Vulkan compute runtime, `.maml` assets) - QR/barcode scanning (zxing) and optional GPS geotagging written into EXIF **Architecture / data-flow:** Single-screen `ui/CameraScreen` + `platform/CameraViewModel` over per-mode `platform/` session objects on the `platform/camera2/` driver; `domain/` holds pure lens-selection logic, `platform/` capability queries; heavy work (stitch, night align, bokeh) goes through Rust JNI (`platform/StitchNative`) and lands in MediaStore via `data/MediaStoreSaver`. `onCreateBeforeContent` only honors the `ACTION_IMAGE_CAPTURE` capture-for-result intent; `Content()` sits behind a camera+mic permission gate.-**Lens selection:** `platform/LensSelector.enumerateLenses` feeds `domain/LensDiscovery` with every top-level camera id plus each logical camera's `getPhysicalCameraIds()` sub-cameras (validated against their stream-configuration maps); the Camera2 preview always opens the facing's logical camera, so picking a lens applies its nominal zoom ratio to that session (sub-1x / tele stops included) rather than opening a sub-camera id.+**Lens selection:** `platform/LensSelector.enumerateLenses` feeds `domain/LensDiscovery` with every top-level camera id plus each logical camera's `getPhysicalCameraIds()` sub-cameras (validated against their stream-configuration maps); the Camera2 preview always opens the facing's logical camera, so lens stops (sub-1x / tele included) are reached through the single continuous `ui/ZoomBar` row and pinch zoom, which apply the ratio to that session via `setZoomRatio` rather than opening a sub-camera id; a committed zoom landing on a lens's nominal ratio also syncs `selectedLens` to that lens (startup persistence + night-detection reset, via `syncSelectedLensToZoomStop`), while a ratio between stops leaves the selection alone. **Entry points + reading order:** `MainActivity.kt` → `Route.kt` (`Route.Camera`/`Settings`) → `ui/CameraScreen.kt` → `platform/CameraViewModel.kt` → `platform/CameraSessions.kt` → `platform/PanoramaEngine.kt` / `NightCaptureEngine.kt`. **Gotchas:** - Capture code lives in `platform/` (the Camera2 driver in `platform/camera2/`); there is no `util/` root in this module@@ -68,7 +68,7 @@ _Install: ./install camera (dev by default)._ - com/vayunmathur/camera/ui/CameraSettingsColumn.kt - com/vayunmathur/camera/ui/CameraStatusIndicators.kt - com/vayunmathur/camera/ui/CameraWideLayout.kt-- com/vayunmathur/camera/ui/LensBar.kt+- com/vayunmathur/camera/ui/ZoomBar.kt — the single zoom row: continuous scrub + lens-stop chips, applying ratios via `setZoomRatio` - com/vayunmathur/camera/ui/SettingsPage.kt - com/vayunmathur/camera/ui/CameraPostProcessingSettings.kt ### platform/ — ViewModel, sessions, engines
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 28e6a61648..230ae4438c 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/CameraControls.kt@@ -32,6 +32,7 @@ fun CameraViewModel.onViewfinderZoomRatio(ratio: Float) { } zoomRatioMutable.value = ratio viewModelScope.launch { ds.setString("camera_zoom_ratio", ratio.toString()) }+ syncSelectedLensToZoomStop(ratio) } /** Live device zoom range from the active session's characteristics; 1x-only when no session. */@@ -54,6 +55,10 @@ fun CameraViewModel.setZoomRatio(ratio: Float) { zoomRatioMutable.value = clamped viewModelScope.launch { ds.setString("camera_zoom_ratio", clamped.toString()) } session?.setZoomRatio(clamped)+ // A committed zoom landing on a lens stop commits that lens too+ // (selectedLens + startup persistence + night reset); between stops+ // the selection is left alone. See syncSelectedLensToZoomStop.+ syncSelectedLensToZoomStop(clamped) } /**
camera/src/main/java/com/vayunmathur/camera/platform/CameraViewModelModeLens.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/CameraViewModelModeLens.kt b/camera/src/main/java/com/vayunmathur/camera/platform/CameraViewModelModeLens.ktindex 0226fc2a86..ffa1a10ad9 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/CameraViewModelModeLens.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/CameraViewModelModeLens.kt@@ -100,9 +100,49 @@ fun CameraViewModel.flipCamera() { * and honours the panorama/photosphere 1x lock, so a lens tap can never * request a ratio the HAL did not expose. */+/** Float tolerance for a committed zoom ratio landing on a lens stop. */+private const val LENS_STOP_MATCH_TOLERANCE = 0.01f++/**+ * Syncs [selectedLens] to the lens whose nominal ratio a committed zoom+ * change landed on (ZoomBar chip/scrub, pinch — all through+ * `setZoomRatio`). Zoom is the only lens-stop UI now, so crossing onto a+ * stop must commit the same lens identity the removed lens pills did:+ * the selection itself, its startup persistence, and the night-detection+ * reset. A ratio between stops leaves the selection alone (it stays the+ * nearest committed stop / facing default).+ *+ * This deliberately does NOT call [selectLens] (which itself calls+ * `setZoomRatio` — that would recurse) and does not re-apply zoom: the+ * caller has already applied [ratio] to the session. No-op when the stop+ * is already selected, while recording (the [selectLens] gate), or in a+ * zoom-locked mode.+ */+internal fun CameraViewModel.syncSelectedLensToZoomStop(ratio: Float) {+ if (cameraModeMutable.value.isZoomLockedTo1x()) return+ if (isRecordingMutable.value) return+ val facing = if (lensFacingMutable.value == android.hardware.camera2.CameraMetadata.LENS_FACING_BACK)+ com.vayunmathur.camera.domain.LensFacing.BACK+ else com.vayunmathur.camera.domain.LensFacing.FRONT+ val match = availableLensesMutable.value+ .filter { it.facing == facing }+ .filter { kotlin.math.abs(it.nominalZoomRatio - ratio) <= LENS_STOP_MATCH_TOLERANCE }+ .minWithOrNull(+ compareBy(+ { kotlin.math.abs(it.nominalZoomRatio - ratio) },+ { it.fallbackPriority },+ )+ )+ ?: return+ if (match == selectedLensMutable.value) return+ selectedLensMutable.value = match+ persistStartupLens(match)+ resetNightModeDetection()+}+ fun CameraViewModel.selectLens(lens: com.vayunmathur.camera.domain.PhysicalLens) { // A lens switch rebinds the session and teardown would stop an active- // recording; gated while recording (the lens bar explains why in the UI).+ // recording; gated while recording. if (isRecordingMutable.value) return if (lens.facing != ( if (lensFacingMutable.value == android.hardware.camera2.CameraMetadata.LENS_FACING_BACK)
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 b316aabd95..dd16846a3e 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraPreviewBox.kt@@ -21,7 +21,6 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.graphics.asComposeRenderEffect import androidx.compose.ui.graphics.graphicsLayer-import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.library.log.Log import com.vayunmathur.camera.platform.BOKEH_SHADER@@ -40,18 +39,9 @@ import com.vayunmathur.camera.platform.setManualIsoIndex import com.vayunmathur.camera.platform.setQrResult import com.vayunmathur.camera.data.setShadows import com.vayunmathur.camera.data.setWarmth-import com.vayunmathur.camera.platform.selectLens import com.vayunmathur.camera.platform.currentZoomRange import com.vayunmathur.camera.platform.setZoomRatio import com.vayunmathur.camera.platform.toggleNightModeOverride-import com.vayunmathur.camera.R-import com.vayunmathur.library.ui.rememberMessenger--/** Maps the CameraX selector facing int to the pure lens-facing model. */-private fun currentLensFacing(selectorInt: Int): com.vayunmathur.camera.domain.LensFacing =- if (selectorInt == android.hardware.camera2.CameraMetadata.LENS_FACING_FRONT)- com.vayunmathur.camera.domain.LensFacing.FRONT- else com.vayunmathur.camera.domain.LensFacing.BACK /** * The still-crop ratios in [CameraScreenState.previewAspectRatio] are portrait (3:4, 9:16,@@ -216,18 +206,8 @@ internal fun BoxWithConstraintsScope.CameraPreviewBox( // below the settings column so its controls stay visually on top. TapToFocus(state = tapToFocusState, modifier = previewSize) - // A lens switch rebinds the session, which would stop an active recording:- // gated in the ViewModel and explained here instead of silently killing the take.- val lensMessenger = rememberMessenger()- val lensBlockedNote = stringResource(R.string.switch_blocked_while_recording) CameraSettingsColumn( activeSetting = state.activeSetting,- availableLenses = state.availableLenses.filter { it.facing == currentLensFacing(state.lensFacing) },- selectedLens = state.selectedLens,- onLensSelected = { lens ->- if (state.isRecording && lens != state.selectedLens) lensMessenger.show(lensBlockedNote)- else viewModel.selectLens(lens)- }, zoomRatio = state.zoomRatio, availableZoomLevels = state.availableZoomLevels, onZoomSelected = { viewModel.setZoomRatio(it) },
camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenEffects.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenEffects.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenEffects.ktindex 590fa7232a..8500f99ea2 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenEffects.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenEffects.kt@@ -102,7 +102,7 @@ internal fun CameraScreenEffects( // new mode also offers (BRIGHTNESS/ZOOM in VIDEO) stays open with its // correct control; a photo-only pane (SHADOWS/WARMTH/EXPOSURE_TIME/ // ISO/PORTRAIT_BLUR) is cleared so the column falls back to the new- // mode's lens/zoom bar instead of showing the stale photo slider, and+ // mode's zoom bar instead of showing the stale photo slider, and // does not resurrect when switching back. CameraSettingsColumn applies // the same effectiveSettingForMode check at render time. LaunchedEffect(cameraMode) {
camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenKit.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenKit.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenKit.ktindex b529578746..05eaa93ae7 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenKit.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenKit.kt@@ -67,7 +67,7 @@ internal fun settingsForMode(mode: CameraMode): List<CameraSetting> { /** * The pane to actually show for [setting] in [mode]: a pane the new mode- * does not offer resolves to null (the lens/zoom bar), so switching modes+ * does not offer resolves to null (the zoom bar), so switching modes * with a photo-only pane open re-renders the mode-appropriate set instead * of leaving the stale slider on screen. */
camera/src/main/java/com/vayunmathur/camera/ui/CameraSettingsColumn.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraSettingsColumn.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraSettingsColumn.ktindex 1f7369d491..cfd84ee1e1 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraSettingsColumn.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraSettingsColumn.kt@@ -24,9 +24,6 @@ import com.vayunmathur.library.ui.IconSunny @Composable internal fun CameraSettingsColumn( activeSetting: CameraSetting?,- availableLenses: List<com.vayunmathur.camera.domain.PhysicalLens>,- selectedLens: com.vayunmathur.camera.domain.PhysicalLens?,- onLensSelected: (com.vayunmathur.camera.domain.PhysicalLens) -> Unit, zoomRatio: Float, availableZoomLevels: List<Pair<String, Float>>, onZoomSelected: (Float) -> Unit,@@ -85,26 +82,18 @@ internal fun CameraSettingsColumn( } } // A pane the current mode does not offer (e.g. SHADOWS left open- // when switching PHOTO -> VIDEO) falls back to the lens/zoom bar+ // when switching PHOTO -> VIDEO) falls back to the zoom bar // instead of rendering the stale slider; CameraScreenEffects also // clears the stored pane so it does not resurrect on switching back. val effectiveSetting = effectiveSettingForMode(activeSetting, cameraMode) when (effectiveSetting) { null, CameraSetting.ZOOM -> {- // Zoom-locked modes (PANORAMA/PHOTOSPHERE) show NEITHER- // bar: the ZoomBar is a control that cannot take effect- // at the locked 1x, and the LensBar is hidden too —- // picking a physical lens (0.5x UW, 3x tele, …) changes- // the native field of view, which is exactly the zoom- // change the lock forbids for stitch input. The lens- // selection itself is left untouched, so leaving the- // mode restores the previous lens + stored zoom.+ // Zoom-locked modes (PANORAMA/PHOTOSPHERE) show no zoom+ // bar: it is a control that cannot take effect at the+ // locked 1x, which is exactly the field-of-view change+ // the lock forbids for stitch input. The stored zoom is+ // left untouched, so leaving the mode restores it. if (!cameraMode.isZoomLockedTo1x()) {- LensBar(- lenses = availableLenses,- selected = selectedLens,- onSelect = onLensSelected- ) ZoomBar( currentZoom = zoomRatio, zoomLevels = availableZoomLevels,
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.ktdeleted file mode 100644index b0d8692108..0000000000--- a/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt+++ /dev/null@@ -1,86 +0,0 @@-package com.vayunmathur.camera.ui--import androidx.compose.foundation.background-import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.shape.CircleShape-import androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.runtime.Composable-import androidx.compose.runtime.remember-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.draw.clip-import androidx.compose.ui.graphics.Color-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-import com.vayunmathur.camera.domain.LensLabels-import com.vayunmathur.camera.domain.PhysicalLens-import com.vayunmathur.library.ui.Text--/**- * Physical-lens picker: one pill per enumerated lens of the current facing,- * labeled Aperture-style (".4", ".5", "1x", "2x"). Pills are fixed 36dp- * circles with 13sp labels (mirroring [ZoomBar]), so labels stay short —- * never the old "UW · 13mm" compound that truncated in the chip.- * Hidden when fewer than two lenses are available. Stateless: the caller- * passes the family plus the selection.- */-@Composable-fun LensBar(- lenses: List<PhysicalLens>,- selected: PhysicalLens?,- onSelect: (PhysicalLens) -> Unit,- modifier: Modifier = Modifier,-) {- if (lenses.size < 2) return- // Pair each lens with its zoom-factor label, then sort ascending (".4",- // ".5", "1x", …) like Aperture regardless of enumeration order. Labels- // are positional — sorted once so every pill matches its lens.- val ordered = remember(lenses) {- val sorted = LensLabels.sortedByFactor(LensLabels.dedupe(lenses))- sorted.zip(LensLabels.labelsFor(sorted))- }- val pickerDescription = stringResource(R.string.lens_picker_description)- Row(- modifier = modifier- .semantics { contentDescription = pickerDescription }- .background(Color(0x99000000), RoundedCornerShape(24.dp))- .padding(horizontal = 6.dp, vertical = 4.dp),- horizontalArrangement = Arrangement.spacedBy(2.dp),- verticalAlignment = Alignment.CenterVertically,- ) {- ordered.forEach { (lens, label) ->- val isSelected = lens == selected- Box(- modifier = Modifier- .size(36.dp)- .selectedPill(isSelected, CircleShape)- .clip(CircleShape)- .clickable { onSelect(lens) },- contentAlignment = Alignment.Center,- ) {- // Precise collision labels (".50", "2.03x") run to 5 glyphs:- // step down to 11sp so they fit the fixed 36dp chip instead- // of clipping (short labels stay at the 13sp ZoomBar size).- Text(- label,- color = if (isSelected) Color.White else Color(0xFFBBBBBB),- 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/res/values-ar/strings.xml
diff --git a/camera/src/main/res/values-ar/strings.xml b/camera/src/main/res/values-ar/strings.xmlindex 6efbbf0cfe..d3fbb741a9 100644--- a/camera/src/main/res/values-ar/strings.xml+++ b/camera/src/main/res/values-ar/strings.xml@@ -27,7 +27,6 @@ <string name="processing_panorama_u2026">جارٍ معالجة البانورامة…</string> <string name="auto">تلقائي</string> <string name="night_2">ليلي %1$s%%</string>- <string name="lens_picker_description">عدسة الكاميرا</string> <string name="settings_save_location">حفظ الموقع</string> <string name="settings_save_location_choose">اختيار مجلد</string> <string name="settings_save_location_reset">إعادة التعيين للافتراضي</string>
camera/src/main/res/values-az/strings.xml
diff --git a/camera/src/main/res/values-az/strings.xml b/camera/src/main/res/values-az/strings.xmlindex f85bb6d71c..40db02379d 100644--- a/camera/src/main/res/values-az/strings.xml+++ b/camera/src/main/res/values-az/strings.xml@@ -28,7 +28,6 @@ <string name="processing_panorama_u2026">Panorama emal edilir…</string> <string name="auto">Avto</string> <string name="night_2">Gecə %1$s%%</string>- <string name="lens_picker_description">Kamera obyektivi</string> <string name="settings_save_location">Məkanı yadda saxla</string> <string name="settings_save_location_default">DCIM/Kamera</string> <string name="settings_save_location_choose">Qovluq seçin</string>
camera/src/main/res/values-et/strings.xml
diff --git a/camera/src/main/res/values-et/strings.xml b/camera/src/main/res/values-et/strings.xmlindex 9a059cee83..bb36ddb714 100644--- a/camera/src/main/res/values-et/strings.xml+++ b/camera/src/main/res/values-et/strings.xml@@ -28,7 +28,6 @@ <string name="settings_mirror_front">Peegepilt selfie jaoks</string> <string name="settings_mirror_front_description">Peegelda esikaamera pilti selfie jaoks nii eelvaates, kui salvestatud failides</string> <string name="qr_scanning_paused">QR-koodi skaneerimine on peatatud</string>- <string name="lens_picker_description">Kaamera</string> <string name="settings_save_location">Salvesta asukoht</string> <string name="settings_save_location_default">DCIM/Camera</string> <string name="settings_save_location_choose">Vali kaust</string>
camera/src/main/res/values-iw/strings.xml
diff --git a/camera/src/main/res/values-iw/strings.xml b/camera/src/main/res/values-iw/strings.xmlindex 63ad206206..8396ca69ed 100644--- a/camera/src/main/res/values-iw/strings.xml+++ b/camera/src/main/res/values-iw/strings.xml@@ -9,6 +9,5 @@ <string name="open_url">פתיחת כתובת</string> <string name="copy_text">העתקה</string> <string name="auto">אוטומטי</string>- <string name="lens_picker_description">עדשות מצלמה</string> <string name="settings_save_location">שמירת מיקום</string> </resources>
camera/src/main/res/values-pl/strings.xml
diff --git a/camera/src/main/res/values-pl/strings.xml b/camera/src/main/res/values-pl/strings.xmlindex 567942da9b..1dcf900302 100644--- a/camera/src/main/res/values-pl/strings.xml+++ b/camera/src/main/res/values-pl/strings.xml@@ -28,7 +28,6 @@ <string name="settings_mirror_front">Lustrzane odbicie selfie</string> <string name="settings_mirror_front_description">Lustrzane odbicie podglądu z przedniego aparatu oraz zapisanych zdjęć selfie</string> <string name="qr_scanning_paused">Skanowanie kodów QR wstrzymane</string>- <string name="lens_picker_description">Obiektyw</string> <string name="settings_save_location">Miejsce zapisu</string> <string name="settings_save_location_default">DCIM/Camera</string> <string name="settings_save_location_choose">Wybierz folder</string>
camera/src/main/res/values-sv/strings.xml
diff --git a/camera/src/main/res/values-sv/strings.xml b/camera/src/main/res/values-sv/strings.xmlindex bd3f7f15fa..9320185e8c 100644--- a/camera/src/main/res/values-sv/strings.xml+++ b/camera/src/main/res/values-sv/strings.xml@@ -28,7 +28,6 @@ <string name="auto">Automatiskt</string> <string name="night_2">Natt %1$s%%</string> <string name="qr_scanning_paused">QR-skanning pausad</string>- <string name="lens_picker_description">Kameralins</string> <string name="mode_photo">Foto</string> <string name="mode_portrait">Porträtt</string> <string name="mode_panorama">Panorama</string>
camera/src/main/res/values-zh-rCN/strings.xml
diff --git a/camera/src/main/res/values-zh-rCN/strings.xml b/camera/src/main/res/values-zh-rCN/strings.xmlindex 1c50d4bb71..bb0ef3e0b1 100644--- a/camera/src/main/res/values-zh-rCN/strings.xml+++ b/camera/src/main/res/values-zh-rCN/strings.xml@@ -28,7 +28,6 @@ <string name="settings_mirror_front">自拍镜像</string> <string name="settings_mirror_front_description">镜像前置摄像头预览和已保存的自拍照</string> <string name="qr_scanning_paused">二维码扫描已暂停</string>- <string name="lens_picker_description">相机镜头</string> <string name="settings_save_location">保存位置</string> <string name="settings_save_location_default">DCIM/Camera</string> <string name="settings_save_location_choose">选择文件夹</string>
camera/src/main/res/values/strings.xml
diff --git a/camera/src/main/res/values/strings.xml b/camera/src/main/res/values/strings.xmlindex d14abd9faf..33191503a4 100644--- a/camera/src/main/res/values/strings.xml+++ b/camera/src/main/res/values/strings.xml@@ -176,14 +176,6 @@ <!-- Messenger note when a video recording fails to start or finalize --> <string name="camera_recording_failed">Recording failed — nothing was saved. Try again.</string> - <!-- LensBar: physical-lens picker above the zoom bar -->- <!-- LensBar: label for the ultra-wide (0.5x) physical lens. Short pill label -->- <!-- LensBar: label for the default wide (1x) physical lens. Short pill label -->- <!-- LensBar: label for the telephoto physical lens. Short pill label -->- <!-- LensBar: label for the monochrome physical lens. Short pill label -->- <!-- LensBar: label for the front-facing lens. Short pill label -->- <!-- LensBar: content description for the physical-lens picker row -->- <string name="lens_picker_description">Camera lens</string> <!-- Save location settings (SettingsPage) --> <!-- SettingsPage: section header for photo/video save location -->
camera/src/test/java/com/vayunmathur/camera/platform/ZoomStopLensSyncTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/ZoomStopLensSyncTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/ZoomStopLensSyncTest.ktnew file mode 100644index 0000000000..772f41dfb9--- /dev/null+++ b/camera/src/test/java/com/vayunmathur/camera/platform/ZoomStopLensSyncTest.kt@@ -0,0 +1,124 @@+package com.vayunmathur.camera.platform++import android.os.Looper+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.camera.domain.LensFacing+import com.vayunmathur.camera.domain.LensType+import com.vayunmathur.camera.domain.PhysicalLens+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.Shadows+import org.robolectric.annotation.Config++/**+ * Zoom-stop lens sync: with the lens pills gone, a committed zoom landing+ * on a lens's nominal ratio must commit that lens (selection, startup+ * persistence, night-detection reset) through the zoom path alone; a+ * ratio between stops leaves the selection alone, and the panorama /+ * photosphere 1x lock is unaffected.+ */+@RunWith(RobolectricTestRunner::class)+@Config(sdk = [34])+class ZoomStopLensSyncTest {++ private fun vm() = CameraViewModel(ApplicationProvider.getApplicationContext())++ private val wide = PhysicalLens(+ logicalCameraId = "0", lensType = LensType.WIDE, facing = LensFacing.BACK,+ focalLengthMm35Eq = 24f, nominalZoomRatio = 1f, fallbackPriority = 0, labelKey = "wide",+ )+ private val tele = PhysicalLens(+ logicalCameraId = "2", lensType = LensType.TELEPHOTO, facing = LensFacing.BACK,+ focalLengthMm35Eq = 48f, nominalZoomRatio = 2f, fallbackPriority = 2, labelKey = "tele",+ )+ private val ultraWide = PhysicalLens(+ logicalCameraId = "1", lensType = LensType.ULTRA_WIDE, facing = LensFacing.BACK,+ focalLengthMm35Eq = 13f, nominalZoomRatio = 0.5f, fallbackPriority = 1, labelKey = "ultrawide",+ )++ private fun vmWithLenses(): CameraViewModel {+ val viewModel = vm()+ // Let the background startup lens enumeration settle first: it+ // writes availableLenses/selectedLens when it lands, and would+ // otherwise race (and overwrite) the fixtures below.+ Shadows.shadowOf(Looper.getMainLooper()).idle()+ Thread.sleep(300)+ Shadows.shadowOf(Looper.getMainLooper()).idle()+ viewModel.availableLensesMutable.value = listOf(wide, tele, ultraWide)+ viewModel.selectedLensMutable.value = wide+ return viewModel+ }++ /** Waits until the async DataStore write is visible in the sync mirror. */+ private fun awaitStored(viewModel: CameraViewModel, key: String, expected: String?) {+ val deadline = System.currentTimeMillis() + 5_000+ while (viewModel.ds.getString(key) != expected) {+ assertTrue(System.currentTimeMillis() < deadline, "stored $key never became $expected")+ Shadows.shadowOf(Looper.getMainLooper()).idle()+ Thread.sleep(20)+ }+ assertEquals(expected, viewModel.ds.getString(key))+ }++ @Test+ fun zoomingToTeleStopSelectsAndPersistsTeleLens() {+ val viewModel = vmWithLenses()+ // Landing on the wide stop syncs back to the wide lens first.+ viewModel.selectedLensMutable.value = ultraWide+ viewModel.setZoomRatio(1f)+ assertEquals(wide, viewModel.selectedLens.value, "zoom to 1x must sync to wide")+ viewModel.lowLightDetectedMutable.value = true++ viewModel.setZoomRatio(2f)++ assertEquals(tele, viewModel.selectedLens.value)+ assertEquals(2f, viewModel.zoomRatio.value)+ // The selectLens side effects: startup persistence + night reset.+ awaitStored(viewModel, LAST_LENS_ID_KEY, "2")+ awaitStored(viewModel, LAST_LENS_FACING_KEY, "BACK")+ assertFalse(viewModel.lowLightDetected.value, "night detection must reset on lens commit")+ }++ @Test+ fun zoomingBetweenStopsLeavesSelectionAlone() {+ val viewModel = vmWithLenses()+ viewModel.lowLightDetectedMutable.value = true++ viewModel.setZoomRatio(1.5f)++ assertEquals(wide, viewModel.selectedLens.value)+ assertEquals(1.5f, viewModel.zoomRatio.value)+ assertTrue(viewModel.lowLightDetected.value, "no lens commit, so no night reset")+ }++ @Test+ fun panoramaLockIgnoresZoomAndDoesNotSyncLens() {+ val viewModel = vmWithLenses()+ viewModel.selectedLensMutable.value = tele+ viewModel.cameraModeMutable.value = CameraMode.PANORAMA+ viewModel.zoomRatioMutable.value = 2.5f++ // 1f is the wide stop, but the lock path must not sync to it, and+ // the stored (non-locked-mode) zoom must survive untouched.+ viewModel.setZoomRatio(1f)+ viewModel.setZoomRatio(2f)++ assertEquals(tele, viewModel.selectedLens.value)+ assertEquals(2.5f, viewModel.zoomRatio.value)+ }++ @Test+ fun selectLensStillAppliesZoomWithoutRecursing() {+ val viewModel = vmWithLenses()++ viewModel.selectLens(tele)++ assertEquals(tele, viewModel.selectedLens.value)+ assertEquals(2f, viewModel.zoomRatio.value)+ awaitStored(viewModel, LAST_LENS_ID_KEY, "2")+ }+}
camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2ComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2ComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2ComposeTest.ktindex b55ac9c78f..bbbba32e40 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2ComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/CameraCovC2ComposeTest.kt@@ -14,9 +14,6 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.unit.dp import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4-import com.vayunmathur.camera.domain.LensFacing-import com.vayunmathur.camera.domain.LensType-import com.vayunmathur.camera.domain.PhysicalLens import com.vayunmathur.camera.platform.CameraMode import com.vayunmathur.camera.platform.GuideDot import com.vayunmathur.camera.platform.GuideDotState@@ -26,25 +23,17 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -/** Cov-c2: settings bars, panorama overlay, overlays, status indicators, lens bar. */+/** Cov-c2: settings bars, panorama overlay, overlays, status indicators, zoom bar. */ @RunWith(AndroidJUnit4::class) class CameraCovC2ComposeTest { @get:Rule val rule = createComposeRule() private val context = ApplicationProvider.getApplicationContext<android.content.Context>() - private fun lens(id: String, type: LensType, zoom: Float) = PhysicalLens(- logicalCameraId = id, lensType = type, facing = LensFacing.BACK,- focalLengthMm35Eq = 24f * zoom, nominalZoomRatio = zoom, fallbackPriority = 0, labelKey = id,- )- private fun settingsColumn(mode: CameraMode, setting: CameraSetting?) { rule.setContent { CameraSettingsColumn(- activeSetting = setting,- availableLenses = listOf(lens("0", LensType.WIDE, 1f), lens("1", LensType.TELEPHOTO, 2f)),- selectedLens = lens("0", LensType.WIDE, 1f),- onLensSelected = {}, zoomRatio = 1.5f,+ activeSetting = setting, zoomRatio = 1.5f, availableZoomLevels = listOf("0.5" to 0.5f, "1" to 1f, "2" to 2f), onZoomSelected = {}, exposureComp = 0.5f, onExposureComp = {}, shadows = -0.5f, onShadows = {}, warmth = 0f, onWarmth = {},@@ -189,19 +178,18 @@ class CameraCovC2ComposeTest { assertTrue(rule.onRoot().fetchSemanticsNode() != null) } - @Test fun lensBarSelectsTelephoto() {- val wide = lens("0", LensType.WIDE, 1f)- val tele = lens("1", LensType.TELEPHOTO, 3f)- var selected: PhysicalLens? = null- rule.setContent { LensBar(lenses = listOf(tele, wide), selected = wide, onSelect = { selected = it }) }+ @Test fun zoomBarSelectsTelephotoLensStop() {+ // Lens stops are reached through the zoom path now: tapping the+ // 3x chip applies that ratio via onZoomSelected (setZoomRatio).+ var selected: Float? = null+ rule.setContent {+ ZoomBar(+ currentZoom = 1f,+ zoomLevels = listOf("1x" to 1f, "3x" to 3f),+ onZoomSelected = { selected = it },+ )+ } rule.onNodeWithText("3x").performClick()- assertEquals(tele, selected)- }-- @Test fun lensBarSingleLensHidden() {- val wide = lens("0", LensType.WIDE, 1f)- rule.setContent { LensBar(lenses = listOf(wide), selected = wide, onSelect = {}) }- rule.waitForIdle()- assertTrue(rule.onAllNodesWithText("1x").fetchSemanticsNodes().isEmpty())+ assertEquals(3f, selected) } }
camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.ktindex 4981d01ab0..d022ef01d9 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/CameraPanesComposeTest.kt@@ -7,9 +7,6 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4-import com.vayunmathur.camera.domain.LensFacing-import com.vayunmathur.camera.domain.LensType-import com.vayunmathur.camera.domain.PhysicalLens import com.vayunmathur.camera.platform.AspectRatioOption import com.vayunmathur.camera.platform.CameraMode import com.vayunmathur.camera.platform.FlashMode@@ -28,11 +25,6 @@ class CameraPanesComposeTest { @get:Rule val rule = createComposeRule() - private val lens = PhysicalLens(- logicalCameraId = "0", lensType = LensType.WIDE, facing = LensFacing.BACK,- focalLengthMm35Eq = 24f, nominalZoomRatio = 1f, fallbackPriority = 0, labelKey = "wide",- )- @Test fun topBarPhotoControlsInvokeCallbacks() { var flash = 0; var grid = 0; var aspect = 0 rule.setContent {@@ -150,12 +142,10 @@ class CameraPanesComposeTest { assertTrue(rule.onRoot().fetchSemanticsNode() != null) } - @Test fun settingsColumnWithLensAndZoom() {+ @Test fun settingsColumnWithZoom() { rule.setContent { CameraSettingsColumn(- activeSetting = null,- availableLenses = listOf(lens), selectedLens = lens,- onLensSelected = {}, zoomRatio = 1f,+ activeSetting = null, zoomRatio = 1f, availableZoomLevels = listOf("1x" to 1f, "2x" to 2f), onZoomSelected = {}, exposureComp = 0f, onExposureComp = {}, shadows = 0f, onShadows = {}, warmth = 0f, onWarmth = {},@@ -171,9 +161,7 @@ class CameraPanesComposeTest { @Test fun settingsColumnActiveSettingShowsSlider() { rule.setContent { CameraSettingsColumn(- activeSetting = CameraSetting.BRIGHTNESS,- availableLenses = emptyList(), selectedLens = null,- onLensSelected = {}, zoomRatio = 1f,+ activeSetting = CameraSetting.BRIGHTNESS, zoomRatio = 1f, availableZoomLevels = emptyList(), onZoomSelected = {}, exposureComp = 0f, onExposureComp = {}, shadows = 0f, onShadows = {}, warmth = 0f, onWarmth = {},@@ -202,13 +190,18 @@ class CameraPanesComposeTest { assertEquals(null, noise) } - @Test fun lensBarSelectsLens() {- var selected: PhysicalLens? = null+ @Test fun zoomBarSelectsLensStopRatio() {+ // Lens stops are reached through the zoom path now: the zoom+ // chip applies the lens's nominal ratio via onZoomSelected.+ var selected: Float? = null rule.setContent {- LensBar(lenses = listOf(lens), selected = lens, onSelect = { selected = it })+ ZoomBar(+ currentZoom = 1f, zoomLevels = listOf("1x" to 1f, "2x" to 2f),+ onZoomSelected = { selected = it },+ ) }- assertTrue(rule.onRoot().fetchSemanticsNode() != null)- assertEquals(null, selected)+ rule.onNodeWithText("2x").performClick()+ assertEquals(2f, selected) } @Test fun zoomAndIsoBarsRender() {
camera/src/test/java/com/vayunmathur/camera/ui/CameraVideoSettingsComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/CameraVideoSettingsComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/CameraVideoSettingsComposeTest.ktindex f676afdf4e..b28ced8ebd 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/CameraVideoSettingsComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/CameraVideoSettingsComposeTest.kt@@ -32,9 +32,7 @@ class CameraVideoSettingsComposeTest { ) { rule.setContent { CameraSettingsColumn(- activeSetting = setting,- availableLenses = emptyList(), selectedLens = null,- onLensSelected = {}, zoomRatio = 1f,+ activeSetting = setting, zoomRatio = 1f, availableZoomLevels = listOf("1x" to 1f, "2x" to 2f), onZoomSelected = onZoom, exposureComp = 0.5f, onExposureComp = {}, shadows = -0.5f, onShadows = {}, warmth = 0f, onWarmth = {},@@ -84,9 +82,7 @@ class CameraVideoSettingsComposeTest { // rendering in VIDEO must not show the stale slider. rule.setContent { CameraSettingsColumn(- activeSetting = CameraSetting.SHADOWS,- availableLenses = emptyList(), selectedLens = null,- onLensSelected = {}, zoomRatio = 1f,+ activeSetting = CameraSetting.SHADOWS, zoomRatio = 1f, availableZoomLevels = listOf("1x" to 1f, "2x" to 2f), onZoomSelected = { zoom = it }, exposureComp = 0f, onExposureComp = {}, shadows = -0.5f, onShadows = {}, warmth = 0f, onWarmth = {},
camera/src/test/java/com/vayunmathur/camera/ui/PanoramaZoomLockComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/PanoramaZoomLockComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/PanoramaZoomLockComposeTest.ktindex ceea2891f2..986eff297e 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/PanoramaZoomLockComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/PanoramaZoomLockComposeTest.kt@@ -6,9 +6,6 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithText import androidx.test.ext.junit.runners.AndroidJUnit4-import com.vayunmathur.camera.domain.LensFacing-import com.vayunmathur.camera.domain.LensType-import com.vayunmathur.camera.domain.PhysicalLens import com.vayunmathur.camera.platform.CameraMode import kotlin.test.Test import kotlin.test.assertEquals@@ -20,34 +17,19 @@ import org.junit.runner.RunWith /** * Panorama/Photosphere zoom lock, UI side: no ZOOM setting is offered,- * and the settings column renders neither the zoom bar nor the lens- * bar (a physical-lens pick would change the native field of view,- * which is the zoom change the lock forbids).+ * and the settings column renders no zoom bar (a zoom change would+ * change the native field of view, which is the change the lock+ * forbids for stitch input). */ @RunWith(AndroidJUnit4::class) class PanoramaZoomLockComposeTest { @get:Rule val rule = createComposeRule() - private val lenses = listOf(- PhysicalLens(- logicalCameraId = "0", lensType = LensType.ULTRA_WIDE, facing = LensFacing.BACK,- focalLengthMm35Eq = 13f, nominalZoomRatio = 0.5f, fallbackPriority = 1,- labelKey = "ultrawide",- ),- PhysicalLens(- logicalCameraId = "0", lensType = LensType.WIDE, facing = LensFacing.BACK,- focalLengthMm35Eq = 24f, nominalZoomRatio = 1f, fallbackPriority = 0,- labelKey = "wide",- ),- )- private fun column(mode: CameraMode, setting: CameraSetting? = null) { rule.setContent { CameraSettingsColumn(- activeSetting = setting,- availableLenses = lenses, selectedLens = lenses[1],- onLensSelected = {}, zoomRatio = 3f,+ activeSetting = setting, zoomRatio = 3f, availableZoomLevels = listOf("1x" to 1f, "2x" to 2f, "5x" to 5f), onZoomSelected = {}, exposureComp = 0f, onExposureComp = {}, shadows = 0f, onShadows = {}, warmth = 0f, onWarmth = {},@@ -79,17 +61,16 @@ class PanoramaZoomLockComposeTest { } @Test- fun panoramaShowsNeitherZoomBarNorLensBar() {+ fun panoramaShowsNoZoomBar() { column(CameraMode.PANORAMA) assertTrue(rule.onAllNodesWithText("2x").fetchSemanticsNodes().isEmpty()) assertTrue(rule.onAllNodesWithText("5x").fetchSemanticsNodes().isEmpty())- // "1x" would come from either bar (zoom pill or wide-lens pill). assertTrue(rule.onAllNodesWithText("1x").fetchSemanticsNodes().isEmpty()) assertTrue(rule.onAllNodesWithText(".5").fetchSemanticsNodes().isEmpty()) } @Test- fun photosphereShowsNeitherZoomBarNorLensBar() {+ fun photosphereShowsNoZoomBar() { column(CameraMode.PHOTOSPHERE, CameraSetting.ZOOM) assertTrue(rule.onAllNodesWithText("2x").fetchSemanticsNodes().isEmpty()) assertTrue(rule.onAllNodesWithText("1x").fetchSemanticsNodes().isEmpty())
camera/src/test/java/com/vayunmathur/camera/ui/SettingsInteractionsComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/SettingsInteractionsComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/SettingsInteractionsComposeTest.ktindex 6327596a67..89ceabf1fb 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/SettingsInteractionsComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/SettingsInteractionsComposeTest.kt@@ -14,9 +14,6 @@ import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.vayunmathur.camera.MainActivity import com.vayunmathur.camera.Route-import com.vayunmathur.camera.domain.LensFacing-import com.vayunmathur.camera.domain.LensType-import com.vayunmathur.camera.domain.PhysicalLens import com.vayunmathur.camera.platform.CameraMode import com.vayunmathur.camera.platform.CameraViewModel import com.vayunmathur.library.util.NavBackStack@@ -55,17 +52,11 @@ class SettingsInteractionsComposeTest { } @Test fun settingsColumnSettingVariants() {- val lens = PhysicalLens(- logicalCameraId = "0", lensType = LensType.WIDE, facing = LensFacing.BACK,- focalLengthMm35Eq = 24f, nominalZoomRatio = 1f, fallbackPriority = 0, labelKey = "wide",- ) var setting by androidx.compose.runtime.mutableStateOf<CameraSetting?>(CameraSetting.BRIGHTNESS) var qr by androidx.compose.runtime.mutableStateOf<String?>("WIFI:T:WPA;S:Home;P:secretpw;;") rule.setContent { CameraSettingsColumn(- activeSetting = setting,- availableLenses = listOf(lens), selectedLens = lens,- onLensSelected = {}, zoomRatio = 2f,+ activeSetting = setting, zoomRatio = 2f, availableZoomLevels = listOf("1x" to 1f, "2x" to 2f), onZoomSelected = {}, exposureComp = 0.3f, onExposureComp = {}, shadows = 0.2f, onShadows = {}, warmth = 0.1f, onWarmth = {},
camera/src/test/java/com/vayunmathur/camera/ui/ZoomBarScrubComposeTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/ui/ZoomBarScrubComposeTest.kt b/camera/src/test/java/com/vayunmathur/camera/ui/ZoomBarScrubComposeTest.ktindex 3dbd144397..927cc09c4c 100644--- a/camera/src/test/java/com/vayunmathur/camera/ui/ZoomBarScrubComposeTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/ui/ZoomBarScrubComposeTest.kt@@ -131,9 +131,7 @@ class ZoomBarScrubComposeTest { // PanoramaZoomLockTest), so a scrub cannot move the locked 1x. rule.setContent { CameraSettingsColumn(- activeSetting = null,- availableLenses = emptyList(), selectedLens = null,- onLensSelected = {}, zoomRatio = 1f,+ activeSetting = null, zoomRatio = 1f, availableZoomLevels = levels, onZoomSelected = {}, exposureComp = 0f, onExposureComp = {}, shadows = 0f, onShadows = {}, warmth = 0f, onWarmth = {},