-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPinchToZoomPlugin.kt
More file actions
54 lines (44 loc) · 1.81 KB
/
PinchToZoomPlugin.kt
File metadata and controls
54 lines (44 loc) · 1.81 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
package co.stonephone.stonecamera.plugins
import android.view.ScaleGestureDetector
import co.stonephone.stonecamera.MyApplication
import co.stonephone.stonecamera.StoneCameraViewModel
class PinchToZoomPlugin : IPlugin {
override val id: String = "zoomScalingPlugin"
override val name: String = "Zoom Scaling"
private var isScaling = false
private var scaleGestureDetector: ScaleGestureDetector? = null
override fun initialize(viewModel: StoneCameraViewModel) {
val zoomBasePlugin =
viewModel.plugins.find { it.id == "zoomBasePlugin" } as ZoomBasePlugin?
if(zoomBasePlugin == null) {
return
}
scaleGestureDetector = ScaleGestureDetector(
MyApplication.getAppContext(),
object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
isScaling = true
return true
}
override fun onScale(detector: ScaleGestureDetector): Boolean {
// Happens when camera changes during zoom
if(zoomBasePlugin == null) {
return false
}
val zoomChange = detector.scaleFactor
val newZoom = zoomBasePlugin.currentZoom * zoomChange
zoomBasePlugin.setZoom(newZoom)
return true
}
override fun onScaleEnd(detector: ScaleGestureDetector) {
isScaling = false
}
}
)
viewModel.registerTouchHandler { event ->
scaleGestureDetector?.onTouchEvent(event)
true
}
}
override val settings: List<PluginSetting> = emptyList()
}