ignore fling events just after releasing an icon from dragging

This commit is contained in:
tibbi 2022-09-25 16:40:08 +02:00
parent 07ea589c73
commit 18486d4b1b
1 changed files with 13 additions and 0 deletions

View File

@ -46,6 +46,10 @@ class MainActivity : SimpleActivity(), FlingListener {
private lateinit var mDetector: GestureDetectorCompat private lateinit var mDetector: GestureDetectorCompat
companion object {
private var mLastUpEvent = 0L
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false useDynamicTheme = false
showTransparentNavigation = true showTransparentNavigation = true
@ -108,6 +112,10 @@ class MainActivity : SimpleActivity(), FlingListener {
} }
override fun onTouchEvent(event: MotionEvent): Boolean { override fun onTouchEvent(event: MotionEvent): Boolean {
if (mLongPressedIcon != null && event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
mLastUpEvent = System.currentTimeMillis()
}
mDetector.onTouchEvent(event) mDetector.onTouchEvent(event)
when (event.actionMasked) { when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
@ -292,6 +300,11 @@ class MainActivity : SimpleActivity(), FlingListener {
} }
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
// ignore fling events just after releasing an icon from dragging
if (System.currentTimeMillis() - mLastUpEvent < 500L) {
return true
}
if (velocityY > 0) { if (velocityY > 0) {
flingListener.onFlingDown() flingListener.onFlingDown()
} else { } else {