From d1e9a995d6fa116e4cf650c0f211a9c7a691797e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Tue, 25 Sep 2018 19:44:37 +0200 Subject: [android] dispatch camera idle/transition cancelling only if required --- .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 49 +++++++++++++++------- 1 file changed, 35 insertions(+), 14 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 b225f35c83..711896e45e 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 @@ -223,9 +223,7 @@ final class MapGestureDetector { case MotionEvent.ACTION_UP: transform.setGestureInProgress(false); - if (scheduledAnimators.isEmpty()) { - cameraChangeDispatcher.onCameraIdle(); - } else { + if (!scheduledAnimators.isEmpty()) { // Start all awaiting velocity animations animationsTimeoutHandler.removeCallbacksAndMessages(null); for (Animator animator : scheduledAnimators) { @@ -251,6 +249,8 @@ final class MapGestureDetector { cancelAnimator(scaleAnimator); cancelAnimator(rotateAnimator); + + dispatchCameraIdle(); } private void cancelAnimator(Animator animator) { @@ -441,7 +441,7 @@ final class MapGestureDetector { return false; } - transform.cancelTransitions(); + cancelTransitionsIfRequired(); sendTelemetryEvent(TelemetryConstants.PAN, detector.getFocalPoint()); notifyOnMoveBeginListeners(detector); return true; @@ -465,7 +465,7 @@ final class MapGestureDetector { @Override public void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY) { - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); notifyOnMoveEndListeners(detector); } } @@ -487,7 +487,7 @@ final class MapGestureDetector { return false; } - transform.cancelTransitions(); + cancelTransitionsIfRequired(); quickZoom = detector.getPointersCount() == 1; if (quickZoom) { @@ -550,7 +550,7 @@ final class MapGestureDetector { if (!uiSettings.isScaleVelocityAnimationEnabled() || velocityXY < minimumVelocity) { // notifying listeners that camera is idle only if there is no follow-up animation - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); return; } @@ -615,7 +615,7 @@ final class MapGestureDetector { return false; } - transform.cancelTransitions(); + cancelTransitionsIfRequired(); if (uiSettings.isIncreaseScaleThresholdWhenRotating()) { // when rotation starts, interrupting scale and increasing the threshold @@ -664,7 +664,7 @@ final class MapGestureDetector { if (!uiSettings.isRotateVelocityAnimationEnabled() || Math.abs(angularVelocity) < minimumAngularVelocity) { // notifying listeners that camera is idle only if there is no follow-up animation - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); return; } @@ -718,12 +718,12 @@ final class MapGestureDetector { @Override public void onAnimationCancel(Animator animation) { - cameraChangeDispatcher.onCameraIdle(); + transform.cancelTransitions(); } @Override public void onAnimationEnd(Animator animation) { - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); } }); @@ -738,7 +738,7 @@ final class MapGestureDetector { return false; } - transform.cancelTransitions(); + cancelTransitionsIfRequired(); sendTelemetryEvent(TelemetryConstants.PITCH, detector.getFocalPoint()); @@ -770,7 +770,7 @@ final class MapGestureDetector { @Override public void onShoveEnd(ShoveGestureDetector detector, float velocityX, float velocityY) { - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); // re-enabling move gesture gesturesManager.getMoveGestureDetector().setEnabled(true); @@ -835,7 +835,7 @@ final class MapGestureDetector { @Override public void onAnimationEnd(Animator animation) { - cameraChangeDispatcher.onCameraIdle(); + dispatchCameraIdle(); } }); return animator; @@ -880,6 +880,27 @@ final class MapGestureDetector { } } + private void dispatchCameraIdle() { + // we need to dispatch camera idle callback only if there is no other gestures in progress + if (noGesturesInProgress()) { + cameraChangeDispatcher.onCameraIdle(); + } + } + + private void cancelTransitionsIfRequired() { + // we need to cancel core transitions only if there is no started gesture yet + if (noGesturesInProgress()) { + transform.cancelTransitions(); + } + } + + private boolean noGesturesInProgress() { + return (!uiSettings.isScrollGesturesEnabled() || !gesturesManager.getMoveGestureDetector().isInProgress()) + && (!uiSettings.isZoomGesturesEnabled() || !gesturesManager.getStandardScaleGestureDetector().isInProgress()) + && (!uiSettings.isRotateGesturesEnabled() || !gesturesManager.getRotateGestureDetector().isInProgress()) + && (!uiSettings.isTiltGesturesEnabled() || !gesturesManager.getShoveGestureDetector().isInProgress()); + } + private void sendTelemetryEvent(String eventType, PointF focalPoint) { TelemetryDefinition telemetry = Mapbox.getTelemetry(); if (telemetry != null) { -- cgit v1.2.1