-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGestureAwareFrameLayout.kt
More file actions
57 lines (47 loc) · 1.7 KB
/
GestureAwareFrameLayout.kt
File metadata and controls
57 lines (47 loc) · 1.7 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
package com.rngooglemapsplus
import android.content.Context
import android.view.MotionEvent
import android.widget.FrameLayout
abstract class GestureAwareFrameLayout(
context: Context,
) : FrameLayout(context) {
private var parentTouchInterceptDisallowed = false
protected abstract val panGestureEnabled: Boolean
protected abstract val multiTouchGestureEnabled: Boolean
protected open val gesturesSupported: Boolean = true
protected fun setParentTouchInterceptDisallowed(blocked: Boolean) {
if (parentTouchInterceptDisallowed == blocked) return
parentTouchInterceptDisallowed = blocked
var p = parent
while (p != null) {
p.requestDisallowInterceptTouchEvent(blocked)
p = p.parent
}
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
if (!gesturesSupported) return super.dispatchTouchEvent(ev)
val anyGestureEnabled = panGestureEnabled || multiTouchGestureEnabled
if (!anyGestureEnabled) return super.dispatchTouchEvent(ev)
when (ev.actionMasked) {
MotionEvent.ACTION_DOWN,
MotionEvent.ACTION_MOVE,
MotionEvent.ACTION_POINTER_DOWN,
-> {
val pointers = ev.pointerCount
val shouldBlockParent = pointers >= (if (panGestureEnabled) 1 else 2)
setParentTouchInterceptDisallowed(shouldBlockParent)
}
MotionEvent.ACTION_POINTER_UP -> {
val pointers = ev.pointerCount - 1
val shouldBlockParent = pointers >= (if (panGestureEnabled) 1 else 2)
setParentTouchInterceptDisallowed(shouldBlockParent)
}
MotionEvent.ACTION_UP,
MotionEvent.ACTION_CANCEL,
-> {
setParentTouchInterceptDisallowed(false)
}
}
return super.dispatchTouchEvent(ev)
}
}