Merge pull request #141 from esensar/fix/139-widgets-scrolling

Fix scrolling on widgets on home screen
This commit is contained in:
Tibor Kaputa 2023-09-22 10:17:46 +02:00 committed by GitHub
commit 2614be4f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -14,7 +14,7 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
private var actionDownCoords = PointF() private var actionDownCoords = PointF()
private var currentCoords = PointF() private var currentCoords = PointF()
private var actionDownMS = 0L private var actionDownMS = 0L
private val moveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt() private val moveGestureThreshold = resources.getDimension(R.dimen.move_gesture_threshold).toInt() / 4
var hasLongPressed = false var hasLongPressed = false
var ignoreTouches = false var ignoreTouches = false
var longPressListener: ((x: Float, y: Float) -> Unit)? = null var longPressListener: ((x: Float, y: Float) -> Unit)? = null
@ -52,7 +52,7 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
currentCoords.x = event.rawX currentCoords.x = event.rawX
currentCoords.y = event.rawY currentCoords.y = event.rawY
if (hasFingerMoved(event.rawX, event.rawY)) { if (abs(actionDownCoords.x - currentCoords.x) > moveGestureThreshold ) {
resetTouches() resetTouches()
return true return true
} }
@ -67,7 +67,7 @@ class MyAppWidgetHostView(context: Context) : AppWidgetHostView(context) {
} }
private val longPressRunnable = Runnable { private val longPressRunnable = Runnable {
if (!hasFingerMoved(currentCoords.x, currentCoords.y)) { if (abs(actionDownCoords.x - currentCoords.x) < moveGestureThreshold && abs(actionDownCoords.y - currentCoords.y) < moveGestureThreshold) {
longPressHandler.removeCallbacksAndMessages(null) longPressHandler.removeCallbacksAndMessages(null)
hasLongPressed = true hasLongPressed = true
longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y) longPressListener?.invoke(actionDownCoords.x, actionDownCoords.y)