diff options
author | Tim Watson <tewatson89@gmail.com> | 2019-04-03 14:51:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 14:51:13 -0700 |
commit | 0ff25060dae4858a1b60e2277dbd8921de7a6785 (patch) | |
tree | d29d578b9b9d6cfb0999b7a30819d379b85172b7 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox | |
parent | ba2b7a74c420856401d344ff15b27771175c9819 (diff) | |
parent | 0f416fbbde9b146eb28a4bf88586738d12505007 (diff) | |
download | qtlocation-mapboxgl-upstream/friedbunny-external-pr-14135.tar.gz |
Merge pull request #1 from mapbox/masterupstream/friedbunny-external-pr-14135
Merge Master
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox')
25 files changed, 345 insertions, 178 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java index 8ae388549e..ce12489b49 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java @@ -5,10 +5,14 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.FloatRange; import android.support.annotation.Keep; - import android.support.annotation.NonNull; import android.support.annotation.Nullable; + +import com.mapbox.geojson.Point; import com.mapbox.mapboxsdk.constants.GeometryConstants; +import com.mapbox.turf.TurfMeasurement; + +import static com.mapbox.turf.TurfConstants.UNIT_METRES; /** @@ -209,7 +213,8 @@ public class LatLng implements Parcelable { @NonNull public LatLng wrap() { return new LatLng(latitude, wrap(longitude, - GeometryConstants.MIN_WRAP_LONGITUDE, GeometryConstants.MAX_WRAP_LONGITUDE)); + GeometryConstants.MIN_WRAP_LONGITUDE, GeometryConstants.MAX_WRAP_LONGITUDE) + ); } @@ -218,8 +223,10 @@ public class LatLng implements Parcelable { * <p> * Same formula as used in Core GL (wrap.hpp) * std::fmod((std::fmod((value - min), d) + d), d) + min; - * + * </p> + * <p> * Multiples of max value will be wrapped to max. + * </p> * * @param value Value to wrap * @param min Minimum value @@ -318,24 +325,10 @@ public class LatLng implements Parcelable { * @return distance in meters */ public double distanceTo(@NonNull LatLng other) { - if (latitude == other.latitude && longitude == other.longitude) { - // return 0.0 to avoid a NaN - return 0.0; - } - - final double a1 = Math.toRadians(this.latitude); - final double a2 = Math.toRadians(this.longitude); - final double b1 = Math.toRadians(other.getLatitude()); - final double b2 = Math.toRadians(other.getLongitude()); - - final double cosa1 = Math.cos(a1); - final double cosb1 = Math.cos(b1); - - final double t1 = cosa1 * Math.cos(a2) * cosb1 * Math.cos(b2); - final double t2 = cosa1 * Math.sin(a2) * cosb1 * Math.sin(b2); - final double t3 = Math.sin(a1) * Math.sin(b1); - final double tt = Math.acos(t1 + t2 + t3); - - return GeometryConstants.RADIUS_EARTH_METERS * tt; + return TurfMeasurement.distance( + Point.fromLngLat(longitude, latitude), + Point.fromLngLat(other.getLongitude(), other.getLatitude()), + UNIT_METRES + ); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java index 4e56c6e9c0..b9aa371a47 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java @@ -77,9 +77,11 @@ final class LocationCameraController { void initializeOptions(LocationComponentOptions options) { this.options = options; if (options.trackingGesturesManagement()) { - mapboxMap.setGesturesManager(internalGesturesManager, true, true); + if (mapboxMap.getGesturesManager() != internalGesturesManager) { + mapboxMap.setGesturesManager(internalGesturesManager, true, true); + } adjustGesturesThresholds(); - } else { + } else if (mapboxMap.getGesturesManager() != initialGesturesManager) { mapboxMap.setGesturesManager(initialGesturesManager, true, true); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index b97ab75b5e..327ab3c8ed 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -220,7 +220,6 @@ public final class LocationComponent { * @param style the proxy object for current map style. More info at {@link Style} * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style) { activateLocationComponent(context, style, @@ -237,7 +236,6 @@ public final class LocationComponent { * there should be no location engine initialized * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine) { @@ -259,7 +257,6 @@ public final class LocationComponent { * @param locationEngineRequest the location request * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine, @@ -284,7 +281,6 @@ public final class LocationComponent { * @param options the options * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine, @@ -309,7 +305,6 @@ public final class LocationComponent { * @param styleRes the LocationComponent style res * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @StyleRes int styleRes) { activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, styleRes)); @@ -327,7 +322,6 @@ public final class LocationComponent { * @param options the options * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @NonNull LocationComponentOptions options) { @@ -346,7 +340,6 @@ public final class LocationComponent { * @param styleRes the LocationComponent style res * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @StyleRes int styleRes) { @@ -365,7 +358,6 @@ public final class LocationComponent { * @param styleRes the LocationComponent style res * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @@ -382,7 +374,6 @@ public final class LocationComponent { * @param locationEngine the engine * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine) { @@ -398,7 +389,6 @@ public final class LocationComponent { * @param locationEngineRequest the location request * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @@ -415,7 +405,6 @@ public final class LocationComponent { * @param options the options * @deprecated use {@link LocationComponentActivationOptions.Builder} instead */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @@ -453,8 +442,7 @@ public final class LocationComponent { * * @param activationOptions a fully built {@link LocationComponentActivationOptions} object */ - public void activateLocationComponent(@NonNull LocationComponentActivationOptions - activationOptions) { + public void activateLocationComponent(@NonNull LocationComponentActivationOptions activationOptions) { LocationComponentOptions options = activationOptions.locationComponentOptions(); if (options == null) { int styleRes = activationOptions.styleRes(); @@ -496,6 +484,7 @@ public final class LocationComponent { * * @param isEnabled true if the plugin should be visible and listen for location updates, false otherwise. */ + @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public void setLocationComponentEnabled(boolean isEnabled) { checkActivationState(); if (isEnabled) { @@ -954,7 +943,6 @@ public final class LocationComponent { * @return the last known location */ @Nullable - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public Location getLastKnownLocation() { checkActivationState(); return lastLocation; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java index 093c91e799..c0173cb8e8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java @@ -1,7 +1,7 @@ package com.mapbox.mapboxsdk.location; /** - * Contains all the constants being used for the Location layer. + * Contains all the constants being used for the {@link LocationComponent}. */ final class LocationComponentConstants { @@ -49,11 +49,31 @@ final class LocationComponentConstants { static final String PROPERTY_BEARING_ICON = "mapbox-property-shadow-icon"; // Layers - static final String SHADOW_LAYER = "mapbox-location-shadow"; - static final String FOREGROUND_LAYER = "mapbox-location-layer"; - static final String BACKGROUND_LAYER = "mapbox-location-stroke-layer"; - static final String ACCURACY_LAYER = "mapbox-location-accuracy-layer"; - static final String BEARING_LAYER = "mapbox-location-bearing-layer"; + + /** + * Layer ID of the location shadow. + */ + public static final String SHADOW_LAYER = "mapbox-location-shadow-layer"; + + /** + * Layer ID of the location foreground icon. + */ + public static final String FOREGROUND_LAYER = "mapbox-location-foreground-layer"; + + /** + * Layer ID of the location background icon. + */ + public static final String BACKGROUND_LAYER = "mapbox-location-background-layer"; + + /** + * Layer ID of the location accuracy. + */ + public static final String ACCURACY_LAYER = "mapbox-location-accuracy-layer"; + + /** + * Layer ID of the location bearing icon. + */ + public static final String BEARING_LAYER = "mapbox-location-bearing-layer"; // Icons static final String FOREGROUND_ICON = "mapbox-location-icon"; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java index f11acacf31..aa8a82bf6d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java @@ -5,6 +5,7 @@ import android.graphics.PointF; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -18,7 +19,6 @@ import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -70,7 +70,8 @@ final class LocationLayerController { private LocationComponentOptions options; private final OnRenderModeChangedListener internalRenderModeChangedListener; - private final List<String> layerMap = new ArrayList<>(); + @VisibleForTesting + final Set<String> layerSet = new HashSet<>(); private Feature locationFeature; private GeoJsonSource locationSource; @@ -112,7 +113,7 @@ final class LocationLayerController { removeLayers(); addLayers(newLayerBelowOption); if (isHidden) { - for (String layerId : layerMap) { + for (String layerId : layerSet) { setLayerVisibility(layerId, false); } } @@ -193,7 +194,7 @@ final class LocationLayerController { void hide() { isHidden = true; - for (String layerId : layerMap) { + for (String layerId : layerSet) { setLayerVisibility(layerId, false); } } @@ -257,14 +258,14 @@ final class LocationLayerController { private void addLayerToMap(Layer layer, @NonNull String idBelowLayer) { style.addLayerBelow(layer, idBelowLayer); - layerMap.add(layer.getId()); + layerSet.add(layer.getId()); } private void removeLayers() { - for (String layerId : layerMap) { + for (String layerId : layerSet) { style.removeLayer(layerId); } - layerMap.clear(); + layerSet.clear(); } private void setBearingProperty(@NonNull String propertyId, float bearing) { @@ -351,7 +352,7 @@ final class LocationLayerController { } private void styleScaling(@NonNull LocationComponentOptions options) { - for (String layerId : layerMap) { + for (String layerId : layerSet) { Layer layer = style.getLayer(layerId); if (layer instanceof SymbolLayer) { layer.setProperties( diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java index b3472ac81e..a1fd4e7e3e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java @@ -142,6 +142,14 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M } } + void onDestroy() { + handler.removeCallbacksAndMessages(null); + onCameraMoveStarted.clear(); + onCameraMoveCanceled.clear(); + onCameraMove.clear(); + onCameraIdle.clear(); + } + private static class CameraChangeHandler extends Handler { private WeakReference<CameraChangeDispatcher> dispatcherWeakReference; 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 c9e6e633aa..9473ea7091 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 @@ -74,7 +74,7 @@ final class MapGestureDetector { * User-set focal point. */ @Nullable - private PointF focalPoint; + private PointF constantFocalPoint; private AndroidGesturesManager gesturesManager; @@ -158,7 +158,7 @@ final class MapGestureDetector { /** * Set the gesture focal point. * <p> - * this is the center point used for calculate transformations from gestures, value is + * This is the center point used for calculate transformations from gestures, value is * overridden if end user provides his own through {@link UiSettings#setFocalPoint(PointF)}. * </p> * @@ -172,22 +172,7 @@ final class MapGestureDetector { focalPoint = uiSettings.getFocalPoint(); } } - this.focalPoint = focalPoint; - } - - /** - * Get the current active gesture focal point. - * <p> - * This could be either the user provided focal point in - * {@link UiSettings#setFocalPoint(PointF)}or <code>null</code>. - * If it's <code>null</code>, gestures will use focal pointed returned by the detector. - * </p> - * - * @return the current active gesture focal point. - */ - @Nullable - PointF getFocalPoint() { - return focalPoint; + this.constantFocalPoint = focalPoint; } /** @@ -357,18 +342,25 @@ final class MapGestureDetector { int action = motionEvent.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { executeDoubleTap = true; + + // disable the move detector in preparation for the quickzoom, + // so that we don't move the map's center slightly before the quickzoom is started (see #14227) + gesturesManager.getMoveGestureDetector().setEnabled(false); } if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { + // re-enabled the move detector + gesturesManager.getMoveGestureDetector().setEnabled(true); + if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled() || !executeDoubleTap) { return false; } PointF zoomFocalPoint; // Single finger double tap - if (focalPoint != null) { + if (constantFocalPoint != null) { // User provided focal point - zoomFocalPoint = focalPoint; + zoomFocalPoint = constantFocalPoint; } else { // Zoom in on gesture zoomFocalPoint = new PointF(motionEvent.getX(), motionEvent.getY()); @@ -468,9 +460,6 @@ final class MapGestureDetector { private final class ScaleGestureListener extends StandardScaleGestureDetector.SimpleStandardOnScaleGestureListener { private final float minimumVelocity; - - @Nullable - private PointF scaleFocalPoint; private boolean quickZoom; ScaleGestureListener(float minimumVelocity) { @@ -496,8 +485,6 @@ final class MapGestureDetector { if (!uiSettings.isQuickZoomGesturesEnabled()) { return false; } - // when quickzoom, disable move gesture - gesturesManager.getMoveGestureDetector().setEnabled(false); } cancelTransitionsIfRequired(); @@ -510,10 +497,7 @@ final class MapGestureDetector { ); } - // setting focalPoint in #onScaleBegin() as well, because #onScale() might not get called before #onScaleEnd() - setScaleFocalPoint(detector); - - sendTelemetryEvent(TelemetryConstants.PINCH, scaleFocalPoint); + sendTelemetryEvent(TelemetryConstants.PINCH, getScaleFocalPoint(detector)); notifyOnScaleBeginListeners(detector); @@ -525,11 +509,10 @@ final class MapGestureDetector { // dispatching camera start event only when the movement actually occurred cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_GESTURE); - setScaleFocalPoint(detector); - float scaleFactor = detector.getScaleFactor(); double zoomBy = getNewZoom(scaleFactor, quickZoom); - transform.zoomBy(zoomBy, scaleFocalPoint); + PointF focalPoint = getScaleFocalPoint(detector); + transform.zoomBy(zoomBy, focalPoint); notifyOnScaleListeners(detector); @@ -538,11 +521,6 @@ final class MapGestureDetector { @Override public void onScaleEnd(@NonNull StandardScaleGestureDetector detector, float velocityX, float velocityY) { - if (quickZoom) { - //if quickzoom, re-enabling move gesture detector - gesturesManager.getMoveGestureDetector().setEnabled(true); - } - if (uiSettings.isIncreaseRotateThresholdWhenScaling()) { // resetting default angle threshold gesturesManager.getRotateGestureDetector().setAngleThreshold( @@ -562,21 +540,23 @@ final class MapGestureDetector { double zoomAddition = calculateScale(velocityXY, detector.isScalingOut()); double currentZoom = transform.getRawZoom(); + PointF focalPoint = getScaleFocalPoint(detector); long animationTime = (long) (Math.abs(zoomAddition) * 1000 / 4); - scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, scaleFocalPoint, animationTime); + scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, focalPoint, animationTime); scheduleAnimator(scaleAnimator); } - private void setScaleFocalPoint(@NonNull StandardScaleGestureDetector detector) { - if (focalPoint != null) { + @NonNull + private PointF getScaleFocalPoint(@NonNull StandardScaleGestureDetector detector) { + if (constantFocalPoint != null) { // around user provided focal point - scaleFocalPoint = focalPoint; + return constantFocalPoint; } else if (quickZoom) { // around center - scaleFocalPoint = new PointF(uiSettings.getWidth() / 2, uiSettings.getHeight() / 2); + return new PointF(uiSettings.getWidth() / 2, uiSettings.getHeight() / 2); } else { // around gesture - scaleFocalPoint = detector.getFocalPoint(); + return detector.getFocalPoint(); } } @@ -603,14 +583,12 @@ final class MapGestureDetector { } private final class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener { - @Nullable - private PointF rotateFocalPoint; private final float minimumScaleSpanWhenRotating; private final float minimumAngularVelocity; private final float defaultSpanSinceStartThreshold; - public RotateGestureListener(float minimumScaleSpanWhenRotating, float minimumAngularVelocity, - float defaultSpanSinceStartThreshold) { + RotateGestureListener(float minimumScaleSpanWhenRotating, float minimumAngularVelocity, + float defaultSpanSinceStartThreshold) { this.minimumScaleSpanWhenRotating = minimumScaleSpanWhenRotating; this.minimumAngularVelocity = minimumAngularVelocity; this.defaultSpanSinceStartThreshold = defaultSpanSinceStartThreshold; @@ -631,10 +609,7 @@ final class MapGestureDetector { gesturesManager.getStandardScaleGestureDetector().interrupt(); } - // setting in #onRotateBegin() as well, because #onRotate() might not get called before #onRotateEnd() - setRotateFocalPoint(detector); - - sendTelemetryEvent(TelemetryConstants.ROTATION, rotateFocalPoint); + sendTelemetryEvent(TelemetryConstants.ROTATION, getRotateFocalPoint(detector)); notifyOnRotateBeginListeners(detector); @@ -647,13 +622,12 @@ final class MapGestureDetector { // dispatching camera start event only when the movement actually occurred cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_GESTURE); - setRotateFocalPoint(detector); - // Calculate map bearing value double bearing = transform.getRawBearing() + rotationDegreesSinceLast; // Rotate the map - transform.setBearing(bearing, rotateFocalPoint.x, rotateFocalPoint.y); + PointF focalPoint = getRotateFocalPoint(detector); + transform.setBearing(bearing, focalPoint.x, focalPoint.y); notifyOnRotateListeners(detector); @@ -687,21 +661,24 @@ final class MapGestureDetector { angularVelocity = -angularVelocity; } - rotateAnimator = createRotateAnimator(angularVelocity, animationTime); + PointF focalPoint = getRotateFocalPoint(detector); + rotateAnimator = createRotateAnimator(angularVelocity, animationTime, focalPoint); scheduleAnimator(rotateAnimator); } - private void setRotateFocalPoint(@NonNull RotateGestureDetector detector) { - if (focalPoint != null) { + @NonNull + private PointF getRotateFocalPoint(@NonNull RotateGestureDetector detector) { + if (constantFocalPoint != null) { // User provided focal point - rotateFocalPoint = focalPoint; + return constantFocalPoint; } else { // around gesture - rotateFocalPoint = detector.getFocalPoint(); + return detector.getFocalPoint(); } } - private Animator createRotateAnimator(float angularVelocity, long animationTime) { + private Animator createRotateAnimator(float angularVelocity, long animationTime, + @NonNull final PointF animationFocalPoint) { ValueAnimator animator = ValueAnimator.ofFloat(angularVelocity, 0f); animator.setDuration(animationTime); animator.setInterpolator(new DecelerateInterpolator()); @@ -710,7 +687,7 @@ final class MapGestureDetector { public void onAnimationUpdate(@NonNull ValueAnimator animation) { transform.setBearing( transform.getRawBearing() + (float) animation.getAnimatedValue(), - rotateFocalPoint.x, rotateFocalPoint.y, + animationFocalPoint.x, animationFocalPoint.y, 0L ); } @@ -802,9 +779,9 @@ final class MapGestureDetector { PointF zoomFocalPoint; // Single finger double tap - if (focalPoint != null) { + if (constantFocalPoint != null) { // User provided focal point - zoomFocalPoint = focalPoint; + zoomFocalPoint = constantFocalPoint; } else { // Zoom in on gesture zoomFocalPoint = detector.getFocalPoint(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index f87c6a854a..23ce2bdef0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -911,7 +911,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { /** * Called when the map has finished rendering. * - * @param fully true if map is fully rendered, false if fully rendered + * @param fully true if map is fully rendered, false if not fully rendered */ void onDidFinishRenderingMap(boolean fully); } @@ -1257,4 +1257,4 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { public static void setMapStrictModeEnabled(boolean strictModeEnabled) { MapStrictMode.setStrictModeEnabled(strictModeEnabled); } -}
\ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index f0155bda58..95d5c29b61 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -128,7 +128,6 @@ public final class MapboxMap { * Called when the hosting Activity/Fragment onStart() method is called. */ void onStart() { - nativeMapView.update(); locationComponent.onStart(); } @@ -174,6 +173,10 @@ public final class MapboxMap { */ void onDestroy() { locationComponent.onDestroy(); + if (style != null) { + style.clear(); + } + cameraChangeDispatcher.onDestroy(); } /** @@ -813,7 +816,7 @@ public final class MapboxMap { public void setStyle(Style.Builder builder, final Style.OnStyleLoaded callback) { locationComponent.onStartLoadingMap(); if (style != null) { - style.onWillStartLoadingMap(); + style.clear(); } if (callback != null) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index cf5961a313..e49126531a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -29,8 +29,6 @@ interface NativeMap { // Lifecycle API // - void update(); - void resizeView(int width, int height); void onLowMemory(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 10942d521c..a5f8be788c 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -136,15 +136,6 @@ final class NativeMapView implements NativeMap { } @Override - public void update() { - if (checkState("update")) { - return; - } - - mapRenderer.requestRender(); - } - - @Override public void resizeView(int width, int height) { if (checkState("resizeView")) { return; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java index f14e034816..5c28b55de8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -100,8 +100,8 @@ public class Style { */ public void addSource(@NonNull Source source) { validateState("addSource"); - sources.put(source.getId(), source); nativeMap.addSource(source); + sources.put(source.getId(), source); } /** @@ -172,8 +172,8 @@ public class Style { */ public void addLayer(@NonNull Layer layer) { validateState("addLayer"); - layers.put(layer.getId(), layer); nativeMap.addLayer(layer); + layers.put(layer.getId(), layer); } /** @@ -184,8 +184,8 @@ public class Style { */ public void addLayerBelow(@NonNull Layer layer, @NonNull String below) { validateState("addLayerBelow"); - layers.put(layer.getId(), layer); nativeMap.addLayerBelow(layer, below); + layers.put(layer.getId(), layer); } /** @@ -196,8 +196,8 @@ public class Style { */ public void addLayerAbove(@NonNull Layer layer, @NonNull String above) { validateState("addLayerAbove"); - layers.put(layer.getId(), layer); nativeMap.addLayerAbove(layer, above); + layers.put(layer.getId(), layer); } /** @@ -209,8 +209,8 @@ public class Style { */ public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) { validateState("addLayerAbove"); - layers.put(layer.getId(), layer); nativeMap.addLayerAt(layer, index); + layers.put(layer.getId(), layer); } /** @@ -437,10 +437,11 @@ public class Style { // /** - * Called when the underlying map will start loading a new style. This method will clean up this style - * by setting the java sources and layers in a detached state and removing them from core. + * Called when the underlying map will start loading a new style or the map is destroyed. + * This method will clean up this style by setting the java sources and layers + * in a detached state and removing them from core. */ - void onWillStartLoadingMap() { + void clear() { fullyLoaded = false; for (Source source : sources.values()) { if (source != null) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 034dc63c35..c671146876 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -10,6 +10,7 @@ import android.os.Bundle; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.Px; import android.support.annotation.UiThread; import android.support.v4.content.ContextCompat; import android.support.v4.content.res.ResourcesCompat; @@ -344,7 +345,7 @@ public final class UiSettings { } /** - * Sets the margins of the compass view. Use this to change the distance of the compass from the + * Sets the margins of the compass view in pixels. Use this to change the distance of the compass from the * map view edge. * * @param left The left margin in pixels. @@ -353,42 +354,46 @@ public final class UiSettings { * @param bottom The bottom margin in pixels. */ @UiThread - public void setCompassMargins(int left, int top, int right, int bottom) { + public void setCompassMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) { setWidgetMargins(compassView, compassMargins, left, top, right, bottom); } /** - * Returns the left side margin of CompassView + * Returns the left side margin of CompassView in pixels. * * @return The left margin in pixels */ + @Px public int getCompassMarginLeft() { return compassMargins[0]; } /** - * Returns the top side margin of CompassView + * Returns the top side margin of CompassView in pixels. * * @return The top margin in pixels */ + @Px public int getCompassMarginTop() { return compassMargins[1]; } /** - * Returns the right side margin of CompassView + * Returns the right side margin of CompassView in pixels. * * @return The right margin in pixels */ + @Px public int getCompassMarginRight() { return compassMargins[2]; } /** - * Returns the bottom side margin of CompassView + * Returns the bottom side margin of CompassView in pixels. * * @return The bottom margin in pixels */ + @Px public int getCompassMarginBottom() { return compassMargins[3]; } @@ -456,7 +461,7 @@ public final class UiSettings { } /** - * Sets the margins of the logo view. Use this to change the distance of the Mapbox logo from the + * Sets the margins of the logo view in pixels. Use this to change the distance of the Mapbox logo from the * map view edge. * * @param left The left margin in pixels. @@ -464,42 +469,46 @@ public final class UiSettings { * @param right The right margin in pixels. * @param bottom The bottom margin in pixels. */ - public void setLogoMargins(int left, int top, int right, int bottom) { + public void setLogoMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) { setWidgetMargins(logoView, logoMargins, left, top, right, bottom); } /** - * Returns the left side margin of the logo + * Returns the left side margin of the logo in pixels. * * @return The left margin in pixels */ + @Px public int getLogoMarginLeft() { return logoMargins[0]; } /** - * Returns the top side margin of the logo + * Returns the top side margin of the logo in pixels. * * @return The top margin in pixels */ + @Px public int getLogoMarginTop() { return logoMargins[1]; } /** - * Returns the right side margin of the logo + * Returns the right side margin of the logo in pixels. * * @return The right margin in pixels */ + @Px public int getLogoMarginRight() { return logoMargins[2]; } /** - * Returns the bottom side margin of the logo + * Returns the bottom side margin of the logo in pixels. * * @return The bottom margin in pixels */ + @Px public int getLogoMarginBottom() { return logoMargins[3]; } @@ -570,14 +579,14 @@ public final class UiSettings { } /** - * Sets the margins of the attribution view. + * Sets the margins of the attribution view in pixels. * * @param left The left margin in pixels. * @param top The top margin in pixels. * @param right The right margin in pixels. * @param bottom The bottom margin in pixels. */ - public void setAttributionMargins(int left, int top, int right, int bottom) { + public void setAttributionMargins(@Px int left, @Px int top, @Px int right, @Px int bottom) { setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom); } @@ -599,37 +608,41 @@ public final class UiSettings { } /** - * Returns the left side margin of the attribution view. + * Returns the left side margin of the attribution view in pixels. * * @return The left margin in pixels */ + @Px public int getAttributionMarginLeft() { return attributionsMargins[0]; } /** - * Returns the top side margin of the attribution view. + * Returns the top side margin of the attribution view in pixels. * * @return The top margin in pixels */ + @Px public int getAttributionMarginTop() { return attributionsMargins[1]; } /** - * Returns the right side margin of the attribution view. + * Returns the right side margin of the attribution view in pixels. * * @return The right margin in pixels */ + @Px public int getAttributionMarginRight() { return attributionsMargins[2]; } /** - * Returns the bottom side margin of the logo + * Returns the bottom side margin of the logo in pixels. * * @return The bottom margin in pixels */ + @Px public int getAttributionMarginBottom() { return attributionsMargins[3]; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java index 9d9a7bd2d4..524c1a62ee 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java @@ -2,10 +2,8 @@ package com.mapbox.mapboxsdk.maps.renderer.glsurfaceview; import android.content.Context; import android.opengl.GLSurfaceView; - import android.support.annotation.NonNull; import android.view.SurfaceHolder; - import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; import com.mapbox.mapboxsdk.maps.renderer.egl.EGLConfigChooser; @@ -25,8 +23,6 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi @NonNull private final GLSurfaceView glSurfaceView; - private boolean requestDestroy; - public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView, String localIdeographFontFamily) { @@ -42,9 +38,8 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi @Override public void surfaceDestroyed(SurfaceHolder holder) { - requestDestroy = true; + onSurfaceDestroyed(); } - }); } @@ -60,9 +55,6 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi @Override public void onDestroy() { - if (requestDestroy) { - onSurfaceDestroyed(); - } super.onDestroy(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java index 96d5e9e943..165b15a512 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java @@ -197,7 +197,6 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu if (destroySurface) { eglHolder.destroySurface(); destroySurface = false; - mapRenderer.onSurfaceDestroyed(); break; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java index 6262418a29..53c0c1c60f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java @@ -7,10 +7,10 @@ import android.support.annotation.Nullable; import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorCompat; import android.support.v4.view.ViewPropertyAnimatorListenerAdapter; -import android.support.v7.widget.AppCompatImageView; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import com.mapbox.mapboxsdk.maps.MapboxMap; @@ -23,7 +23,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; * use {@link com.mapbox.mapboxsdk.maps.UiSettings}. * </p> */ -public final class CompassView extends AppCompatImageView implements Runnable { +public final class CompassView extends ImageView implements Runnable { public static final long TIME_WAIT_IDLE = 500; public static final long TIME_MAP_NORTH_ANIMATION = 150; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java index b88e1885ca..12d1fe46cf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PerformanceEvent.java @@ -1,20 +1,55 @@ package com.mapbox.mapboxsdk.module.telemetry; +import com.google.gson.Gson; + +import com.google.gson.JsonObject; + +import com.google.gson.reflect.TypeToken; import com.mapbox.android.telemetry.Event; import android.os.Bundle; import android.os.Parcel; + import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Locale; /** * Generic Performance Event that can be used for performance measurements. * Customer measurements can be added to the bundle. + * + * Bundle is expected to have following properties: + * "attributes", "counters", and "metadata" with String values. + * + * Attributes: a string representing an array of name/string value pair objects. + * Counters: a string representing an array of name/number value pair objects. + * Metadata is a string representation of a JsonObject with string values. + * + * Here is an example of a Performance event bundle data: + * + * "attributes": [{ "name": "style_id", "value": "mapbox://styles/mapbox/streets-v10"}] + * + * "counters": [{"name": "fps_average", "value": 90.7655486547093}, + * {"name": "fps_deviation", "value": 29.301809631465574}] + * “metadata”: { + * “version”: “9”, + * “screenSize”: “1080x1794”, + * “country”: “US”, + * “device”: “Pixel 2”, + * “abi”: “arm64-v8a”, + * “brand”: “google”, + * “ram”: “3834167296”, + * “os”: “android”, + * “gpu”: “Qualcomm, Adreno (TM) 540, OpenGL ES 3.2 V@313.0 (GIT@7bf2852, Ie32bfa6f6f)“, + * “manufacturer”: “Google” + * } */ public class PerformanceEvent extends Event { - private static final String PERFORMANCE_TRACE = "performance.trace"; + + private static final String PERFORMANCE_TRACE = "mobile.performance_trace"; private final String event; @@ -22,23 +57,36 @@ public class PerformanceEvent extends Event { private final String sessionId; - private final Bundle data; + private final List<Attribute<String>> attributes; + + private final List<Attribute<Double>> counters; + + private final JsonObject metadata; + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); - PerformanceEvent(String sessionId, Bundle data) { + PerformanceEvent(String sessionId, Bundle bundle) { + this.event = PERFORMANCE_TRACE; this.created = DATE_FORMAT.format(new Date()); this.sessionId = sessionId; - this.data = data; + this.attributes = initList(bundle.getString("attributes"), + new TypeToken<ArrayList<Attribute<String>>>() {}); + this.counters = initList(bundle.getString("counters"), + new TypeToken<ArrayList<Attribute<Double>>>() {}); + this.metadata = initMetaData(bundle.getString("metadata")); } private PerformanceEvent(Parcel in) { this.event = in.readString(); this.created = in.readString(); this.sessionId = in.readString(); - this.data = in.readBundle(); + + this.attributes = initList(in.readString(), new TypeToken<ArrayList<Attribute<String>>>() {}); + this.counters = initList(in.readString(), new TypeToken<ArrayList<Attribute<Double>>>() {}); + this.metadata = initMetaData(in.readString()); } @Override @@ -51,7 +99,30 @@ public class PerformanceEvent extends Event { parcel.writeString(event); parcel.writeString(created); parcel.writeString(sessionId); - parcel.writeBundle(data); + + Gson gson = new Gson(); + + parcel.writeString(gson.toJson(attributes)); + parcel.writeString(gson.toJson(counters)); + + if (metadata != null) { + parcel.writeString(metadata.toString()); + } + } + + private <T> ArrayList<Attribute<T>> initList(String fromString, TypeToken typeToken) { + if (fromString == null || fromString.isEmpty()) { + return new ArrayList<>(); + } + return new Gson().fromJson(fromString, typeToken.getType()); + } + + private JsonObject initMetaData(String fromString) { + if (fromString == null) { + return new JsonObject(); + } else { + return new Gson().fromJson(fromString, JsonObject.class); + } } public static final Creator<PerformanceEvent> CREATOR = new Creator<PerformanceEvent>() { @@ -65,4 +136,15 @@ public class PerformanceEvent extends Event { return new PerformanceEvent[size]; } }; + + + private class Attribute<T> { + private final String name; + private final T value; + + Attribute(String name, T value) { + this.name = name; + this.value = value; + } + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java index 5e021f961e..697a51286f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java @@ -111,8 +111,9 @@ public class TelemetryImpl implements TelemetryDefinition { @Override public void onPerformanceEvent(Bundle data) { - if (data != null && !data.isEmpty()) { - telemetry.push(new PerformanceEvent(UUID.randomUUID().toString(), data)); + if (data == null) { + data = new Bundle(); } + telemetry.push(new PerformanceEvent(UUID.randomUUID().toString(), data)); } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java index 01ac098d16..8684d7c6f1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java @@ -26,7 +26,11 @@ import java.nio.channels.FileChannel; /** * The offline manager is the main entry point for offline-related functionality. + * <p> * It'll help you list and create offline regions. + * </p> + * + * @see <a href="https://docs.mapbox.com/help/troubleshooting/mobile-offline/">Offline Maps Information/</a> */ public class OfflineManager { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index 1c87b9004b..57cf6271c9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java @@ -323,6 +323,10 @@ public final class Property { // TEXT_JUSTIFY: Text justification options. /** + * The text is aligned towards the anchor position. + */ + public static final String TEXT_JUSTIFY_AUTO = "auto"; + /** * The text is aligned to the left. */ public static final String TEXT_JUSTIFY_LEFT = "left"; @@ -339,6 +343,7 @@ public final class Property { * Text justification options. */ @StringDef({ + TEXT_JUSTIFY_AUTO, TEXT_JUSTIFY_LEFT, TEXT_JUSTIFY_CENTER, TEXT_JUSTIFY_RIGHT, diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 3d8b921a79..01908b1b0b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -2276,6 +2276,46 @@ public class PropertyFactory { } /** + * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Float> textRadialOffset(Float value) { + return new LayoutPropertyValue<>("text-radial-offset", value); + } + + /** + * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with {@link PropertyFactory#textVariableAnchor}, which doesn't support the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a Float value + * @return property wrapper around Float + */ + public static PropertyValue<Expression> textRadialOffset(Expression value) { + return new LayoutPropertyValue<>("text-radial-offset", value); + } + + /** + * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a String[] value + * @return property wrapper around String[] + */ + public static PropertyValue<String[]> textVariableAnchor(String[] value) { + return new LayoutPropertyValue<>("text-variable-anchor", value); + } + + /** + * To increase the chance of placing high-priority labels on the map, you can provide an array of {@link Property.TEXT_ANCHOR} locations: the render will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the {@link PropertyFactory#textRadialOffset} instead of the two-dimensional {@link PropertyFactory#textOffset}. + * + * @param value a String[] value + * @return property wrapper around String[] + */ + public static PropertyValue<Expression> textVariableAnchor(Expression value) { + return new LayoutPropertyValue<>("text-variable-anchor", value); + } + + /** * Part of the text placed closest to the anchor. * * @param value a String value diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index ab45cb04f2..75473f0f30 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -470,6 +470,30 @@ public class SymbolLayer extends Layer { } /** + * Get the TextRadialOffset property + * + * @return property wrapper value around Float + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue<Float> getTextRadialOffset() { + checkThread(); + return (PropertyValue<Float>) new PropertyValue("text-radial-offset", nativeGetTextRadialOffset()); + } + + /** + * Get the TextVariableAnchor property + * + * @return property wrapper value around String[] + */ + @NonNull + @SuppressWarnings("unchecked") + public PropertyValue<String[]> getTextVariableAnchor() { + checkThread(); + return (PropertyValue<String[]>) new PropertyValue("text-variable-anchor", nativeGetTextVariableAnchor()); + } + + /** * Get the TextAnchor property * * @return property wrapper value around String @@ -1187,6 +1211,14 @@ public class SymbolLayer extends Layer { @NonNull @Keep + private native Object nativeGetTextRadialOffset(); + + @NonNull + @Keep + private native Object nativeGetTextVariableAnchor(); + + @NonNull + @Keep private native Object nativeGetTextAnchor(); @NonNull diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java index fb2d361bfc..b76e4f4417 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java @@ -58,4 +58,12 @@ public class Formatted { public int hashCode() { return Arrays.hashCode(formattedSections); } + + @Override + public String toString() { + return "Formatted{" + + "formattedSections=" + + Arrays.toString(formattedSections) + + '}'; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java index a5b0dfbfe8..859fcff378 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java @@ -228,4 +228,14 @@ public class FormattedSection { params.put("text-color", textColor); return new Object[] {text, params}; } + + @Override + public String toString() { + return "FormattedSection{" + + "text='" + text + '\'' + + ", fontScale=" + fontScale + + ", fontStack=" + Arrays.toString(fontStack) + + ", textColor='" + textColor + '\'' + + '}'; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java index 3ef8e93cae..3570aa2c0b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -13,7 +13,6 @@ import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; -import android.support.v7.content.res.AppCompatResources; import android.view.View; import java.io.ByteArrayOutputStream; @@ -152,7 +151,7 @@ public class BitmapUtils { @Nullable public static Drawable getDrawableFromRes(@NonNull Context context, @DrawableRes int drawableRes, @Nullable @ColorInt Integer tintColor) { - Drawable drawable = AppCompatResources.getDrawable(context, drawableRes); + Drawable drawable = context.getResources().getDrawable(drawableRes); if (drawable == null) { return null; } |