Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Expose LocationComponentOptions#trackingMultiFingerProtectedMoveArea
Browse files Browse the repository at this point in the history
This option provides a way of defining a protected area on the screen which prevents breaking the camera location when executing a multi finger gesture as long as the focal point of the gesture is within this area.
  • Loading branch information
Łukasz Paczos committed Apr 29, 2020
1 parent 5d64f0d commit 504c2ba
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import android.content.Context;
import android.graphics.PointF;
import android.graphics.RectF;
import android.location.Location;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import android.view.MotionEvent;

import com.mapbox.android.gestures.AndroidGesturesManager;
import com.mapbox.android.gestures.MoveGestureDetector;
Expand Down Expand Up @@ -314,6 +316,7 @@ private void adjustGesturesThresholds() {
moveGestureDetector.setMoveThreshold(options.trackingInitialMoveThreshold());
} else {
moveGestureDetector.setMoveThreshold(0f);
moveGestureDetector.setMoveThresholdRect(null);
}
}
}
Expand Down Expand Up @@ -359,17 +362,43 @@ private void notifyCameraTrackingChangeListener(boolean wasTracking) {

@Override
public void onMoveBegin(@NonNull MoveGestureDetector detector) {
if (options.trackingGesturesManagement()
&& detector.getPointersCount() > 1
&& detector.getMoveThreshold() != options.trackingMultiFingerMoveThreshold()
&& isLocationTracking()) {
detector.setMoveThreshold(options.trackingMultiFingerMoveThreshold());
interrupt = true;
if (options.trackingGesturesManagement() && isLocationTracking()) {
if (detector.getPointersCount() > 1) {
applyMultiFingerThresholdArea(detector);
applyMultiFingerMoveThreshold(detector);
} else {
applySingleFingerMoveThreshold(detector);
}
} else {
setCameraMode(CameraMode.NONE);
}
}

private void applyMultiFingerThresholdArea(@NonNull MoveGestureDetector detector) {
RectF currentRect = detector.getMoveThresholdRect();
if (currentRect != null && !currentRect.equals(options.trackingMultiFingerProtectedMoveArea())) {
detector.setMoveThresholdRect(options.trackingMultiFingerProtectedMoveArea());
interrupt = true;
} else if (currentRect == null && options.trackingMultiFingerProtectedMoveArea() != null) {
detector.setMoveThresholdRect(options.trackingMultiFingerProtectedMoveArea());
interrupt = true;
}
}

private void applyMultiFingerMoveThreshold(@NonNull MoveGestureDetector detector) {
if (detector.getMoveThreshold() != options.trackingMultiFingerMoveThreshold()) {
detector.setMoveThreshold(options.trackingMultiFingerMoveThreshold());
interrupt = true;
}
}

private void applySingleFingerMoveThreshold(@NonNull MoveGestureDetector detector) {
if (detector.getMoveThreshold() != options.trackingInitialMoveThreshold()) {
detector.setMoveThreshold(options.trackingInitialMoveThreshold());
interrupt = true;
}
}

@Override
public void onMove(@NonNull MoveGestureDetector detector) {
if (interrupt) {
Expand All @@ -387,6 +416,7 @@ public void onMove(@NonNull MoveGestureDetector detector) {
public void onMoveEnd(@NonNull MoveGestureDetector detector) {
if (options.trackingGesturesManagement() && !interrupt && isLocationTracking()) {
detector.setMoveThreshold(options.trackingInitialMoveThreshold());
detector.setMoveThresholdRect(null);
}
interrupt = false;
}
Expand Down
Loading

0 comments on commit 504c2ba

Please sign in to comment.