mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-11 14:54:31 +02:00
handle MotionEvent.ACTION_CANCEL in TouchGestureDetector (see #126)
Some checks are pending
Android CI / build (push) Waiting to run
Some checks are pending
Android CI / build (push) Waiting to run
This commit is contained in:
parent
75b22400c5
commit
72f9c0595f
1 changed files with 20 additions and 4 deletions
|
@ -87,24 +87,40 @@ class TouchGestureDetector(
|
||||||
}
|
}
|
||||||
|
|
||||||
private var paths = HashMap<Int, PointerPath>()
|
private var paths = HashMap<Int, PointerPath>()
|
||||||
private var gestureIsLongClick = false
|
|
||||||
|
/* Set when
|
||||||
|
* - the longPressHandler has detected this gesture as a long press
|
||||||
|
* - the gesture was cancelled by MotionEvent.ACTION_CANCEL
|
||||||
|
* In any case, the current gesture should be ignored by further detection logic.
|
||||||
|
*/
|
||||||
|
private var cancelled = false
|
||||||
|
|
||||||
private var lastTappedTime = 0L
|
private var lastTappedTime = 0L
|
||||||
private var lastTappedLocation: Vector? = null
|
private var lastTappedLocation: Vector? = null
|
||||||
|
|
||||||
fun onTouchEvent(event: MotionEvent) {
|
fun onTouchEvent(event: MotionEvent) {
|
||||||
|
|
||||||
|
if (event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||||
|
synchronized(this@TouchGestureDetector) {
|
||||||
|
cancelled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val pointerIdToIndex =
|
val pointerIdToIndex =
|
||||||
(0..<event.pointerCount).associateBy { event.getPointerId(it) }
|
(0..<event.pointerCount).associateBy { event.getPointerId(it) }
|
||||||
|
|
||||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
synchronized(this@TouchGestureDetector) {
|
synchronized(this@TouchGestureDetector) {
|
||||||
paths = HashMap()
|
paths = HashMap()
|
||||||
gestureIsLongClick = false
|
cancelled = false
|
||||||
}
|
}
|
||||||
longPressHandler.postDelayed({
|
longPressHandler.postDelayed({
|
||||||
synchronized(this@TouchGestureDetector) {
|
synchronized(this@TouchGestureDetector) {
|
||||||
|
if (cancelled) {
|
||||||
|
return@postDelayed
|
||||||
|
}
|
||||||
if (paths.entries.size == 1 && paths.entries.firstOrNull()?.value?.isTap() == true) {
|
if (paths.entries.size == 1 && paths.entries.firstOrNull()?.value?.isTap() == true) {
|
||||||
gestureIsLongClick = true
|
cancelled = true
|
||||||
Gesture.LONG_CLICK.invoke(context)
|
Gesture.LONG_CLICK.invoke(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +158,7 @@ class TouchGestureDetector(
|
||||||
// if the long press handler is still running, kill it
|
// if the long press handler is still running, kill it
|
||||||
longPressHandler.removeCallbacksAndMessages(null)
|
longPressHandler.removeCallbacksAndMessages(null)
|
||||||
// if the gesture was already detected as a long click, there is nothing to do
|
// if the gesture was already detected as a long click, there is nothing to do
|
||||||
if (gestureIsLongClick) {
|
if (cancelled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue