-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTapToFocusPlugin.kt
More file actions
56 lines (46 loc) · 1.78 KB
/
TapToFocusPlugin.kt
File metadata and controls
56 lines (46 loc) · 1.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
package co.stonephone.stonecamera.plugins
import android.annotation.SuppressLint
import android.view.MotionEvent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import co.stonephone.stonecamera.StoneCameraViewModel
import co.stonephone.stonecamera.ui.FocusReticle
class TapToFocusPlugin : IPlugin {
override val id: String = "tapToFocusPlugin"
override val name: String = "Tap to Focus"
private var focusBasePlugin: FocusBasePlugin? = null
@Composable
override fun renderViewfinder(viewModel: StoneCameraViewModel, pluginInstance: IPlugin) {
val context = LocalContext.current
if (focusBasePlugin == null) {
return
}
val focusPointDp by remember { focusBasePlugin!!::focusPointDp }
focusPointDp?.let { (x, y) ->
FocusReticle(
xDp = x,
yDp = y,
initialBrightness = 0f,
onDismissFocus = {
focusBasePlugin?.clearFocus()
},
onSetBrightness = { brightness -> viewModel.setBrightness(brightness) },
context = context
)
}
}
@SuppressLint("ClickableViewAccessibility")
override fun initialize(viewModel: StoneCameraViewModel) {
focusBasePlugin = viewModel.plugins.find { it.id == "focusBase" } as FocusBasePlugin?
viewModel.registerTouchHandler { event ->
if (event.action == MotionEvent.ACTION_UP) {
val x = event.x
val y = event.y
focusBasePlugin?.setFocusPoint(x, y)
}
true
}
}
override val settings: List<PluginSetting> = emptyList() // No settings for tap-to-focus yet
}