feat: Ghost Mode (3)

This commit is contained in:
zhoubinjia committed 2026-02-26 19:21:04 +08:00
1 parent fccf23309a
commit bb5f737bc6
9 files changed
+185 -179

No files matched your search

@@ -5,7 +5,6 @@ import android.content.pm.PackageManager
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.KeyEvent
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@@ -54,11 +53,8 @@ import com.hinnka.mycamera.utils.BuglyHelper
import com.hinnka.mycamera.utils.OrientationObserver
import com.hinnka.mycamera.viewmodel.CameraViewModel
import com.hinnka.mycamera.viewmodel.GalleryViewModel
import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import com.hinnka.mycamera.ghost.GhostService
import com.hinnka.mycamera.utils.PLog
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
/**
@@ -116,12 +112,12 @@ class MainActivity : ComponentActivity() {
}
lifecycleScope.launch {
cameraViewModel.ghostMode.collect { ghostMode ->
PLog.d("MainActivity", "ghostMode: $ghostMode")
if (ghostMode) {
MyCameraApplication.ghostService.start()
cameraViewModel.phantomMode.collect { phantomMode ->
PLog.d("MainActivity", "phantomMode: $phantomMode")
if (phantomMode) {
MyCameraApplication.phantomService.start()
} else {
MyCameraApplication.ghostService.stop()
MyCameraApplication.phantomService.stop()
}
}
}
@@ -3,7 +3,7 @@ package com.hinnka.mycamera
import android.annotation.SuppressLint
import android.app.Application
import com.hinnka.mycamera.data.ContentRepository
import com.hinnka.mycamera.ghost.GhostService
import com.hinnka.mycamera.phantom.PhantomService
import com.hinnka.mycamera.utils.BuglyHelper
class MyCameraApplication : Application() {
@@ -13,12 +13,12 @@ class MyCameraApplication : Application() {
instance = this
BuglyHelper.init(this)
ContentRepository.getInstance(this).initialize()
ghostService = GhostService(this)
phantomService = PhantomService(this)
}
companion object {
lateinit var instance: MyCameraApplication
@SuppressLint("StaticFieldLeak")
lateinit var ghostService: GhostService
lateinit var phantomService: PhantomService
}
}
@@ -67,7 +67,7 @@ data class UserPreferences(
val logCurve: LogCurve = LogCurve.FLOG2, // 默认 F-Log2
val rawLuts: Map<String, String> = emptyMap(),
val useP010: Boolean = false,
val ghostMode: Boolean = false,
val phantomMode: Boolean = false,
)
/**
@@ -121,7 +121,7 @@ class UserPreferencesRepository(private val context: Context) {
private val COLOR_SPACE = stringPreferencesKey("color_space")
private val LOG_CURVE = stringPreferencesKey("log_curve")
private val USE_P010 = booleanPreferencesKey("use_p010")
private val GHOST_MODE = booleanPreferencesKey("ghost_mode")
private val PHANTOM_MODE = booleanPreferencesKey("phantom_mode")
}
/**
@@ -169,7 +169,7 @@ class UserPreferencesRepository(private val context: Context) {
logCurve = LogCurve.valueOf(preferences[LOG_CURVE] ?: LogCurve.FLOG2.name),
rawLuts = parseRawLuts(preferences),
useP010 = preferences[USE_P010] ?: false,
ghostMode = preferences[GHOST_MODE] ?: false,
phantomMode = preferences[PHANTOM_MODE] ?: false,
)
}
@@ -554,11 +554,11 @@ class UserPreferencesRepository(private val context: Context) {
}
/**
* 保存是否启用幽灵模式
* 保存是否启用幻影模式
*/
suspend fun saveGhostMode(enabled: Boolean) {
suspend fun savePhantomMode(enabled: Boolean) {
context.dataStore.edit { preferences ->
preferences[GHOST_MODE] = enabled
preferences[PHANTOM_MODE] = enabled
}
}
}
@@ -11,11 +11,10 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import androidx.core.graphics.createBitmap
import androidx.exifinterface.media.ExifInterface
import com.hinnka.mycamera.camera.AspectRatio
import com.hinnka.mycamera.ghost.GhostService
import com.hinnka.mycamera.phantom.PhantomService
import com.hinnka.mycamera.livephoto.GoogleLivePhotoCreator
import com.hinnka.mycamera.livephoto.MotionPhotoWriter
import com.hinnka.mycamera.livephoto.VivoLivePhotoCreator
@@ -260,124 +259,127 @@ object PhotoManager {
context: Context,
id: String,
uri: Uri,
path: String,
photoProcessor: PhotoProcessor,
metadata: PhotoMetadata,
): GhostService.ProcessingInfo? {
return withContext(Dispatchers.IO) {
val tempExportFile = File(context.cacheDir, "temp_export_${System.nanoTime()}.jpg")
try {
// 读取照片
val processedBitmap = photoProcessor.process(
context, id, metadata,
0f, 0f, 0f
) ?: return@withContext null
): PhantomService.ProcessingInfo? {
val tempExportFile = File(context.cacheDir, "temp_export_${System.nanoTime()}.jpg")
try {
// 读取照片
val processedBitmap = photoProcessor.process(
context, id, metadata,
0f, 0f, 0f
) ?: return null
val videoFile = File(getPhotoDir(context, id), VIDEO_FILE)
val photoFile = getPhotoFile(context, id)
FileOutputStream(tempExportFile).use { outputStream ->
processedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)
}
ExifWriter.writeExif(
tempExportFile, metadata.toCaptureInfo().copy(
imageWidth = processedBitmap.width,
imageHeight = processedBitmap.height
)
)
val videoFile = File(getPhotoDir(context, id), VIDEO_FILE)
val photoFile = getPhotoFile(context, id)
var size = 0L
if (videoFile.exists()) {
val tempMotionPhotoFile = File(context.cacheDir, "temp_motion_${System.nanoTime()}.jpg")
try {
PLog.d(
TAG,
"Attempting to create Motion Photo for export: JPEG=${tempExportFile.length()}, Video=${videoFile.length()}"
)
val creator = if (Build.MANUFACTURER.lowercase().contains("vivo") && videoFile.exists()) {
// Vivo Live Photo 照片中没有内嵌视频文件,存在视频文件说明非 Vivo Live Photo
// 而是 Google Live Photo,需要特殊处理
GoogleLivePhotoCreator()
} else null
// 重新从磁盘加载最新元数据,以获取可能刚写回的 presentationTimestampUs
val latestMetadata = loadMetadata(context, id) ?: metadata
val success = MotionPhotoWriter.write(
tempExportFile.absolutePath,
videoFile.absolutePath,
tempMotionPhotoFile.absolutePath,
latestMetadata.presentationTimestampUs ?: 0L,
context,
creator
)
PLog.d(TAG, "MotionPhotoWriter result: $success")
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
if (success) {
size = tempMotionPhotoFile.length()
tempMotionPhotoFile.inputStream().use { input -> input.copyTo(outputStream) }
PLog.d(
TAG,
"Exported Live Photo successfully: ${tempMotionPhotoFile.length()} bytes"
)
} else {
size = tempExportFile.length()
// Fallback to normal JPEG (with EXIF)
PLog.w(TAG, "Motion Photo synthesis failed, falling back to JPEG")
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
}
}
} finally {
tempMotionPhotoFile.delete()
}
} else if (VivoLivePhotoCreator.isVivoPhoto(photoFile.absolutePath)) {
// 如果是 Vivo Photo,特殊处理
val vivoMetadata = VivoLivePhotoCreator.extractVivoMetadata(photoFile.absolutePath)
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
if (vivoMetadata != null) {
outputStream.write(vivoMetadata)
}
size = tempExportFile.length() + (vivoMetadata?.size?.toLong() ?: 0L)
}
} else {
// 3b. Normal Export: Copy Temp File (with EXIF) to MediaStore
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
size = tempExportFile.length()
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
}
}
val contentValues = ContentValues().apply {
put(MediaStore.Images.Media.DATE_MODIFIED, System.currentTimeMillis() / 1000)
}
context.contentResolver.update(uri, contentValues, null, null)
// Save exported URI to metadata
val currentMetadata = loadMetadata(context, id) ?: metadata
val updatedMetadata = currentMetadata.copy(
exportedUris = currentMetadata.exportedUris + uri.toString()
)
saveMetadata(context, id, updatedMetadata)
PLog.d(TAG, "Exported URI saved: $uri for photo $id")
val thumbnail = ThumbnailUtils.extractThumbnail(processedBitmap, 512, 512)
GhostService.ProcessingInfo(
uri = uri,
photoId = id,
thumbnail = thumbnail,
size = size
)
} catch (e: Exception) {
PLog.e(TAG, "Failed to export photo", e)
null
} finally {
tempExportFile.delete()
FileOutputStream(tempExportFile).use { outputStream ->
processedBitmap.compress(Bitmap.CompressFormat.JPEG, 97, outputStream)
}
PLog.d(TAG, "updateExternalPhoto: $path ${photoFile.length()} ${tempExportFile.length()}")
ExifWriter.writeExif(
tempExportFile, metadata.toCaptureInfo().copy(
imageWidth = processedBitmap.width,
imageHeight = processedBitmap.height
)
)
var size = 0L
if (videoFile.exists()) {
val tempMotionPhotoFile = File(context.cacheDir, "temp_motion_${System.nanoTime()}.jpg")
try {
PLog.d(
TAG,
"Attempting to create Motion Photo for export: JPEG=${tempExportFile.length()}, Video=${videoFile.length()}"
)
val creator = if (Build.MANUFACTURER.lowercase().contains("vivo") && videoFile.exists()) {
// Vivo Live Photo 照片中没有内嵌视频文件,存在视频文件说明非 Vivo Live Photo
// 而是 Google Live Photo,需要特殊处理
GoogleLivePhotoCreator()
} else null
// 重新从磁盘加载最新元数据,以获取可能刚写回的 presentationTimestampUs
val latestMetadata = loadMetadata(context, id) ?: metadata
val success = MotionPhotoWriter.write(
tempExportFile.absolutePath,
videoFile.absolutePath,
tempMotionPhotoFile.absolutePath,
latestMetadata.presentationTimestampUs ?: 0L,
context,
creator
)
PLog.d(TAG, "MotionPhotoWriter result: $success")
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
if (success) {
size = tempMotionPhotoFile.length()
tempMotionPhotoFile.inputStream().use { input -> input.copyTo(outputStream) }
PLog.d(
TAG,
"Exported Live Photo successfully: ${tempMotionPhotoFile.length()} bytes"
)
} else {
size = tempExportFile.length()
// Fallback to normal JPEG (with EXIF)
PLog.w(TAG, "Motion Photo synthesis failed, falling back to JPEG")
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
}
}
} finally {
tempMotionPhotoFile.delete()
}
} else if (VivoLivePhotoCreator.isVivoPhoto(photoFile.absolutePath)) {
// 如果是 Vivo Photo,特殊处理
val vivoMetadata = VivoLivePhotoCreator.extractVivoMetadata(photoFile.absolutePath)
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
if (vivoMetadata != null) {
outputStream.write(vivoMetadata)
}
size = tempExportFile.length() + (vivoMetadata?.size?.toLong() ?: 0L)
}
} else {
// 3b. Normal Export: Copy Temp File (with EXIF) to MediaStore
context.contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
size = tempExportFile.length()
tempExportFile.inputStream().use { input -> input.copyTo(outputStream) }
}
}
val contentValues = ContentValues().apply {
put(MediaStore.Images.Media.DATE_MODIFIED, System.currentTimeMillis() / 1000)
}
context.contentResolver.update(uri, contentValues, null, null)
// Save exported URI to metadata
val currentMetadata = loadMetadata(context, id) ?: metadata
val updatedMetadata = currentMetadata.copy(
exportedUris = currentMetadata.exportedUris + uri.toString()
)
saveMetadata(context, id, updatedMetadata)
PLog.d(TAG, "Exported URI saved: $uri for photo $id")
val thumbnail = ThumbnailUtils.extractThumbnail(processedBitmap, 512, 512)
return PhantomService.ProcessingInfo(
uri = uri,
photoId = id,
path = path,
thumbnail = thumbnail,
size = size
)
} catch (e: Exception) {
PLog.e(TAG, "Failed to export photo", e)
return null
} finally {
tempExportFile.delete()
}
}
@@ -1,4 +1,4 @@
package com.hinnka.mycamera.ghost
package com.hinnka.mycamera.phantom
import android.content.Context
import android.content.Intent
@@ -6,6 +6,7 @@ import android.database.ContentObserver
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.net.Uri
import android.os.Environment
import android.os.Handler
import android.os.Looper
import android.provider.MediaStore
@@ -26,7 +27,6 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Filter
import androidx.compose.material.icons.filled.Stop
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
@@ -77,9 +77,10 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.use
class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwner {
class PhantomService(val context: Context) : LifecycleOwner, SavedStateRegistryOwner {
private companion object {
const val TAG = "GhostService"
@@ -88,6 +89,7 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
data class ProcessingInfo(
val uri: Uri,
val path: String,
val photoId: String,
val thumbnail: Bitmap? = null,
val size: Long
@@ -111,18 +113,19 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
private val userPreferencesRepository = UserPreferencesRepository(context)
private val processPhotoTaskMap = mutableMapOf<Uri, Deferred<*>>()
private val processPhotoTaskMap = mutableMapOf<String, Deferred<*>>()
private var processingInfo: ProcessingInfo? by mutableStateOf(null)
private val contentObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
override fun onChange(selfChange: Boolean, uri: Uri?) {
super.onChange(selfChange, uri)
val uri = uri ?: return
uri ?: return
if (selfChange) return
val projection = arrayOf(
OpenableColumns.DISPLAY_NAME,
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.SIZE,
MediaStore.MediaColumns.IS_PENDING,
MediaStore.MediaColumns.IS_TRASHED,
@@ -136,28 +139,38 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
val pendingIndex = cursor.getColumnIndex(MediaStore.Images.Media.IS_PENDING)
val sizeIndex = cursor.getColumnIndex(MediaStore.MediaColumns.SIZE)
val dataIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATA)
val isTrashedIndex = cursor.getColumnIndex(MediaStore.MediaColumns.IS_TRASHED)
val relativePathIndex = cursor.getColumnIndex(MediaStore.MediaColumns.RELATIVE_PATH)
val name = if (nameIndex != -1) cursor.getString(nameIndex) else "Unknown"
val isPending = if (pendingIndex != -1) cursor.getInt(pendingIndex) else 0
val size = if (sizeIndex != -1) cursor.getLong(sizeIndex) else 0L
val data = if (dataIndex != -1) cursor.getString(dataIndex) else ""
val isTrashed = if (isTrashedIndex != -1) cursor.getInt(isTrashedIndex) else 0
val relativePath = if (relativePathIndex != -1) cursor.getString(relativePathIndex) else ""
if (isPending != 0) return
if (isTrashed != 0) return
if (size <= MIN_IMPORT_SIZE) return
if (processingInfo?.uri == uri && processingInfo?.size == size) return
if (!relativePath.contains("DCIM/Camera", ignoreCase = true)) return
PLog.d(TAG, "Content changed: $name, size: $size, relativePath: $relativePath")
processPhotoTaskMap[uri]?.cancel()
processPhotoTaskMap[uri] = lifecycleScope.async {
val path = data.ifEmpty {
val dir = File(Environment.getExternalStorageDirectory(), relativePath)
File(dir, name).absolutePath
}
PLog.d(TAG, "Content changed detected: path=$path size=$size")
processPhotoTaskMap[path]?.cancel()
processPhotoTaskMap[path] = lifecycleScope.async {
delay(200L)
if (isActive) {
photoProcessTask(uri)
processPhotoTaskMap.remove(uri)
// 在延迟后再次检查,此时上一个任务可能已经更新了 processingInfo
if (processingInfo?.path == path && processingInfo?.size == size) {
PLog.d(TAG, "Ignore change for $path as it matches current state (size $size)")
return@async
}
photoProcessTask(uri, path)
processPhotoTaskMap.remove(path)
}
}
}
@@ -223,7 +236,7 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
}
}
private suspend fun photoProcessTask(uri: Uri) = withContext(Dispatchers.IO) {
private suspend fun photoProcessTask(uri: Uri, path: String) = withContext(Dispatchers.IO) {
val userPreferencesRepository = ContentRepository.getInstance(context).userPreferencesRepository
val availableLutList = ContentRepository.getInstance(context).getAvailableLuts()
val photoProcessor = ContentRepository.getInstance(context).photoProcessor
@@ -237,7 +250,11 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
return@withContext
}
if (!isActive) return@withContext
this@GhostService.processingInfo = PhotoManager.updateExternalPhoto(context, photoId, uri, photoProcessor, metadata)
val result = PhotoManager.updateExternalPhoto(context, photoId, uri, path, photoProcessor, metadata)
if (result != null) {
this@PhantomService.processingInfo = result
// PLog.d(TAG, "Processing info updated: $result")
}
delay(200L)
}
@@ -272,7 +289,7 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
Row(
modifier = Modifier
.padding(8.dp)
.padding(4.dp)
.background(Color.Black.copy(alpha = 0.6f), RoundedCornerShape(24.dp))
.padding(4.dp)
.pointerInput(Unit) {
@@ -338,7 +355,7 @@ class GhostService(val context: Context) : LifecycleOwner, SavedStateRegistryOwn
Spacer(modifier = Modifier.width(8.dp))
IconButton(onClick = {
scope.launch {
userPreferencesRepository.saveGhostMode(false)
userPreferencesRepository.savePhantomMode(false)
stop()
}
}) {
@@ -56,7 +56,6 @@ import com.hinnka.mycamera.ui.components.LutControlPanel
import com.hinnka.mycamera.ui.components.PaymentDialog
import com.hinnka.mycamera.ui.components.rememberBackgroundPainter
import com.hinnka.mycamera.utils.OrientationObserver
import com.hinnka.mycamera.utils.PLog
import com.hinnka.mycamera.viewmodel.CameraViewModel
import com.hinnka.mycamera.viewmodel.GalleryViewModel
import kotlin.math.abs
@@ -93,7 +92,7 @@ fun CameraScreen(
val useMultiFrame by viewModel.useMultiFrame.collectAsState()
val useSuperResolution by viewModel.useSuperResolution.collectAsState()
val useLivePhoto by viewModel.useLivePhoto.collectAsState()
val ghostMode by viewModel.ghostMode.collectAsState()
val phantomMode by viewModel.phantomMode.collectAsState()
// 标记相机是否已打开
var cameraOpened by remember { mutableStateOf(false) }
@@ -143,8 +142,8 @@ fun CameraScreen(
} else if (hasOverlay && hasFiles) {
// All permissions granted
isGhostPermissionFlowActive = false
if (!ghostMode) {
viewModel.toggleGhostMode()
if (!phantomMode) {
viewModel.togglePhantomMode()
}
} else if (!hasOverlay) {
// If overlay is still missing after returning, user might have cancelled
@@ -240,7 +239,7 @@ fun CameraScreen(
)
} else {
isGhostPermissionFlowActive = false
viewModel.toggleGhostMode()
viewModel.togglePhantomMode()
}
}
) {
@@ -557,12 +556,12 @@ fun CameraScreen(
activePanel = ActivePanel.NONE
onFilterManagementClick()
},
ghostMode = ghostMode,
onGhostModeToggle = {
phantomMode = phantomMode,
onPhantomModeToggle = {
if (it && (!Settings.canDrawOverlays(context) || !Environment.isExternalStorageManager())) {
showGhostPermissionDialog = true
} else {
viewModel.toggleGhostMode()
viewModel.togglePhantomMode()
}
},
onMoreSettingsClick = {
@@ -7,9 +7,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Brightness6
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.filled.Masks
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
@@ -39,8 +37,8 @@ fun CameraTopSheet(
availableNrLevels: IntArray,
onNRLevelChange: (Int) -> Unit,
onFilterManageClick: () -> Unit,
ghostMode: Boolean,
onGhostModeToggle: (Boolean) -> Unit,
phantomMode: Boolean,
onPhantomModeToggle: (Boolean) -> Unit,
onMoreSettingsClick: () -> Unit,
useMultiFrame: Boolean,
onMultiFrameToggle: (Boolean) -> Unit,
@@ -96,7 +94,7 @@ fun CameraTopSheet(
}
}
Spacer(modifier = Modifier.height(24.dp))
Spacer(modifier = Modifier.height(16.dp))
// Display settings section (Grid & Level)
Row(
@@ -183,8 +181,8 @@ fun CameraTopSheet(
QuickSettingToggle(
title = stringResource(R.string.ghost_mode),
checked = ghostMode,
onCheckedChange = onGhostModeToggle,
checked = phantomMode,
onCheckedChange = onPhantomModeToggle,
modifier = Modifier.weight(1f)
)
@@ -204,7 +202,7 @@ fun CameraTopSheet(
)*/
}
Spacer(modifier = Modifier.height(24.dp))
Spacer(modifier = Modifier.height(16.dp))
// More Settings Button
Surface(
@@ -215,7 +213,7 @@ fun CameraTopSheet(
) {
Row(
modifier = Modifier
.padding(16.dp),
.padding(16.dp, 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Box(
@@ -296,9 +294,9 @@ fun QuickSettingButton(
) {
Box(
modifier = modifier
.height(56.dp)
.height(48.dp)
.clip(RoundedCornerShape(12.dp))
.background(Color.White.copy(alpha = 0.05f))
.background(Color.White.copy(alpha = 0.15f))
.clickable { onClick() }
.padding(horizontal = 16.dp),
contentAlignment = Alignment.CenterStart
@@ -2,13 +2,11 @@ package com.hinnka.mycamera.viewmodel
import android.app.Application
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.SurfaceTexture
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CaptureResult
import android.net.Uri
import androidx.activity.result.ActivityResultLauncher
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
@@ -17,14 +15,10 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.hinnka.mycamera.camera.*
import com.hinnka.mycamera.data.ContentRepository
import com.hinnka.mycamera.data.UserPreferencesRepository
import com.hinnka.mycamera.data.VolumeKeyAction
import com.hinnka.mycamera.frame.FrameInfo
import com.hinnka.mycamera.frame.FrameRenderer
import com.hinnka.mycamera.gallery.PhotoManager
import com.hinnka.mycamera.gallery.PhotoMetadata
import com.hinnka.mycamera.gallery.PhotoProcessor
import com.hinnka.mycamera.ghost.GhostService
import com.hinnka.mycamera.lut.LutConfig
import com.hinnka.mycamera.lut.LutInfo
import com.hinnka.mycamera.model.ColorRecipeParams
@@ -177,8 +171,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
.map { it.useP010 }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val ghostMode: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.ghostMode }
val phantomMode: StateFlow<Boolean> = userPreferencesRepository.userPreferences
.map { it.phantomMode }
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
// 软件处理参数 Flow
@@ -1757,10 +1751,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
}
}
fun toggleGhostMode() {
val newMode = !ghostMode.value
fun togglePhantomMode() {
val newMode = !phantomMode.value
viewModelScope.launch {
userPreferencesRepository.saveGhostMode(newMode)
userPreferencesRepository.savePhantomMode(newMode)
}
}
}
+2 -2
View File
@@ -319,8 +319,8 @@
<string name="settings_color_space">RAW 色彩空间</string>
<string name="settings_color_space_description">选择 RAW 处理的目标色彩空间。</string>
<string name="settings_log_curve">RAW 伽马</string>
<string name="ghost_mode">幽灵模式</string>
<string name="ghost_mode_dialog_title">开启幽灵模式</string>
<string name="ghost_mode">幻影模式</string>
<string name="ghost_mode_dialog_title">开启幻影模式</string>
<string name="ghost_mode_dialog_description">开启后,App 将在后台自动为系统相机拍摄的照片(DCIM/Camera 目录)应用当前选择的 LUT 效果。</string>
<string name="ghost_mode_permissions_required">需开启以下权限:</string>
<string name="ghost_mode_overlay_permission">• 悬浮窗权限:允许 App 在后台稳定运行而不被系统清理,确保监测的连续性。</string>