diff options
author | Tobrun <tobrun@mapbox.com> | 2017-06-29 09:29:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-29 09:29:23 +0200 |
commit | 200d184738a2a5c8e7cb19a0f5eaa06d34cb1774 (patch) | |
tree | 2780cb51938f6bb2fbb6da9912e1013c15c2d5cc /platform/android | |
parent | 34453eb4e27c0bf45027700e45ad69435f3566d7 (diff) | |
download | qtlocation-mapboxgl-200d184738a2a5c8e7cb19a0f5eaa06d34cb1774.tar.gz |
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
Diffstat (limited to 'platform/android')
6 files changed, 47 insertions, 19 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java index bd028aecb6..6f7d7c0080 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java @@ -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(); + } } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 5346baa4e2..3607703ab1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -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; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index 89fbb79504..d788b7772b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -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(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 72868a91d8..8b6b93e03a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -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; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java index 60518239c8..cb2f57d860 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java @@ -28,6 +28,7 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe private MapView mapView; private MapboxMap mapboxMap; + private FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { @@ -40,13 +41,14 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe } @Override - public void onMapReady(@NonNull final MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; + public void onMapReady(@NonNull final MapboxMap map) { + mapboxMap = map; mapboxMap.setOnCameraIdleListener(new MapboxMap.OnCameraIdleListener() { @Override public void onCameraIdle() { Timber.e("OnCameraIdle"); + fab.setColorFilter(ContextCompat.getColor(CameraPositionActivity.this, android.R.color.holo_green_dark)); } }); @@ -61,6 +63,7 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe @Override public void onCameraMove() { Timber.e("OnCameraMove"); + fab.setColorFilter(ContextCompat.getColor(CameraPositionActivity.this, android.R.color.holo_orange_dark)); } }); @@ -71,12 +74,13 @@ public class CameraPositionActivity extends AppCompatActivity implements OnMapRe @Override public void onCameraMoveStarted(int reason) { // reason ranges from 1 <-> 3 + fab.setColorFilter(ContextCompat.getColor(CameraPositionActivity.this, android.R.color.holo_red_dark)); Timber.e("OnCameraMoveStarted: %s", REASONS[reason - 1]); } }); // add a listener to FAB - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab = (FloatingActionButton) findViewById(R.id.fab); fab.setColorFilter(ContextCompat.getColor(CameraPositionActivity.this, R.color.primary)); fab.setOnClickListener(new View.OnClickListener() { @Override diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java index 91f3de0837..c4d29bebec 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MyLocationTrackingModeActivity.java @@ -236,8 +236,8 @@ public class MyLocationTrackingModeActivity extends AppCompatActivity implements @Override protected void onStop() { super.onStop(); - LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this); if (lostApiClient.isConnected()) { + LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this); lostApiClient.unregisterConnectionCallbacks(this); lostApiClient.disconnect(); } |