[android] #4924 - Make Gesture Focal Point Configurable

This commit is contained in:
Tobrun Van Nuland
2016-06-13 14:11:18 +02:00
committed by Brad Leege
parent 7c213e3cd0
commit b3467a555a
3 changed files with 69 additions and 25 deletions

View File

@@ -152,6 +152,8 @@ public class MapView extends FrameLayout {
private int mContentPaddingRight;
private int mContentPaddingBottom;
private PointF mFocalPoint;
private StyleInitializer mStyleInitializer;
private List<OnMapReadyCallback> mOnMapReadyCallbackList;
@@ -566,6 +568,18 @@ public class MapView extends FrameLayout {
}
}
void setFocalPoint(PointF focalPoint) {
if (focalPoint == null) {
// resetting focal point,
UiSettings uiSettings = mMapboxMap.getUiSettings();
// need to validate if we need to reset focal point with user provided one
if (uiSettings.getFocalPoint() != null) {
focalPoint = uiSettings.getFocalPoint();
}
}
mFocalPoint = focalPoint;
}
/**
* You must call this method from the parent's {@link Activity#onLowMemory()} or {@link Fragment#onLowMemory()}.
*/
@@ -1548,8 +1562,12 @@ public class MapView extends FrameLayout {
|| mShoveGestureDetector.isInProgress();
if (mTwoTap && isTap && !inProgress) {
PointF focalPoint = TwoFingerGestureDetector.determineFocalPoint(event);
zoom(false, focalPoint.x, focalPoint.y);
if (mFocalPoint != null) {
zoom(false, mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else {
PointF focalPoint = TwoFingerGestureDetector.determineFocalPoint(event);
zoom(false, focalPoint.x, focalPoint.y);
}
mTwoTap = false;
return true;
}
@@ -1608,12 +1626,12 @@ public class MapView extends FrameLayout {
}
// Single finger double tap
if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// User provided focal point
zoom(true, mFocalPoint.x, mFocalPoint.y);
} else {
// Zoom in on gesture
zoom(true, e.getX(), e.getY());
} else {
// Zoom in on user location view
zoom(true, mMyLocationView.getCenterX(), mMyLocationView.getCenterY());
}
break;
}
@@ -1839,23 +1857,18 @@ public class MapView extends FrameLayout {
// Gesture is a quickzoom if there aren't two fingers
mQuickZoom = !mTwoTap;
TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
// Scale the map
if (uiSettings.isScrollGesturesEnabled() && !mQuickZoom && trackingSettings.isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// arround user provided focal point
mNativeMapView.scaleBy(detector.getScaleFactor(), mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else if (mQuickZoom) {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
} else {
// around gesture
mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity);
} else {
if (trackingSettings.isLocationTrackingDisabled()) {
// around center map
mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity);
} else {
// around user location view
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
mNativeMapView.scaleBy(detector.getScaleFactor(), x / mScreenDensity, y / mScreenDensity);
}
}
return true;
}
}
@@ -1925,16 +1938,14 @@ public class MapView extends FrameLayout {
bearing += detector.getRotationDegreesDelta();
// Rotate the map
if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) {
if (mFocalPoint != null) {
// User provided focal point
mNativeMapView.setBearing(bearing, mFocalPoint.x / mScreenDensity, mFocalPoint.y / mScreenDensity);
} else {
// around gesture
mNativeMapView.setBearing(bearing,
detector.getFocusX() / mScreenDensity,
detector.getFocusY() / mScreenDensity);
} else {
// around center userlocation
float x = mMyLocationView.getX() + mMyLocationView.getWidth() / 2;
float y = mMyLocationView.getY() + mMyLocationView.getHeight() / 2;
mNativeMapView.setBearing(bearing, x / mScreenDensity, y / mScreenDensity);
}
return true;
}
@@ -2426,6 +2437,13 @@ public class MapView extends FrameLayout {
mMapboxMap.setMyLocationEnabled(true);
}
mMyLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
setFocalPoint(new PointF(mMyLocationView.getCenterX(), mMyLocationView.getCenterY()));
} else {
setFocalPoint(null);
}
MapboxMap.OnMyLocationTrackingModeChangeListener listener = mMapboxMap.getOnMyLocationTrackingModeChangeListener();
if (listener != null) {
listener.onMyLocationTrackingModeChange(myLocationTrackingMode);

View File

@@ -1,7 +1,9 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.view.Gravity;
import android.view.View;
@@ -35,6 +37,8 @@ public class UiSettings {
private boolean deselectMarkersOnTap = true;
private PointF focalPoint;
UiSettings(@NonNull MapView mapView) {
this.mapView = mapView;
this.compassSettings = new ViewSettings();
@@ -563,6 +567,25 @@ public class UiSettings {
setZoomGesturesEnabled(enabled);
}
/**
* Sets the focal point used as center for a gesture
*
* @param focalPoint the focal point to be used.
*/
public void setFocalPoint(@Nullable PointF focalPoint) {
this.focalPoint = focalPoint;
mapView.setFocalPoint(focalPoint);
}
/**
* Returns the gesture focal point
*
* @return The focal point
*/
public PointF getFocalPoint() {
return focalPoint;
}
/**
* Returns the measured height of the MapView
*