summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
diff options
context:
space:
mode:
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.java98
1 files changed, 53 insertions, 45 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 d82eec45ea..ec2b238ff4 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
@@ -6,6 +6,7 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.PointF;
import android.os.Handler;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.InputDevice;
import android.view.MotionEvent;
@@ -72,6 +73,7 @@ final class MapGestureDetector {
/**
* User-set focal point.
*/
+ @Nullable
private PointF focalPoint;
private AndroidGesturesManager gesturesManager;
@@ -85,9 +87,10 @@ final class MapGestureDetector {
* Cancels scheduled velocity animations if user doesn't lift fingers within
* {@link MapboxConstants#SCHEDULED_ANIMATION_TIMEOUT}
*/
+ @NonNull
private Handler animationsTimeoutHandler = new Handler();
- MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
+ MapGestureDetector(@Nullable Context context, Transform transform, Projection projection, UiSettings uiSettings,
AnnotationManager annotationManager, CameraChangeDispatcher cameraChangeDispatcher) {
this.annotationManager = annotationManager;
this.transform = transform;
@@ -106,7 +109,7 @@ final class MapGestureDetector {
}
}
- private void initializeGestureListeners(Context context, boolean attachDefaultListeners) {
+ private void initializeGestureListeners(@NonNull Context context, boolean attachDefaultListeners) {
if (attachDefaultListeners) {
StandardGestureListener standardGestureListener = new StandardGestureListener();
MoveGestureListener moveGestureListener = new MoveGestureListener();
@@ -128,7 +131,7 @@ final class MapGestureDetector {
}
}
- private void initializeGesturesManager(AndroidGesturesManager androidGesturesManager,
+ private void initializeGesturesManager(@NonNull AndroidGesturesManager androidGesturesManager,
boolean setDefaultMutuallyExclusives) {
if (setDefaultMutuallyExclusives) {
Set<Integer> shoveScaleSet = new HashSet<>();
@@ -158,7 +161,7 @@ final class MapGestureDetector {
*
* @param focalPoint the center point for gestures
*/
- void setFocalPoint(PointF focalPoint) {
+ void setFocalPoint(@Nullable PointF focalPoint) {
if (focalPoint == null) {
// resetting focal point,
if (uiSettings.getFocalPoint() != null) {
@@ -193,7 +196,7 @@ final class MapGestureDetector {
* @param motionEvent the MotionEvent
* @return True if touch event is handled
*/
- boolean onTouchEvent(MotionEvent motionEvent) {
+ boolean onTouchEvent(@Nullable MotionEvent motionEvent) {
// Framework can return null motion events in edge cases #9432
if (motionEvent == null) {
return false;
@@ -244,7 +247,7 @@ final class MapGestureDetector {
dispatchCameraIdle();
}
- private void cancelAnimator(Animator animator) {
+ private void cancelAnimator(@Nullable Animator animator) {
if (animator != null && animator.isStarted()) {
animator.cancel();
}
@@ -253,6 +256,7 @@ final class MapGestureDetector {
/**
* Posted on main thread with {@link #animationsTimeoutHandler}. Cancels all scheduled animators if needed.
*/
+ @NonNull
private Runnable cancelAnimatorsRunnable = new Runnable() {
@Override
public void run() {
@@ -427,7 +431,7 @@ final class MapGestureDetector {
private final class MoveGestureListener extends MoveGestureDetector.SimpleOnMoveGestureListener {
@Override
- public boolean onMoveBegin(MoveGestureDetector detector) {
+ public boolean onMoveBegin(@NonNull MoveGestureDetector detector) {
if (!uiSettings.isScrollGesturesEnabled()) {
return false;
}
@@ -439,7 +443,7 @@ final class MapGestureDetector {
}
@Override
- public boolean onMove(MoveGestureDetector detector, float distanceX, float distanceY) {
+ public boolean onMove(@NonNull MoveGestureDetector detector, float distanceX, float distanceY) {
// first move event is often delivered with no displacement
if (distanceX != 0 || distanceY != 0) {
// dispatching camera start event only when the movement actually occurred
@@ -454,7 +458,7 @@ final class MapGestureDetector {
}
@Override
- public void onMoveEnd(MoveGestureDetector detector, float velocityX, float velocityY) {
+ public void onMoveEnd(@NonNull MoveGestureDetector detector, float velocityX, float velocityY) {
dispatchCameraIdle();
notifyOnMoveEndListeners(detector);
}
@@ -464,6 +468,7 @@ final class MapGestureDetector {
private final float minimumVelocity;
+ @Nullable
private PointF scaleFocalPoint;
private boolean quickZoom;
@@ -472,7 +477,7 @@ final class MapGestureDetector {
}
@Override
- public boolean onScaleBegin(StandardScaleGestureDetector detector) {
+ public boolean onScaleBegin(@NonNull StandardScaleGestureDetector detector) {
if (!uiSettings.isZoomGesturesEnabled()) {
return false;
}
@@ -505,7 +510,7 @@ final class MapGestureDetector {
}
@Override
- public boolean onScale(StandardScaleGestureDetector detector) {
+ public boolean onScale(@NonNull StandardScaleGestureDetector detector) {
// dispatching camera start event only when the movement actually occurred
cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_GESTURE);
@@ -521,7 +526,7 @@ final class MapGestureDetector {
}
@Override
- public void onScaleEnd(StandardScaleGestureDetector detector, float velocityX, float velocityY) {
+ public void onScaleEnd(@NonNull StandardScaleGestureDetector detector, float velocityX, float velocityY) {
if (quickZoom) {
//if quickzoom, re-enabling move gesture detector
gesturesManager.getMoveGestureDetector().setEnabled(true);
@@ -551,7 +556,7 @@ final class MapGestureDetector {
scheduleAnimator(scaleAnimator);
}
- private void setScaleFocalPoint(StandardScaleGestureDetector detector) {
+ private void setScaleFocalPoint(@NonNull StandardScaleGestureDetector detector) {
if (focalPoint != null) {
// around user provided focal point
scaleFocalPoint = focalPoint;
@@ -587,6 +592,7 @@ final class MapGestureDetector {
}
private final class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
+ @Nullable
private PointF rotateFocalPoint;
private final float minimumScaleSpanWhenRotating;
private final float minimumAngularVelocity;
@@ -600,7 +606,7 @@ final class MapGestureDetector {
}
@Override
- public boolean onRotateBegin(RotateGestureDetector detector) {
+ public boolean onRotateBegin(@NonNull RotateGestureDetector detector) {
if (!uiSettings.isRotateGesturesEnabled()) {
return false;
}
@@ -625,7 +631,7 @@ final class MapGestureDetector {
}
@Override
- public boolean onRotate(RotateGestureDetector detector, float rotationDegreesSinceLast,
+ public boolean onRotate(@NonNull RotateGestureDetector detector, float rotationDegreesSinceLast,
float rotationDegreesSinceFirst) {
// dispatching camera start event only when the movement actually occurred
cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_GESTURE);
@@ -644,7 +650,8 @@ final class MapGestureDetector {
}
@Override
- public void onRotateEnd(RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity) {
+ public void onRotateEnd(@NonNull RotateGestureDetector detector, float velocityX,
+ float velocityY, float angularVelocity) {
if (uiSettings.isIncreaseScaleThresholdWhenRotating()) {
// resetting default scale threshold values
gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(defaultSpanSinceStartThreshold);
@@ -673,7 +680,7 @@ final class MapGestureDetector {
scheduleAnimator(rotateAnimator);
}
- private void setRotateFocalPoint(RotateGestureDetector detector) {
+ private void setRotateFocalPoint(@NonNull RotateGestureDetector detector) {
if (focalPoint != null) {
// User provided focal point
rotateFocalPoint = focalPoint;
@@ -689,7 +696,7 @@ final class MapGestureDetector {
animator.setInterpolator(new DecelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
- public void onAnimationUpdate(ValueAnimator animation) {
+ public void onAnimationUpdate(@NonNull ValueAnimator animation) {
transform.setBearing(
transform.getRawBearing() + (float) animation.getAnimatedValue(),
rotateFocalPoint.x, rotateFocalPoint.y,
@@ -723,7 +730,7 @@ final class MapGestureDetector {
private final class ShoveGestureListener extends ShoveGestureDetector.SimpleOnShoveGestureListener {
@Override
- public boolean onShoveBegin(ShoveGestureDetector detector) {
+ public boolean onShoveBegin(@NonNull ShoveGestureDetector detector) {
if (!uiSettings.isTiltGesturesEnabled()) {
return false;
}
@@ -741,7 +748,8 @@ final class MapGestureDetector {
}
@Override
- public boolean onShove(ShoveGestureDetector detector, float deltaPixelsSinceLast, float deltaPixelsSinceStart) {
+ public boolean onShove(@NonNull ShoveGestureDetector detector,
+ float deltaPixelsSinceLast, float deltaPixelsSinceStart) {
// dispatching camera start event only when the movement actually occurred
cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_GESTURE);
@@ -759,7 +767,7 @@ final class MapGestureDetector {
}
@Override
- public void onShoveEnd(ShoveGestureDetector detector, float velocityX, float velocityY) {
+ public void onShoveEnd(@NonNull ShoveGestureDetector detector, float velocityX, float velocityY) {
dispatchCameraIdle();
// re-enabling move gesture
@@ -771,7 +779,7 @@ final class MapGestureDetector {
private final class TapGestureListener implements MultiFingerTapGestureDetector.OnMultiFingerTapGestureListener {
@Override
- public boolean onMultiFingerTap(MultiFingerTapGestureDetector detector, int pointersCount) {
+ public boolean onMultiFingerTap(@NonNull MultiFingerTapGestureDetector detector, int pointersCount) {
if (!uiSettings.isZoomGesturesEnabled() || pointersCount != 2) {
return false;
}
@@ -797,15 +805,15 @@ final class MapGestureDetector {
}
}
- private Animator createScaleAnimator(double currentZoom, double zoomAddition, final PointF animationFocalPoint,
- long animationTime) {
+ private Animator createScaleAnimator(double currentZoom, double zoomAddition,
+ @NonNull final PointF animationFocalPoint, long animationTime) {
ValueAnimator animator = ValueAnimator.ofFloat((float) currentZoom, (float) (currentZoom + zoomAddition));
animator.setDuration(animationTime);
animator.setInterpolator(new DecelerateInterpolator());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
- public void onAnimationUpdate(ValueAnimator animation) {
+ public void onAnimationUpdate(@NonNull ValueAnimator animation) {
transform.setZoom((Float) animation.getAnimatedValue(), animationFocalPoint);
}
});
@@ -838,7 +846,7 @@ final class MapGestureDetector {
* @param runImmediately if true, animation will be started right away, otherwise it will wait until
* {@link MotionEvent#ACTION_UP} is registered.
*/
- void zoomInAnimated(PointF zoomFocalPoint, boolean runImmediately) {
+ void zoomInAnimated(@NonNull PointF zoomFocalPoint, boolean runImmediately) {
zoomAnimated(true, zoomFocalPoint, runImmediately);
}
@@ -849,11 +857,11 @@ final class MapGestureDetector {
* @param runImmediately if true, animation will be started right away, otherwise it will wait until
* {@link MotionEvent#ACTION_UP} is registered.
*/
- void zoomOutAnimated(PointF zoomFocalPoint, boolean runImmediately) {
+ void zoomOutAnimated(@NonNull PointF zoomFocalPoint, boolean runImmediately) {
zoomAnimated(false, zoomFocalPoint, runImmediately);
}
- private void zoomAnimated(boolean zoomIn, PointF zoomFocalPoint, boolean runImmediately) {
+ private void zoomAnimated(boolean zoomIn, @NonNull PointF zoomFocalPoint, boolean runImmediately) {
//canceling here as well, because when using a button it will not be canceled automatically by onDown()
cancelAnimator(scaleAnimator);
@@ -891,7 +899,7 @@ final class MapGestureDetector {
&& (!uiSettings.isTiltGesturesEnabled() || !gesturesManager.getShoveGestureDetector().isInProgress());
}
- private void sendTelemetryEvent(String eventType, PointF focalPoint) {
+ private void sendTelemetryEvent(String eventType, @NonNull PointF focalPoint) {
TelemetryDefinition telemetry = Mapbox.getTelemetry();
if (telemetry != null) {
CameraPosition cameraPosition = transform.getCameraPosition();
@@ -909,7 +917,7 @@ final class MapGestureDetector {
return mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM;
}
- void notifyOnMapClickListeners(PointF tapPoint) {
+ void notifyOnMapClickListeners(@NonNull PointF tapPoint) {
for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
if (listener.onMapClick(projection.fromScreenLocation(tapPoint))) {
return;
@@ -917,7 +925,7 @@ final class MapGestureDetector {
}
}
- void notifyOnMapLongClickListeners(PointF longClickPoint) {
+ void notifyOnMapLongClickListeners(@NonNull PointF longClickPoint) {
for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
if (listener.onMapLongClick(projection.fromScreenLocation(longClickPoint))) {
return;
@@ -931,73 +939,73 @@ final class MapGestureDetector {
}
}
- void notifyOnMoveBeginListeners(MoveGestureDetector detector) {
+ void notifyOnMoveBeginListeners(@NonNull MoveGestureDetector detector) {
for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
listener.onMoveBegin(detector);
}
}
- void notifyOnMoveListeners(MoveGestureDetector detector) {
+ void notifyOnMoveListeners(@NonNull MoveGestureDetector detector) {
for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
listener.onMove(detector);
}
}
- void notifyOnMoveEndListeners(MoveGestureDetector detector) {
+ void notifyOnMoveEndListeners(@NonNull MoveGestureDetector detector) {
for (MapboxMap.OnMoveListener listener : onMoveListenerList) {
listener.onMoveEnd(detector);
}
}
- void notifyOnRotateBeginListeners(RotateGestureDetector detector) {
+ void notifyOnRotateBeginListeners(@NonNull RotateGestureDetector detector) {
for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
listener.onRotateBegin(detector);
}
}
- void notifyOnRotateListeners(RotateGestureDetector detector) {
+ void notifyOnRotateListeners(@NonNull RotateGestureDetector detector) {
for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
listener.onRotate(detector);
}
}
- void notifyOnRotateEndListeners(RotateGestureDetector detector) {
+ void notifyOnRotateEndListeners(@NonNull RotateGestureDetector detector) {
for (MapboxMap.OnRotateListener listener : onRotateListenerList) {
listener.onRotateEnd(detector);
}
}
- void notifyOnScaleBeginListeners(StandardScaleGestureDetector detector) {
+ void notifyOnScaleBeginListeners(@NonNull StandardScaleGestureDetector detector) {
for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
listener.onScaleBegin(detector);
}
}
- void notifyOnScaleListeners(StandardScaleGestureDetector detector) {
+ void notifyOnScaleListeners(@NonNull StandardScaleGestureDetector detector) {
for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
listener.onScale(detector);
}
}
- void notifyOnScaleEndListeners(StandardScaleGestureDetector detector) {
+ void notifyOnScaleEndListeners(@NonNull StandardScaleGestureDetector detector) {
for (MapboxMap.OnScaleListener listener : onScaleListenerList) {
listener.onScaleEnd(detector);
}
}
- void notifyOnShoveBeginListeners(ShoveGestureDetector detector) {
+ void notifyOnShoveBeginListeners(@NonNull ShoveGestureDetector detector) {
for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
listener.onShoveBegin(detector);
}
}
- void notifyOnShoveListeners(ShoveGestureDetector detector) {
+ void notifyOnShoveListeners(@NonNull ShoveGestureDetector detector) {
for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
listener.onShove(detector);
}
}
- void notifyOnShoveEndListeners(ShoveGestureDetector detector) {
+ void notifyOnShoveEndListeners(@NonNull ShoveGestureDetector detector) {
for (MapboxMap.OnShoveListener listener : onShoveListenerList) {
listener.onShoveEnd(detector);
}
@@ -1063,8 +1071,8 @@ final class MapGestureDetector {
return gesturesManager;
}
- void setGesturesManager(Context context, AndroidGesturesManager gesturesManager, boolean attachDefaultListeners,
- boolean setDefaultMutuallyExclusives) {
+ void setGesturesManager(@NonNull Context context, @NonNull AndroidGesturesManager gesturesManager,
+ boolean attachDefaultListeners, boolean setDefaultMutuallyExclusives) {
initializeGesturesManager(gesturesManager, setDefaultMutuallyExclusives);
initializeGestureListeners(context, attachDefaultListeners);
}