Skip to content

Commit

Permalink
manually mark double tap as finished on ACTION_UP if the quick-zoom w…
Browse files Browse the repository at this point in the history
…asn't started
  • Loading branch information
Łukasz Paczos committed Aug 20, 2019
1 parent bdca305 commit 063e93a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.android.gestures

import GesturesUiTestUtils.DEFAULT_GESTURE_DURATION
import GesturesUiTestUtils.move
import GesturesUiTestUtils.pinch
import GesturesUiTestUtils.quickScale
import android.os.Build
Expand All @@ -11,7 +12,7 @@ import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import com.mapbox.android.gestures.testapp.R
import com.mapbox.android.gestures.testapp.TestActivity
import junit.framework.Assert
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -596,4 +597,25 @@ class ScaleGestureDetectorTest {
onView(withId(R.id.content)).perform(quickScale(delta))
}

@Test
fun doubleTap_move_doNotQuickZoom() {
gesturesManager.setStandardScaleGestureListener(object : StandardScaleGestureDetector.StandardOnScaleGestureListener {
override fun onScaleBegin(detector: StandardScaleGestureDetector): Boolean {
Assert.fail("scale detector should not be called")
return true
}

override fun onScale(detector: StandardScaleGestureDetector): Boolean {
Assert.fail("scale detector should not be called")
return true
}

override fun onScaleEnd(detector: StandardScaleGestureDetector, velocityX: Float, velocityY: Float) {
Assert.fail("scale detector should not be called")
}
})

onView(withId(R.id.content)).perform(quickScale(gesturesManager.standardScaleGestureDetector.spanSinceStartThreshold / 2, withVelocity = false, duration = 50L))
onView(withId(R.id.content)).perform(move(300f, 300f, withVelocity = false))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,23 @@ protected void reset() {
@Override
protected boolean analyzeEvent(MotionEvent motionEvent) {
int action = motionEvent.getActionMasked();
if (action == MotionEvent.ACTION_POINTER_DOWN || action == MotionEvent.ACTION_CANCEL) {
if (quickScale) {

if (quickScale) {
if (action == MotionEvent.ACTION_POINTER_DOWN || action == MotionEvent.ACTION_CANCEL) {
if (isInProgress()) {
interrupt();
} else if (quickScale) {
} else {
// since the double tap has been registered and canceled but the gesture wasn't started,
// we need to mark it manually
quickScale = false;
}
} else if (!isInProgress() && action == MotionEvent.ACTION_UP) {
// if double tap has been registered but the threshold was not met and gesture is not in progress,
// we need to manually mark the finish of a double tap
quickScale = false;
}
}

boolean handled = super.analyzeEvent(motionEvent);
return handled | innerGestureDetector.onTouchEvent(motionEvent);
}
Expand Down

0 comments on commit 063e93a

Please sign in to comment.