Skip to content

Commit 063e93a

Browse files
author
Łukasz Paczos
committed
manually mark double tap as finished on ACTION_UP if the quick-zoom wasn't started
1 parent bdca305 commit 063e93a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

app/src/androidTest/java/com/mapbox/android/gestures/ScaleGestureDetectorTest.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapbox.android.gestures
22

33
import GesturesUiTestUtils.DEFAULT_GESTURE_DURATION
4+
import GesturesUiTestUtils.move
45
import GesturesUiTestUtils.pinch
56
import GesturesUiTestUtils.quickScale
67
import android.os.Build
@@ -11,7 +12,7 @@ import android.support.test.rule.ActivityTestRule
1112
import android.support.test.runner.AndroidJUnit4
1213
import com.mapbox.android.gestures.testapp.R
1314
import com.mapbox.android.gestures.testapp.TestActivity
14-
import junit.framework.Assert
15+
import org.junit.Assert
1516
import org.junit.Before
1617
import org.junit.Rule
1718
import org.junit.Test
@@ -596,4 +597,25 @@ class ScaleGestureDetectorTest {
596597
onView(withId(R.id.content)).perform(quickScale(delta))
597598
}
598599

600+
@Test
601+
fun doubleTap_move_doNotQuickZoom() {
602+
gesturesManager.setStandardScaleGestureListener(object : StandardScaleGestureDetector.StandardOnScaleGestureListener {
603+
override fun onScaleBegin(detector: StandardScaleGestureDetector): Boolean {
604+
Assert.fail("scale detector should not be called")
605+
return true
606+
}
607+
608+
override fun onScale(detector: StandardScaleGestureDetector): Boolean {
609+
Assert.fail("scale detector should not be called")
610+
return true
611+
}
612+
613+
override fun onScaleEnd(detector: StandardScaleGestureDetector, velocityX: Float, velocityY: Float) {
614+
Assert.fail("scale detector should not be called")
615+
}
616+
})
617+
618+
onView(withId(R.id.content)).perform(quickScale(gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L))
619+
onView(withId(R.id.content)).perform(move(300f, 300f, withVelocity = false))
620+
}
599621
}

library/src/main/java/com/mapbox/android/gestures/StandardScaleGestureDetector.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,23 @@ protected void reset() {
139139
@Override
140140
protected boolean analyzeEvent(MotionEvent motionEvent) {
141141
int action = motionEvent.getActionMasked();
142-
if (action == MotionEvent.ACTION_POINTER_DOWN || action == MotionEvent.ACTION_CANCEL) {
143-
if (quickScale) {
142+
143+
if (quickScale) {
144+
if (action == MotionEvent.ACTION_POINTER_DOWN || action == MotionEvent.ACTION_CANCEL) {
144145
if (isInProgress()) {
145146
interrupt();
146-
} else if (quickScale) {
147+
} else {
147148
// since the double tap has been registered and canceled but the gesture wasn't started,
148149
// we need to mark it manually
149150
quickScale = false;
150151
}
152+
} else if (!isInProgress() && action == MotionEvent.ACTION_UP) {
153+
// if double tap has been registered but the threshold was not met and gesture is not in progress,
154+
// we need to manually mark the finish of a double tap
155+
quickScale = false;
151156
}
152157
}
158+
153159
boolean handled = super.analyzeEvent(motionEvent);
154160
return handled | innerGestureDetector.onTouchEvent(motionEvent);
155161
}

0 commit comments

Comments
 (0)