[android] separate quick zoom gestures option
This commit is contained in:
committed by
Łukasz Paczos
parent
8fedfbf160
commit
be94efa402
@@ -130,6 +130,7 @@ public class MapboxConstants {
|
||||
public static final String STATE_ROTATE_ENABLED = "mapbox_rotateEnabled";
|
||||
public static final String STATE_TILT_ENABLED = "mapbox_tiltEnabled";
|
||||
public static final String STATE_DOUBLE_TAP_ENABLED = "mapbox_doubleTapEnabled";
|
||||
public static final String STATE_QUICK_ZOOM_ENABLED = "mapbox_quickZoom";
|
||||
public static final String STATE_DEBUG_ACTIVE = "mapbox_debugActive";
|
||||
public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled";
|
||||
public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity";
|
||||
@@ -158,5 +159,4 @@ public class MapboxConstants {
|
||||
public static final String STATE_FLING_ANIMATION_ENABLED = "mapbox_flingAnimationEnabled";
|
||||
public static final String STATE_INCREASE_ROTATE_THRESHOLD = "mapbox_increaseRotateThreshold";
|
||||
public static final String STATE_INCREASE_SCALE_THRESHOLD = "mapbox_increaseScaleThreshold";
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ final class MapGestureDetector {
|
||||
private PointF focalPoint;
|
||||
|
||||
private AndroidGesturesManager gesturesManager;
|
||||
private boolean executeDoubleTap;
|
||||
|
||||
private Animator scaleAnimator;
|
||||
private Animator rotateAnimator;
|
||||
@@ -208,13 +207,14 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
cancelAnimators();
|
||||
transform.setGestureInProgress(true);
|
||||
}
|
||||
|
||||
boolean result = gesturesManager.onTouchEvent(motionEvent);
|
||||
|
||||
switch (motionEvent.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
cancelAnimators();
|
||||
transform.setGestureInProgress(true);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
transform.setGestureInProgress(false);
|
||||
|
||||
@@ -257,7 +257,7 @@ final class MapGestureDetector {
|
||||
* Posted on main thread with {@link #animationsTimeoutHandler}. Cancels all scheduled animators if needed.
|
||||
*/
|
||||
@NonNull
|
||||
private Runnable cancelAnimatorsRunnable = new Runnable() {
|
||||
private final Runnable cancelAnimatorsRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cancelAnimators();
|
||||
@@ -353,16 +353,10 @@ final class MapGestureDetector {
|
||||
public boolean onDoubleTapEvent(MotionEvent motionEvent) {
|
||||
int action = motionEvent.getActionMasked();
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
executeDoubleTap = true;
|
||||
}
|
||||
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled() || !executeDoubleTap) {
|
||||
if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
transform.cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
|
||||
PointF zoomFocalPoint;
|
||||
// Single finger double tap
|
||||
if (focalPoint != null) {
|
||||
@@ -374,11 +368,13 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
zoomInAnimated(zoomFocalPoint, false);
|
||||
}
|
||||
|
||||
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
|
||||
sendTelemetryEvent(TelemetryConstants.DOUBLE_TAP, new PointF(motionEvent.getX(), motionEvent.getY()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onDoubleTapEvent(motionEvent);
|
||||
}
|
||||
|
||||
@@ -482,15 +478,16 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
cancelTransitionsIfRequired();
|
||||
|
||||
quickZoom = detector.getPointersCount() == 1;
|
||||
if (quickZoom) {
|
||||
// when quickzoom, dismiss double tap and disable move gesture
|
||||
executeDoubleTap = false;
|
||||
if (!uiSettings.isQuickZoomGesturesEnabled()) {
|
||||
return false;
|
||||
}
|
||||
gesturesManager.getMoveGestureDetector().setEnabled(false);
|
||||
}
|
||||
|
||||
cancelTransitionsIfRequired();
|
||||
|
||||
if (uiSettings.isIncreaseRotateThresholdWhenScaling()) {
|
||||
// increase rotate angle threshold when scale is detected first
|
||||
gesturesManager.getRotateGestureDetector().setAngleThreshold(
|
||||
|
||||
@@ -64,6 +64,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private boolean tiltGesturesEnabled = true;
|
||||
private boolean zoomGesturesEnabled = true;
|
||||
private boolean doubleTapGesturesEnabled = true;
|
||||
private boolean quickZoomGesturesEnabled = true;
|
||||
|
||||
private boolean prefetchesTiles = true;
|
||||
private boolean zMediaOverlay = false;
|
||||
@@ -118,6 +119,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
tiltGesturesEnabled = in.readByte() != 0;
|
||||
zoomGesturesEnabled = in.readByte() != 0;
|
||||
doubleTapGesturesEnabled = in.readByte() != 0;
|
||||
quickZoomGesturesEnabled = in.readByte() != 0;
|
||||
|
||||
apiBaseUrl = in.readString();
|
||||
textureMode = in.readByte() != 0;
|
||||
@@ -505,6 +507,18 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether the user may zoom the map by tapping twice, holding and moving the pointer up and down.
|
||||
*
|
||||
* @param enabled True and gesture will be enabled
|
||||
* @return This
|
||||
*/
|
||||
@NonNull
|
||||
public MapboxMapOptions quickZoomGesturesEnabled(boolean enabled) {
|
||||
quickZoomGesturesEnabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable {@link android.view.TextureView} as rendered surface.
|
||||
* <p>
|
||||
@@ -790,6 +804,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return doubleTapGesturesEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the user may zoom the map by tapping twice, holding and moving the pointer up and down.
|
||||
*
|
||||
* @return True indicates gesture is enabled
|
||||
*/
|
||||
public boolean getQuickZoomGesturesEnabled() {
|
||||
return quickZoomGesturesEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured visibility state for attribution for a map view.
|
||||
*
|
||||
@@ -922,6 +945,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
dest.writeByte((byte) (tiltGesturesEnabled ? 1 : 0));
|
||||
dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0));
|
||||
dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0));
|
||||
dest.writeByte((byte) (quickZoomGesturesEnabled ? 1 : 0));
|
||||
|
||||
dest.writeString(apiBaseUrl);
|
||||
dest.writeByte((byte) (textureMode ? 1 : 0));
|
||||
@@ -998,6 +1022,9 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (doubleTapGesturesEnabled != options.doubleTapGesturesEnabled) {
|
||||
return false;
|
||||
}
|
||||
if (quickZoomGesturesEnabled != options.quickZoomGesturesEnabled) {
|
||||
return false;
|
||||
}
|
||||
if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null) {
|
||||
return false;
|
||||
}
|
||||
@@ -1061,6 +1088,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
result = 31 * result + (tiltGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (zoomGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (doubleTapGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (quickZoomGesturesEnabled ? 1 : 0);
|
||||
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
|
||||
result = 31 * result + (textureMode ? 1 : 0);
|
||||
result = 31 * result + (translucentTextureSurface ? 1 : 0);
|
||||
|
||||
@@ -58,6 +58,8 @@ public final class UiSettings {
|
||||
|
||||
private boolean doubleTapGesturesEnabled = true;
|
||||
|
||||
private boolean quickZoomGesturesEnabled = true;
|
||||
|
||||
private boolean scaleVelocityAnimationEnabled = true;
|
||||
private boolean rotateVelocityAnimationEnabled = true;
|
||||
private boolean flingVelocityAnimationEnabled = true;
|
||||
@@ -113,6 +115,7 @@ public final class UiSettings {
|
||||
setRotateGesturesEnabled(options.getRotateGesturesEnabled());
|
||||
setTiltGesturesEnabled(options.getTiltGesturesEnabled());
|
||||
setDoubleTapGesturesEnabled(options.getDoubleTapGesturesEnabled());
|
||||
setQuickZoomGesturesEnabled(options.getQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
private void saveGestures(Bundle outState) {
|
||||
@@ -126,6 +129,7 @@ public final class UiSettings {
|
||||
outState.putBoolean(MapboxConstants.STATE_FLING_ANIMATION_ENABLED, isFlingVelocityAnimationEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD, isIncreaseRotateThresholdWhenScaling());
|
||||
outState.putBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD, isIncreaseScaleThresholdWhenRotating());
|
||||
outState.putBoolean(MapboxConstants.STATE_QUICK_ZOOM_ENABLED, isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
private void restoreGestures(Bundle savedInstanceState) {
|
||||
@@ -141,6 +145,7 @@ public final class UiSettings {
|
||||
savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD));
|
||||
setIncreaseScaleThresholdWhenRotating(
|
||||
savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD));
|
||||
setQuickZoomGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_QUICK_ZOOM_ENABLED));
|
||||
}
|
||||
|
||||
private void initialiseCompass(MapboxMapOptions options, @NonNull Resources resources) {
|
||||
@@ -730,6 +735,29 @@ public final class UiSettings {
|
||||
return doubleTapGesturesEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the user may zoom the map by tapping twice, holding and moving the pointer up and down.
|
||||
*
|
||||
* @return If true, zooming by tapping twice and holding is enabled.
|
||||
*/
|
||||
public boolean isQuickZoomGesturesEnabled() {
|
||||
return quickZoomGesturesEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes whether the user may zoom the map by tapping twice, holding and moving the pointer up and down.
|
||||
* <p>
|
||||
* This setting controls only user interactions with the map. If you set the value to false,
|
||||
* you may still change the map location programmatically.
|
||||
* </p>
|
||||
* The default value is true.
|
||||
*
|
||||
* @param quickZoomGesturesEnabled If true, zooming by tapping twice and holding is enabled.
|
||||
*/
|
||||
public void setQuickZoomGesturesEnabled(boolean quickZoomGesturesEnabled) {
|
||||
this.quickZoomGesturesEnabled = quickZoomGesturesEnabled;
|
||||
}
|
||||
|
||||
private void restoreDeselectMarkersOnTap(Bundle savedInstanceState) {
|
||||
setDeselectMarkersOnTap(savedInstanceState.getBoolean(MapboxConstants.STATE_DESELECT_MARKER_ON_TAP));
|
||||
}
|
||||
@@ -899,6 +927,8 @@ public final class UiSettings {
|
||||
* @see #setScrollGesturesEnabled(boolean)
|
||||
* @see #setRotateGesturesEnabled(boolean)
|
||||
* @see #setTiltGesturesEnabled(boolean)
|
||||
* @see #setDoubleTapGesturesEnabled(boolean)
|
||||
* @see #setQuickZoomGesturesEnabled(boolean)
|
||||
*/
|
||||
public void setAllGesturesEnabled(boolean enabled) {
|
||||
setScrollGesturesEnabled(enabled);
|
||||
@@ -906,6 +936,7 @@ public final class UiSettings {
|
||||
setTiltGesturesEnabled(enabled);
|
||||
setZoomGesturesEnabled(enabled);
|
||||
setDoubleTapGesturesEnabled(enabled);
|
||||
setQuickZoomGesturesEnabled(enabled);
|
||||
}
|
||||
|
||||
private void saveFocalPoint(Bundle outState) {
|
||||
|
||||
@@ -248,6 +248,26 @@ public class UiSettingsTest {
|
||||
assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesEnabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be enabled", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesDisabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be disabled", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGestureChangeAllowed() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be false", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be true", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesEnabled() {
|
||||
uiSettings.setScrollGesturesEnabled(true);
|
||||
|
||||
@@ -30,8 +30,8 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.UiSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.FontCache;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
@@ -66,18 +66,15 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gesture_detector);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
GestureDetectorActivity.this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
initializeMap();
|
||||
}
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
GestureDetectorActivity.this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
initializeMap();
|
||||
});
|
||||
|
||||
recyclerView = (RecyclerView) findViewById(R.id.alerts_recycler);
|
||||
recyclerView = findViewById(R.id.alerts_recycler);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
gestureAlertsAdapter = new GestureAlertsAdapter();
|
||||
@@ -127,6 +124,11 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
private void initializeMap() {
|
||||
gesturesManager = mapboxMap.getGesturesManager();
|
||||
|
||||
@@ -136,47 +138,50 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
recyclerView.setLayoutParams(layoutParams);
|
||||
|
||||
attachListeners();
|
||||
|
||||
focusOnAPoint(mapboxMap.getUiSettings().getFocalPoint() != null);
|
||||
}
|
||||
|
||||
public void attachListeners() {
|
||||
mapboxMap.addOnMoveListener(new MapboxMap.OnMoveListener() {
|
||||
@Override
|
||||
public void onMoveBegin(MoveGestureDetector detector) {
|
||||
public void onMoveBegin(@NonNull MoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_START, "MOVE START"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(MoveGestureDetector detector) {
|
||||
public void onMove(@NonNull MoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_PROGRESS, "MOVE PROGRESS"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoveEnd(MoveGestureDetector detector) {
|
||||
public void onMoveEnd(@NonNull MoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_END, "MOVE END"));
|
||||
recalculateFocalPoint();
|
||||
}
|
||||
});
|
||||
|
||||
mapboxMap.addOnRotateListener(new MapboxMap.OnRotateListener() {
|
||||
@Override
|
||||
public void onRotateBegin(RotateGestureDetector detector) {
|
||||
public void onRotateBegin(@NonNull RotateGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_START, "ROTATE START"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRotate(RotateGestureDetector detector) {
|
||||
public void onRotate(@NonNull RotateGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_PROGRESS, "ROTATE PROGRESS"));
|
||||
recalculateFocalPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRotateEnd(RotateGestureDetector detector) {
|
||||
public void onRotateEnd(@NonNull RotateGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_END, "ROTATE END"));
|
||||
}
|
||||
});
|
||||
|
||||
mapboxMap.addOnScaleListener(new MapboxMap.OnScaleListener() {
|
||||
@Override
|
||||
public void onScaleBegin(StandardScaleGestureDetector detector) {
|
||||
public void onScaleBegin(@NonNull StandardScaleGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_START, "SCALE START"));
|
||||
if (focalPointLatLng != null) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_OTHER, "INCREASING MOVE THRESHOLD"));
|
||||
@@ -190,12 +195,12 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScale(StandardScaleGestureDetector detector) {
|
||||
public void onScale(@NonNull StandardScaleGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_PROGRESS, "SCALE PROGRESS"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleEnd(StandardScaleGestureDetector detector) {
|
||||
public void onScaleEnd(@NonNull StandardScaleGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_END, "SCALE END"));
|
||||
|
||||
if (focalPointLatLng != null) {
|
||||
@@ -207,17 +212,17 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
|
||||
mapboxMap.addOnShoveListener(new MapboxMap.OnShoveListener() {
|
||||
@Override
|
||||
public void onShoveBegin(ShoveGestureDetector detector) {
|
||||
public void onShoveBegin(@NonNull ShoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_START, "SHOVE START"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShove(ShoveGestureDetector detector) {
|
||||
public void onShove(@NonNull ShoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_PROGRESS, "SHOVE PROGRESS"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShoveEnd(ShoveGestureDetector detector) {
|
||||
public void onShoveEnd(@NonNull ShoveGestureDetector detector) {
|
||||
gestureAlertsAdapter.addAlert(new GestureAlert(GestureAlert.TYPE_END, "SHOVE END"));
|
||||
}
|
||||
});
|
||||
@@ -231,31 +236,50 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
resetModes();
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_gesture_none:
|
||||
return true;
|
||||
case R.id.menu_gesture_focus_point:
|
||||
focalPointLatLng = new LatLng(51.50325, -0.12968);
|
||||
marker = mapboxMap.addMarker(new MarkerOptions().position(focalPointLatLng));
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(focalPointLatLng, 16));
|
||||
mapboxMap.getUiSettings().setFocalPoint(mapboxMap.getProjection().toScreenLocation(focalPointLatLng));
|
||||
focusOnAPoint(focalPointLatLng == null);
|
||||
return true;
|
||||
case R.id.menu_gesture_animation:
|
||||
mapboxMap.getUiSettings().setAllVelocityAnimationsEnabled(false);
|
||||
uiSettings.setScaleVelocityAnimationEnabled(!uiSettings.isScaleVelocityAnimationEnabled());
|
||||
uiSettings.setRotateVelocityAnimationEnabled(!uiSettings.isRotateGesturesEnabled());
|
||||
uiSettings.setFlingVelocityAnimationEnabled(!uiSettings.isFlingVelocityAnimationEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_rotate:
|
||||
uiSettings.setRotateGesturesEnabled(!uiSettings.isRotateGesturesEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_tilt:
|
||||
uiSettings.setTiltGesturesEnabled(!uiSettings.isTiltGesturesEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_zoom:
|
||||
uiSettings.setZoomGesturesEnabled(!uiSettings.isZoomGesturesEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_scroll:
|
||||
uiSettings.setScrollGesturesEnabled(!uiSettings.isScrollGesturesEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_double_tap:
|
||||
uiSettings.setDoubleTapGesturesEnabled(!uiSettings.isDoubleTapGesturesEnabled());
|
||||
return true;
|
||||
case R.id.menu_gesture_quick_zoom:
|
||||
uiSettings.setQuickZoomGesturesEnabled(!uiSettings.isQuickZoomGesturesEnabled());
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void resetModes() {
|
||||
focalPointLatLng = null;
|
||||
mapboxMap.getUiSettings().setFocalPoint(null);
|
||||
gesturesManager.getMoveGestureDetector().setMoveThreshold(0f);
|
||||
mapboxMap.getUiSettings().setAllVelocityAnimationsEnabled(true);
|
||||
|
||||
if (marker != null) {
|
||||
mapboxMap.removeMarker(marker);
|
||||
marker = null;
|
||||
private void focusOnAPoint(boolean focus) {
|
||||
if (focus) {
|
||||
focalPointLatLng = new LatLng(51.50325, -0.12968);
|
||||
marker = mapboxMap.addMarker(new MarkerOptions().position(focalPointLatLng));
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(focalPointLatLng, 16));
|
||||
} else {
|
||||
if (marker != null) {
|
||||
mapboxMap.removeMarker(marker);
|
||||
marker = null;
|
||||
}
|
||||
focalPointLatLng = null;
|
||||
mapboxMap.getUiSettings().setFocalPoint(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,20 +307,21 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
Typeface typeface = FontCache.get("Roboto-Regular.ttf", view.getContext());
|
||||
alertMessageTv = (TextView) view.findViewById(R.id.alert_message);
|
||||
alertMessageTv = view.findViewById(R.id.alert_message);
|
||||
alertMessageTv.setTypeface(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gesture_alert, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
GestureAlert alert = alerts.get(position);
|
||||
holder.alertMessageTv.setText(alert.getMessage());
|
||||
holder.alertMessageTv.setTextColor(
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/menu_gesture_none"
|
||||
android:title="None" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_focus_point"
|
||||
android:title="Focus on a point" />
|
||||
android:title="Toggle focus on a point" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_animation"
|
||||
android:title="Turn off velocity animations" />
|
||||
android:title="Toggle velocity animations" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_rotate"
|
||||
android:title="Toggle rotate enabled" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_tilt"
|
||||
android:title="Toggle tilt enabled" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_zoom"
|
||||
android:title="Toggle zoom enabled" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_scroll"
|
||||
android:title="Toggle scroll enabled" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_double_tap"
|
||||
android:title="Toggle double tap enabled" />
|
||||
<item
|
||||
android:id="@+id/menu_gesture_quick_zoom"
|
||||
android:title="Toggle quick zoom enabled" />
|
||||
</menu>
|
||||
Reference in New Issue
Block a user