feat: camera screen ui
This commit is contained in:
1 parent
1a45453117
commit
ee9e55fb35
7 files changed
+144
-67
No files matched your search
@@ -3,9 +3,11 @@ package com.hinnka.mycamera.ui.camera
|
||||
import android.hardware.camera2.CameraMetadata
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -26,6 +28,7 @@ import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.camera.CameraState
|
||||
import com.hinnka.mycamera.camera.CameraUtils
|
||||
import com.hinnka.mycamera.video.CaptureMode
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
internal val CameraParameterAccent = Color(0xFFFFD700)
|
||||
@@ -55,43 +58,50 @@ fun CameraParameterBar(
|
||||
internal data class CameraParameterItem(
|
||||
val parameter: CameraParameter,
|
||||
val label: String,
|
||||
val value: String,
|
||||
val value: String?,
|
||||
val isEnabled: Boolean = true,
|
||||
val isWarning: Boolean = false
|
||||
)
|
||||
|
||||
@Composable
|
||||
internal fun cameraParameterItems(state: CameraState): List<CameraParameterItem> = listOf(
|
||||
CameraParameterItem(
|
||||
CameraParameter.EXPOSURE_COMPENSATION,
|
||||
stringResource(R.string.camera_parameter_exposure),
|
||||
CameraUtils.formatExposureCompensation(state.exposureCompensation, state.getExposureCompensationStep()),
|
||||
isEnabled = state.isAutoExposure
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.SHUTTER_SPEED,
|
||||
stringResource(R.string.camera_parameter_shutter),
|
||||
formatShutterSpeedValue(state.shutterSpeed),
|
||||
isWarning = state.isPreviewExposureLimited()
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.ISO,
|
||||
stringResource(R.string.camera_parameter_iso),
|
||||
state.iso.toString()
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.FOCUS,
|
||||
stringResource(R.string.camera_parameter_focus),
|
||||
formatFocusDistance(state.focusDistance),
|
||||
isEnabled = state.minimumFocusDistance > 0f
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.WHITE_BALANCE,
|
||||
stringResource(R.string.camera_parameter_white_balance),
|
||||
formatWhiteBalanceValue(state),
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null
|
||||
internal fun cameraParameterItems(state: CameraState): List<CameraParameterItem> {
|
||||
// Match the mode switcher: PHOTO capture also backs the RAW professional mode.
|
||||
val showValues = state.captureMode == CaptureMode.VIDEO ||
|
||||
(state.useRaw && state.isRawSupported)
|
||||
return listOf(
|
||||
CameraParameterItem(
|
||||
CameraParameter.EXPOSURE_COMPENSATION,
|
||||
stringResource(R.string.camera_parameter_exposure),
|
||||
if (showValues) CameraUtils.formatExposureCompensation(
|
||||
state.exposureCompensation, state.getExposureCompensationStep()
|
||||
) else null,
|
||||
isEnabled = state.isAutoExposure
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.SHUTTER_SPEED,
|
||||
stringResource(R.string.camera_parameter_shutter),
|
||||
if (showValues) formatShutterSpeedValue(state.shutterSpeed) else null,
|
||||
isWarning = showValues && state.isPreviewExposureLimited()
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.ISO,
|
||||
stringResource(R.string.camera_parameter_iso),
|
||||
if (showValues) state.iso.toString() else null
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.FOCUS,
|
||||
stringResource(R.string.camera_parameter_focus),
|
||||
if (showValues) formatFocusDistance(state.focusDistance) else null,
|
||||
isEnabled = state.minimumFocusDistance > 0f
|
||||
),
|
||||
CameraParameterItem(
|
||||
CameraParameter.WHITE_BALANCE,
|
||||
stringResource(R.string.camera_parameter_white_balance),
|
||||
if (showValues) formatWhiteBalanceValue(state) else null,
|
||||
isEnabled = state.canAdjustWhiteBalance || state.actualAwbTemperature != null
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ParameterItem(
|
||||
@@ -101,6 +111,7 @@ internal fun ParameterItem(
|
||||
vertical: Boolean = false,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titleOnly = item.value == null
|
||||
val valueColor by animateColorAsState(
|
||||
targetValue = when {
|
||||
item.isWarning -> Color(0xFFFF6666)
|
||||
@@ -113,7 +124,8 @@ internal fun ParameterItem(
|
||||
val labelColor by animateColorAsState(
|
||||
targetValue = when {
|
||||
!item.isEnabled -> Color.White.copy(alpha = 0.3f)
|
||||
isSelected -> CameraParameterAccent.copy(alpha = 0.8f)
|
||||
isSelected -> CameraParameterAccent.copy(alpha = if (titleOnly) 1f else 0.8f)
|
||||
titleOnly -> Color.White.copy(alpha = 0.9f)
|
||||
else -> Color.White.copy(alpha = 0.6f)
|
||||
},
|
||||
label = "parameterLabelColor"
|
||||
@@ -124,6 +136,7 @@ internal fun ParameterItem(
|
||||
if (vertical) Modifier.size(48.dp, 76.dp)
|
||||
else Modifier.height(CameraControlsLayoutDefaults.ParameterBarHeight)
|
||||
)
|
||||
.then(if (titleOnly) Modifier.clip(RoundedCornerShape(8.dp)) else Modifier)
|
||||
.semantics { selected = isSelected }
|
||||
.clickable(enabled = item.isEnabled, role = Role.Button, onClick = onClick),
|
||||
contentAlignment = Alignment.Center
|
||||
@@ -136,30 +149,39 @@ internal fun ParameterItem(
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||
) {
|
||||
Text(
|
||||
text = item.value,
|
||||
color = valueColor,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
style = TextStyle(shadow = ViewfinderTextShadow),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
softWrap = false
|
||||
)
|
||||
Text(
|
||||
text = item.label,
|
||||
if (item.value == null) {
|
||||
PhotoParameterTitle(
|
||||
label = item.label,
|
||||
color = labelColor,
|
||||
fontSize = 9.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
style = TextStyle(shadow = ViewfinderTextShadow),
|
||||
maxLines = 1
|
||||
isSelected = isSelected,
|
||||
isEnabled = item.isEnabled
|
||||
)
|
||||
} else {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||
) {
|
||||
Text(
|
||||
text = item.value,
|
||||
color = valueColor,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
style = TextStyle(shadow = ViewfinderTextShadow),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
softWrap = false
|
||||
)
|
||||
Text(
|
||||
text = item.label,
|
||||
color = labelColor,
|
||||
fontSize = 9.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
style = TextStyle(shadow = ViewfinderTextShadow),
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
}
|
||||
if (isSelected) {
|
||||
if (isSelected && !titleOnly) {
|
||||
Box(
|
||||
Modifier.align(Alignment.BottomCenter)
|
||||
.padding(bottom = 3.dp)
|
||||
@@ -172,6 +194,51 @@ internal fun ParameterItem(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PhotoParameterTitle(
|
||||
label: String,
|
||||
color: Color,
|
||||
isSelected: Boolean,
|
||||
isEnabled: Boolean
|
||||
) {
|
||||
val backgroundColor by animateColorAsState(
|
||||
targetValue = when {
|
||||
!isEnabled -> Color.Black.copy(alpha = 0.12f)
|
||||
isSelected -> CameraParameterAccent.copy(alpha = 0.16f)
|
||||
else -> Color.Black.copy(alpha = 0.28f)
|
||||
},
|
||||
label = "photoParameterBackground"
|
||||
)
|
||||
val borderColor by animateColorAsState(
|
||||
targetValue = when {
|
||||
!isEnabled -> Color.White.copy(alpha = 0.05f)
|
||||
isSelected -> CameraParameterAccent.copy(alpha = 0.6f)
|
||||
else -> Color.White.copy(alpha = 0.12f)
|
||||
},
|
||||
label = "photoParameterBorder"
|
||||
)
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
.fillMaxWidth()
|
||||
.height(34.dp)
|
||||
.background(backgroundColor, shape),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = color,
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
style = TextStyle(shadow = ViewfinderTextShadow),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 1,
|
||||
softWrap = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun formatShutterSpeedValue(value: Long): String {
|
||||
return when {
|
||||
value <= 0L -> "0"
|
||||
|
||||
@@ -1400,10 +1400,20 @@ fun CameraScreen(
|
||||
}
|
||||
|
||||
if (isXpan) {
|
||||
// Center both side bars in the space above the capture controls, which
|
||||
// overlap the lower part of the XPAN viewfinder.
|
||||
val sideControlsBottom = minOf(
|
||||
viewfinderTop + cardHeight,
|
||||
contentHeight - CameraControlsLayoutDefaults.CaptureAreaHeight -
|
||||
CameraControlsLayoutDefaults.CaptureClearance
|
||||
)
|
||||
val sideControlsHeight = (sideControlsBottom - viewfinderTop)
|
||||
.coerceIn(0.dp, cardHeight)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(cardHeight),
|
||||
.height(cardHeight)
|
||||
.padding(bottom = cardHeight - sideControlsHeight),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Box(
|
||||
|
||||
@@ -1809,7 +1809,7 @@ fun SettingsScreen(
|
||||
}
|
||||
|
||||
SettingsPage.PHOTO_MODE -> {
|
||||
// 拍照模式设置
|
||||
// 照片模式设置
|
||||
SettingsSection(
|
||||
title = stringResource(R.string.settings_section_photo_mode),
|
||||
showTitle = false
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<string name="unknown">未知</string>
|
||||
<string name="take_photo">拍照</string>
|
||||
<string name="capture_mode_professional">專業</string>
|
||||
<string name="capture_mode_photo">拍照</string>
|
||||
<string name="capture_mode_photo">照片</string>
|
||||
<string name="capture_mode_video">影片</string>
|
||||
|
||||
<!-- Exposure Controls -->
|
||||
@@ -223,7 +223,7 @@
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
<string name="settings_video_lock_white_balance_description">影片錄製過程中鎖定白平衡。</string>
|
||||
<string name="settings_section_quality_perf">畫質與性能</string>
|
||||
<string name="settings_section_photo_mode">拍照模式設定</string>
|
||||
<string name="settings_section_photo_mode">照片模式設定</string>
|
||||
<string name="settings_section_professional_mode">專業模式設定</string>
|
||||
<string name="settings_professional_parameters">專業模式參數</string>
|
||||
<string name="preset_professional_mode_only">僅在專業模式下可用</string>
|
||||
@@ -260,7 +260,7 @@
|
||||
<string name="settings_raw_max_output_scale_description">調整 HDR+ 相片的輸出尺寸。倍率越高,相片尺寸和檔案大小越大,處理時間也可能更長。</string>
|
||||
<string name="settings_raw_max_output_scale_value">%1$.2f×</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count">多幀降噪幀數</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">拍照模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">照片模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_hdr_plus_frame_count">HDR+ 幀數</string>
|
||||
<string name="settings_hdr_plus_frame_count_description">HDR+ 拍攝使用的幀數。開啟包圍曝光後,最低為 2 幀,使用一般曝光與可用的長曝光;3 幀及以上使用完整包圍曝光方案。</string>
|
||||
<string name="settings_hdr_plus_bracket_exposure">HDR+ 包圍曝光</string>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<string name="unknown">未知</string>
|
||||
<string name="take_photo">拍照</string>
|
||||
<string name="capture_mode_professional">专业</string>
|
||||
<string name="capture_mode_photo">拍照</string>
|
||||
<string name="capture_mode_photo">照片</string>
|
||||
<string name="capture_mode_video">视频</string>
|
||||
|
||||
<!-- Exposure Controls -->
|
||||
@@ -223,7 +223,7 @@
|
||||
<string name="settings_video_lock_white_balance">锁定白平衡</string>
|
||||
<string name="settings_video_lock_white_balance_description">视频录制过程中锁定白平衡。</string>
|
||||
<string name="settings_section_quality_perf">画质与性能</string>
|
||||
<string name="settings_section_photo_mode">拍照模式设置</string>
|
||||
<string name="settings_section_photo_mode">照片模式设置</string>
|
||||
<string name="settings_section_professional_mode">专业模式设置</string>
|
||||
<string name="settings_professional_parameters">专业模式参数</string>
|
||||
<string name="preset_professional_mode_only">仅在专业模式下可用</string>
|
||||
@@ -260,7 +260,7 @@
|
||||
<string name="settings_raw_max_output_scale_description">调整 HDR+ 照片的输出尺寸。倍率越高,照片尺寸和文件体积越大,处理时间也可能更长。</string>
|
||||
<string name="settings_raw_max_output_scale_value">%1$.2f×</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count">多帧降噪帧数</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">拍照模式下多帧降噪使用的帧数。帧数越多降噪越明显,但处理时间也越长。</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">照片模式下多帧降噪使用的帧数。帧数越多降噪越明显,但处理时间也越长。</string>
|
||||
<string name="settings_hdr_plus_frame_count">HDR+ 帧数</string>
|
||||
<string name="settings_hdr_plus_frame_count_description">HDR+ 拍摄使用的帧数。开启包围曝光后,最低为 2 帧,使用普通曝光和可用的长曝光;3 帧及以上使用完整包围曝光方案。</string>
|
||||
<string name="settings_hdr_plus_bracket_exposure">HDR+ 包围曝光</string>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<string name="unknown">未知</string>
|
||||
<string name="take_photo">拍照</string>
|
||||
<string name="capture_mode_professional">專業</string>
|
||||
<string name="capture_mode_photo">拍照</string>
|
||||
<string name="capture_mode_photo">照片</string>
|
||||
<string name="capture_mode_video">影片</string>
|
||||
|
||||
<!-- Exposure Controls -->
|
||||
@@ -223,7 +223,7 @@
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
<string name="settings_video_lock_white_balance_description">影片錄製過程中鎖定白平衡。</string>
|
||||
<string name="settings_section_quality_perf">畫質與性能</string>
|
||||
<string name="settings_section_photo_mode">拍照模式設定</string>
|
||||
<string name="settings_section_photo_mode">照片模式設定</string>
|
||||
<string name="settings_section_professional_mode">專業模式設定</string>
|
||||
<string name="settings_professional_parameters">專業模式參數</string>
|
||||
<string name="preset_professional_mode_only">僅在專業模式下可用</string>
|
||||
@@ -260,7 +260,7 @@
|
||||
<string name="settings_raw_max_output_scale_description">調整 HDR+ 相片的輸出尺寸。倍率越高,相片尺寸和檔案大小越大,處理時間也可能更長。</string>
|
||||
<string name="settings_raw_max_output_scale_value">%1$.2f×</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count">多幀降噪幀數</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">拍照模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">照片模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_hdr_plus_frame_count">HDR+ 幀數</string>
|
||||
<string name="settings_hdr_plus_frame_count_description">HDR+ 拍攝使用的幀數。開啟包圍曝光後,最低為 2 幀,使用一般曝光與可用的長曝光;3 幀及以上使用完整包圍曝光方案。</string>
|
||||
<string name="settings_hdr_plus_bracket_exposure">HDR+ 包圍曝光</string>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<string name="unknown">未知</string>
|
||||
<string name="take_photo">拍照</string>
|
||||
<string name="capture_mode_professional">專業</string>
|
||||
<string name="capture_mode_photo">拍照</string>
|
||||
<string name="capture_mode_photo">照片</string>
|
||||
<string name="capture_mode_video">影片</string>
|
||||
|
||||
<!-- Exposure Controls -->
|
||||
@@ -223,7 +223,7 @@
|
||||
<string name="settings_video_lock_white_balance">鎖定白平衡</string>
|
||||
<string name="settings_video_lock_white_balance_description">影片錄製過程中鎖定白平衡。</string>
|
||||
<string name="settings_section_quality_perf">畫質與性能</string>
|
||||
<string name="settings_section_photo_mode">拍照模式設定</string>
|
||||
<string name="settings_section_photo_mode">照片模式設定</string>
|
||||
<string name="settings_section_professional_mode">專業模式設定</string>
|
||||
<string name="settings_professional_parameters">專業模式參數</string>
|
||||
<string name="preset_professional_mode_only">僅在專業模式下可用</string>
|
||||
@@ -260,7 +260,7 @@
|
||||
<string name="settings_raw_max_output_scale_description">調整 HDR+ 相片的輸出尺寸。倍率越高,相片尺寸和檔案大小越大,處理時間也可能更長。</string>
|
||||
<string name="settings_raw_max_output_scale_value">%1$.2f×</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count">多幀降噪幀數</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">拍照模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_multi_frame_denoise_frame_count_description">照片模式下多幀降噪使用的幀數。幀數越多降噪越明顯,但處理時間也越長。</string>
|
||||
<string name="settings_hdr_plus_frame_count">HDR+ 幀數</string>
|
||||
<string name="settings_hdr_plus_frame_count_description">HDR+ 拍攝使用的幀數。開啟包圍曝光後,最低為 2 幀,使用一般曝光與可用的長曝光;3 幀及以上使用完整包圍曝光方案。</string>
|
||||
<string name="settings_hdr_plus_bracket_exposure">HDR+ 包圍曝光</string>
|
||||
|
||||
Reference in new issue
Block a user