-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShutterFlashPlugin.kt
More file actions
65 lines (56 loc) · 2.16 KB
/
ShutterFlashPlugin.kt
File metadata and controls
65 lines (56 loc) · 2.16 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
package co.stonephone.stonecamera.plugins
import android.annotation.SuppressLint
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import co.stonephone.stonecamera.StoneCameraViewModel
import kotlinx.coroutines.delay
class ShutterFlashPlugin : IPlugin {
override val id: String = "shutterFlashPlugin"
override val name: String = "Shutter Flash"
private var showShutterFlash by mutableStateOf(false)
@Composable
override fun renderViewfinder(
viewModel: StoneCameraViewModel,
pluginInstance: IPlugin
) {
var isFadingOut by remember { mutableStateOf(false) }
if (showShutterFlash) {
LaunchedEffect(Unit) {
// Wait for the fade-in duration
delay(20)
// Trigger fade-out
isFadingOut = true
// Wait for the fade-out duration
delay(50)
// Reset state
showShutterFlash = false
isFadingOut = false
}
}
AnimatedVisibility(
visible = showShutterFlash || isFadingOut,
enter = fadeIn(animationSpec = androidx.compose.animation.core.tween(20)), // Fade in over 100ms
exit = fadeOut(animationSpec = androidx.compose.animation.core.tween(50)) // Fade out over 200ms
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = Color.Black.copy(alpha = 0.7f))
)
}
}
@SuppressLint("ClickableViewAccessibility")
override fun initialize(viewModel: StoneCameraViewModel) {
}
override fun onCaptureStarted(stoneCameraViewModel: StoneCameraViewModel) {
showShutterFlash = true
}
override val settings: List<PluginSetting> = emptyList() // No settings for tap-to-focus yet
}