diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-09-25 17:41:43 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-09-26 11:38:17 +0200 |
commit | 095ea17c7d04a7af6ec3d5bc6d1fb7035e67799f (patch) | |
tree | fa26b3a7ae695119cc11d3a269faa3069bcea3ab /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | |
parent | 66e95ac2ab6260654ba09b26e83591e3d4334c02 (diff) | |
download | qtlocation-mapboxgl-095ea17c7d04a7af6ec3d5bc6d1fb7035e67799f.tar.gz |
[android] clear CameraChangeDispatcher message queue when camera move is restarted
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 47 |
1 files changed, 24 insertions, 23 deletions
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 977afe4bd9..b225f35c83 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 @@ -10,6 +10,7 @@ import android.support.annotation.Nullable; import android.view.InputDevice; import android.view.MotionEvent; import android.view.animation.DecelerateInterpolator; + import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.Constants; import com.mapbox.android.gestures.MoveGestureDetector; @@ -222,16 +223,21 @@ final class MapGestureDetector { case MotionEvent.ACTION_UP: transform.setGestureInProgress(false); - // Start all awaiting velocity animations - animationsTimeoutHandler.removeCallbacksAndMessages(null); - for (Animator animator : scheduledAnimators) { - animator.start(); + if (scheduledAnimators.isEmpty()) { + cameraChangeDispatcher.onCameraIdle(); + } else { + // Start all awaiting velocity animations + animationsTimeoutHandler.removeCallbacksAndMessages(null); + for (Animator animator : scheduledAnimators) { + animator.start(); + } + scheduledAnimators.clear(); } - scheduledAnimators.clear(); break; case MotionEvent.ACTION_CANCEL: scheduledAnimators.clear(); + transform.cancelTransitions(); transform.setGestureInProgress(false); break; } @@ -526,8 +532,6 @@ final class MapGestureDetector { @Override public void onScaleEnd(StandardScaleGestureDetector detector, float velocityX, float velocityY) { - cameraChangeDispatcher.onCameraIdle(); - if (quickZoom) { //if quickzoom, re-enabling move gesture detector gesturesManager.getMoveGestureDetector().setEnabled(true); @@ -542,18 +546,19 @@ final class MapGestureDetector { notifyOnScaleEndListeners(detector); - if (!uiSettings.isScaleVelocityAnimationEnabled()) { + float velocityXY = Math.abs(velocityX) + Math.abs(velocityY); + + if (!uiSettings.isScaleVelocityAnimationEnabled() || velocityXY < minimumVelocity) { + // notifying listeners that camera is idle only if there is no follow-up animation + cameraChangeDispatcher.onCameraIdle(); return; } - float velocityXY = Math.abs(velocityX) + Math.abs(velocityY); - if (velocityXY > minimumVelocity) { - double zoomAddition = calculateScale(velocityXY, detector.isScalingOut()); - double currentZoom = transform.getRawZoom(); - long animationTime = (long) (Math.abs(zoomAddition) * 1000 / 4); - scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, scaleFocalPoint, animationTime); - scheduleAnimator(scaleAnimator); - } + double zoomAddition = calculateScale(velocityXY, detector.isScalingOut()); + double currentZoom = transform.getRawZoom(); + long animationTime = (long) (Math.abs(zoomAddition) * 1000 / 4); + scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, scaleFocalPoint, animationTime); + scheduleAnimator(scaleAnimator); } private void setScaleFocalPoint(StandardScaleGestureDetector detector) { @@ -650,8 +655,6 @@ final class MapGestureDetector { @Override public void onRotateEnd(RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity) { - cameraChangeDispatcher.onCameraIdle(); - if (uiSettings.isIncreaseScaleThresholdWhenRotating()) { // resetting default scale threshold values gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(defaultSpanSinceStartThreshold); @@ -659,11 +662,9 @@ final class MapGestureDetector { notifyOnRotateEndListeners(detector); - if (!uiSettings.isRotateVelocityAnimationEnabled()) { - return; - } - - if (Math.abs(angularVelocity) < minimumAngularVelocity) { + if (!uiSettings.isRotateVelocityAnimationEnabled() || Math.abs(angularVelocity) < minimumAngularVelocity) { + // notifying listeners that camera is idle only if there is no follow-up animation + cameraChangeDispatcher.onCameraIdle(); return; } |