feat: live photo animation

This commit is contained in:
Hinnka committed 2026-01-31 23:32:13 +08:00
1 parent 822ffce6c4
commit 27b0f4e57b
4 files changed
+51 -2

No files matched your search

@@ -1759,6 +1759,11 @@ class Camera2Controller(private val context: Context) {
}
fun setCapturingLivePhoto(enabled: Boolean) {
_state.value = _state.value.copy(isCapturingLivePhoto = enabled)
}
// ==================== 拍照 ====================
/**
@@ -176,6 +176,8 @@ data class CameraState(
val useSuperResolution: Boolean = false,
val useRaw: Boolean = false,
val useLivePhoto: Boolean = false,
// 是否正在拍摄 Live Photo (用于 UI 动画)
val isCapturingLivePhoto: Boolean = false,
) {
/**
* 是否全自动曝光
@@ -506,6 +506,7 @@ fun Controls(
// 拍照按钮 (Center)
CaptureButton(
isCapturing = state.isCapturing,
isCapturingLivePhoto = state.isCapturingLivePhoto,
onClick = { viewModel.capture() }
)
@@ -535,6 +536,7 @@ fun Controls(
@Composable
fun CaptureButton(
isCapturing: Boolean,
isCapturingLivePhoto: Boolean = false,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
@@ -544,11 +546,17 @@ fun CaptureButton(
label = "captureScale"
)
val rotation by animateFloatAsState(
targetValue = if (isCapturingLivePhoto) 360f else 0f,
animationSpec = if (isCapturingLivePhoto) tween(1500) else tween(0),
label = "livePhotoRotation"
)
Box(
modifier = modifier
.size(80.dp)
.size(72.dp)
.scale(scale)
.clickable(enabled = !isCapturing) { onClick() },
.clickable(enabled = !isCapturing && !isCapturingLivePhoto) { onClick() },
contentAlignment = Alignment.Center
) {
// Inner Yellow Ring
@@ -558,6 +566,23 @@ fun CaptureButton(
.border(2.dp, Color(0xFFFFD700), CircleShape)
)
// Live Photo Indicator (Spinning dash)
if (isCapturingLivePhoto) {
Canvas(modifier = Modifier.fillMaxSize()) {
val strokeWidth = 3.dp.toPx()
drawArc(
color = Color(0xFFFFD700),
startAngle = rotation - 90f,
sweepAngle = 90f,
useCenter = false,
style = androidx.compose.ui.graphics.drawscope.Stroke(
width = strokeWidth,
cap = androidx.compose.ui.graphics.StrokeCap.Round
)
)
}
}
// Center Solid Button (When not capturing)
if (!isCapturing) {
Box(
@@ -390,6 +390,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
generateThumbnail()
// 倒计时结束,拍照
cameraController.setCountdownValue(0)
if (useLivePhoto.value) {
cameraController.setCapturingLivePhoto(true)
viewModelScope.launch {
delay(1500)
cameraController.setCapturingLivePhoto(false)
}
}
cameraController.capture()
}
} else {
@@ -400,12 +407,22 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
if (useMultiFrame.value) {
isBursting = true
if (useLivePhoto.value) {
cameraController.setCapturingLivePhoto(true)
viewModelScope.launch {
delay(1500)
cameraController.setCapturingLivePhoto(false)
}
cameraController.snapshotLivePhoto()
}
cameraController.capture()
} else {
isBursting = false
if (useLivePhoto.value) {
cameraController.setCapturingLivePhoto(true)
viewModelScope.launch {
delay(1500)
cameraController.setCapturingLivePhoto(false)
}
cameraController.snapshotLivePhoto()
}
// 普通拍摄:直接拍照