From 600eeab6b01c8b486d8a3a0eded18f2fc0791e59 Mon Sep 17 00:00:00 2001 From: Kimberly Crevecoeur Date: Thu, 29 Feb 2024 11:32:45 -0800 Subject: [PATCH] move single/multi stream capture mode toggle to quick settings (#121) * remove temporary button and add single/multi stream capture toggle to quick settings menu --- .../feature/preview/PreviewScreen.kt | 11 ++++---- .../feature/preview/PreviewViewModel.kt | 11 ++------ .../preview/ui/CameraControlsOverlay.kt | 23 ++------------- .../preview/src/main/res/values/strings.xml | 2 -- .../quicksettings/QuickSettingsEnums.kt | 19 +++++++++++++ .../quicksettings/QuickSettingsScreen.kt | 20 ++++++++++--- .../ui/QuickSettingsComponents.kt | 28 ++++++++++++++++++- .../main/res/drawable/multi_stream_icon.xml | 21 ++++++++++++++ .../drawable/single_stream_capture_icon.xml | 21 ++++++++++++++ .../src/main/res/values/strings.xml | 28 ++++++++----------- 10 files changed, 127 insertions(+), 57 deletions(-) create mode 100644 feature/quicksettings/src/main/res/drawable/multi_stream_icon.xml create mode 100644 feature/quicksettings/src/main/res/drawable/single_stream_capture_icon.xml diff --git a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewScreen.kt b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewScreen.kt index 6a0b524b..92639f07 100644 --- a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewScreen.kt +++ b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewScreen.kt @@ -47,6 +47,7 @@ import com.google.jetpackcamera.feature.preview.ui.ScreenFlashScreen import com.google.jetpackcamera.feature.preview.ui.ShowTestableToast import com.google.jetpackcamera.feature.quicksettings.QuickSettingsScreenOverlay import com.google.jetpackcamera.settings.model.AspectRatio +import com.google.jetpackcamera.settings.model.CaptureMode import com.google.jetpackcamera.settings.model.FlashMode private const val TAG = "PreviewScreen" @@ -93,12 +94,12 @@ fun PreviewScreen( onChangeZoomScale = viewModel::setZoomScale, onChangeFlash = viewModel::setFlash, onChangeAspectRatio = viewModel::setAspectRatio, + onChangeCaptureMode = viewModel::setCaptureMode, onToggleQuickSettings = viewModel::toggleQuickSettings, onCaptureImage = viewModel::captureImage, onCaptureImageWithUri = viewModel::captureImageWithUri, onStartVideoRecording = viewModel::startVideoRecording, onStopVideoRecording = viewModel::stopVideoRecording, - onToggleCaptureMode = viewModel::toggleCaptureMode, onToastShown = viewModel::onToastShown ) } @@ -117,6 +118,7 @@ private fun ContentScreen( onChangeZoomScale: (Float) -> Unit = {}, onChangeFlash: (FlashMode) -> Unit = {}, onChangeAspectRatio: (AspectRatio) -> Unit = {}, + onChangeCaptureMode: (CaptureMode) -> Unit = {}, onToggleQuickSettings: () -> Unit = {}, onCaptureImage: () -> Unit = {}, onCaptureImageWithUri: ( @@ -126,7 +128,6 @@ private fun ContentScreen( ) -> Unit = { _, _, _ -> }, onStartVideoRecording: () -> Unit = {}, onStopVideoRecording: () -> Unit = {}, - onToggleCaptureMode: () -> Unit = {}, onToastShown: () -> Unit = {} ) { // display camera feed. this stays behind everything else @@ -145,7 +146,8 @@ private fun ContentScreen( currentCameraSettings = previewUiState.currentCameraSettings, onLensFaceClick = { onFlipCamera() }, onFlashModeClick = onChangeFlash, - onAspectRatioClick = onChangeAspectRatio + onAspectRatioClick = onChangeAspectRatio, + onCaptureModeClick = onChangeCaptureMode // onTimerClick = {}/*TODO*/ ) // relative-grid style overlay on top of preview display @@ -159,8 +161,7 @@ private fun ContentScreen( onCaptureImage = onCaptureImage, onCaptureImageWithUri = onCaptureImageWithUri, onStartVideoRecording = onStartVideoRecording, - onStopVideoRecording = onStopVideoRecording, - onToggleCaptureMode = onToggleCaptureMode + onStopVideoRecording = onStopVideoRecording ) // displays toast when there is a message to show diff --git a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewViewModel.kt b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewViewModel.kt index 3724976d..561ba3ea 100644 --- a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewViewModel.kt +++ b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/PreviewViewModel.kt @@ -168,24 +168,19 @@ class PreviewViewModel @Inject constructor( ) } - fun toggleCaptureMode() { - val newCaptureMode = when (previewUiState.value.currentCameraSettings.captureMode) { - CaptureMode.MULTI_STREAM -> CaptureMode.SINGLE_STREAM - CaptureMode.SINGLE_STREAM -> CaptureMode.MULTI_STREAM - } - + fun setCaptureMode(captureMode: CaptureMode) { stopCamera() runningCameraJob = viewModelScope.launch { _previewUiState.emit( previewUiState.value.copy( currentCameraSettings = previewUiState.value.currentCameraSettings.copy( - captureMode = newCaptureMode + captureMode = captureMode ) ) ) // apply to cameraUseCase - cameraUseCase.setCaptureMode(newCaptureMode) + cameraUseCase.setCaptureMode(captureMode) } } diff --git a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/ui/CameraControlsOverlay.kt b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/ui/CameraControlsOverlay.kt index e22d087f..e5b080a1 100644 --- a/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/ui/CameraControlsOverlay.kt +++ b/feature/preview/src/main/java/com/google/jetpackcamera/feature/preview/ui/CameraControlsOverlay.kt @@ -37,19 +37,16 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.google.jetpackcamera.feature.preview.MultipleEventsCutter import com.google.jetpackcamera.feature.preview.PreviewMode import com.google.jetpackcamera.feature.preview.PreviewUiState import com.google.jetpackcamera.feature.preview.PreviewViewModel -import com.google.jetpackcamera.feature.preview.R import com.google.jetpackcamera.feature.preview.VideoRecordingState import com.google.jetpackcamera.feature.quicksettings.ui.QuickSettingsIndicators import com.google.jetpackcamera.feature.quicksettings.ui.ToggleQuickSettingsButton import com.google.jetpackcamera.settings.model.CameraAppSettings -import com.google.jetpackcamera.settings.model.CaptureMode import com.google.jetpackcamera.settings.model.FlashMode import com.google.jetpackcamera.settings.model.Stabilization import com.google.jetpackcamera.settings.model.SupportedStabilizationMode @@ -82,8 +79,7 @@ fun CameraControlsOverlay( (PreviewViewModel.ImageCaptureEvent) -> Unit ) -> Unit = { _, _, _ -> }, onStartVideoRecording: () -> Unit = {}, - onStopVideoRecording: () -> Unit = {}, - onToggleCaptureMode: () -> Unit = {} + onStopVideoRecording: () -> Unit = {} ) { // Show the current zoom level for a short period of time, only when the level changes. var firstRun by remember { mutableStateOf(true) } @@ -106,8 +102,7 @@ fun CameraControlsOverlay( currentCameraSettings = previewUiState.currentCameraSettings, onNavigateToSettings = onNavigateToSettings, onChangeFlash = onChangeFlash, - onToggleQuickSettings = onToggleQuickSettings, - onToggleCaptureMode = onToggleCaptureMode + onToggleQuickSettings = onToggleQuickSettings ) } @@ -139,8 +134,7 @@ private fun ControlsTop( modifier: Modifier = Modifier, onNavigateToSettings: () -> Unit = {}, onChangeFlash: (FlashMode) -> Unit = {}, - onToggleQuickSettings: () -> Unit = {}, - onToggleCaptureMode: () -> Unit = {} + onToggleQuickSettings: () -> Unit = {} ) { Row(modifier, verticalAlignment = Alignment.CenterVertically) { Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { @@ -162,17 +156,6 @@ private fun ControlsTop( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceEvenly ) { - // For debug purposes, display whether the stream is in single/multi mode. - TestingButton( - modifier = Modifier.testTag("ToggleCaptureMode"), - onClick = onToggleCaptureMode, - text = stringResource( - when (currentCameraSettings.captureMode) { - CaptureMode.SINGLE_STREAM -> R.string.capture_mode_single_stream - CaptureMode.MULTI_STREAM -> R.string.capture_mode_multi_stream - } - ) - ) StabilizationIcon( supportedStabilizationMode = currentCameraSettings.supportedStabilizationModes, videoStabilization = currentCameraSettings.videoCaptureStabilization, diff --git a/feature/preview/src/main/res/values/strings.xml b/feature/preview/src/main/res/values/strings.xml index b2713f5f..aa52e3f5 100644 --- a/feature/preview/src/main/res/values/strings.xml +++ b/feature/preview/src/main/res/values/strings.xml @@ -17,8 +17,6 @@ Camera Loading… Settings - Single Stream - Multi Stream Flip Camera Image Capture Success diff --git a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsEnums.kt b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsEnums.kt index 99a93157..c782dd44 100644 --- a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsEnums.kt +++ b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsEnums.kt @@ -97,3 +97,22 @@ enum class CameraAspectRatio : QuickSettingsEnum { R.string.quick_settings_aspect_ratio_1_1_description } } + +enum class CameraCaptureMode : QuickSettingsEnum { + MULTI_STREAM { + override fun getDrawableResId(): Int = R.drawable.multi_stream_icon + + override fun getTextResId(): Int = R.string.quick_settings_capture_mode_multi + + override fun getDescriptionResId(): Int = + R.string.quick_settings_capture_mode_multi_description + }, + SINGLE_STREAM { + override fun getDrawableResId(): Int = R.drawable.single_stream_capture_icon + + override fun getTextResId(): Int = R.string.quick_settings_capture_mode_single + + override fun getDescriptionResId(): Int = + R.string.quick_settings_capture_mode_single_description + } +} diff --git a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsScreen.kt b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsScreen.kt index 8a8a60ff..15d400cb 100644 --- a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsScreen.kt +++ b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/QuickSettingsScreen.kt @@ -38,12 +38,14 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.dimensionResource import com.google.jetpackcamera.feature.quicksettings.ui.ExpandedQuickSetRatio import com.google.jetpackcamera.feature.quicksettings.ui.QuickFlipCamera +import com.google.jetpackcamera.feature.quicksettings.ui.QuickSetCaptureMode import com.google.jetpackcamera.feature.quicksettings.ui.QuickSetFlash import com.google.jetpackcamera.feature.quicksettings.ui.QuickSetRatio import com.google.jetpackcamera.feature.quicksettings.ui.QuickSettingsGrid import com.google.jetpackcamera.quicksettings.R import com.google.jetpackcamera.settings.model.AspectRatio import com.google.jetpackcamera.settings.model.CameraAppSettings +import com.google.jetpackcamera.settings.model.CaptureMode import com.google.jetpackcamera.settings.model.FlashMode /** @@ -58,7 +60,8 @@ fun QuickSettingsScreenOverlay( toggleIsOpen: () -> Unit, onLensFaceClick: (lensFace: Boolean) -> Unit, onFlashModeClick: (flashMode: FlashMode) -> Unit, - onAspectRatioClick: (aspectRation: AspectRatio) -> Unit + onAspectRatioClick: (aspectRation: AspectRatio) -> Unit, + onCaptureModeClick: (captureMode: CaptureMode) -> Unit ) { var shouldShowQuickSetting by remember { mutableStateOf(IsExpandedQuickSetting.NONE) @@ -103,7 +106,8 @@ fun QuickSettingsScreenOverlay( }, onLensFaceClick = onLensFaceClick, onFlashModeClick = onFlashModeClick, - onAspectRatioClick = onAspectRatioClick + onAspectRatioClick = onAspectRatioClick, + onCaptureModeClick = onCaptureModeClick ) } } else { @@ -125,9 +129,10 @@ private fun ExpandedQuickSettingsUi( currentCameraSettings: CameraAppSettings, onLensFaceClick: (lensFacingFront: Boolean) -> Unit, onFlashModeClick: (flashMode: FlashMode) -> Unit, + onAspectRatioClick: (aspectRation: AspectRatio) -> Unit, + onCaptureModeClick: (captureMode: CaptureMode) -> Unit, shouldShowQuickSetting: IsExpandedQuickSetting, - setVisibleQuickSetting: (IsExpandedQuickSetting) -> Unit, - onAspectRatioClick: (aspectRation: AspectRatio) -> Unit + setVisibleQuickSetting: (IsExpandedQuickSetting) -> Unit ) { Column( modifier = @@ -169,6 +174,13 @@ private fun ExpandedQuickSettingsUi( ratio = currentCameraSettings.aspectRatio, currentRatio = currentCameraSettings.aspectRatio ) + }, + { + QuickSetCaptureMode( + modifier = Modifier.testTag(""), + setCaptureMode = { c: CaptureMode -> onCaptureModeClick(c) }, + currentCaptureMode = currentCameraSettings.captureMode + ) } ) QuickSettingsGrid(quickSettingsButtons = displayedQuickSettings) diff --git a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/ui/QuickSettingsComponents.kt b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/ui/QuickSettingsComponents.kt index ccf194a6..d7348ae5 100644 --- a/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/ui/QuickSettingsComponents.kt +++ b/feature/quicksettings/src/main/java/com/google/jetpackcamera/feature/quicksettings/ui/QuickSettingsComponents.kt @@ -40,13 +40,16 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.google.jetpackcamera.feature.quicksettings.CameraAspectRatio +import com.google.jetpackcamera.feature.quicksettings.CameraCaptureMode import com.google.jetpackcamera.feature.quicksettings.CameraFlashMode import com.google.jetpackcamera.feature.quicksettings.CameraLensFace import com.google.jetpackcamera.feature.quicksettings.QuickSettingsEnum import com.google.jetpackcamera.quicksettings.R import com.google.jetpackcamera.settings.model.AspectRatio +import com.google.jetpackcamera.settings.model.CaptureMode import com.google.jetpackcamera.settings.model.FlashMode import kotlin.math.min @@ -163,6 +166,29 @@ fun QuickFlipCamera( ) } +@Composable +fun QuickSetCaptureMode( + modifier: Modifier = Modifier, + setCaptureMode: (CaptureMode) -> Unit, + currentCaptureMode: CaptureMode +) { + val enum: CameraCaptureMode = + when (currentCaptureMode) { + CaptureMode.MULTI_STREAM -> CameraCaptureMode.MULTI_STREAM + CaptureMode.SINGLE_STREAM -> CameraCaptureMode.SINGLE_STREAM + } + QuickSettingUiItem( + modifier = modifier, + enum = enum, + onClick = { + when (currentCaptureMode) { + CaptureMode.MULTI_STREAM -> setCaptureMode(CaptureMode.SINGLE_STREAM) + CaptureMode.SINGLE_STREAM -> setCaptureMode(CaptureMode.MULTI_STREAM) + } + } + ) +} + /** * Button to toggle quick settings */ @@ -239,7 +265,7 @@ fun QuickSettingUiItem( .size(dimensionResource(id = R.dimen.quick_settings_ui_item_icon_size)) ) - Text(text = text, color = tint) + Text(text = text, color = tint, textAlign = TextAlign.Center) } } diff --git a/feature/quicksettings/src/main/res/drawable/multi_stream_icon.xml b/feature/quicksettings/src/main/res/drawable/multi_stream_icon.xml new file mode 100644 index 00000000..834ee33a --- /dev/null +++ b/feature/quicksettings/src/main/res/drawable/multi_stream_icon.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/feature/quicksettings/src/main/res/drawable/single_stream_capture_icon.xml b/feature/quicksettings/src/main/res/drawable/single_stream_capture_icon.xml new file mode 100644 index 00000000..cc818a10 --- /dev/null +++ b/feature/quicksettings/src/main/res/drawable/single_stream_capture_icon.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/feature/quicksettings/src/main/res/values/strings.xml b/feature/quicksettings/src/main/res/values/strings.xml index e571f3e7..530fdef7 100644 --- a/feature/quicksettings/src/main/res/values/strings.xml +++ b/feature/quicksettings/src/main/res/values/strings.xml @@ -17,33 +17,27 @@ FRONT BACK + Front Camera + Back Camera 3:4 9:16 1:1 - - OFF - AUTO - ON - - OFF - - - - Quick settings drop down - - Front Camera - Back Camera - 3 to 4 aspect ratio 9 to 16 aspect ratio 1 to 1 aspect ratio + OFF + AUTO + ON Flash off Auto flash Flash on - Timer off - 3 seconds timer - 10 seconds timer + Single Stream + Multi Stream + Single-stream capture mode on + Multi-stream capture mode on + + Quick settings drop down \ No newline at end of file