From a700cebe9e79d4eac506be5792048793cfcd5df7 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Fri, 22 Oct 2021 22:33:54 +0200 Subject: [PATCH] Fix TapDetector requering N+1 click --- .../java/net/kdt/pojavlaunch/TapDetector.java | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TapDetector.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TapDetector.java index 9695604b3..e9bf9a04f 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TapDetector.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/TapDetector.java @@ -24,7 +24,9 @@ public class TapDetector { private final int tapNumberToDetect; private int currentTapNumber = 0; + private final int detectionMethod; + private long mLastEventTime = 0; private float mLastX = 9999; private float mLastY = 9999; @@ -43,57 +45,59 @@ public class TapDetector { * @param e The MotionEvent to inspect * @return whether or not a X-tap happened for a pointer */ - public boolean onTouchEvent(MotionEvent e){ - int eventAction = e.getActionMasked(); - int pointerIndex; - int base_action, alternate_action; + public boolean onTouchEvent(MotionEvent e){ + int eventAction = e.getActionMasked(); + int pointerIndex; + int base_action, alternate_action; - //Get the event to look forward - if(detectDownTouch()){ + //Get the event to look forward + if(detectDownTouch()){ base_action = ACTION_DOWN; alternate_action = ACTION_POINTER_DOWN; - }else if(detectUpTouch()){ + }else if(detectUpTouch()){ base_action = ACTION_UP; alternate_action = ACTION_POINTER_UP; - }else return false; + }else return false; - //Get the pointer index we want to look at - if(eventAction == base_action) pointerIndex = 0; - else if(eventAction == alternate_action) pointerIndex = e.getActionIndex(); - else return false; + //Get the pointer index we want to look at + if(eventAction == base_action) pointerIndex = 0; + else if(eventAction == alternate_action) pointerIndex = e.getActionIndex(); + else return false; - //Store current event info - float eventX = e.getX(pointerIndex); - float eventY = e.getY(pointerIndex); - long eventTime = e.getEventTime(); + //Store current event info + float eventX = e.getX(pointerIndex); + float eventY = e.getY(pointerIndex); + long eventTime = e.getEventTime(); - //Compute deltas - long deltaTime = eventTime - mLastEventTime; - int deltaX = (int) mLastX - (int) eventX; - int deltaY = (int) mLastY - (int) eventY; + //Compute deltas + long deltaTime = eventTime - mLastEventTime; + int deltaX = (int) mLastX - (int) eventX; + int deltaY = (int) mLastY - (int) eventY; - //Store current event info to persist on next event - mLastEventTime = eventTime; - mLastX = eventX; - mLastY = eventY; + //Store current event info to persist on next event + mLastEventTime = eventTime; + mLastX = eventX; + mLastY = eventY; - //Check for high enough speed and precision - if ((deltaTime < DOUBLE_TAP_MIN_DELTA_MS || deltaTime > DOUBLE_TAP_MAX_DELTA_MS) || - ((deltaX*deltaX + deltaY*deltaY) > DOUBLE_TAP_SLOP_SQUARE_PX)) { - currentTapNumber = 0; - return false; + //Check for high enough speed and precision + if(currentTapNumber > 0){ + if ((deltaTime < DOUBLE_TAP_MIN_DELTA_MS || deltaTime > DOUBLE_TAP_MAX_DELTA_MS) || + ((deltaX*deltaX + deltaY*deltaY) > DOUBLE_TAP_SLOP_SQUARE_PX)) { + currentTapNumber = 0; + return false; + } } //A worthy tap happened - currentTapNumber += 1; - if(currentTapNumber == tapNumberToDetect){ + currentTapNumber += 1; + if(currentTapNumber == tapNumberToDetect){ resetTapDetectionState(); return true; - } + } - //If not enough taps are reached - return false; - } + //If not enough taps are reached + return false; + } /** * Reset the double tap values.