feat: camera screen ui
This commit is contained in:
1 parent
5ef12b1679
commit
215f848b4e
10 files changed
+349
-524
No files matched your search
@@ -275,6 +275,8 @@ data class UserPreferences(
|
||||
data class PreferenceUpdateValue<T>(val value: T)
|
||||
|
||||
data class CameraFeaturePreferencesUpdate(
|
||||
val captureMode: PreferenceUpdateValue<CaptureMode>? = null,
|
||||
val videoLogProfile: PreferenceUpdateValue<VideoLogProfile>? = null,
|
||||
val lutId: PreferenceUpdateValue<String?>? = null,
|
||||
val effects: PreferenceUpdateValue<EffectParams>? = null,
|
||||
val aspectRatio: PreferenceUpdateValue<String>? = null,
|
||||
@@ -2294,6 +2296,12 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
|
||||
suspend fun saveCameraFeaturePreferences(update: CameraFeaturePreferencesUpdate) {
|
||||
context.dataStore.edit { preferences ->
|
||||
update.captureMode?.let {
|
||||
preferences[CAPTURE_MODE] = it.value.name
|
||||
}
|
||||
update.videoLogProfile?.let {
|
||||
preferences[VIDEO_LOG_PROFILE] = it.value.name
|
||||
}
|
||||
update.lutId?.let {
|
||||
if (it.value != null) {
|
||||
preferences[LUT_ID_KEY] = it.value
|
||||
|
||||
@@ -114,11 +114,14 @@ private const val DefaultShutterSpeedNs = 1_000_000_000f / 60f
|
||||
private const val DefaultIso = 100f
|
||||
private const val DefaultAwbTemperature = 5000f
|
||||
private const val DefaultFocusDistance = 0f
|
||||
private val ProfessionalModeColor = Color(0xFFFFA36C)
|
||||
private val CameraTopBarBaseTopPadding = 32.dp
|
||||
private val CameraTopBarBaseHeight = 80.dp
|
||||
private val VideoViewfinderRaisedOffset = 16.dp
|
||||
private val OpenGateVideoViewfinderRaisedOffset = 56.dp
|
||||
private val VideoTopBarBaseHeight = 80.dp
|
||||
private val VideoTopBarLoweredOffset = 36.dp
|
||||
private val XpanViewfinderInnerBorder = 4.dp
|
||||
private val XpanSideControlReservedWidth = 56.dp
|
||||
private val XpanBottomControlClearance = 64.dp
|
||||
|
||||
private fun formatVirtualApertureFStop(aperture: Float): String {
|
||||
val rounded = aperture.roundToInt()
|
||||
@@ -316,6 +319,7 @@ fun CameraScreen(
|
||||
var activePanel by remember { mutableStateOf(ActivePanel.NONE) }
|
||||
var selectedParameter by remember { mutableStateOf(CameraParameter.EXPOSURE_COMPENSATION) }
|
||||
var showVideoParameterRuler by remember { mutableStateOf(false) }
|
||||
var showPhotoParameterRuler by remember { mutableStateOf(false) }
|
||||
val isXpan = state.aspectRatio == AspectRatio.XPAN
|
||||
val burstCapturingCount = viewModel.burstImageCount
|
||||
|
||||
@@ -345,8 +349,8 @@ fun CameraScreen(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(useRaw, state.captureMode) {
|
||||
if (!useRaw || state.captureMode != CaptureMode.PHOTO) {
|
||||
LaunchedEffect(state.useRaw, state.captureMode) {
|
||||
if (!state.useRaw || state.captureMode != CaptureMode.PHOTO) {
|
||||
rawCaptureTapLocked = false
|
||||
}
|
||||
}
|
||||
@@ -574,7 +578,7 @@ fun CameraScreen(
|
||||
}
|
||||
if (
|
||||
targetCaptureMode == state.captureMode &&
|
||||
(targetUseRaw == null || targetUseRaw == useRaw)
|
||||
(targetUseRaw == null || targetUseRaw == state.useRaw)
|
||||
) {
|
||||
return
|
||||
}
|
||||
@@ -583,12 +587,7 @@ fun CameraScreen(
|
||||
if (targetCaptureMode == CaptureMode.VIDEO && state.aspectRatio == AspectRatio.XPAN) {
|
||||
viewModel.setAspectRatio(AspectRatio.RATIO_4_3)
|
||||
}
|
||||
if (targetCaptureMode != state.captureMode) {
|
||||
viewModel.setCaptureMode(targetCaptureMode)
|
||||
}
|
||||
if (targetUseRaw != null && targetUseRaw != useRaw) {
|
||||
viewModel.setUseRaw(targetUseRaw)
|
||||
}
|
||||
viewModel.setShootingMode(targetCaptureMode, targetUseRaw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,10 +669,9 @@ fun CameraScreen(
|
||||
|
||||
var showGhostPermissionDialog by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(state.captureMode) {
|
||||
if (state.captureMode != CaptureMode.PHOTO) {
|
||||
showVideoParameterRuler = false
|
||||
}
|
||||
LaunchedEffect(state.captureMode, state.useRaw) {
|
||||
showVideoParameterRuler = false
|
||||
showPhotoParameterRuler = false
|
||||
}
|
||||
|
||||
LaunchedEffect(viewModel.showGhostPermissions) {
|
||||
@@ -798,13 +796,25 @@ fun CameraScreen(
|
||||
|
||||
val isVideoMode = state.captureMode == CaptureMode.VIDEO
|
||||
val isPhotoStyleMode = state.captureMode != CaptureMode.VIDEO
|
||||
val isProfessionalMode = isPhotoStyleMode && state.useRaw && state.isRawSupported
|
||||
val isPhotoParameterRulerVisible = isProfessionalMode || showPhotoParameterRuler
|
||||
val onPhotoParameterClick: (CameraParameter) -> Unit = { parameter ->
|
||||
val wasSelected = selectedParameter == parameter
|
||||
selectedParameter = parameter
|
||||
if (!isProfessionalMode) {
|
||||
showPhotoParameterRuler = !wasSelected || !showPhotoParameterRuler
|
||||
}
|
||||
}
|
||||
LaunchedEffect(isPhotoStyleMode) {
|
||||
if (!isPhotoStyleMode) {
|
||||
parameterRulerBounds = null
|
||||
}
|
||||
}
|
||||
val videoAspectRatio =
|
||||
state.videoConfig.aspectRatio.getPortraitAspectRatio(state.videoCapabilities.openGatePortraitAspectRatio)
|
||||
LaunchedEffect(isPhotoParameterRulerVisible) {
|
||||
if (!isPhotoParameterRulerVisible) {
|
||||
parameterRulerBounds = null
|
||||
}
|
||||
}
|
||||
val isOpenGateVideo =
|
||||
isVideoMode && state.videoConfig.aspectRatio == VideoAspectRatio.OPEN_GATE
|
||||
|
||||
@@ -812,39 +822,52 @@ fun CameraScreen(
|
||||
val width = with(density) { constraints.maxWidth.toDp() }
|
||||
val height = with(density) { constraints.maxHeight.toDp() }
|
||||
val topSafePadding = cameraTopSafePadding()
|
||||
val topBarHeight = CameraTopBarBaseHeight + topSafePadding
|
||||
val topBarOffset = 0.dp
|
||||
val topBarBaseHeight = if (isVideoMode) {
|
||||
VideoTopBarBaseHeight
|
||||
} else {
|
||||
CameraTopBarBaseHeight
|
||||
}
|
||||
val topBarHeight = topBarBaseHeight + topSafePadding
|
||||
val topBarBottom = topBarHeight + topBarOffset - 4.dp
|
||||
val navigationBarHeight = with(density) {
|
||||
WindowInsets.navigationBars.getBottom(this).toDp()
|
||||
}
|
||||
val cardWidth = if (isXpan) {
|
||||
(height - topSafePadding - 280.dp) * 24 / 65 + 8.dp
|
||||
val contentHeight = (height - navigationBarHeight).coerceAtLeast(0.dp)
|
||||
val viewfinderFramePadding = if (isXpan) XpanViewfinderInnerBorder * 2 else 0.dp
|
||||
val sideControlSpace = if (isXpan) XpanSideControlReservedWidth else 0.dp
|
||||
val maxCardWidth = (width - sideControlSpace * 2)
|
||||
.coerceAtLeast(viewfinderFramePadding)
|
||||
val maxCardHeight = if (isXpan) {
|
||||
(contentHeight - topBarBottom - XpanBottomControlClearance)
|
||||
.coerceAtLeast(viewfinderFramePadding)
|
||||
} else {
|
||||
width
|
||||
contentHeight
|
||||
}
|
||||
val cardHeight = if (isXpan) {
|
||||
height - topSafePadding - 272.dp
|
||||
} else if (isVideoMode) {
|
||||
width / videoAspectRatio
|
||||
val maxViewfinderContentWidth = (maxCardWidth - viewfinderFramePadding)
|
||||
.coerceAtLeast(0.dp)
|
||||
val maxViewfinderContentHeight = (maxCardHeight - viewfinderFramePadding)
|
||||
.coerceAtLeast(0.dp)
|
||||
val viewfinderContentWidth = minOf(
|
||||
maxViewfinderContentWidth,
|
||||
maxViewfinderContentHeight * previewAspectRatio
|
||||
)
|
||||
val cardWidth = viewfinderContentWidth + viewfinderFramePadding
|
||||
val cardHeight = viewfinderContentWidth / previewAspectRatio + viewfinderFramePadding
|
||||
val xpanSideWidth = ((width - cardWidth) / 2).coerceAtLeast(0.dp)
|
||||
val placeViewfinderBelowTopBar = contentHeight - cardHeight >= topBarBottom
|
||||
val viewfinderAlignment = if (placeViewfinderBelowTopBar) {
|
||||
Alignment.TopCenter
|
||||
} else {
|
||||
val standardHeight = width * 4 / 3
|
||||
val bottomMinHeight = 188.dp // parameterBar (44.dp) + controls (136.dp min) + 8.dp buffer
|
||||
val maxCardHeight = (height - topBarHeight - bottomMinHeight - navigationBarHeight).coerceAtLeast(300.dp)
|
||||
standardHeight.coerceAtMost(maxCardHeight)
|
||||
Alignment.Center
|
||||
}
|
||||
val videoContentHeight = (height - navigationBarHeight).coerceAtLeast(0.dp)
|
||||
val requestedVideoViewfinderOffset = if (isOpenGateVideo) {
|
||||
OpenGateVideoViewfinderRaisedOffset
|
||||
val viewfinderOffset = if (placeViewfinderBelowTopBar) topBarBottom else 0.dp
|
||||
val viewfinderTop = if (placeViewfinderBelowTopBar) {
|
||||
topBarBottom
|
||||
} else {
|
||||
VideoViewfinderRaisedOffset
|
||||
}
|
||||
val videoViewfinderOffset = if (
|
||||
isVideoMode &&
|
||||
(videoContentHeight - cardHeight) / 2 >= requestedVideoViewfinderOffset
|
||||
) {
|
||||
-requestedVideoViewfinderOffset
|
||||
} else {
|
||||
0.dp
|
||||
((contentHeight - cardHeight) / 2).coerceAtLeast(0.dp)
|
||||
}
|
||||
val viewfinderTopOverlayPadding = (topBarBottom - viewfinderTop).coerceAtLeast(0.dp)
|
||||
|
||||
val topBar = @Composable {
|
||||
CameraTopBar(
|
||||
@@ -878,13 +901,7 @@ fun CameraScreen(
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(top = topSafePadding)
|
||||
.offset(
|
||||
y = if (isVideoMode && !isOpenGateVideo) {
|
||||
VideoTopBarLoweredOffset
|
||||
} else {
|
||||
0.dp
|
||||
}
|
||||
)
|
||||
.offset(y = topBarOffset)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1000,10 +1017,12 @@ fun CameraScreen(
|
||||
)
|
||||
}
|
||||
|
||||
val parameterBar = @Composable { onParameterClick: (CameraParameter) -> Unit ->
|
||||
val parameterBar = @Composable {
|
||||
activeParameter: CameraParameter?,
|
||||
onParameterClick: (CameraParameter) -> Unit ->
|
||||
CameraParameterBar(
|
||||
state = state,
|
||||
selectedParameter = selectedParameter,
|
||||
selectedParameter = activeParameter,
|
||||
onParameterClick = onParameterClick
|
||||
)
|
||||
}
|
||||
@@ -1014,14 +1033,12 @@ fun CameraScreen(
|
||||
.animateContentSize(alignment = Alignment.Center)
|
||||
.width(cardWidth)
|
||||
.height(cardHeight),
|
||||
shape = RoundedCornerShape(if (isXpan) 4.dp else 0.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.Black
|
||||
)
|
||||
shape = RoundedCornerShape(if (isXpan) XpanViewfinderInnerBorder else 0.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.Black)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(if (isXpan) 4.dp else 0.dp)
|
||||
.padding(if (isXpan) XpanViewfinderInnerBorder else 0.dp)
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
@@ -1245,7 +1262,8 @@ fun CameraScreen(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = CameraParameterValuesOverlayHeight + 8.dp,
|
||||
top = viewfinderTopOverlayPadding +
|
||||
CameraParameterValuesOverlayHeight + 8.dp,
|
||||
end = 12.dp
|
||||
)
|
||||
.align(Alignment.TopEnd),
|
||||
@@ -1311,7 +1329,8 @@ fun CameraScreen(
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
start = 8.dp,
|
||||
top = CameraParameterValuesOverlayHeight + 8.dp
|
||||
top = viewfinderTopOverlayPadding +
|
||||
CameraParameterValuesOverlayHeight + 8.dp
|
||||
)
|
||||
.size(80.dp, 40.dp)
|
||||
.align(Alignment.TopStart)
|
||||
@@ -1364,40 +1383,23 @@ fun CameraScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// Zoom bar overlaid on preview for photo-style modes.
|
||||
if (isPhotoStyleMode) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(bottom = CameraParameterRulerHeight),
|
||||
contentAlignment = Alignment.BottomCenter
|
||||
) {
|
||||
zoomBar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CornerOverlay(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
radius = if (isXpan) 4.dp else 0.dp,
|
||||
color = Color.Black
|
||||
)
|
||||
if (isXpan) {
|
||||
CornerOverlay(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
radius = XpanViewfinderInnerBorder,
|
||||
color = Color.Black
|
||||
)
|
||||
}
|
||||
|
||||
CameraParameterValuesOverlay(
|
||||
state = state,
|
||||
modifier = Modifier.align(Alignment.TopCenter)
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
.padding(top = viewfinderTopOverlayPadding)
|
||||
)
|
||||
|
||||
if (isPhotoStyleMode) {
|
||||
parameterRuler(
|
||||
Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
parameterRulerBounds = coordinates.boundsInRoot()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
LutNameOverlay(
|
||||
state = lutNameOverlayState,
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
@@ -1415,7 +1417,8 @@ fun CameraScreen(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterStart)
|
||||
.width((width - cardWidth) / 2)
|
||||
.width(xpanSideWidth),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
ZoomControlBarVerticel(
|
||||
viewModel = viewModel,
|
||||
@@ -1426,27 +1429,23 @@ fun CameraScreen(
|
||||
onZoomStopClick = { animateZoomStopWithPreviewTransition(it) },
|
||||
onLensSwitch = { lensId -> switchToLensWithPreviewTransition(lensId) },
|
||||
onFilterClick = {
|
||||
// Toggle Filter Panel
|
||||
activePanel =
|
||||
if (activePanel == ActivePanel.FILTERS) ActivePanel.NONE else ActivePanel.FILTERS
|
||||
},
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
}
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterEnd)
|
||||
.width((width - cardWidth) / 2)
|
||||
.width(xpanSideWidth),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CameraParameterBarVerticel(
|
||||
state = state,
|
||||
selectedParameter = selectedParameter,
|
||||
onParameterClick = { param ->
|
||||
selectedParameter = param
|
||||
selectedParameter = selectedParameter.takeIf {
|
||||
isPhotoParameterRulerVisible
|
||||
},
|
||||
modifier = Modifier
|
||||
.align(Alignment.Center)
|
||||
onParameterClick = onPhotoParameterClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1460,7 +1459,6 @@ fun CameraScreen(
|
||||
viewModel = viewModel,
|
||||
galleryViewModel = galleryViewModel,
|
||||
latestPhoto = latestPhoto,
|
||||
useRaw = useRaw && state.isRawSupported,
|
||||
useMultipleExposure = useMultipleExposure,
|
||||
multipleExposureState = multipleExposureState,
|
||||
onGalleryThumbnailBoundsChanged = { bounds ->
|
||||
@@ -1468,8 +1466,10 @@ fun CameraScreen(
|
||||
},
|
||||
onSwitchCameraClick = ::switchCameraWithPreviewTransition,
|
||||
onCaptureModeSelected = ::setShootingModeWithPreviewTransition,
|
||||
modeSwitchEnabled = !previewTransitionActive,
|
||||
onCaptureTap = {
|
||||
val shouldDebounceRawCapture = useRaw && state.captureMode == CaptureMode.PHOTO
|
||||
val shouldDebounceRawCapture =
|
||||
state.useRaw && state.captureMode == CaptureMode.PHOTO
|
||||
if (shouldDebounceRawCapture) {
|
||||
if (rawCaptureTapLocked) {
|
||||
return@Controls
|
||||
@@ -1496,99 +1496,77 @@ fun CameraScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (isVideoMode) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.paint(backgroundPainter, contentScale = ContentScale.Crop)
|
||||
.navigationBarsPadding(),
|
||||
) {
|
||||
// The viewfinder is always the bottom layer. Its selected aspect ratio is fitted
|
||||
// to the full available area before camera controls are overlaid.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.paint(backgroundPainter, contentScale = ContentScale.Crop)
|
||||
.navigationBarsPadding(),
|
||||
.fillMaxWidth()
|
||||
.height(cardHeight)
|
||||
.align(viewfinderAlignment)
|
||||
.offset(y = viewfinderOffset)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
viewfinderAreaBounds = coordinates.boundsInRoot()
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
// Keep the viewfinder centered on compact screens; use spare height on taller screens.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(cardHeight)
|
||||
.align(Alignment.Center)
|
||||
.offset(y = videoViewfinderOffset)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
viewfinderAreaBounds = coordinates.boundsInRoot()
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
viewfinder()
|
||||
}
|
||||
viewfinder()
|
||||
}
|
||||
|
||||
// UI Overlays
|
||||
topBar()
|
||||
topBar()
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
zoomBar()
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
zoomBar()
|
||||
if (isVideoMode) {
|
||||
AnimatedVisibility(visible = showVideoParameterRuler) {
|
||||
parameterRuler(Modifier)
|
||||
}
|
||||
parameterBar { param ->
|
||||
val wasSelected = selectedParameter == param
|
||||
selectedParameter = param
|
||||
parameterBar(
|
||||
selectedParameter.takeIf { showVideoParameterRuler }
|
||||
) { parameter ->
|
||||
val wasSelected = selectedParameter == parameter
|
||||
selectedParameter = parameter
|
||||
showVideoParameterRuler = if (wasSelected) {
|
||||
!showVideoParameterRuler
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
controls(Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.paint(backgroundPainter, contentScale = ContentScale.Crop)
|
||||
.navigationBarsPadding(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
topBar()
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(cardHeight)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
viewfinderAreaBounds = coordinates.boundsInRoot()
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
viewfinder()
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.then(if (isXpan) Modifier.height(144.dp) else Modifier.weight(1f)),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = !isXpan && isPhotoStyleMode,
|
||||
) {
|
||||
parameterBar { param ->
|
||||
selectedParameter = param
|
||||
} else {
|
||||
AnimatedVisibility(visible = isPhotoParameterRulerVisible) {
|
||||
parameterRuler(
|
||||
Modifier
|
||||
.then(
|
||||
if (isXpan) Modifier.width(viewfinderContentWidth)
|
||||
else Modifier
|
||||
)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
parameterRulerBounds = coordinates.boundsInRoot()
|
||||
}
|
||||
)
|
||||
}
|
||||
AnimatedVisibility(visible = !isXpan) {
|
||||
parameterBar(
|
||||
selectedParameter.takeIf { isPhotoParameterRulerVisible },
|
||||
onPhotoParameterClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
controls(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.then(if (isXpan) Modifier.height(144.dp) else Modifier.weight(1f)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
controls(Modifier.fillMaxSize())
|
||||
}
|
||||
.then(
|
||||
if (isXpan) Modifier.height(144.dp)
|
||||
else Modifier.wrapContentHeight()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1903,12 +1881,12 @@ private fun Controls(
|
||||
viewModel: CameraViewModel,
|
||||
galleryViewModel: GalleryViewModel,
|
||||
latestPhoto: com.hinnka.mycamera.gallery.MediaData?,
|
||||
useRaw: Boolean,
|
||||
useMultipleExposure: Boolean,
|
||||
multipleExposureState: com.hinnka.mycamera.viewmodel.MultipleExposureSessionState,
|
||||
onGalleryThumbnailBoundsChanged: (Rect) -> Unit,
|
||||
onSwitchCameraClick: () -> Unit,
|
||||
onCaptureModeSelected: (CameraShootingMode) -> Unit,
|
||||
modeSwitchEnabled: Boolean,
|
||||
onCaptureTap: () -> Unit,
|
||||
onGalleryClick: () -> Unit,
|
||||
modifier: Modifier = Modifier.fillMaxSize()
|
||||
@@ -1950,6 +1928,7 @@ private fun Controls(
|
||||
|
||||
CaptureButton(
|
||||
captureMode = state.captureMode,
|
||||
isProfessionalMode = state.useRaw && state.isRawSupported,
|
||||
isCapturing = state.isCapturing,
|
||||
isVideoRecording = state.videoRecordingState.isRecording,
|
||||
isVideoProcessing = state.videoRecordingState.isProcessing,
|
||||
@@ -2036,11 +2015,12 @@ private fun Controls(
|
||||
CaptureModeSwitcher(
|
||||
shootingMode = when {
|
||||
state.captureMode == CaptureMode.VIDEO -> CameraShootingMode.VIDEO
|
||||
useRaw -> CameraShootingMode.PROFESSIONAL
|
||||
state.useRaw && state.isRawSupported -> CameraShootingMode.PROFESSIONAL
|
||||
else -> CameraShootingMode.PHOTO
|
||||
},
|
||||
professionalModeEnabled = state.isRawSupported,
|
||||
enabled = !state.videoRecordingState.isRecording &&
|
||||
enabled = modeSwitchEnabled &&
|
||||
!state.videoRecordingState.isRecording &&
|
||||
!state.videoRecordingState.isProcessing,
|
||||
onModeSelected = onCaptureModeSelected
|
||||
)
|
||||
@@ -2055,6 +2035,7 @@ private fun Controls(
|
||||
@Composable
|
||||
fun CaptureButton(
|
||||
captureMode: CaptureMode,
|
||||
isProfessionalMode: Boolean,
|
||||
isCapturing: Boolean,
|
||||
isVideoRecording: Boolean,
|
||||
isVideoProcessing: Boolean,
|
||||
@@ -2168,8 +2149,7 @@ fun CaptureButton(
|
||||
if (isPaused) Color.White.copy(alpha = 0.8f)
|
||||
else Color.Red.copy(alpha = pulseAlpha)
|
||||
}
|
||||
captureMode == CaptureMode.VIDEO -> Color.White.copy(alpha = 0.32f)
|
||||
else -> Color.Transparent
|
||||
else -> Color.White.copy(alpha = 0.32f)
|
||||
}
|
||||
|
||||
Box(
|
||||
@@ -2208,26 +2188,34 @@ fun CaptureButton(
|
||||
targetValue = if (captureMode == CaptureMode.VIDEO && isVideoRecording) 8.dp else 36.dp,
|
||||
label = "centerCorner"
|
||||
)
|
||||
val defaultCenterBrush = if (captureMode == CaptureMode.VIDEO) {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color(0xFFFF6668),
|
||||
Color(0xFFE4383C)
|
||||
val defaultCenterBackground = when {
|
||||
captureMode == CaptureMode.VIDEO -> {
|
||||
Modifier.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color(0xFFFF6668),
|
||||
Color(0xFFE4383C)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.White,
|
||||
Color(0xFFD7D7D7)
|
||||
}
|
||||
isProfessionalMode -> Modifier.background(ProfessionalModeColor)
|
||||
else -> {
|
||||
Modifier.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.White,
|
||||
Color(0xFFD7D7D7)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
val useCustomAppearance = captureMode != CaptureMode.VIDEO
|
||||
val centerBackgroundModifier = when {
|
||||
useCustomAppearance && customStyle == CaptureButtonStyle.COLOR ->
|
||||
Modifier.background(Color(customColor))
|
||||
else -> Modifier.background(defaultCenterBrush)
|
||||
else -> defaultCenterBackground
|
||||
}
|
||||
|
||||
Box(
|
||||
@@ -2295,7 +2283,7 @@ private fun CaptureModeSwitcher(
|
||||
)
|
||||
val selectedBackground by animateColorAsState(
|
||||
targetValue = if (shootingMode == CameraShootingMode.PROFESSIONAL) {
|
||||
Color(0xFFFFA36C)
|
||||
ProfessionalModeColor
|
||||
} else {
|
||||
Color.White
|
||||
},
|
||||
@@ -2474,36 +2462,33 @@ fun Modifier.autoRotate(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun CornerOverlay(
|
||||
private fun CornerOverlay(
|
||||
modifier: Modifier = Modifier,
|
||||
radius: Dp,
|
||||
color: Color = Color.Black
|
||||
) {
|
||||
Canvas(modifier = modifier) {
|
||||
val path = Path().apply {
|
||||
// 创建一个全屏矩形
|
||||
val frame = Path().apply {
|
||||
addRect(Rect(0f, 0f, size.width, size.height))
|
||||
// 减去中间的圆角矩形
|
||||
val roundedRect = Path().apply {
|
||||
addRoundRect(
|
||||
RoundRect(
|
||||
left = 0f,
|
||||
top = 0f,
|
||||
right = size.width,
|
||||
bottom = size.height,
|
||||
cornerRadius = CornerRadius(radius.toPx(), radius.toPx()),
|
||||
)
|
||||
)
|
||||
}
|
||||
// 关键:计算差集 (全屏 - 圆角矩形 = 四个角)
|
||||
op(this, roundedRect, PathOperation.Difference)
|
||||
}
|
||||
drawPath(path, color)
|
||||
val roundedContent = Path().apply {
|
||||
addRoundRect(
|
||||
RoundRect(
|
||||
left = 0f,
|
||||
top = 0f,
|
||||
right = size.width,
|
||||
bottom = size.height,
|
||||
cornerRadius = CornerRadius(radius.toPx(), radius.toPx())
|
||||
)
|
||||
)
|
||||
}
|
||||
frame.op(frame, roundedContent, PathOperation.Difference)
|
||||
drawPath(frame, color)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun Context.findActivity(): Activity? {
|
||||
var context = this
|
||||
while (context is ContextWrapper) {
|
||||
|
||||
@@ -174,7 +174,7 @@ private fun VideoTopBar(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 32.dp, start = 8.dp, end = 8.dp)
|
||||
.padding(top = 24.dp, start = 8.dp, end = 8.dp)
|
||||
.height(56.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -15,11 +14,8 @@ 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.Path
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextMeasurer
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.drawText
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -44,6 +40,13 @@ enum class CameraParameter {
|
||||
}
|
||||
|
||||
internal val CameraParameterRulerHeight = 40.dp
|
||||
private val ParameterRulerElementSize = 18.dp
|
||||
private val ParameterRulerNormalTickHeight = 10.dp
|
||||
private val ParameterRulerVerticalPadding = 4.dp
|
||||
private val ParameterRulerAutoButtonOffset =
|
||||
CameraParameterRulerHeight / 2 -
|
||||
ParameterRulerVerticalPadding -
|
||||
ParameterRulerElementSize / 2
|
||||
|
||||
/**
|
||||
* Parameter ruler component for adjusting camera parameters
|
||||
@@ -71,6 +74,7 @@ fun ParameterRuler(
|
||||
val currentValueState by rememberUpdatedState(currentValue)
|
||||
val resetValueState by rememberUpdatedState(resetValue)
|
||||
var selectedValue by remember(parameter) { mutableStateOf(currentValue) }
|
||||
var isDragging by remember(parameter) { mutableStateOf(false) }
|
||||
val isAdjustableState by rememberUpdatedState(isAdjustable)
|
||||
val scaleValues = remember(parameter, minValue, maxValue) {
|
||||
getScaleValues(parameter, minValue, maxValue)
|
||||
@@ -97,7 +101,8 @@ fun ParameterRuler(
|
||||
enabled = isAutoModeToggleEnabled,
|
||||
modifier = Modifier
|
||||
.padding(start = 8.dp)
|
||||
.size(25.dp),
|
||||
.offset(y = ParameterRulerAutoButtonOffset)
|
||||
.size(ParameterRulerElementSize),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (!isAdjustable) yellow else Color.Gray.copy(alpha = 0.5f),
|
||||
contentColor = if (!isAdjustable) Color.Black else Color.White,
|
||||
@@ -109,7 +114,7 @@ fun ParameterRuler(
|
||||
) {
|
||||
Text(
|
||||
text = "A",
|
||||
fontSize = 12.sp,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
@@ -129,7 +134,7 @@ fun ParameterRuler(
|
||||
.weight(1f)
|
||||
.fillMaxHeight()
|
||||
.padding(horizontal = 16.dp)
|
||||
.pointerInput(minValue, maxValue) {
|
||||
.pointerInput(parameter, minValue, maxValue) {
|
||||
detectTapGestures(
|
||||
onDoubleTap = {
|
||||
val value = resetValueState
|
||||
@@ -153,20 +158,32 @@ fun ParameterRuler(
|
||||
}
|
||||
)
|
||||
}
|
||||
.pointerInput(minValue, maxValue) {
|
||||
detectDragGestures { change, _ ->
|
||||
if (isAdjustableState) {
|
||||
change.consume()
|
||||
val width = size.width
|
||||
val stepWidth = width / (scaleValues.size - 1).coerceAtLeast(1)
|
||||
val index =
|
||||
(change.position.x / stepWidth).roundToInt().coerceIn(0, scaleValues.lastIndex)
|
||||
selectedValue = scaleValues[index]
|
||||
if (selectedValue != currentValueState) {
|
||||
onValueChange(selectedValue)
|
||||
.pointerInput(parameter, minValue, maxValue) {
|
||||
detectDragGestures(
|
||||
onDragStart = {
|
||||
isDragging = isAdjustableState
|
||||
},
|
||||
onDragEnd = {
|
||||
isDragging = false
|
||||
},
|
||||
onDragCancel = {
|
||||
isDragging = false
|
||||
},
|
||||
onDrag = { change, _ ->
|
||||
if (isAdjustableState) {
|
||||
change.consume()
|
||||
val width = size.width
|
||||
val stepWidth = width / (scaleValues.size - 1).coerceAtLeast(1)
|
||||
val index = (change.position.x / stepWidth)
|
||||
.roundToInt()
|
||||
.coerceIn(0, scaleValues.lastIndex)
|
||||
selectedValue = scaleValues[index]
|
||||
if (selectedValue != currentValueState) {
|
||||
onValueChange(selectedValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) {
|
||||
// Scale marks
|
||||
@@ -174,7 +191,8 @@ fun ParameterRuler(
|
||||
parameter = parameter,
|
||||
minValue = minValue,
|
||||
maxValue = maxValue,
|
||||
currentValue = selectedValue
|
||||
currentValue = selectedValue,
|
||||
showCurrentValue = isDragging,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -192,13 +210,14 @@ private fun HyperfocalFocusButton(
|
||||
onClick = onToggle,
|
||||
modifier = Modifier
|
||||
.padding(start = 6.dp)
|
||||
.offset(y = ParameterRulerAutoButtonOffset)
|
||||
.width(58.dp)
|
||||
.height(34.dp),
|
||||
.height(ParameterRulerElementSize),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = if (enabled) yellow else Color.Gray.copy(alpha = 0.45f),
|
||||
contentColor = if (enabled) Color.Black else Color.White
|
||||
),
|
||||
shape = RoundedCornerShape(17.dp),
|
||||
shape = RoundedCornerShape(ParameterRulerElementSize / 2),
|
||||
contentPadding = PaddingValues(horizontal = 0.dp, vertical = 0.dp)
|
||||
) {
|
||||
Column(
|
||||
@@ -207,16 +226,16 @@ private fun HyperfocalFocusButton(
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.camera_hyperfocal_label),
|
||||
fontSize = 9.sp,
|
||||
lineHeight = 9.sp,
|
||||
fontSize = 8.sp,
|
||||
lineHeight = 8.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1
|
||||
)
|
||||
if (enabled && distanceMeters > 0f) {
|
||||
Text(
|
||||
text = formatHyperfocalDistance(distanceMeters),
|
||||
fontSize = 8.sp,
|
||||
lineHeight = 8.sp,
|
||||
fontSize = 7.sp,
|
||||
lineHeight = 7.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1
|
||||
)
|
||||
@@ -245,41 +264,46 @@ private fun RulerScale(
|
||||
parameter: CameraParameter,
|
||||
minValue: Float,
|
||||
maxValue: Float,
|
||||
currentValue: Float
|
||||
currentValue: Float,
|
||||
showCurrentValue: Boolean,
|
||||
) {
|
||||
val scaleValues = getScaleValues(parameter, minValue, maxValue)
|
||||
val yellow = Color(0xFFFFD700)
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
|
||||
Canvas(modifier = Modifier.fillMaxSize().padding(vertical = 4.dp)) {
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(vertical = ParameterRulerVerticalPadding)
|
||||
) {
|
||||
val width = size.width
|
||||
val height = size.height
|
||||
val stepCount = scaleValues.size
|
||||
|
||||
if (stepCount <= 1) return@Canvas
|
||||
|
||||
// Calculate step width
|
||||
val stepWidth = width / (stepCount - 1)
|
||||
|
||||
// Find current value position
|
||||
val currentPosition = findValuePosition(currentValue, scaleValues, stepWidth)
|
||||
|
||||
// Draw each scale value
|
||||
val matchingIndex = scaleValues.indexOfFirst {
|
||||
isSameParameterValue(it, currentValue, parameter)
|
||||
}
|
||||
val selectedIndex = if (matchingIndex >= 0) {
|
||||
matchingIndex
|
||||
} else {
|
||||
scaleValues.indices.minByOrNull { index ->
|
||||
abs(scaleValues[index] - currentValue)
|
||||
} ?: 0
|
||||
}
|
||||
|
||||
scaleValues.forEachIndexed { index, value ->
|
||||
val x = index * stepWidth
|
||||
|
||||
val isCurrent = isSameParameterValue(value, currentValue, parameter)
|
||||
|
||||
// Determine if we should show label
|
||||
val shouldShowLabel = isCurrent || index == 0 || index == scaleValues.lastIndex || value == 0f
|
||||
|
||||
// Draw label
|
||||
if (shouldShowLabel) {
|
||||
val isCurrent = index == selectedIndex
|
||||
|
||||
if (showCurrentValue && isCurrent) {
|
||||
val text = formatParameterValue(parameter, value)
|
||||
val textStyle = TextStyle(
|
||||
fontSize = if (isCurrent) 12.sp else 10.sp,
|
||||
fontWeight = if (isCurrent) FontWeight.Bold else FontWeight.Medium,
|
||||
color = if (isCurrent) yellow else Color.White,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = yellow,
|
||||
textAlign = TextAlign.Center,
|
||||
shadow = ViewfinderTextShadow
|
||||
)
|
||||
@@ -294,20 +318,25 @@ private fun RulerScale(
|
||||
softWrap = false,
|
||||
maxLines = 1
|
||||
)
|
||||
|
||||
// Draw text centered on the tick mark
|
||||
val textX = (x - textLayoutResult.size.width / 2f).coerceIn(
|
||||
minimumValue = 0f,
|
||||
maximumValue = (width - textLayoutResult.size.width).coerceAtLeast(0f),
|
||||
)
|
||||
drawText(
|
||||
textLayoutResult = textLayoutResult,
|
||||
topLeft = Offset(
|
||||
x = x - textLayoutResult.size.width / 2f,
|
||||
x = textX,
|
||||
y = 0f
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Draw tick mark
|
||||
val tickHeight = if (isCurrent) 13.dp.toPx() else 9.dp.toPx()
|
||||
val tickWidth = if (isCurrent) 2.dp.toPx() else 1.dp.toPx()
|
||||
|
||||
val tickHeight = if (isCurrent) {
|
||||
ParameterRulerElementSize.toPx()
|
||||
} else {
|
||||
ParameterRulerNormalTickHeight.toPx()
|
||||
}
|
||||
val tickWidth = if (isCurrent) 1.5.dp.toPx() else 1.dp.toPx()
|
||||
val tickColor = if (isCurrent) yellow else Color.White.copy(alpha = 0.6f)
|
||||
|
||||
drawRect(
|
||||
@@ -316,29 +345,9 @@ private fun RulerScale(
|
||||
size = androidx.compose.ui.geometry.Size(tickWidth, tickHeight)
|
||||
)
|
||||
}
|
||||
|
||||
// Draw indicator if current value is between two scale values
|
||||
if (!isValueOnScale(currentValue, scaleValues, parameter)) {
|
||||
drawCurrentValueIndicator(
|
||||
currentPosition = currentPosition,
|
||||
height = height,
|
||||
yellow = yellow
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current value matches any scale value
|
||||
*/
|
||||
private fun isValueOnScale(
|
||||
currentValue: Float,
|
||||
scaleValues: List<Float>,
|
||||
parameter: CameraParameter
|
||||
): Boolean {
|
||||
return scaleValues.any { isSameParameterValue(it, currentValue, parameter) }
|
||||
}
|
||||
|
||||
private fun isSameParameterValue(
|
||||
value: Float,
|
||||
currentValue: Float,
|
||||
@@ -353,65 +362,6 @@ private fun isSameParameterValue(
|
||||
return abs(value - currentValue) < tolerance
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the position (x coordinate) of the current value
|
||||
*/
|
||||
private fun findValuePosition(
|
||||
currentValue: Float,
|
||||
scaleValues: List<Float>,
|
||||
stepWidth: Float
|
||||
): Float {
|
||||
if (scaleValues.isEmpty()) return 0f
|
||||
if (scaleValues.size == 1) return 0f
|
||||
|
||||
// Find the two scale values that bracket the current value
|
||||
for (i in 0 until scaleValues.size - 1) {
|
||||
val v1 = scaleValues[i]
|
||||
val v2 = scaleValues[i + 1]
|
||||
|
||||
if (currentValue in v1..v2 || currentValue in v2..v1) {
|
||||
// Linear interpolation
|
||||
val ratio = if (v2 != v1) {
|
||||
(currentValue - v1) / (v2 - v1)
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
return i * stepWidth + ratio * stepWidth
|
||||
}
|
||||
}
|
||||
|
||||
// If not found, clamp to edges
|
||||
return when {
|
||||
currentValue < scaleValues.first() -> 0f
|
||||
currentValue > scaleValues.last() -> (scaleValues.size - 1) * stepWidth
|
||||
else -> 0f
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a triangle indicator at the current value position
|
||||
*/
|
||||
private fun DrawScope.drawCurrentValueIndicator(
|
||||
currentPosition: Float,
|
||||
height: Float,
|
||||
yellow: Color
|
||||
) {
|
||||
val trianglePath = Path().apply {
|
||||
val triangleHeight = 8.dp.toPx()
|
||||
val triangleWidth = 6.dp.toPx()
|
||||
val y = height - 13.dp.toPx() - 2.dp.toPx() // Position above the tallest tick
|
||||
|
||||
moveTo(currentPosition, y)
|
||||
lineTo(currentPosition - triangleWidth / 2f, y - triangleHeight)
|
||||
lineTo(currentPosition + triangleWidth / 2f, y - triangleHeight)
|
||||
close()
|
||||
}
|
||||
|
||||
drawPath(
|
||||
path = trianglePath,
|
||||
color = yellow
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scale values for the parameter
|
||||
|
||||
@@ -166,7 +166,7 @@ fun ZoomControlBar(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp)
|
||||
.padding(horizontal = 8.dp)
|
||||
.height(32.dp)
|
||||
.pointerInput(isCameraReady, minZoom, maxZoom, zoomStops) {
|
||||
if (!isCameraReady) return@pointerInput
|
||||
|
||||
@@ -67,8 +67,8 @@ private val LutPanelAccent = Color(0xFFFFD700)
|
||||
private val LutPanelSurface = Color.Black.copy(alpha = 0.15f)
|
||||
internal val LutPanelOptionSize = 64.dp
|
||||
internal val LutPanelOptionShape = RoundedCornerShape(8.dp)
|
||||
internal val LutPanelOptionSurface = Color.Black.copy(alpha = 0.18f)
|
||||
internal val LutPanelOptionSelectedSurface = Color.White.copy(alpha = 0.2f)
|
||||
internal val LutPanelOptionSurface = Color.Black.copy(alpha = 0.2f)
|
||||
internal val LutPanelOptionSelectedSurface = Color.White.copy(alpha = 0.3f)
|
||||
internal val LutPanelOptionBorder = Color.White.copy(alpha = 0.2f)
|
||||
internal val LutPanelOptionSelectedBorder = Color.White
|
||||
|
||||
|
||||
@@ -1,109 +1,27 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
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.draw.drawWithCache
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.LinearGradientShader
|
||||
import androidx.compose.ui.graphics.Shader
|
||||
import androidx.compose.ui.graphics.ShaderBrush
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.drawOutline
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.hinnka.mycamera.utils.OrientationObserver
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
private const val HighlightGlowLayerCount = 8
|
||||
private const val HighlightGlowLayerAlpha = 0.032f
|
||||
|
||||
internal fun physicalTopDirection(orientationDegrees: Float): Offset {
|
||||
val radians = Math.toRadians(orientationDegrees.toDouble())
|
||||
return Offset(
|
||||
x = -sin(radians).toFloat(),
|
||||
y = -cos(radians).toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
private class PhysicalButtonHighlightBrush(
|
||||
enabled: Boolean,
|
||||
private val orientationDegrees: Float
|
||||
) : ShaderBrush() {
|
||||
private val strength = if (enabled) 1f else 0.55f
|
||||
private val colors = listOf(
|
||||
Color.White.copy(alpha = 0.36f * strength),
|
||||
Color.White.copy(alpha = 0.16f * strength),
|
||||
Color.White.copy(alpha = 0.08f * strength),
|
||||
Color.White.copy(alpha = 0.05f * strength)
|
||||
)
|
||||
private val colorStops = listOf(0f, 0.38f, 0.72f, 1f)
|
||||
|
||||
override fun createShader(size: Size): Shader {
|
||||
val brightDirection = physicalTopDirection(orientationDegrees)
|
||||
val halfGradientLength = (
|
||||
abs(brightDirection.x) * size.width +
|
||||
abs(brightDirection.y) * size.height
|
||||
) * 0.5f
|
||||
val center = Offset(size.width * 0.5f, size.height * 0.5f)
|
||||
val extent = halfGradientLength.coerceAtLeast(1f)
|
||||
val start = Offset(
|
||||
x = center.x + brightDirection.x * extent,
|
||||
y = center.y + brightDirection.y * extent
|
||||
)
|
||||
val end = Offset(
|
||||
x = center.x - brightDirection.x * extent,
|
||||
y = center.y - brightDirection.y * extent
|
||||
)
|
||||
return LinearGradientShader(
|
||||
from = start,
|
||||
to = end,
|
||||
colors = colors,
|
||||
colorStops = colorStops
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object PhysicalButtonDefaults {
|
||||
val BackgroundColor = Color(0xFF191919)
|
||||
val HighlightGlowWidth = 4.dp
|
||||
|
||||
fun highlightBrush(
|
||||
enabled: Boolean = true,
|
||||
orientationDegrees: Float = 0f
|
||||
): Brush {
|
||||
return PhysicalButtonHighlightBrush(enabled, orientationDegrees)
|
||||
}
|
||||
val BackgroundColor = Color.Black.copy(alpha = 0.4f)
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟实体相机按键的通用表面。
|
||||
*
|
||||
* 绘制跟随设备姿态的渐变高光细边、向内衰减的柔和辉光和纯色按键面。
|
||||
* 普通半透明黑色按钮表面。
|
||||
*/
|
||||
@Composable
|
||||
fun PhysicalButton(
|
||||
@@ -112,27 +30,12 @@ fun PhysicalButton(
|
||||
enabled: Boolean = true,
|
||||
shape: Shape = CircleShape,
|
||||
backgroundColor: Color = PhysicalButtonDefaults.BackgroundColor,
|
||||
highlightBorderWidth: Dp = 1.dp,
|
||||
highlightGlowWidth: Dp = PhysicalButtonDefaults.HighlightGlowWidth,
|
||||
contentAlignment: Alignment = Alignment.Center,
|
||||
contentShape: Shape = shape,
|
||||
content: @Composable BoxScope.() -> Unit
|
||||
) {
|
||||
val orientationDegrees = OrientationObserver.continuousOrientationDegrees
|
||||
val highlightBrush = remember(enabled, orientationDegrees) {
|
||||
PhysicalButtonDefaults.highlightBrush(enabled, orientationDegrees)
|
||||
}
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isPressed by interactionSource.collectIsPressedAsState()
|
||||
val pressScale by animateFloatAsState(
|
||||
targetValue = if (isPressed) 0.97f else 1f,
|
||||
animationSpec = spring(dampingRatio = 0.72f, stiffness = 700f),
|
||||
label = "physicalButtonPress"
|
||||
)
|
||||
val clickModifier = if (onClick != null) {
|
||||
Modifier.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = null,
|
||||
enabled = enabled,
|
||||
role = Role.Button,
|
||||
onClick = onClick
|
||||
@@ -143,40 +46,14 @@ fun PhysicalButton(
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
scaleX = pressScale
|
||||
scaleY = pressScale
|
||||
}
|
||||
.clip(shape)
|
||||
.background(backgroundColor)
|
||||
.drawWithCache {
|
||||
val outline = shape.createOutline(size, layoutDirection, this)
|
||||
val glowWidthPx = highlightGlowWidth.toPx().coerceAtLeast(0f)
|
||||
val glowLayerStepPx = glowWidthPx / HighlightGlowLayerCount
|
||||
|
||||
onDrawBehind {
|
||||
for (layer in HighlightGlowLayerCount downTo 1) {
|
||||
drawOutline(
|
||||
outline = outline,
|
||||
brush = highlightBrush,
|
||||
alpha = HighlightGlowLayerAlpha,
|
||||
style = Stroke(width = glowLayerStepPx * layer * 2f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.border(
|
||||
width = highlightBorderWidth,
|
||||
brush = highlightBrush,
|
||||
shape = shape
|
||||
)
|
||||
.then(clickModifier),
|
||||
contentAlignment = Alignment.Center
|
||||
contentAlignment = contentAlignment
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(highlightBorderWidth)
|
||||
.clip(contentShape),
|
||||
contentAlignment = contentAlignment,
|
||||
content = content
|
||||
|
||||
@@ -1890,9 +1890,7 @@ private fun GalleryCircleActionButton(
|
||||
onClick = onClick,
|
||||
enabled = isInteractive,
|
||||
shape = CircleShape,
|
||||
backgroundColor = GalleryToolbarButton,
|
||||
highlightBorderWidth = 0.5.dp,
|
||||
highlightGlowWidth = 1.5.dp
|
||||
backgroundColor = GalleryToolbarButton
|
||||
) {
|
||||
if (isLoading) {
|
||||
CircularProgressIndicator(
|
||||
@@ -1967,9 +1965,7 @@ private fun GalleryMoreActionCard(
|
||||
onClick = action.onClick,
|
||||
enabled = isInteractive,
|
||||
shape = CircleShape,
|
||||
backgroundColor = GalleryToolbarButton,
|
||||
highlightBorderWidth = 0.5.dp,
|
||||
highlightGlowWidth = 1.5.dp
|
||||
backgroundColor = GalleryToolbarButton
|
||||
) {
|
||||
if (action.isLoading) {
|
||||
CircularProgressIndicator(
|
||||
|
||||
@@ -414,6 +414,7 @@ internal fun resolveLutIdForCaptureMode(
|
||||
}
|
||||
|
||||
private data class CameraFeatureUpdate(
|
||||
val captureMode: SettingValue<CaptureMode>? = null,
|
||||
val lutId: SettingValue<String?>? = null,
|
||||
val colorRecipe: SettingValue<ColorRecipeParams>? = null,
|
||||
val effects: SettingValue<EffectParams>? = null,
|
||||
@@ -671,6 +672,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
private var presetApplyGeneration = 0L
|
||||
private var lutLoadJob: Job? = null
|
||||
private var lutLoadGeneration = 0L
|
||||
private var shootingModeSwitchJob: Job? = null
|
||||
|
||||
fun prepareCurrentSettingsPresetDraft(name: String): com.hinnka.mycamera.model.CameraPreset {
|
||||
return createPresetFromCurrentSettings(
|
||||
@@ -827,7 +829,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun applyCameraFeatureUpdate(update: CameraFeatureUpdate) {
|
||||
private suspend fun applyCameraFeatureUpdate(
|
||||
update: CameraFeatureUpdate,
|
||||
reconfigureCameraIfNeeded: Boolean = true,
|
||||
) {
|
||||
val prefs = userPreferencesRepository.userPreferences.first()
|
||||
var desiredUseRaw = prefs.useRaw
|
||||
var desiredUseJpgMax = prefs.useJpgMax
|
||||
@@ -875,6 +880,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawMaxOutputScale = prefs.rawMaxOutputScale,
|
||||
)
|
||||
val currentState = state.value
|
||||
val targetCaptureMode = update.captureMode?.value ?: currentState.captureMode
|
||||
val captureModeWillChange = targetCaptureMode != currentState.captureMode
|
||||
val persistLutInVideoSlot = currentState.captureMode == CaptureMode.VIDEO &&
|
||||
prefs.separateVideoLutEnabled && update.lutId != null
|
||||
val targetAspectRatio = update.aspectRatio?.value
|
||||
@@ -916,7 +923,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
enabled = desiredUseRaw,
|
||||
// This transaction already performs the required reopen below. Avoid a
|
||||
// duplicate restart, but still let same-value calls repair a stale output.
|
||||
reconfigureCaptureOutputIfNeeded = !needsCameraReopen
|
||||
reconfigureCaptureOutputIfNeeded =
|
||||
reconfigureCameraIfNeeded &&
|
||||
!needsCameraReopen &&
|
||||
!captureModeWillChange
|
||||
)
|
||||
}
|
||||
if (update.useJpgMax != null || update.useRawMax != null ||
|
||||
@@ -925,6 +935,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.setMultiFrameOutputScale(desiredMultiFrameOutputScale)
|
||||
}
|
||||
|
||||
if (captureModeWillChange) {
|
||||
cameraController.setCaptureMode(targetCaptureMode)
|
||||
resolveLutIdForMode(prefs, targetCaptureMode)?.let(::applyLut)
|
||||
currentSurfaceTexture = null
|
||||
cameraController.closeCamera()
|
||||
}
|
||||
|
||||
update.frameId?.let {
|
||||
currentFrameId = it.value
|
||||
}
|
||||
@@ -955,6 +972,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
userPreferencesRepository.saveCameraFeaturePreferences(
|
||||
CameraFeaturePreferencesUpdate(
|
||||
captureMode = update.captureMode?.let { PreferenceUpdateValue(it.value) },
|
||||
videoLogProfile = update.captureMode
|
||||
?.takeIf {
|
||||
it.value != CaptureMode.VIDEO &&
|
||||
prefs.videoLogProfile != VideoLogProfile.OFF
|
||||
}
|
||||
?.let { PreferenceUpdateValue(VideoLogProfile.OFF) },
|
||||
lutId = if (persistLutInVideoSlot) {
|
||||
null
|
||||
} else {
|
||||
@@ -1044,7 +1068,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
userPreferencesRepository.saveVideoLutConfig(update.lutId.value ?: "none")
|
||||
}
|
||||
|
||||
if (needsCameraReopen) {
|
||||
if (reconfigureCameraIfNeeded && needsCameraReopen && !captureModeWillChange) {
|
||||
reopenCamera()
|
||||
}
|
||||
}
|
||||
@@ -3475,20 +3499,35 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
fun setCaptureMode(mode: CaptureMode) {
|
||||
if (state.value.videoRecordingState.isRecording && mode != state.value.captureMode) return
|
||||
val shouldDisableVideoLog = mode != CaptureMode.VIDEO &&
|
||||
state.value.videoConfig.logProfile != VideoLogProfile.OFF
|
||||
cameraController.setCaptureMode(mode)
|
||||
resolveLutIdForMode(userPreferences.value, mode)?.let {
|
||||
applyLut(it)
|
||||
setShootingMode(mode, useRaw = null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the three-way shooting mode selection as one ordered operation.
|
||||
*
|
||||
* RAW is updated before leaving video mode so the public camera state never passes through
|
||||
* the other photo mode (VIDEO -> PROFESSIONAL -> PHOTO, for example). The capture-mode
|
||||
* change then owns the single camera restart required by the operation.
|
||||
*/
|
||||
fun setShootingMode(mode: CaptureMode, useRaw: Boolean?) {
|
||||
if (state.value.videoRecordingState.isRecording ||
|
||||
state.value.videoRecordingState.isProcessing
|
||||
) {
|
||||
return
|
||||
}
|
||||
currentSurfaceTexture = null
|
||||
cameraController.closeCamera()
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveCaptureMode(mode)
|
||||
if (shouldDisableVideoLog) {
|
||||
userPreferencesRepository.saveVideoLogProfile(VideoLogProfile.OFF)
|
||||
}
|
||||
|
||||
shootingModeSwitchJob?.cancel()
|
||||
val rawNeedsUpdate = useRaw != null &&
|
||||
(state.value.useRaw != useRaw || this.useRaw.value != useRaw)
|
||||
if (state.value.captureMode == mode && !rawNeedsUpdate) return
|
||||
|
||||
shootingModeSwitchJob = viewModelScope.launch {
|
||||
applyCameraFeatureUpdate(
|
||||
CameraFeatureUpdate(
|
||||
captureMode = SettingValue(mode),
|
||||
useRaw = useRaw?.let(::SettingValue),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class PhysicalButtonHighlightDirectionTest {
|
||||
|
||||
@Test
|
||||
fun `physical top follows continuous device orientation`() {
|
||||
assertDirection(orientationDegrees = 0f, expectedX = 0f, expectedY = -1f)
|
||||
assertDirection(orientationDegrees = 90f, expectedX = -1f, expectedY = 0f)
|
||||
assertDirection(orientationDegrees = 180f, expectedX = 0f, expectedY = 1f)
|
||||
assertDirection(orientationDegrees = 270f, expectedX = 1f, expectedY = 0f)
|
||||
assertDirection(
|
||||
orientationDegrees = 45f,
|
||||
expectedX = -0.70710677f,
|
||||
expectedY = -0.70710677f
|
||||
)
|
||||
}
|
||||
|
||||
private fun assertDirection(
|
||||
orientationDegrees: Float,
|
||||
expectedX: Float,
|
||||
expectedY: Float
|
||||
) {
|
||||
val direction = physicalTopDirection(orientationDegrees)
|
||||
assertEquals(expectedX, direction.x, 0.000001f)
|
||||
assertEquals(expectedY, direction.y, 0.000001f)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user