feat: camera ui
This commit is contained in:
1 parent
c77c98606d
commit
b3a3b7aa95
13 files changed
+800
-135
No files matched your search
@@ -1,17 +1,25 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import android.hardware.camera2.CameraMetadata
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.camera.CameraState
|
||||
import com.hinnka.mycamera.camera.CameraUtils
|
||||
import com.hinnka.mycamera.ui.components.PhysicalButton
|
||||
|
||||
internal val CameraParameterValuesOverlayHeight = 24.dp
|
||||
|
||||
@Composable
|
||||
fun CameraParameterBar(
|
||||
@@ -20,8 +28,6 @@ fun CameraParameterBar(
|
||||
onParameterClick: (CameraParameter) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val yellow = Color(0xFFFFD700) // Design uses a yellow/gold color for labels
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
@@ -31,44 +37,30 @@ fun CameraParameterBar(
|
||||
) {
|
||||
ParameterItem(
|
||||
label = "AE",
|
||||
value = String.format("%.1f", state.exposureCompensation * state.getExposureCompensationStep()),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.EXPOSURE_COMPENSATION,
|
||||
isEnabled = state.isAutoExposure, // Only available in auto exposure mode
|
||||
onClick = { onParameterClick(CameraParameter.EXPOSURE_COMPENSATION) }
|
||||
)
|
||||
val tvValue = if (state.shutterSpeed <= 0) "0"
|
||||
else if (state.shutterSpeed >= 1_000_000_000.0) (state.shutterSpeed / 1_000_000_000.0).toInt().toString()
|
||||
else "1/${(1_000_000_000.0 / state.shutterSpeed).toInt()}"
|
||||
ParameterItem(
|
||||
label = "Tv",
|
||||
value = tvValue,
|
||||
labelColor = yellow,
|
||||
valueColor = if (state.isPreviewExposureLimited()) Color.Red else null,
|
||||
isSelected = selectedParameter == CameraParameter.SHUTTER_SPEED,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.SHUTTER_SPEED) }
|
||||
)
|
||||
ParameterItem(
|
||||
label = "ISO",
|
||||
value = state.iso.toString(),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.ISO,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.ISO) }
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AF",
|
||||
value = formatFocusDistance(state.focusDistance),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.FOCUS,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.FOCUS) }
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AWB",
|
||||
value = formatWhiteBalanceValue(state),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.WHITE_BALANCE,
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null,
|
||||
onClick = { onParameterClick(CameraParameter.WHITE_BALANCE) }
|
||||
@@ -79,44 +71,118 @@ fun CameraParameterBar(
|
||||
@Composable
|
||||
fun ParameterItem(
|
||||
label: String,
|
||||
value: String,
|
||||
labelColor: Color,
|
||||
valueColor: Color? = null,
|
||||
isSelected: Boolean,
|
||||
isEnabled: Boolean,
|
||||
onClick: () -> Unit,
|
||||
vertical: Boolean = false,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
PhysicalButton(
|
||||
modifier = modifier
|
||||
.width(60.dp)
|
||||
.heightIn(min = 48.dp)
|
||||
.autoRotate()
|
||||
.then(
|
||||
if (isEnabled) {
|
||||
Modifier.clickable { onClick() }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
)
|
||||
.width(if (vertical) 40.dp else 60.dp)
|
||||
.height(if (vertical) 60.dp else 40.dp),
|
||||
onClick = onClick,
|
||||
enabled = isEnabled,
|
||||
shape = RoundedCornerShape(18.dp)
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = if (isSelected) Color(0xFFFFD700) else labelColor.copy(alpha = if (isEnabled) 1f else 0.5f),
|
||||
fontSize = 10.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
color = valueColor ?: if (isSelected) Color(0xFFFFD700) else Color.White.copy(alpha = if (isEnabled) 1f else 0.5f),
|
||||
fontSize = 11.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Bold
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
modifier = if (vertical) Modifier.rotate(90f) else Modifier,
|
||||
color = if (isSelected) {
|
||||
Color(0xFFFFD700)
|
||||
} else {
|
||||
Color.White.copy(alpha = if (isEnabled) 1f else 0.5f)
|
||||
},
|
||||
fontSize = 11.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CameraParameterValuesOverlay(
|
||||
state: CameraState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
BoxWithConstraints(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(CameraParameterValuesOverlayHeight)
|
||||
.background(Color.Black.copy(alpha = 0.48f))
|
||||
.padding(horizontal = 6.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
val showLabels = maxWidth >= 300.dp
|
||||
val valueFontSize = if (showLabels) 10.sp else 9.sp
|
||||
val values = listOf(
|
||||
CameraParameterValue(
|
||||
label = "AE",
|
||||
value = CameraUtils.formatExposureCompensation(
|
||||
state.exposureCompensation,
|
||||
state.getExposureCompensationStep()
|
||||
)
|
||||
),
|
||||
CameraParameterValue(
|
||||
label = "Tv",
|
||||
value = formatShutterSpeedValue(state.shutterSpeed),
|
||||
valueColor = if (state.isPreviewExposureLimited()) Color.Red else Color.White
|
||||
),
|
||||
CameraParameterValue(label = "ISO", value = state.iso.toString()),
|
||||
CameraParameterValue(label = "AF", value = formatFocusDistance(state.focusDistance)),
|
||||
CameraParameterValue(label = "AWB", value = formatWhiteBalanceValue(state))
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
values.forEach { item ->
|
||||
Row(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (showLabels) {
|
||||
Text(
|
||||
text = item.label,
|
||||
color = Color(0xFFFFD700).copy(alpha = 0.82f),
|
||||
fontSize = 8.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
maxLines = 1
|
||||
)
|
||||
Spacer(modifier = Modifier.width(3.dp))
|
||||
}
|
||||
Text(
|
||||
text = item.value,
|
||||
color = item.valueColor,
|
||||
fontSize = valueFontSize,
|
||||
fontWeight = FontWeight.Medium,
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
softWrap = false,
|
||||
overflow = TextOverflow.Clip
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class CameraParameterValue(
|
||||
val label: String,
|
||||
val value: String,
|
||||
val valueColor: Color = Color.White
|
||||
)
|
||||
|
||||
internal fun formatShutterSpeedValue(value: Long): String {
|
||||
return if (value <= 0L) "0" else CameraUtils.formatShutterSpeed(value)
|
||||
}
|
||||
|
||||
internal fun formatFocusDistance(value: Float): String {
|
||||
return if (value <= 0.01f) "∞"
|
||||
else {
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.hinnka.mycamera.ui.camera
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.camera.CameraState
|
||||
|
||||
@Composable
|
||||
@@ -21,8 +16,6 @@ fun CameraParameterBarVerticel(
|
||||
onParameterClick: (CameraParameter) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val yellow = Color(0xFFFFD700) // Design uses a yellow/gold color for labels
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
@@ -32,47 +25,38 @@ fun CameraParameterBarVerticel(
|
||||
) {
|
||||
ParameterItem(
|
||||
label = "AE",
|
||||
value = String.format("%.1f", state.exposureCompensation * state.getExposureCompensationStep()),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.EXPOSURE_COMPENSATION,
|
||||
isEnabled = state.isAutoExposure, // Only available in auto exposure mode
|
||||
onClick = { onParameterClick(CameraParameter.EXPOSURE_COMPENSATION) }
|
||||
onClick = { onParameterClick(CameraParameter.EXPOSURE_COMPENSATION) },
|
||||
vertical = true
|
||||
)
|
||||
val tvValue = if (state.shutterSpeed <= 0) "0"
|
||||
else if (state.shutterSpeed >= 1_000_000_000.0) (state.shutterSpeed / 1_000_000_000.0).toInt().toString()
|
||||
else "1/${(1_000_000_000.0 / state.shutterSpeed).toInt()}"
|
||||
ParameterItem(
|
||||
label = "Tv",
|
||||
value = tvValue,
|
||||
labelColor = yellow,
|
||||
valueColor = if (state.isPreviewExposureLimited()) Color.Red else null,
|
||||
isSelected = selectedParameter == CameraParameter.SHUTTER_SPEED,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.SHUTTER_SPEED) }
|
||||
onClick = { onParameterClick(CameraParameter.SHUTTER_SPEED) },
|
||||
vertical = true
|
||||
)
|
||||
ParameterItem(
|
||||
label = "ISO",
|
||||
value = state.iso.toString(),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.ISO,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.ISO) }
|
||||
onClick = { onParameterClick(CameraParameter.ISO) },
|
||||
vertical = true
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AF",
|
||||
value = formatFocusDistance(state.focusDistance),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.FOCUS,
|
||||
isEnabled = true,
|
||||
onClick = { onParameterClick(CameraParameter.FOCUS) }
|
||||
onClick = { onParameterClick(CameraParameter.FOCUS) },
|
||||
vertical = true
|
||||
)
|
||||
ParameterItem(
|
||||
label = "AWB",
|
||||
value = formatWhiteBalanceValue(state),
|
||||
labelColor = yellow,
|
||||
isSelected = selectedParameter == CameraParameter.WHITE_BALANCE,
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null,
|
||||
onClick = { onParameterClick(CameraParameter.WHITE_BALANCE) }
|
||||
onClick = { onParameterClick(CameraParameter.WHITE_BALANCE) },
|
||||
vertical = true
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -274,6 +274,7 @@ fun CameraScreen(
|
||||
var previewBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
var viewfinderAreaBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
var zoomBarBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
var parameterRulerBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
var galleryThumbnailBounds by remember { mutableStateOf<Rect?>(null) }
|
||||
var captureAnimationSnapshot by remember { mutableStateOf<CaptureAnimationSnapshot?>(null) }
|
||||
var previewTransitionActive by remember { mutableStateOf(true) }
|
||||
@@ -730,6 +731,11 @@ fun CameraScreen(
|
||||
|
||||
val isVideoMode = state.captureMode == CaptureMode.VIDEO
|
||||
val isPhotoStyleMode = state.captureMode != CaptureMode.VIDEO
|
||||
LaunchedEffect(isPhotoStyleMode) {
|
||||
if (!isPhotoStyleMode) {
|
||||
parameterRulerBounds = null
|
||||
}
|
||||
}
|
||||
val videoAspectRatio =
|
||||
state.videoConfig.aspectRatio.getPortraitAspectRatio(state.videoCapabilities.openGatePortraitAspectRatio)
|
||||
|
||||
@@ -744,12 +750,12 @@ fun CameraScreen(
|
||||
width
|
||||
}
|
||||
val cardHeight = if (isXpan) {
|
||||
height - topSafePadding - 224.dp
|
||||
height - topSafePadding - 272.dp
|
||||
} else if (isVideoMode) {
|
||||
width / videoAspectRatio
|
||||
} else {
|
||||
val standardHeight = (width - 24.dp) * 4 / 3 + 50.dp
|
||||
val bottomMinHeight = 196.dp // Precise height for parameterBar (52.dp) + controls (136.dp min + 8.dp buffer)
|
||||
val standardHeight = width * 4 / 3
|
||||
val bottomMinHeight = 188.dp // parameterBar (44.dp) + controls (136.dp min) + 8.dp buffer
|
||||
val navigationBarHeight = with(density) {
|
||||
WindowInsets.navigationBars.getBottom(this).toDp()
|
||||
}
|
||||
@@ -823,7 +829,7 @@ fun CameraScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val parameterRuler = @Composable {
|
||||
val parameterRuler = @Composable { rulerModifier: Modifier ->
|
||||
val whiteBalanceCurrentValue = if (
|
||||
state.awbMode == android.hardware.camera2.CameraMetadata.CONTROL_AWB_MODE_AUTO
|
||||
) {
|
||||
@@ -905,6 +911,7 @@ fun CameraScreen(
|
||||
else -> {}
|
||||
}
|
||||
},
|
||||
modifier = rulerModifier,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -921,17 +928,16 @@ fun CameraScreen(
|
||||
modifier = Modifier
|
||||
.animateContentSize(alignment = Alignment.Center)
|
||||
.width(cardWidth)
|
||||
.height(cardHeight)
|
||||
.padding(horizontal = if (isXpan || isVideoMode) 0.dp else 8.dp),
|
||||
shape = RoundedCornerShape(if (isVideoMode) 0.dp else 4.dp),
|
||||
.height(cardHeight),
|
||||
shape = RoundedCornerShape(if (isXpan) 4.dp else 0.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.Black
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(if (isVideoMode) 0.dp else 4.dp)
|
||||
.weight(1f)
|
||||
.padding(if (isXpan) 4.dp else 0.dp)
|
||||
.fillMaxSize()
|
||||
.background(Color.Black)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
previewBounds = coordinates.boundsInRoot()
|
||||
@@ -939,23 +945,24 @@ fun CameraScreen(
|
||||
.pointerInput(state.availableCameras) {
|
||||
var totalDrag = 0f
|
||||
awaitEachGesture {
|
||||
var gestureStartedInZoomBar: Boolean? = null
|
||||
var gestureStartedInPreviewControl: Boolean? = null
|
||||
while (true) {
|
||||
val event = awaitPointerEvent()
|
||||
if (gestureStartedInZoomBar == null) {
|
||||
if (gestureStartedInPreviewControl == null) {
|
||||
val firstPressedChange =
|
||||
event.changes.firstOrNull { it.pressed }
|
||||
val currentPreviewBounds = previewBounds
|
||||
gestureStartedInZoomBar =
|
||||
gestureStartedInPreviewControl =
|
||||
if (firstPressedChange != null && currentPreviewBounds != null) {
|
||||
val positionInRoot =
|
||||
currentPreviewBounds.topLeft + firstPressedChange.position
|
||||
zoomBarBounds?.contains(positionInRoot) == true
|
||||
zoomBarBounds?.contains(positionInRoot) == true ||
|
||||
parameterRulerBounds?.contains(positionInRoot) == true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
if (gestureStartedInZoomBar == true) {
|
||||
if (gestureStartedInPreviewControl == true) {
|
||||
if (event.changes.all { !it.pressed }) {
|
||||
viewModel.isZooming = false
|
||||
totalDrag = 0f
|
||||
@@ -1120,7 +1127,10 @@ fun CameraScreen(
|
||||
if (state.captureMode == CaptureMode.PHOTO && useLivePhoto) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.padding(12.dp)
|
||||
.padding(
|
||||
top = CameraParameterValuesOverlayHeight + 8.dp,
|
||||
end = 12.dp
|
||||
)
|
||||
.align(Alignment.TopEnd),
|
||||
color = Color.Black.copy(alpha = 0.8f),
|
||||
shape = CircleShape
|
||||
@@ -1158,7 +1168,10 @@ fun CameraScreen(
|
||||
HistogramView(
|
||||
histogram = state.histogram,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.padding(
|
||||
start = 8.dp,
|
||||
top = CameraParameterValuesOverlayHeight + 8.dp
|
||||
)
|
||||
.size(80.dp, 40.dp)
|
||||
.align(Alignment.TopStart)
|
||||
.autoRotate(dx = -20.dp, dy = 20.dp)
|
||||
@@ -1192,7 +1205,9 @@ fun CameraScreen(
|
||||
if (state.burstCapturing && burstCapturingCount > 0) {
|
||||
BurstCaptureOverlay(
|
||||
count = burstCapturingCount,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = CameraParameterValuesOverlayHeight)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1202,7 +1217,27 @@ fun CameraScreen(
|
||||
onFinish = { viewModel.finishMultipleExposureSession() },
|
||||
onUndo = { viewModel.undoLastMultipleExposureFrame() },
|
||||
onCancel = { viewModel.cancelMultipleExposureSession() },
|
||||
modifier = Modifier.fillMaxSize()
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = CameraParameterValuesOverlayHeight)
|
||||
)
|
||||
}
|
||||
|
||||
if (isPhotoStyleMode) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(CameraParameterRulerHeight + 64.dp)
|
||||
.align(Alignment.BottomCenter)
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.Transparent,
|
||||
Color.Black.copy(alpha = 0.2f),
|
||||
Color.Black.copy(alpha = 0.6f)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1211,7 +1246,7 @@ fun CameraScreen(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(bottom = 8.dp),
|
||||
.padding(bottom = CameraParameterRulerHeight),
|
||||
contentAlignment = Alignment.BottomCenter
|
||||
) {
|
||||
zoomBar()
|
||||
@@ -1221,18 +1256,30 @@ fun CameraScreen(
|
||||
|
||||
CornerOverlay(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
radius = if (isVideoMode) 0.dp else 4.dp,
|
||||
radius = if (isXpan) 4.dp else 0.dp,
|
||||
color = Color.Black
|
||||
)
|
||||
|
||||
CameraParameterValuesOverlay(
|
||||
state = state,
|
||||
modifier = Modifier.align(Alignment.TopCenter)
|
||||
)
|
||||
|
||||
if (isPhotoStyleMode) {
|
||||
parameterRuler(
|
||||
Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.onGloballyPositioned { coordinates ->
|
||||
parameterRulerBounds = coordinates.boundsInRoot()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
LutNameOverlay(
|
||||
state = lutNameOverlayState,
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
)
|
||||
}
|
||||
if (isPhotoStyleMode) {
|
||||
parameterRuler()
|
||||
}
|
||||
}
|
||||
|
||||
if (isXpan) {
|
||||
@@ -1353,7 +1400,7 @@ fun CameraScreen(
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
zoomBar()
|
||||
AnimatedVisibility(visible = showVideoParameterRuler) {
|
||||
parameterRuler()
|
||||
parameterRuler(Modifier)
|
||||
}
|
||||
parameterBar { param ->
|
||||
val wasSelected = selectedParameter == param
|
||||
@@ -1933,19 +1980,20 @@ fun Controls(
|
||||
)
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
PhysicalButton(
|
||||
onClick = onSwitchCameraClick,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterEnd)
|
||||
.padding(end = 40.dp)
|
||||
.size(48.dp)
|
||||
.autoRotate()
|
||||
.autoRotate(),
|
||||
shape = CircleShape
|
||||
) {
|
||||
Icon(
|
||||
imageVector = AppIcons.Cameraswitch,
|
||||
contentDescription = stringResource(R.string.switch_camera),
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(32.dp)
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1981,9 +2029,10 @@ fun CaptureButton(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "infinite transition")
|
||||
var isPressed by remember { mutableStateOf(false) }
|
||||
|
||||
val scale by animateFloatAsState(
|
||||
targetValue = if (isCapturing || isVideoRecording) 0.95f else 1f,
|
||||
targetValue = if (isPressed || isCapturing || isVideoRecording) 0.95f else 1f,
|
||||
animationSpec = spring(dampingRatio = 0.5f),
|
||||
label = "captureScale"
|
||||
)
|
||||
@@ -2007,7 +2056,7 @@ fun CaptureButton(
|
||||
|
||||
val currentDisabled by rememberUpdatedState(isCapturing || (captureMode == CaptureMode.VIDEO && isVideoRecording))
|
||||
|
||||
Box(
|
||||
PhysicalButton(
|
||||
modifier = modifier
|
||||
.size(72.dp)
|
||||
.scale(scale)
|
||||
@@ -2028,10 +2077,12 @@ fun CaptureButton(
|
||||
}
|
||||
} else null,
|
||||
onPress = {
|
||||
isPressed = true
|
||||
isLongPressStarted = false
|
||||
try {
|
||||
tryAwaitRelease()
|
||||
} finally {
|
||||
isPressed = false
|
||||
if (isLongPressStarted) {
|
||||
onLongPressEnd()
|
||||
}
|
||||
@@ -2039,6 +2090,8 @@ fun CaptureButton(
|
||||
}
|
||||
)
|
||||
},
|
||||
shape = CircleShape,
|
||||
outerBorderWidth = 3.dp,
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (multipleExposureEnabled) {
|
||||
@@ -2063,18 +2116,15 @@ fun CaptureButton(
|
||||
if (isPaused) Color.White.copy(alpha = 0.8f)
|
||||
else Color.Red.copy(alpha = pulseAlpha)
|
||||
}
|
||||
captureMode == CaptureMode.VIDEO -> Color.White.copy(alpha = 0.8f)
|
||||
multipleExposureEnabled -> Color.White.copy(alpha = 0.55f)
|
||||
else -> Color(0xFFFFD700)
|
||||
captureMode == CaptureMode.VIDEO -> Color.White.copy(alpha = 0.32f)
|
||||
else -> Color.Transparent
|
||||
}
|
||||
|
||||
val ringWidth = if (multipleExposureEnabled) 1.dp else 2.dp
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.border(
|
||||
width = ringWidth,
|
||||
width = 1.dp,
|
||||
color = ringColor,
|
||||
shape = CircleShape
|
||||
)
|
||||
@@ -2096,9 +2146,9 @@ fun CaptureButton(
|
||||
}
|
||||
}
|
||||
|
||||
// Center Solid Button
|
||||
// Center shutter surface
|
||||
val centerPadding by animateDpAsState(
|
||||
targetValue = if (captureMode == CaptureMode.VIDEO && isVideoRecording) 24.dp else 6.dp,
|
||||
targetValue = if (captureMode == CaptureMode.VIDEO && isVideoRecording) 19.dp else 2.dp,
|
||||
animationSpec = spring(dampingRatio = 0.7f, stiffness = Spring.StiffnessLow),
|
||||
label = "centerPadding"
|
||||
)
|
||||
@@ -2106,14 +2156,28 @@ fun CaptureButton(
|
||||
targetValue = if (captureMode == CaptureMode.VIDEO && isVideoRecording) 8.dp else 36.dp,
|
||||
label = "centerCorner"
|
||||
)
|
||||
val centerColor = if (captureMode == CaptureMode.VIDEO) Color(0xFFFF4D4F) else Color.White
|
||||
val centerBrush = if (captureMode == CaptureMode.VIDEO) {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color(0xFFFF6668),
|
||||
Color(0xFFE4383C)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.White,
|
||||
Color(0xFFD7D7D7)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(centerPadding)
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(centerCorner))
|
||||
.background(centerColor)
|
||||
.background(centerBrush)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ enum class CameraParameter {
|
||||
WHITE_BALANCE // AWB
|
||||
}
|
||||
|
||||
internal val CameraParameterRulerHeight = 40.dp
|
||||
|
||||
/**
|
||||
* Parameter ruler component for adjusting camera parameters
|
||||
*/
|
||||
@@ -81,7 +83,7 @@ fun ParameterRuler(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
.height(CameraParameterRulerHeight)
|
||||
.padding(horizontal = 8.dp)
|
||||
) {
|
||||
Row(
|
||||
@@ -249,7 +251,7 @@ private fun RulerScale(
|
||||
val yellow = Color(0xFFFFD700)
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
|
||||
Canvas(modifier = Modifier.fillMaxSize().padding(vertical = 8.dp)) {
|
||||
Canvas(modifier = Modifier.fillMaxSize().padding(vertical = 4.dp)) {
|
||||
val width = size.width
|
||||
val height = size.height
|
||||
val stepCount = scaleValues.size
|
||||
|
||||
@@ -7,8 +7,6 @@ import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -236,8 +234,8 @@ fun ZoomControlBar(
|
||||
Icon(
|
||||
imageVector = AppIcons.SwapHoriz,
|
||||
contentDescription = stringResource(R.string.toggle_display_mode),
|
||||
modifier = Modifier.size(32.dp)
|
||||
.background(Color.Black.copy(alpha = 0.3f), CircleShape)
|
||||
modifier = Modifier
|
||||
.size(32.dp)
|
||||
.padding(8.dp),
|
||||
tint = Color.White
|
||||
)
|
||||
@@ -258,8 +256,8 @@ fun ZoomControlBar(
|
||||
Icon(
|
||||
imageVector = AppIcons.AutoAwesome,
|
||||
contentDescription = stringResource(R.string.filters_panel),
|
||||
modifier = Modifier.size(32.dp)
|
||||
.background(Color.Black.copy(alpha = 0.3f), CircleShape)
|
||||
modifier = Modifier
|
||||
.size(32.dp)
|
||||
.padding(8.dp),
|
||||
tint = Color.Yellow
|
||||
)
|
||||
@@ -373,8 +371,7 @@ private fun ZoomRuler(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(adaptiveMetrics.rulerLength)
|
||||
.fillMaxHeight()
|
||||
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp)),
|
||||
.fillMaxHeight(),
|
||||
horizontalArrangement = Arrangement.spacedBy(adaptiveMetrics.spacing, Alignment.CenterHorizontally),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
@@ -504,10 +501,7 @@ fun ZoomContinuousRuler(
|
||||
val yellow = Color(0xFFFFD700)
|
||||
val textMeasurer = rememberTextMeasurer()
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.background(Color.Black.copy(alpha = 0.3f), RoundedCornerShape(16.dp))
|
||||
) {
|
||||
Box(modifier = modifier) {
|
||||
Canvas(modifier = Modifier.fillMaxSize().padding(horizontal = 24.dp, vertical = 4.dp)) {
|
||||
val width = size.width
|
||||
val height = size.height
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
@@ -11,9 +9,8 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -38,14 +35,11 @@ fun GalleryThumbnail(
|
||||
val context = LocalContext.current
|
||||
val refreshKey = latestPhoto?.id?.let { viewModel.getPreparedPhotoThumbnailRefreshKey(it) } ?: 0L
|
||||
|
||||
Box(
|
||||
PhysicalButton(
|
||||
modifier = modifier
|
||||
.size(48.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(Color.Black.copy(alpha = 0.5f))
|
||||
.border(2.dp, Color.White.copy(alpha = 0.3f), RoundedCornerShape(8.dp))
|
||||
.clickable { onClick() },
|
||||
contentAlignment = Alignment.Center
|
||||
.size(48.dp),
|
||||
onClick = onClick,
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
if (latestPhoto != null) {
|
||||
AsyncImage(
|
||||
@@ -68,6 +62,19 @@ fun GalleryThumbnail(
|
||||
modifier = Modifier.size(20.dp)
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.White.copy(alpha = 0.08f),
|
||||
Color.Transparent,
|
||||
Color.Black.copy(alpha = 0.14f)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// 没有照片时显示图标
|
||||
Icon(
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
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.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.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.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
|
||||
|
||||
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.45f
|
||||
private val colors = listOf(
|
||||
Color.White.copy(alpha = 0.52f * strength),
|
||||
Color.White.copy(alpha = 0.18f * strength),
|
||||
Color.Black.copy(alpha = 0.24f * strength),
|
||||
Color.Black.copy(alpha = 0.48f * strength)
|
||||
)
|
||||
private val colorStops = listOf(0f, 0.28f, 0.68f, 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 OuterBorderColor = Color(0xFF030303)
|
||||
|
||||
fun highlightBrush(
|
||||
enabled: Boolean = true,
|
||||
orientationDegrees: Float = 0f
|
||||
): Brush {
|
||||
return PhysicalButtonHighlightBrush(enabled, orientationDegrees)
|
||||
}
|
||||
|
||||
fun backgroundBrush(enabled: Boolean = true): Brush {
|
||||
return if (enabled) {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color(0xFF17181A),
|
||||
Color(0xFF202124),
|
||||
Color(0xFF2B2C2F),
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color(0xFF141517),
|
||||
Color(0xFF191A1C),
|
||||
Color(0xFF202124),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟实体相机按键的通用表面。
|
||||
*
|
||||
* 从外向内依次绘制黑色间隙、跟随设备姿态的渐变高光细边和轻微纵向渐变的按键面。
|
||||
*/
|
||||
@Composable
|
||||
fun PhysicalButton(
|
||||
modifier: Modifier = Modifier,
|
||||
onClick: (() -> Unit)? = null,
|
||||
enabled: Boolean = true,
|
||||
shape: Shape = CircleShape,
|
||||
outerBorderWidth: Dp = 2.dp,
|
||||
highlightBorderWidth: Dp = 1.dp,
|
||||
backgroundBrush: Brush = PhysicalButtonDefaults.backgroundBrush(enabled),
|
||||
contentAlignment: Alignment = Alignment.Center,
|
||||
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
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
scaleX = pressScale
|
||||
scaleY = pressScale
|
||||
}
|
||||
.clip(shape)
|
||||
.background(backgroundBrush)
|
||||
.border(
|
||||
width = outerBorderWidth,
|
||||
color = PhysicalButtonDefaults.OuterBorderColor,
|
||||
shape = shape
|
||||
)
|
||||
.border(
|
||||
width = outerBorderWidth + highlightBorderWidth,
|
||||
brush = highlightBrush,
|
||||
shape = shape
|
||||
)
|
||||
.then(clickModifier),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(outerBorderWidth + highlightBorderWidth)
|
||||
.clip(shape),
|
||||
contentAlignment = contentAlignment,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.view.OrientationEventListener
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import kotlin.math.abs
|
||||
@@ -28,6 +29,11 @@ object OrientationObserver {
|
||||
var rotationDegrees by mutableStateOf(0f)
|
||||
private set
|
||||
|
||||
// 连续的设备姿态传感器角,用于材质高光等不应按横竖屏档位跳变的视觉效果。
|
||||
// 消费方负责将传感器的顺时针角度转换到自己的屏幕坐标系。
|
||||
var continuousOrientationDegrees by mutableFloatStateOf(0f)
|
||||
private set
|
||||
|
||||
// 存储拍摄方向,包含反向竖屏,用于照片保存/处理
|
||||
var captureRotationDegrees by mutableStateOf(0f)
|
||||
private set
|
||||
@@ -42,6 +48,8 @@ object OrientationObserver {
|
||||
return
|
||||
}
|
||||
|
||||
continuousOrientationDegrees = orientation.toFloat()
|
||||
|
||||
// 右侧朝上(手机顺时针旋转90°)
|
||||
when (orientation) {
|
||||
in 45..135 -> {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 323 KiB After Width: | Height: | Size: 460 KiB |
+30
@@ -0,0 +1,30 @@
|
||||
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