Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually mark double tap as finished on ACTION_UP if the quick-zoom wasn't started #88

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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