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

Commit

Permalink
[android] - fine tune gesture zoom & rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Oct 9, 2017
1 parent a1aed6f commit 9048d6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public TwoFingerGestureDetector(Context context) {

ViewConfiguration config = ViewConfiguration.get(context);

edgeSlop = config.getScaledEdgeSlop();
// lowering the edgeSlop allows to execute gesture faster
// https://github.com/mapbox/mapbox-gl-native/issues/10102
edgeSlop = config.getScaledEdgeSlop() / 3.0f;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ public boolean onScale(ScaleGestureDetector detector) {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {

private static final long ROTATE_INVOKE_WAIT_TIME = 1500;
private static final long ROTATE_INVOKE_WAIT_TIME = 750;
private static final float ROTATE_INVOKE_ANGLE = 17.5f;

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

// Called when two fingers first touch the screen
Expand All @@ -551,7 +551,6 @@ public boolean onRotateBegin(RotateGestureDetector detector) {
public void onRotateEnd(RotateGestureDetector detector) {
// notify camera change listener
beginTime = 0;
totalAngle = 0.0f;
started = false;
}

Expand All @@ -573,8 +572,8 @@ public boolean onRotate(RotateGestureDetector detector) {

// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
totalAngle += detector.getRotationDegreesDelta();
if (totalAngle > 35.0f || totalAngle < -35.0f) {
float angle = detector.getRotationDegreesDelta();
if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_ROTATION_START, transform));
Expand All @@ -589,9 +588,8 @@ public boolean onRotate(RotateGestureDetector detector) {
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);

// Get rotate value
double bearing = transform.getRawBearing();
bearing += detector.getRotationDegreesDelta();
// Calculate map bearing value
double bearing = transform.getRawBearing() + angle;

// Rotate the map
if (focalPoint != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ public void onDestroy() {

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isMapInitialized()) {
return super.onTouchEvent(event);
}

if (event.getAction() == MotionEvent.ACTION_DOWN) {
mapZoomButtonController.setVisible(true);
}
Expand Down Expand Up @@ -471,7 +475,7 @@ public void setStyleUrl(@NonNull String url) {
if (destroyed) {
return;
}
if (nativeMapView == null) {
if (!isMapInitialized()) {
mapboxMapOptions.styleUrl(url);
return;
}
Expand All @@ -488,7 +492,7 @@ protected void onSizeChanged(int width, int height, int oldw, int oldh) {
return;
}

if (!isInEditMode() && nativeMapView != null) {
if (!isInEditMode() && isMapInitialized()) {
nativeMapView.resizeView(width, height);
}
}
Expand Down Expand Up @@ -574,6 +578,10 @@ public void getMapAsync(final OnMapReadyCallback callback) {
}
}

private boolean isMapInitialized() {
return nativeMapView != null;
}

MapboxMap getMapboxMap() {
return mapboxMap;
}
Expand Down

0 comments on commit 9048d6c

Please sign in to comment.