OnCameraIdle hook into quickzoom gesture (#9339)
* [android] - OnCameraIdle hook into quickzoom gesture * double tap fix * show MyLocationView bearing for GPS when Compass is not available, only show error about missing compass once, fix test activity. * fix accessor lint warning
This commit is contained in:
@@ -2,8 +2,8 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
|
||||
|
||||
class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener,
|
||||
MapboxMap.OnCameraMoveCanceledListener, OnCameraIdleListener {
|
||||
@@ -59,9 +59,11 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
|
||||
|
||||
@Override
|
||||
public void onCameraIdle() {
|
||||
if (onCameraIdleListener != null && !idle) {
|
||||
if (!idle) {
|
||||
idle = true;
|
||||
onCameraIdleListener.onCameraIdle();
|
||||
if (onCameraIdleListener != null) {
|
||||
onCameraIdleListener.onCameraIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ final class MapGestureDetector {
|
||||
private boolean quickZoom = false;
|
||||
private boolean scrollInProgress = false;
|
||||
private boolean scaleGestureOccurred = false;
|
||||
private boolean recentScaleGestureOccurred = false;
|
||||
|
||||
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
|
||||
TrackingSettings trackingSettings, AnnotationManager annotationManager,
|
||||
@@ -148,7 +149,7 @@ final class MapGestureDetector {
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// First pointer down, reset scaleGestureOccurred, used to avoid triggering a fling after a scale gesture #7666
|
||||
scaleGestureOccurred = false;
|
||||
recentScaleGestureOccurred = false;
|
||||
transform.setGestureInProgress(true);
|
||||
break;
|
||||
|
||||
@@ -274,7 +275,7 @@ final class MapGestureDetector {
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (quickZoom) {
|
||||
// insert here?
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
quickZoom = false;
|
||||
break;
|
||||
}
|
||||
@@ -341,7 +342,7 @@ final class MapGestureDetector {
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || scaleGestureOccurred) {
|
||||
if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || recentScaleGestureOccurred) {
|
||||
// don't allow a fling is scroll is disabled
|
||||
// and ignore when a scale gesture has occurred
|
||||
return false;
|
||||
@@ -392,12 +393,17 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scaleGestureOccurred) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!scrollInProgress) {
|
||||
scrollInProgress = true;
|
||||
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(e1.getX(), e1.getY()),
|
||||
MapboxEvent.GESTURE_PAN_START, transform));
|
||||
@@ -432,6 +438,7 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
scaleGestureOccurred = true;
|
||||
recentScaleGestureOccurred = true;
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
@@ -442,9 +449,11 @@ final class MapGestureDetector {
|
||||
// Called when fingers leave screen
|
||||
@Override
|
||||
public void onScaleEnd(ScaleGestureDetector detector) {
|
||||
scaleGestureOccurred = false;
|
||||
beginTime = 0;
|
||||
scaleFactor = 1.0f;
|
||||
zoomStarted = false;
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
|
||||
// Called each time a finger moves
|
||||
@@ -480,6 +489,9 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
// Gesture is a quickzoom if there aren't two fingers
|
||||
if (!quickZoom && !twoTap) {
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
}
|
||||
quickZoom = !twoTap;
|
||||
|
||||
// make an assumption here; if the zoom center is specified by the gesture, it's NOT going
|
||||
@@ -492,6 +504,7 @@ final class MapGestureDetector {
|
||||
// arround user provided focal point
|
||||
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
|
||||
} else if (quickZoom) {
|
||||
cameraChangeDispatcher.onCameraMove();
|
||||
// clamp scale factors we feed to core #7514
|
||||
float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
|
||||
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
|
||||
@@ -553,7 +566,7 @@ final class MapGestureDetector {
|
||||
// If rotate is large enough ignore a tap
|
||||
// Also is zoom already started, don't rotate
|
||||
totalAngle += detector.getRotationDegreesDelta();
|
||||
if (!zoomStarted && ((totalAngle > 20.0f) || (totalAngle < -20.0f))) {
|
||||
if (totalAngle > 20.0f || totalAngle < -20.0f) {
|
||||
started = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -215,6 +215,9 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
if (cameraPosition != null) {
|
||||
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
|
||||
setZoom(newZoom, focalPoint, MapboxConstants.ANIMATION_DURATION);
|
||||
} else {
|
||||
// we are not transforming, notify about being idle
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,8 +230,8 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
@Override
|
||||
public void onMapChanged(int change) {
|
||||
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -327,7 +330,7 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(int change) {
|
||||
if (change == MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED) {
|
||||
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
|
||||
@@ -348,12 +348,17 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
// draw foreground
|
||||
if (myBearingTrackingMode == MyBearingTracking.NONE || !compassListener.isSensorAvailable()) {
|
||||
if (myBearingTrackingMode == MyBearingTracking.NONE) {
|
||||
if (foregroundDrawable != null) {
|
||||
foregroundDrawable.draw(canvas);
|
||||
}
|
||||
} else if (foregroundBearingDrawable != null && foregroundBounds != null) {
|
||||
foregroundBearingDrawable.draw(canvas);
|
||||
if (myBearingTrackingMode == MyBearingTracking.GPS || compassListener.isSensorAvailable()) {
|
||||
foregroundBearingDrawable.draw(canvas);
|
||||
} else {
|
||||
// We are tracking MyBearingTracking.COMPASS, but sensor is not available.
|
||||
foregroundDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,9 +779,9 @@ public class MyLocationView extends View {
|
||||
private final SensorManager sensorManager;
|
||||
|
||||
private Sensor rotationVectorSensor;
|
||||
float[] matrix = new float[9];
|
||||
float[] orientation = new float[3];
|
||||
|
||||
private float[] matrix = new float[9];
|
||||
private float[] orientation = new float[3];
|
||||
private boolean reportMissingSensor = true;
|
||||
// Compass data
|
||||
private long compassUpdateNextTimestamp = 0;
|
||||
|
||||
@@ -794,7 +799,8 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
public boolean isSensorAvailable() {
|
||||
if (rotationVectorSensor == null) {
|
||||
if (rotationVectorSensor == null && reportMissingSensor) {
|
||||
reportMissingSensor = false;
|
||||
Timber.e("Sensor.TYPE_ROTATION_VECTOR is missing from this device. Unable to use MyBearingTracking.COMPASS.");
|
||||
}
|
||||
return rotationVectorSensor != null;
|
||||
|
||||
Reference in New Issue
Block a user