-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFlash.kt
More file actions
93 lines (86 loc) · 3.78 KB
/
Flash.kt
File metadata and controls
93 lines (86 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package co.stonephone.stonecamera.plugins
import android.util.Log
import androidx.camera.core.ImageCapture
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.FlashAuto
import androidx.compose.material.icons.filled.FlashOff
import androidx.compose.material.icons.filled.FlashOn
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import co.stonephone.stonecamera.StoneCameraViewModel
import co.stonephone.stonecamera.utils.Translatable
import co.stonephone.stonecamera.utils.TranslatableString
import co.stonephone.stonecamera.utils.i18n
class FlashPlugin : IPlugin {
override val id: String = "flashPlugin"
override val name: String = "Flash"
override fun initialize(viewModel: StoneCameraViewModel) {
}
override fun onImageCapture(
viewModel: StoneCameraViewModel, imageCapture: ImageCapture.Builder
): ImageCapture.Builder {
val flashMode = viewModel.getSetting<TranslatableString>("flash") ?: "OFF".i18n()
val mode = flashModeStringToMode(flashMode.resolve())
imageCapture.setFlashMode(mode)
return imageCapture
}
private fun flashModeStringToMode(modeStr: String): Int {
return when (modeStr.uppercase()) {
"ON" -> ImageCapture.FLASH_MODE_ON
"OFF" -> ImageCapture.FLASH_MODE_OFF
"AUTO" -> ImageCapture.FLASH_MODE_AUTO
else -> {
Log.e("StoneCameraViewModel", "Invalid flash mode: $modeStr. Defaulting to OFF.")
ImageCapture.FLASH_MODE_OFF
}
}
}
override val settings: (StoneCameraViewModel) -> List<PluginSetting> = { viewModel ->
listOf(
PluginSetting.EnumSetting(
key = "flash",
label = @Translatable "Flash".i18n(),
defaultValue = @Translatable "OFF".i18n(),
options = listOf(
@Translatable "OFF".i18n(),
@Translatable "ON".i18n(),
@Translatable "AUTO".i18n()
),
render = { flashMode, isSelected ->
Box(
modifier = Modifier.padding(8.dp)
) {
Icon(
imageVector = when (flashMode) {
"OFF".i18n() -> Icons.Default.FlashOff // Replace with your preferred icon
"ON".i18n() -> Icons.Default.FlashOn
"AUTO".i18n() -> Icons.Default.FlashAuto // You may need to add custom icons for Flash Auto
else -> {
Icons.Default.FlashOff
}
},
contentDescription = when (flashMode) {
"OFF".i18n() -> @Translatable "Flash Off".i18n().resolve()
"ON".i18n() -> @Translatable "Flash On".i18n().resolve()
"AUTO".i18n() -> @Translatable "Flash Auto".i18n().resolve()
else -> {
"Flash"
}
},
tint = if (isSelected) Color(0xFFFFCC00) else Color.White
)
}
},
onChange = { viewModel, value ->
viewModel.recreateUseCases()
},
renderLocation = SettingLocation.TOP
)
)
}
}