Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - disable rotation gesture when pinch zooming
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Sep 25, 2017
1 parent 04d7ace commit e6fea1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public TwoFingerGestureDetector(Context context) {

ViewConfiguration config = ViewConfiguration.get(context);

// We divide edge slop by 2 to make rotation gesture happen more easily #6870
edgeSlop = config.getScaledEdgeSlop() / 2;
edgeSlop = config.getScaledEdgeSlop();
}

@Override
Expand Down Expand Up @@ -222,4 +221,4 @@ public float getFocusY() {
return focus.y;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ final class MapGestureDetector {
private boolean quickZoom;
private boolean tiltGestureOccurred;
private boolean scrollGestureOccurred;

private boolean scaleGestureOccurred;
private boolean recentScaleGestureOccurred;
private long scaleBeginTime;

MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
Expand Down Expand Up @@ -144,8 +146,8 @@ boolean onTouchEvent(MotionEvent event) {
}

// Check two finger gestures first
rotateGestureDetector.onTouchEvent(event);
scaleGestureDetector.onTouchEvent(event);
rotateGestureDetector.onTouchEvent(event);
shoveGestureDetector.onTouchEvent(event);

// Handle two finger tap
Expand Down Expand Up @@ -428,8 +430,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
*/
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {

long beginTime = 0;
float scaleFactor = 1.0f;
private float scaleFactor = 1.0f;

// Called when two fingers first touch the screen
@Override
Expand All @@ -438,9 +439,8 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
return false;
}

scaleGestureOccurred = true;
recentScaleGestureOccurred = true;
beginTime = detector.getEventTime();
scaleBeginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_PINCH_START, transform));
Expand All @@ -451,7 +451,7 @@ public boolean onScaleBegin(ScaleGestureDetector detector) {
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
scaleGestureOccurred = false;
beginTime = 0;
scaleBeginTime = 0;
scaleFactor = 1.0f;
cameraChangeDispatcher.onCameraIdle();
}
Expand All @@ -471,7 +471,7 @@ public boolean onScale(ScaleGestureDetector detector) {
// Ignore short touches in case it is a tap
// Also ignore small scales
long time = detector.getEventTime();
long interval = time - beginTime;
long interval = time - scaleBeginTime;
if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
Expand Down Expand Up @@ -517,7 +517,6 @@ public boolean onScale(ScaleGestureDetector detector) {
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2),
detector.getFocusX(), detector.getFocusY());
}

return true;
}
}
Expand All @@ -527,9 +526,11 @@ public boolean onScale(ScaleGestureDetector detector) {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {

long beginTime = 0;
float totalAngle = 0.0f;
boolean started = false;
private static final long ROTATE_INVOKE_WAIT_TIME = 1500;

private long beginTime = 0;
private float totalAngle = 0.0f;
private boolean started = false;

// Called when two fingers first touch the screen
@Override
Expand Down Expand Up @@ -566,7 +567,7 @@ public boolean onRotate(RotateGestureDetector detector) {
// Also ignore small rotate
long time = detector.getEventTime();
long interval = time - beginTime;
if (!started && (interval <= ViewConfiguration.getTapTimeout())) {
if (!started && (interval <= ViewConfiguration.getTapTimeout() || isScaleGestureActive(time))) {
return false;
}

Expand All @@ -583,6 +584,7 @@ public boolean onRotate(RotateGestureDetector detector) {
if (!started) {
return false;
}

// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
Expand All @@ -601,6 +603,13 @@ public boolean onRotate(RotateGestureDetector detector) {
}
return true;
}

private boolean isScaleGestureActive(long time) {
long scaleExecutionTime = time - scaleBeginTime;
boolean scaleGestureStarted = scaleBeginTime != 0;
boolean scaleOffsetTimeValid = scaleExecutionTime > ROTATE_INVOKE_WAIT_TIME;
return (scaleGestureStarted && scaleOffsetTimeValid) || scaleGestureOccurred;
}
}

/**
Expand Down

0 comments on commit e6fea1e

Please sign in to comment.