From 6cabcf51bd78979377bf7a04d67081bc7a7936c3 Mon Sep 17 00:00:00 2001 From: Josia Pietsch Date: Tue, 22 Oct 2024 12:41:52 +0200 Subject: [PATCH] limit angular tolerance of gesture detection (see #59) --- .../java/de/jrpie/android/launcher/ui/HomeActivity.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt b/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt index acff3c2..f23d25e 100644 --- a/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt +++ b/app/src/main/java/de/jrpie/android/launcher/ui/HomeActivity.kt @@ -28,6 +28,7 @@ import kotlin.concurrent.fixedRateTimer import kotlin.math.abs import kotlin.math.max import kotlin.math.min +import kotlin.math.tan /** @@ -203,13 +204,15 @@ class HomeActivity : UIObject, AppCompatActivity(), val threshold = ViewConfiguration.get(this).scaledTouchSlop - var gesture = if (abs(diffX) > abs(diffY)) { // horizontal swipe + val angularThreshold = tan(Math.PI / 6) + + var gesture = if (angularThreshold * abs(diffX) > abs(diffY)) { // horizontal swipe if (diffX > threshold) Gesture.SWIPE_LEFT else if (diffX < -threshold) Gesture.SWIPE_RIGHT else null - } else { // vertical swipe + } else if (angularThreshold * abs(diffY) > abs(diffX)){ // vertical swipe // Only open if the swipe was not from the phones top edge // TODO: replace 100px by sensible dp value (e.g. twice the height of the status bar) if (diffY < -threshold && e1.y > 100) @@ -217,7 +220,7 @@ class HomeActivity : UIObject, AppCompatActivity(), else if (diffY > threshold) Gesture.SWIPE_UP else null - } + } else null if (doubleActions && bufferedPointerCount > 1) { gesture = gesture?.let(Gesture::getDoubleVariant)