[android] Release android-v5.1.0-beta.2 (#8976)
* [android] url getter on sources * [android] fix ui test filter in makefile * [android] - build SNAPSHOT from release branch (#8958) * [android] - update changelog for 5.1.0-beta.2 * [android] - bump version number * [android] - Camera change listener v2.0 * [core] allow filesource url transform reset * [android] Update attribution wordmark (#8774) * Update wordmark on android * Moved attribution i icon to the right of mapbox word (in mapview preview image) * update padding and margin * [android] update hardcoded branch name * revert version to 5.1.0-SNAPSHOT
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener;
|
||||
|
||||
class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener,
|
||||
MapboxMap.OnCameraMoveCanceledListener, OnCameraIdleListener {
|
||||
|
||||
private boolean idle = true;
|
||||
|
||||
private OnCameraMoveStartedListener onCameraMoveStartedListener;
|
||||
private OnCameraMoveCanceledListener onCameraMoveCanceledListener;
|
||||
private OnCameraMoveListener onCameraMoveListener;
|
||||
private OnCameraIdleListener onCameraIdleListener;
|
||||
|
||||
void setOnCameraMoveStartedListener(OnCameraMoveStartedListener onCameraMoveStartedListener) {
|
||||
this.onCameraMoveStartedListener = onCameraMoveStartedListener;
|
||||
}
|
||||
|
||||
void setOnCameraMoveCanceledListener(OnCameraMoveCanceledListener onCameraMoveCanceledListener) {
|
||||
this.onCameraMoveCanceledListener = onCameraMoveCanceledListener;
|
||||
}
|
||||
|
||||
void setOnCameraMoveListener(OnCameraMoveListener onCameraMoveListener) {
|
||||
this.onCameraMoveListener = onCameraMoveListener;
|
||||
}
|
||||
|
||||
void setOnCameraIdleListener(OnCameraIdleListener onCameraIdleListener) {
|
||||
this.onCameraIdleListener = onCameraIdleListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraMoveStarted(int reason) {
|
||||
if (!idle) {
|
||||
return;
|
||||
}
|
||||
|
||||
idle = false;
|
||||
if (onCameraMoveStartedListener != null) {
|
||||
onCameraMoveStartedListener.onCameraMoveStarted(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraMove() {
|
||||
if (onCameraMoveListener != null && !idle) {
|
||||
onCameraMoveListener.onCameraMove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraMoveCanceled() {
|
||||
if (onCameraMoveCanceledListener != null && !idle) {
|
||||
onCameraMoveCanceledListener.onCameraMoveCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraIdle() {
|
||||
if (onCameraIdleListener != null && !idle) {
|
||||
idle = true;
|
||||
onCameraIdleListener.onCameraIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
import com.mapbox.services.android.telemetry.utils.MathUtils;
|
||||
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE;
|
||||
|
||||
/**
|
||||
* Manages gestures events on a MapView.
|
||||
* <p>
|
||||
@@ -35,6 +37,7 @@ final class MapGestureDetector {
|
||||
private final UiSettings uiSettings;
|
||||
private final TrackingSettings trackingSettings;
|
||||
private final AnnotationManager annotationManager;
|
||||
private final CameraChangeDispatcher cameraChangeDispatcher;
|
||||
|
||||
private final GestureDetectorCompat gestureDetector;
|
||||
private final ScaleGestureDetector scaleGestureDetector;
|
||||
@@ -56,12 +59,14 @@ final class MapGestureDetector {
|
||||
private boolean scaleGestureOccurred = false;
|
||||
|
||||
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
|
||||
TrackingSettings trackingSettings, AnnotationManager annotationManager) {
|
||||
TrackingSettings trackingSettings, AnnotationManager annotationManager,
|
||||
CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.annotationManager = annotationManager;
|
||||
this.transform = transform;
|
||||
this.projection = projection;
|
||||
this.uiSettings = uiSettings;
|
||||
this.trackingSettings = trackingSettings;
|
||||
this.cameraChangeDispatcher = cameraChangeDispatcher;
|
||||
|
||||
// Touch gesture detectors
|
||||
gestureDetector = new GestureDetectorCompat(context, new GestureListener());
|
||||
@@ -187,6 +192,7 @@ final class MapGestureDetector {
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent(
|
||||
getLocationFromGesture(event.getX(), event.getY()), transform));
|
||||
scrollInProgress = false;
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
|
||||
twoTap = false;
|
||||
@@ -273,6 +279,9 @@ final class MapGestureDetector {
|
||||
break;
|
||||
}
|
||||
|
||||
// notify camera change listener
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
|
||||
// Single finger double tap
|
||||
if (focalPoint != null) {
|
||||
// User provided focal point
|
||||
@@ -337,6 +346,7 @@ final class MapGestureDetector {
|
||||
// and ignore when a scale gesture has occurred
|
||||
return false;
|
||||
}
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
|
||||
float screenDensity = uiSettings.getPixelRatio();
|
||||
|
||||
@@ -362,9 +372,7 @@ final class MapGestureDetector {
|
||||
long animationTime = (long) (velocityXY / 7 / tiltFactor + MapboxConstants.ANIMATION_DURATION_FLING_BASE);
|
||||
|
||||
// update transformation
|
||||
transform.setGestureInProgress(true);
|
||||
transform.moveBy(offsetX, offsetY, animationTime);
|
||||
transform.setGestureInProgress(false);
|
||||
|
||||
if (onFlingListener != null) {
|
||||
onFlingListener.onFling();
|
||||
@@ -377,6 +385,10 @@ final class MapGestureDetector {
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
if (!scrollInProgress) {
|
||||
scrollInProgress = true;
|
||||
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(e1.getX(), e1.getY()),
|
||||
MapboxEvent.GESTURE_PAN_START, transform));
|
||||
@@ -391,8 +403,6 @@ final class MapGestureDetector {
|
||||
|
||||
// reset tracking if needed
|
||||
trackingSettings.resetTrackingModesIfRequired(true, false);
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
|
||||
// Scroll the map
|
||||
transform.moveBy(-distanceX, -distanceY, 0 /*no duration*/);
|
||||
@@ -446,6 +456,8 @@ final class MapGestureDetector {
|
||||
// If scale is large enough ignore a tap
|
||||
scaleFactor *= detector.getScaleFactor();
|
||||
if ((scaleFactor > 1.05f) || (scaleFactor < 0.95f)) {
|
||||
// notify camera change listener
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
zoomStarted = true;
|
||||
}
|
||||
|
||||
@@ -465,9 +477,6 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
|
||||
// Gesture is a quickzoom if there aren't two fingers
|
||||
quickZoom = !twoTap;
|
||||
|
||||
@@ -512,6 +521,9 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
// notify camera change listener
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
@@ -522,6 +534,7 @@ final class MapGestureDetector {
|
||||
// Called when the fingers leave the screen
|
||||
@Override
|
||||
public void onRotateEnd(RotateGestureDetector detector) {
|
||||
// notify camera change listener
|
||||
beginTime = 0;
|
||||
totalAngle = 0.0f;
|
||||
started = false;
|
||||
@@ -553,13 +566,8 @@ final class MapGestureDetector {
|
||||
if (!started) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
|
||||
// rotation constitutes translation of anything except the center of
|
||||
// rotation, so cancel both location and bearing tracking if required
|
||||
|
||||
trackingSettings.resetTrackingModesIfRequired(true, true);
|
||||
|
||||
// Get rotate value
|
||||
@@ -593,6 +601,8 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
// notify camera change listener
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
@@ -633,9 +643,6 @@ final class MapGestureDetector {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cancel any animation
|
||||
transform.cancelTransitions();
|
||||
|
||||
// Get tilt value (scale and clamp)
|
||||
double pitch = transform.getTilt();
|
||||
pitch -= 0.1 * detector.getShovePixelsDelta();
|
||||
|
||||
@@ -129,6 +129,9 @@ public class MapView extends FrameLayout {
|
||||
// callback for zooming in the camera
|
||||
CameraZoomInvalidator zoomInvalidator = new CameraZoomInvalidator();
|
||||
|
||||
// callback for camera change events
|
||||
CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, view.findViewById(R.id.logoView));
|
||||
@@ -136,12 +139,14 @@ public class MapView extends FrameLayout {
|
||||
MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj, focalPoint);
|
||||
MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer));
|
||||
AnnotationManager annotations = new AnnotationManager(nativeMapView, this, markerViewManager);
|
||||
Transform transform = new Transform(nativeMapView, annotations.getMarkerViewManager(), trackingSettings);
|
||||
Transform transform = new Transform(nativeMapView, annotations.getMarkerViewManager(), trackingSettings,
|
||||
cameraChangeDispatcher);
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings, proj,
|
||||
registerTouchListener, annotations);
|
||||
registerTouchListener, annotations, cameraChangeDispatcher);
|
||||
|
||||
// user input
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings, annotations);
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings, annotations,
|
||||
cameraChangeDispatcher);
|
||||
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);
|
||||
|
||||
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
|
||||
|
||||
@@ -69,6 +69,7 @@ public final class MapboxMap {
|
||||
private final Transform transform;
|
||||
private final AnnotationManager annotationManager;
|
||||
private final MyLocationViewSettings myLocationViewSettings;
|
||||
private final CameraChangeDispatcher cameraChangeDispatcher;
|
||||
|
||||
private final OnRegisterTouchListener onRegisterTouchListener;
|
||||
|
||||
@@ -76,7 +77,7 @@ public final class MapboxMap {
|
||||
|
||||
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, TrackingSettings tracking,
|
||||
MyLocationViewSettings myLocationView, Projection projection, OnRegisterTouchListener listener,
|
||||
AnnotationManager annotations) {
|
||||
AnnotationManager annotations, CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.nativeMapView = map;
|
||||
this.uiSettings = ui;
|
||||
this.trackingSettings = tracking;
|
||||
@@ -85,6 +86,7 @@ public final class MapboxMap {
|
||||
this.annotationManager = annotations.bind(this);
|
||||
this.transform = transform;
|
||||
this.onRegisterTouchListener = listener;
|
||||
this.cameraChangeDispatcher = cameraChangeDispatcher;
|
||||
}
|
||||
|
||||
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
|
||||
@@ -1595,10 +1597,51 @@ public final class MapboxMap {
|
||||
* To unset the callback, use null.
|
||||
*/
|
||||
@UiThread
|
||||
@Deprecated
|
||||
public void setOnCameraChangeListener(@Nullable OnCameraChangeListener listener) {
|
||||
transform.setOnCameraChangeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a callback that is invoked when camera movement has ended.
|
||||
*
|
||||
* @param listener the listener to notify
|
||||
*/
|
||||
@UiThread
|
||||
public void setOnCameraIdleListener(@Nullable OnCameraIdleListener listener) {
|
||||
cameraChangeDispatcher.setOnCameraIdleListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a callback that is invoked when camera movement was cancelled.
|
||||
*
|
||||
* @param listener the listener to notify
|
||||
*/
|
||||
@UiThread
|
||||
public void setOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) {
|
||||
cameraChangeDispatcher.setOnCameraMoveCanceledListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a callback that is invoked when camera movement has started.
|
||||
*
|
||||
* @param listener the listener to notify
|
||||
*/
|
||||
@UiThread
|
||||
public void setOnCameraMoveStartedistener(@Nullable OnCameraMoveStartedListener listener) {
|
||||
cameraChangeDispatcher.setOnCameraMoveStartedListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a callback that is invoked when camera position changes.
|
||||
*
|
||||
* @param listener the listener to notify
|
||||
*/
|
||||
@UiThread
|
||||
public void setOnCameraMoveListener(@Nullable OnCameraMoveListener listener) {
|
||||
cameraChangeDispatcher.setOnCameraMoveListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a callback that's invoked on every frame rendered to the map view.
|
||||
*
|
||||
@@ -1913,7 +1956,12 @@ public final class MapboxMap {
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the camera changes position.
|
||||
*
|
||||
* @deprecated Replaced by MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener and
|
||||
* MapboxMap.OnCameraIdleListener. The order in which the deprecated onCameraChange method will be called in relation
|
||||
* to the methods in the new camera change listeners is undefined.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface OnCameraChangeListener {
|
||||
/**
|
||||
* Called after the camera position has changed. During an animation,
|
||||
@@ -1925,6 +1973,56 @@ public final class MapboxMap {
|
||||
void onCameraChange(CameraPosition position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked for when the camera motion starts.
|
||||
*/
|
||||
public interface OnCameraMoveStartedListener {
|
||||
int REASON_API_GESTURE = 1;
|
||||
int REASON_DEVELOPER_ANIMATION = 2;
|
||||
int REASON_API_ANIMATION = 3;
|
||||
|
||||
/**
|
||||
* Called when the camera starts moving after it has been idle or when the reason for camera motion has changed.
|
||||
*
|
||||
* @param reason the reason for the camera change
|
||||
*/
|
||||
void onCameraMoveStarted(int reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked for when the camera changes position.
|
||||
*/
|
||||
public interface OnCameraMoveListener {
|
||||
/**
|
||||
* Called repeatedly as the camera continues to move after an onCameraMoveStarted call.
|
||||
* This may be called as often as once every frame and should not perform expensive operations.
|
||||
*/
|
||||
void onCameraMove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked for when the camera's motion has been stopped or when the camera
|
||||
* starts moving for a new reason.
|
||||
*/
|
||||
public interface OnCameraMoveCanceledListener {
|
||||
/**
|
||||
* Called when the developer explicitly calls the cancelTransitions() method or if the reason for camera motion has
|
||||
* changed before the onCameraIdle had a chance to fire after the previous animation.
|
||||
* Do not update or animate the camera from within this method.
|
||||
*/
|
||||
void onCameraMoveCanceled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked for when camera movement has ended.
|
||||
*/
|
||||
public interface OnCameraIdleListener {
|
||||
/**
|
||||
* Called when camera movement has ended.
|
||||
*/
|
||||
void onCameraIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when a frame is rendered to the map view.
|
||||
*
|
||||
|
||||
@@ -35,10 +35,8 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
private static final float DIMENSION_SEVEN_DP = 7f;
|
||||
private static final float DIMENSION_TEN_DP = 10f;
|
||||
private static final float DIMENSION_SIXTEEN_DP = 16f;
|
||||
private static final float DIMENSION_SEVENTY_SIX_DP = 76f;
|
||||
private static final float FOUR_DP = 4f;
|
||||
private static final float EIGHTY_NINE_DP = 92f;
|
||||
|
||||
private CameraPosition cameraPosition;
|
||||
|
||||
@@ -206,13 +204,13 @@ public class MapboxMapOptions implements Parcelable {
|
||||
Gravity.TOP | Gravity.END));
|
||||
mapboxMapOptions.compassMargins(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginLeft,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginTop,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginRight,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginBottom,
|
||||
DIMENSION_TEN_DP * pxlRatio))});
|
||||
FOUR_DP * pxlRatio))});
|
||||
mapboxMapOptions.compassFadesWhenFacingNorth(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassFadeFacingNorth, true));
|
||||
Drawable compassDrawable = typedArray.getDrawable(
|
||||
@@ -227,13 +225,13 @@ public class MapboxMapOptions implements Parcelable {
|
||||
Gravity.BOTTOM | Gravity.START));
|
||||
mapboxMapOptions.logoMargins(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginLeft,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginTop,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginRight,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginBottom,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio))});
|
||||
FOUR_DP * pxlRatio))});
|
||||
|
||||
mapboxMapOptions.attributionTintColor(typedArray.getColor(
|
||||
R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1));
|
||||
@@ -243,13 +241,13 @@ public class MapboxMapOptions implements Parcelable {
|
||||
R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM));
|
||||
mapboxMapOptions.attributionMargins(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft,
|
||||
DIMENSION_SEVENTY_SIX_DP) * pxlRatio),
|
||||
EIGHTY_NINE_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop,
|
||||
DIMENSION_SEVEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight,
|
||||
DIMENSION_SEVEN_DP * pxlRatio)),
|
||||
FOUR_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginBottom,
|
||||
DIMENSION_SEVEN_DP * pxlRatio))});
|
||||
FOUR_DP * pxlRatio))});
|
||||
|
||||
mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false));
|
||||
mapboxMapOptions.myLocationForegroundTintColor(
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED;
|
||||
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
|
||||
|
||||
/**
|
||||
* Resembles the current Map transformation.
|
||||
@@ -33,13 +34,18 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
|
||||
private CameraPosition cameraPosition;
|
||||
private MapboxMap.CancelableCallback cameraCancelableCallback;
|
||||
|
||||
private MapboxMap.OnCameraChangeListener onCameraChangeListener;
|
||||
|
||||
Transform(NativeMapView mapView, MarkerViewManager markerViewManager, TrackingSettings trackingSettings) {
|
||||
private CameraChangeDispatcher cameraChangeDispatcher;
|
||||
|
||||
Transform(NativeMapView mapView, MarkerViewManager markerViewManager, TrackingSettings trackingSettings,
|
||||
CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.mapView = mapView;
|
||||
this.markerViewManager = markerViewManager;
|
||||
this.trackingSettings = trackingSettings;
|
||||
this.myLocationView = trackingSettings.getMyLocationView();
|
||||
this.cameraChangeDispatcher = cameraChangeDispatcher;
|
||||
}
|
||||
|
||||
void initialise(@NonNull MapboxMap mapboxMap, @NonNull MapboxMapOptions options) {
|
||||
@@ -79,6 +85,7 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
cameraCancelableCallback.onFinish();
|
||||
cameraCancelableCallback = null;
|
||||
}
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
}
|
||||
}
|
||||
@@ -89,10 +96,12 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
if (!cameraPosition.equals(this.cameraPosition)) {
|
||||
trackingSettings.resetTrackingModesIfRequired(cameraPosition);
|
||||
cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
|
||||
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
|
||||
if (callback != null) {
|
||||
callback.onFinish();
|
||||
}
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +112,8 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
if (!cameraPosition.equals(this.cameraPosition)) {
|
||||
trackingSettings.resetTrackingModesIfRequired(cameraPosition);
|
||||
cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
|
||||
|
||||
if (callback != null) {
|
||||
cameraCancelableCallback = callback;
|
||||
mapView.addOnMapChangedListener(this);
|
||||
@@ -119,8 +130,9 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
|
||||
if (!cameraPosition.equals(this.cameraPosition)) {
|
||||
trackingSettings.resetTrackingModesIfRequired(cameraPosition);
|
||||
|
||||
cancelTransitions();
|
||||
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
|
||||
|
||||
if (callback != null) {
|
||||
cameraCancelableCallback = callback;
|
||||
mapView.addOnMapChangedListener(this);
|
||||
@@ -135,7 +147,12 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
@Nullable
|
||||
CameraPosition invalidateCameraPosition() {
|
||||
if (mapView != null) {
|
||||
cameraPosition = mapView.getCameraPosition();
|
||||
CameraPosition cameraPosition = mapView.getCameraPosition();
|
||||
if (this.cameraPosition != null && !this.cameraPosition.equals(cameraPosition)) {
|
||||
cameraChangeDispatcher.onCameraMove();
|
||||
}
|
||||
|
||||
this.cameraPosition = cameraPosition;
|
||||
if (onCameraChangeListener != null) {
|
||||
onCameraChangeListener.onCameraChange(this.cameraPosition);
|
||||
}
|
||||
@@ -144,10 +161,17 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
}
|
||||
|
||||
void cancelTransitions() {
|
||||
// notify user about cancel
|
||||
cameraChangeDispatcher.onCameraMoveCanceled();
|
||||
|
||||
// notify animateCamera and easeCamera about cancelling
|
||||
if (cameraCancelableCallback != null) {
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
cameraCancelableCallback.onCancel();
|
||||
cameraCancelableCallback = null;
|
||||
}
|
||||
|
||||
// cancel ongoing transitions
|
||||
mapView.cancelTransitions();
|
||||
}
|
||||
|
||||
@@ -157,6 +181,10 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
mapView.resetNorth();
|
||||
}
|
||||
|
||||
//
|
||||
// Camera change listener API
|
||||
//
|
||||
|
||||
void setOnCameraChangeListener(@Nullable MapboxMap.OnCameraChangeListener listener) {
|
||||
this.onCameraChangeListener = listener;
|
||||
}
|
||||
@@ -172,9 +200,6 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
}
|
||||
|
||||
void zoom(boolean zoomIn, @NonNull PointF focalPoint) {
|
||||
// Cancel any animation
|
||||
cancelTransitions();
|
||||
|
||||
CameraPosition cameraPosition = invalidateCameraPosition();
|
||||
if (cameraPosition != null) {
|
||||
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
|
||||
@@ -187,6 +212,15 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
}
|
||||
|
||||
void setZoom(double zoom, @NonNull PointF focalPoint, long duration) {
|
||||
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(int change) {
|
||||
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
}
|
||||
});
|
||||
mapView.setZoom(zoom, focalPoint, duration);
|
||||
}
|
||||
|
||||
@@ -278,6 +312,17 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
}
|
||||
|
||||
void moveBy(double offsetX, double offsetY, long duration) {
|
||||
if (duration > 0) {
|
||||
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(int change) {
|
||||
if (change == MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED) {
|
||||
mapView.removeOnMapChangedListener(this);
|
||||
cameraChangeDispatcher.onCameraIdle();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
mapView.moveBy(offsetX, offsetY, duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public final class UiSettings {
|
||||
if (compassMargins != null) {
|
||||
setCompassMargins(compassMargins[0], compassMargins[1], compassMargins[2], compassMargins[3]);
|
||||
} else {
|
||||
int tenDp = (int) resources.getDimension(R.dimen.mapbox_ten_dp);
|
||||
int tenDp = (int) resources.getDimension(R.dimen.mapbox_four_dp);
|
||||
setCompassMargins(tenDp, tenDp, tenDp, tenDp);
|
||||
}
|
||||
setCompassFadeFacingNorth(options.getCompassFadeFacingNorth());
|
||||
@@ -171,9 +171,7 @@ public final class UiSettings {
|
||||
private byte[] convert(Bitmap resource) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
resource.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
byte[] byteArray = stream.toByteArray();
|
||||
|
||||
return byteArray;
|
||||
return stream.toByteArray();
|
||||
}
|
||||
|
||||
private void restoreCompass(Bundle savedInstanceState) {
|
||||
@@ -189,10 +187,7 @@ public final class UiSettings {
|
||||
|
||||
private Drawable decode(byte[] bitmap) {
|
||||
Bitmap compass = BitmapFactory.decodeByteArray(bitmap, 0, bitmap.length);
|
||||
|
||||
Drawable compassImage = new BitmapDrawable(compassView.getResources(), compass);
|
||||
|
||||
return compassImage;
|
||||
return new BitmapDrawable(compassView.getResources(), compass);
|
||||
}
|
||||
|
||||
private void initialiseLogo(MapboxMapOptions options, Resources resources) {
|
||||
@@ -202,8 +197,8 @@ public final class UiSettings {
|
||||
if (logoMargins != null) {
|
||||
setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]);
|
||||
} else {
|
||||
int sixteenDp = (int) resources.getDimension(R.dimen.mapbox_sixteen_dp);
|
||||
setLogoMargins(sixteenDp, sixteenDp, sixteenDp, sixteenDp);
|
||||
int twoDp = (int) resources.getDimension(R.dimen.mapbox_two_dp);
|
||||
setLogoMargins(twoDp, twoDp, twoDp, twoDp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,16 +221,12 @@ public final class UiSettings {
|
||||
}
|
||||
|
||||
private void initialiseAttribution(Context context, MapboxMapOptions options) {
|
||||
Resources resources = context.getResources();
|
||||
setAttributionEnabled(options.getAttributionEnabled());
|
||||
setAttributionGravity(options.getAttributionGravity());
|
||||
int[] attributionMargins = options.getAttributionMargins();
|
||||
if (attributionMargins != null) {
|
||||
setAttributionMargins(attributionMargins[0], attributionMargins[1], attributionMargins[2], attributionMargins[3]);
|
||||
} else {
|
||||
int sevenDp = (int) resources.getDimension(R.dimen.mapbox_seven_dp);
|
||||
int seventySixDp = (int) resources.getDimension(R.dimen.mapbox_seventy_six_dp);
|
||||
setAttributionMargins(seventySixDp, sevenDp, sevenDp, sevenDp);
|
||||
setAttributionMargins(attributionMargins[0], attributionMargins[1],
|
||||
attributionMargins[2], attributionMargins[3]);
|
||||
}
|
||||
|
||||
int attributionTintColor = options.getAttributionTintColor();
|
||||
|
||||
@@ -227,6 +227,14 @@ public class GeoJsonSource extends Source {
|
||||
nativeSetUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUrl() {
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the source for features.
|
||||
*
|
||||
@@ -243,6 +251,8 @@ public class GeoJsonSource extends Source {
|
||||
|
||||
protected native void nativeSetUrl(String url);
|
||||
|
||||
protected native String nativeGetUrl();
|
||||
|
||||
private native void nativeSetGeoJsonString(String geoJson);
|
||||
|
||||
private native void nativeSetFeatureCollection(FeatureCollection geoJson);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.mapbox.mapboxsdk.style.sources;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
@@ -72,8 +74,19 @@ public class RasterSource extends Source {
|
||||
initialize(id, tileSet.toValueObject(), tileSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUrl() {
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
protected native void initialize(String layerId, Object payload, int tileSize);
|
||||
|
||||
@Override
|
||||
protected native void finalize() throws Throwable;
|
||||
|
||||
protected native String nativeGetUrl();
|
||||
|
||||
}
|
||||
|
||||
@@ -76,11 +76,21 @@ public class VectorSource extends Source {
|
||||
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The url or null
|
||||
*/
|
||||
@Nullable
|
||||
public String getUrl() {
|
||||
return nativeGetUrl();
|
||||
}
|
||||
|
||||
protected native void initialize(String layerId, Object payload);
|
||||
|
||||
@Override
|
||||
protected native void finalize() throws Throwable;
|
||||
|
||||
protected native String nativeGetUrl();
|
||||
|
||||
private native Feature[] querySourceFeatures(String[] sourceLayerId,
|
||||
Object[] filter);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user