fix: phantom mode

This commit is contained in:
Hinnka committed 2026-03-01 12:57:59 +08:00
1 parent 4703b7f67b
commit 7b41eddee2
9 files changed
+78 -39

No files matched your search

+2 -1
View File
@@ -8,4 +8,5 @@
.externalNativeBuild
.cxx
local.properties
app/*/release
app/*/release
Handheld-Multi-Frame-Super-Resolution-main
@@ -42,14 +42,22 @@ class MyCameraApplication : Application() {
private fun updateShortcuts(isActive: Boolean) {
val shortcutManager = getSystemService(android.content.pm.ShortcutManager::class.java)
val shortcut = android.content.pm.ShortcutInfo.Builder(this, "phantom_toggle")
val phantomShortcut = android.content.pm.ShortcutInfo.Builder(this, "phantom_toggle")
.setShortLabel(getString(if (isActive) R.string.close_ghost_mode else R.string.ghost_mode))
.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_camera_shortcut))
.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_camera))
.setIntent(Intent(this, PhantomShortcutActivity::class.java).apply {
action = Intent.ACTION_VIEW
})
.build()
shortcutManager.dynamicShortcuts = listOf(shortcut)
val lutShortcut = android.content.pm.ShortcutInfo.Builder(this, "lut_manage")
.setShortLabel(getString(R.string.filter_management_title))
.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.auto_awesome_color))
.setIntent(Intent(this, MainActivity::class.java).apply {
action = Intent.ACTION_VIEW
putExtra("route", Routes.FILTER_MANAGEMENT)
})
.build()
shortcutManager.dynamicShortcuts = listOf(phantomShortcut, lutShortcut)
}
companion object {
@@ -264,7 +264,7 @@ class LutRenderer : GLSurfaceView.Renderer {
* Surface 尺寸变化时调用
*/
override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
PLog.d(TAG, "onSurfaceChanged: ${width}x${height}")
// PLog.d(TAG, "onSurfaceChanged: ${width}x${height}")
viewportWidth = width
viewportHeight = height
@@ -15,7 +15,9 @@ import com.hinnka.mycamera.MainActivity
import com.hinnka.mycamera.R
import com.hinnka.mycamera.data.ContentRepository
import com.hinnka.mycamera.gallery.PhotoData
import com.hinnka.mycamera.gallery.PhotoManager
import com.hinnka.mycamera.utils.DeviceUtil
import com.hinnka.mycamera.utils.PLog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -26,6 +28,8 @@ import kotlinx.coroutines.withContext
class PhantomWidgetProvider : AppWidgetProvider() {
companion object {
private const val TAG = "PhantomWidgetProvider"
private const val ACTION_TOGGLE_PHANTOM = "com.hinnka.mycamera.phantom.ACTION_TOGGLE_PHANTOM"
private const val ACTION_OPEN_APP = "com.hinnka.mycamera.phantom.ACTION_OPEN_APP"
private const val ACTION_OPEN_FILTERS = "com.hinnka.mycamera.phantom.ACTION_OPEN_FILTERS"
@@ -42,7 +46,9 @@ class PhantomWidgetProvider : AppWidgetProvider() {
providerScope.launch {
val phantomMode = userPreferencesRepository.userPreferences.first().phantomMode
val latestPhoto = withContext(Dispatchers.IO) {
galleryRepository.getLatestPhoto()
galleryRepository.getLatestPhoto()?.apply {
metadata = PhotoManager.loadMetadata(context, id)
}
}
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId, phantomMode, latestPhoto)
@@ -164,6 +170,8 @@ class PhantomWidgetProvider : AppWidgetProvider() {
views.setOnClickPendingIntent(R.id.btn_frames, getPendingSelfIntent(context, ACTION_OPEN_FRAMES))
views.setOnClickPendingIntent(R.id.btn_recent_header, getPendingSelfIntent(context, ACTION_OPEN_GALLERY))
// PLog.d(TAG, "updateAppWidget: $appWidgetId $latestPhoto")
// Update Recent Photos
if (latestPhoto != null) {
providerScope.launch {
@@ -171,8 +179,14 @@ class PhantomWidgetProvider : AppWidgetProvider() {
try {
val contextResolver = context.contentResolver
val inputStream = contextResolver.openInputStream(latestPhoto.thumbnailUri)
android.graphics.BitmapFactory.decodeStream(inputStream)
val input = android.graphics.BitmapFactory.decodeStream(inputStream)
latestPhoto.metadata?.let {
ContentRepository.getInstance(context).photoProcessor.processBitmap(
input, it,
)
}
} catch (e: Exception) {
PLog.e(TAG, "Failed to process photo", e)
null
}
}
@@ -81,6 +81,8 @@ fun CameraPreviewGL(
// 标记是否已经通知过 SurfaceTexture
var surfaceTextureNotified by remember { mutableStateOf(false) }
// 标记 Surface 是否已经准备好
var surfaceAvailable by remember { mutableStateOf(false) }
Box(
modifier = Modifier
@@ -109,6 +111,7 @@ fun CameraPreviewGL(
// 更新闭包捕获的状态
glSurfaceView.onSurfaceReady = { _ ->
// SurfaceTexture 已经准备好,可以开始预览
surfaceAvailable = true
glSurfaceView.getSurfaceTexture()?.let { surfaceTexture ->
glSurfaceView.setPreviewSize(previewSize.width, previewSize.height)
// 取消从这里回调,统一在 update 中处理
@@ -116,6 +119,7 @@ fun CameraPreviewGL(
}
glSurfaceView.onSurfaceDestroyed = {
surfaceAvailable = false
surfaceTextureNotified = false
onSurfaceDestroyed()
}
@@ -136,7 +140,7 @@ fun CameraPreviewGL(
// 我们只需更新 glSurfaceView 的参数,不需要重新打开相机,否则会打断正在开启的相机。
// 因此,只要 surfaceTextureNotified 为 true,就不会再触发 onSurfaceTextureReady。
// 如果需要重新打开相机,由外部自己掌控,这里只负责 GL 的同步。
if (viewWidth > 0 && viewHeight > 0) {
if (viewWidth > 0 && viewHeight > 0 && surfaceAvailable) {
glSurfaceView.getSurfaceTexture()?.let { surfaceTexture ->
glSurfaceView.setPreviewSize(previewSize.width, previewSize.height)
if (!surfaceTextureNotified) {
@@ -77,6 +77,7 @@ import com.hinnka.mycamera.ui.camera.autoRotate
import com.hinnka.mycamera.ui.components.LogViewerDialog
import com.hinnka.mycamera.ui.components.SliderSettingItem
import com.hinnka.mycamera.ui.components.rememberBackgroundPainter
import com.hinnka.mycamera.utils.DeviceUtil
import com.hinnka.mycamera.viewmodel.CameraViewModel
import kotlin.math.roundToInt
@@ -552,40 +553,42 @@ fun SettingsScreen(
)
}
Spacer(modifier = Modifier.height(24.dp))
if (DeviceUtil.isChinaFlavor) {
Spacer(modifier = Modifier.height(24.dp))
// 幻影模式设置
SettingsSection(title = stringResource(R.string.ghost_mode)) {
SwitchSettingItem(
title = stringResource(R.string.ghost_mode),
description = stringResource(R.string.ghost_mode_dialog_description),
checked = phantomMode,
onCheckedChange = { viewModel.togglePhantomMode() }
)
// 幻影模式设置
SettingsSection(title = stringResource(R.string.ghost_mode)) {
SwitchSettingItem(
title = stringResource(R.string.ghost_mode),
description = stringResource(R.string.ghost_mode_dialog_description),
checked = phantomMode,
onCheckedChange = { viewModel.togglePhantomMode() }
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 8.dp)
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 8.dp)
)
SwitchSettingItem(
title = stringResource(R.string.settings_phantom_button_hidden),
description = stringResource(R.string.settings_phantom_button_hidden_description),
checked = phantomButtonHidden,
onCheckedChange = { viewModel.setPhantomButtonHidden(it) }
)
SwitchSettingItem(
title = stringResource(R.string.settings_phantom_button_hidden),
description = stringResource(R.string.settings_phantom_button_hidden_description),
checked = phantomButtonHidden,
onCheckedChange = { viewModel.setPhantomButtonHidden(it) }
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 8.dp)
)
HorizontalDivider(
color = Color.White.copy(alpha = 0.1f),
modifier = Modifier.padding(vertical = 8.dp)
)
SwitchSettingItem(
title = stringResource(R.string.settings_launch_camera_on_phantom_mode),
description = stringResource(R.string.settings_launch_camera_on_phantom_mode_description),
checked = launchCameraOnPhantomMode,
onCheckedChange = { viewModel.setLaunchCameraOnPhantomMode(it) }
)
SwitchSettingItem(
title = stringResource(R.string.settings_launch_camera_on_phantom_mode),
description = stringResource(R.string.settings_launch_camera_on_phantom_mode_description),
checked = launchCameraOnPhantomMode,
onCheckedChange = { viewModel.setLaunchCameraOnPhantomMode(it) }
)
}
}
Spacer(modifier = Modifier.height(24.dp))
@@ -91,7 +91,7 @@ object PLog {
fun e(tag: String, message: String, throwable: Throwable? = null) {
addLog(LogLevel.ERROR, tag, message, throwable)
if (throwable != null) {
BuglyHelper.error(throwable)
BuglyHelper.error(Throwable("$tag: $message", throwable))
Log.e("PLog_$tag", message, throwable)
} else {
Log.e("PLog_$tag", message)
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M810.6,384l-53.4,-117.4L640,213.4l117.3,-53.4L810.6,42.6l53.4,117.4 117.3,53.4 -117.3,53.3L810.6,384zM810.6,981.4l-53.4,-117.4 -117.3,-53.4 117.3,-53.3 53.4,-117.4 53.4,117.4 117.3,53.3 -117.3,53.4 -53.4,117.4zM384,853.4l-106.7,-234.7L42.6,512l234.6,-106.6L384,170.6l106.6,234.7L725.3,512l-234.6,106.6L384,853.4zM384,646.4l42.6,-91.8L518.4,512l-91.8,-42.6L384,377.6l-42.7,91.8L249.6,512l91.7,42.6 42.7,91.8z"
android:fillColor="#FF6B35"/>
</vector>
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/phantom_widget"
android:minWidth="220dp"
android:minWidth="250dp"
android:minHeight="110dp"
android:targetCellWidth="4"
android:targetCellHeight="2"