Merge branch 'release-ios-v3.6.0-android-v5.1.0'

# Conflicts:
#	.travis.yml
#	circle.yml
#	cmake/core-files.cmake
#	include/mbgl/style/function/composite_function.hpp
#	platform/android/CHANGELOG.md
#	platform/android/MapboxGLAndroidSDK/build.gradle
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
#	platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LightTest.java
#	platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/light.junit.ejs
#	platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.java
#	platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/userlocation/MockLocationEngine.java
#	platform/android/dependencies.gradle
#	platform/android/src/native_map_view.cpp
#	platform/darwin/scripts/generate-style-code.js
#	platform/darwin/src/MGLGeometry_Private.h
#	platform/darwin/src/MGLLight.h
#	platform/darwin/src/MGLLight.mm
#	platform/darwin/src/MGLSource.h
#	platform/darwin/src/MGLStyle.h
#	platform/darwin/src/MGLStyle.mm
#	platform/darwin/test/MGLLightTest.mm
#	platform/default/default_file_source.cpp
#	platform/ios/CHANGELOG.md
#	platform/ios/Mapbox-iOS-SDK-symbols.podspec
#	platform/ios/Mapbox-iOS-SDK.podspec
#	platform/ios/resources/Images.xcassets/default_marker.imageset/default_marker.pdf
#	platform/macos/CHANGELOG.md
#	scripts/generate-shaders.js
#	src/mbgl/layout/symbol_layout.cpp
#	src/mbgl/programs/program.hpp
#	src/mbgl/programs/symbol_program.hpp
#	src/mbgl/programs/uniforms.hpp
#	src/mbgl/renderer/frame_history.cpp
#	src/mbgl/renderer/paint_property_binder.hpp
#	src/mbgl/shaders/line.cpp
#	src/mbgl/shaders/line_pattern.cpp
#	src/mbgl/shaders/line_sdf.cpp
#	src/mbgl/sprite/sprite_atlas.hpp
#	src/mbgl/style/layers/line_layer_properties.hpp
#	src/mbgl/style/sources/geojson_source.cpp
#	src/mbgl/style/style.cpp
#	src/mbgl/text/glyph_atlas.hpp
#	src/mbgl/tile/geometry_tile.cpp
#	src/mbgl/tile/geometry_tile.hpp
#	test/style/style.test.cpp
This commit is contained in:
Tobrun
2017-07-05 08:37:27 +02:00
150 changed files with 10299 additions and 6982 deletions

View File

@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk;
import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -17,10 +16,10 @@ import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
/**
* The entry point of the Mapbox Android SDK.
* The entry point to initialize the Mapbox Android SDK.
* <p>
* Obtain a reference by calling {@link #getInstance(Context, String)}. Usually this class is configured in
* {@link Application#onCreate()} and is responsible for the active access token, application context, and
* Application#onCreate() and is responsible for the active access token, application context, and
* connectivity state.
* </p>
*/
@@ -31,6 +30,7 @@ public final class Mapbox {
private Context context;
private String accessToken;
private Boolean connected;
private LocationSource locationSource;
/**
* Get an instance of Mapbox.
@@ -46,8 +46,8 @@ public final class Mapbox {
public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull String accessToken) {
if (INSTANCE == null) {
Context appContext = context.getApplicationContext();
INSTANCE = new Mapbox(appContext, accessToken);
LocationEngine locationEngine = LocationSource.getLocationEngine(appContext);
INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext));
LocationEngine locationEngine = new LocationSource(appContext);
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
MapboxTelemetry.getInstance().initialize(
appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
@@ -56,9 +56,10 @@ public final class Mapbox {
return INSTANCE;
}
Mapbox(@NonNull Context context, @NonNull String accessToken) {
Mapbox(@NonNull Context context, @NonNull String accessToken, LocationSource locationSource) {
this.context = context;
this.accessToken = accessToken;
this.locationSource = locationSource;
}
/**
@@ -96,6 +97,8 @@ public final class Mapbox {
/**
* Application context
*
* @return the application context
*/
public static Context getApplicationContext() {
return INSTANCE.context;
@@ -129,4 +132,8 @@ public final class Mapbox {
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return (activeNetwork != null && activeNetwork.isConnected());
}
public static LocationSource getLocationSource() {
return INSTANCE.locationSource;
}
}

View File

@@ -27,14 +27,32 @@ public class BubbleLayout extends LinearLayout {
private float strokeWidth;
private int strokeColor;
/**
* Creates an instance of bubble layout.
*
* @param context The context used to inflate this bubble layout
*/
public BubbleLayout(Context context) {
this(context, null, 0);
}
/**
* Creates an instance of bubble layout.
*
* @param context The context used to inflate this bubble layout
* @param attrs The attribute set to initialise this bubble layout from
*/
public BubbleLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* Creates an instance of bubble layout.
*
* @param context The context used to inflate this bubble layout
* @param attrs The attribute set to initialise this bubble layout from
* @param defStyleAttr The default style to apply this bubble layout with
*/
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@@ -78,10 +96,21 @@ public class BubbleLayout extends LinearLayout {
return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
/**
* Get the arrow direction.
*
* @return the arrow direction
*/
public ArrowDirection getArrowDirection() {
return arrowDirection;
}
/**
* Set the arrow direction.
*
* @param arrowDirection The direction of the arrow
* @return this
*/
public BubbleLayout setArrowDirection(ArrowDirection arrowDirection) {
resetPadding();
this.arrowDirection = arrowDirection;
@@ -89,10 +118,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
/**
* Get the arrow width.
*
* @return the width of the arrow
*/
public float getArrowWidth() {
return arrowWidth;
}
/**
* Set the arrow width.
*
* @param arrowWidth The width of the arrow
* @return this
*/
public BubbleLayout setArrowWidth(float arrowWidth) {
resetPadding();
this.arrowWidth = arrowWidth;
@@ -100,10 +140,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
/**
* Get the arrow height
*
* @return the height of the arrow
*/
public float getArrowHeight() {
return arrowHeight;
}
/**
* Set the arrow height.
*
* @param arrowHeight The height of the arrow
* @return this
*/
public BubbleLayout setArrowHeight(float arrowHeight) {
resetPadding();
this.arrowHeight = arrowHeight;
@@ -111,10 +162,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
/**
* Get the arrow position.
*
* @return the arrow position
*/
public float getArrowPosition() {
return arrowPosition;
}
/**
* Get the arrow position.
*
* @param arrowPosition The arrow position
* @return this
*/
public BubbleLayout setArrowPosition(float arrowPosition) {
resetPadding();
this.arrowPosition = arrowPosition;
@@ -122,30 +184,63 @@ public class BubbleLayout extends LinearLayout {
return this;
}
/**
* Get the corner radius
*
* @return the corner radius
*/
public float getCornersRadius() {
return cornersRadius;
}
/**
* Set the corner radius
*
* @param cornersRadius The corner radius
* @return this
*/
public BubbleLayout setCornersRadius(float cornersRadius) {
this.cornersRadius = cornersRadius;
requestLayout();
return this;
}
/**
* Get the bubble color.
*
* @return the bubble color
*/
public int getBubbleColor() {
return bubbleColor;
}
/**
* Set the bubble color.
*
* @param bubbleColor The buble color
* @return this
*/
public BubbleLayout setBubbleColor(int bubbleColor) {
this.bubbleColor = bubbleColor;
requestLayout();
return this;
}
/**
* Get stroke width.
*
* @return the stroke width
*/
public float getStrokeWidth() {
return strokeWidth;
}
/**
* Set the stroke width.
*
* @param strokeWidth The stroke width
* @return this
*/
public BubbleLayout setStrokeWidth(float strokeWidth) {
resetPadding();
this.strokeWidth = strokeWidth;
@@ -153,10 +248,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
/**
* Get the stroke color.
*
* @return the stroke color
*/
public int getStrokeColor() {
return strokeColor;
}
/**
* Set the stroke color.
*
* @param strokeColor The stroke color
* @return this
*/
public BubbleLayout setStrokeColor(int strokeColor) {
this.strokeColor = strokeColor;
requestLayout();

View File

@@ -23,7 +23,7 @@ import java.io.InputStream;
/**
* Factory for creating Icons from bitmap images.
* <p>
* {@link Icon} is used to display bitmaps on top of the map using {@link Marker} and {@link MarkerView}.
* icon is used to display bitmaps on top of the map using {@link Marker} and {@link MarkerView}.
* </p>
*
* @see Icon
@@ -42,6 +42,12 @@ public final class IconFactory {
private int nextId = 0;
/**
* Get a single instance of IconFactory.
*
* @param context the context to derive the application context from
* @return the single instance of IconFactory
*/
public static synchronized IconFactory getInstance(@NonNull Context context) {
if (instance == null) {
instance = new IconFactory(context.getApplicationContext());
@@ -71,10 +77,10 @@ public final class IconFactory {
}
/**
* Creates an {@link Icon} from a given Bitmap image.
* Creates an icon from a given Bitmap image.
*
* @param bitmap image used for creating the Icon.
* @return The {@link Icon} using the given Bitmap image.
* @return The icon using the given Bitmap image.
*/
public Icon fromBitmap(@NonNull Bitmap bitmap) {
if (nextId < 0) {
@@ -85,10 +91,10 @@ public final class IconFactory {
}
/**
* Create an {@link Icon} using the resource ID of a Bitmap image.
* Creates an icon using the resource ID of a Bitmap image.
*
* @param resourceId The resource ID of a Bitmap image.
* @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
* @return The icon that was loaded from the asset or {@code null} if failed to load.
*/
public Icon fromResource(@DrawableRes int resourceId) {
Drawable drawable = ContextCompat.getDrawable(context, resourceId);
@@ -101,9 +107,9 @@ public final class IconFactory {
}
/**
* Provides an {@link Icon} using the default marker icon used for {@link Marker}.
* Provides an icon using the default marker icon used for {@link Marker}.
*
* @return An {@link Icon} with the default {@link Marker} icon.
* @return An icon with the default {@link Marker} icon.
*/
public Icon defaultMarker() {
if (defaultMarker == null) {
@@ -113,9 +119,9 @@ public final class IconFactory {
}
/**
* Provides an {@link Icon} using the default marker icon used for {@link MarkerView}.
* Provides an icon using the default marker icon used for {@link MarkerView}.
*
* @return An {@link Icon} with the default {@link MarkerView} icon.
* @return An icon with the default {@link MarkerView} icon.
*/
public Icon defaultMarkerView() {
if (defaultMarkerView == null) {
@@ -130,10 +136,10 @@ public final class IconFactory {
}
/**
* Creates an {@link Icon} using the name of a Bitmap image in the assets directory.
* Creates an Icon using the name of a Bitmap image in the assets directory.
*
* @param assetName The name of a Bitmap image in the assets directory.
* @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
* @return The Icon that was loaded from the asset or null if failed to load.
*/
public Icon fromAsset(@NonNull String assetName) {
InputStream is;
@@ -146,11 +152,10 @@ public final class IconFactory {
}
/**
* Creates an {@link Icon} using the absolute file path of a Bitmap image.
* Creates an Icon using the absolute file path of a Bitmap image.
*
* @param absolutePath The absolute path of the Bitmap image.
* @return The {@link Icon} that was loaded from the absolute path or {@code null} if failed to
* load.
* @return The Icon that was loaded from the absolute path or null if failed to load.
*/
public Icon fromPath(@NonNull String absolutePath) {
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, options);
@@ -158,11 +163,11 @@ public final class IconFactory {
}
/**
* Create an {@link Icon} using the name of a Bitmap image file located in the internal storage.
* In particular, this calls {@link Context#openFileInput(String)}.
* Create an Icon using the name of a Bitmap image file located in the internal storage.
* In particular, this calls Context#openFileInput(String).
*
* @param fileName The name of the Bitmap image file.
* @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
* @return The Icon that was loaded from the asset or null if failed to load.
* @see <a href="https://developer.android.com/guide/topics/data/data-storage.html#filesInternal">
* Using the Internal Storage</a>
*/
@@ -177,12 +182,11 @@ public final class IconFactory {
}
/**
* Create an {@link Icon} using a previously created icon identifier along with a provided
* Bitmap.
* Create an Icon using a previously created icon identifier along with a provided Bitmap.
*
* @param iconId The {@link Icon} identifier you'd like to recreate.
* @param iconId The Icon identifier you'd like to recreate.
* @param bitmap a Bitmap used to replace the current one.
* @return The {@link Icon} using the new Bitmap.
* @return The Icon using the new Bitmap.
*/
public static Icon recreate(@NonNull String iconId, @NonNull Bitmap bitmap) {
return new Icon(iconId, bitmap);

View File

@@ -10,6 +10,7 @@ import android.support.v4.util.LongSparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
@@ -33,6 +34,15 @@ import java.util.Map;
public class MarkerViewManager implements MapView.OnMapChangedListener {
private final ViewGroup markerViewContainer;
private final ViewTreeObserver.OnPreDrawListener markerViewPreDrawObserver =
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
invalidateViewMarkersInVisibleRegion();
markerViewContainer.getViewTreeObserver().removeOnPreDrawListener(markerViewPreDrawObserver);
return false;
}
};
private final Map<MarkerView, View> markerViewMap = new HashMap<>();
private final LongSparseArray<OnMarkerViewAddedListener> markerViewAddedListenerMap = new LongSparseArray<>();
private final List<MapboxMap.MarkerViewAdapter> markerViewAdapters = new ArrayList<>();
@@ -125,6 +135,12 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
}
/**
* Set the rotation of a MarkerView to a given rotation value.
*
* @param marker The MarkerView to change its rotation value
* @param rotation The rotation value
*/
public void setRotation(@NonNull MarkerView marker, float rotation) {
View convertView = markerViewMap.get(marker);
if (convertView != null) {
@@ -180,14 +196,16 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
// ensure view is measured first
// #6805 invalidate marker views to ensure convertView width and height
// values are properly measured and up to date
if (marker.getWidth() == 0) {
convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
if (convertView.getMeasuredWidth() != 0) {
marker.setWidth(convertView.getMeasuredWidth());
marker.setHeight(convertView.getMeasuredHeight());
}
convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver);
}
}
marker.setWidth(convertView.getWidth());
marker.setHeight(convertView.getHeight());
if (marker.getWidth() != 0) {
int x = (int) (marker.getAnchorU() * marker.getWidth());
int y = (int) (marker.getAnchorV() * marker.getHeight());
@@ -532,10 +550,11 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
* When the provided {@link MarkerView} is clicked on by a user, we check if a custom click
* event has been created and if not, display a {@link InfoWindow}.
* When the provided MarkerView is clicked on by a user, we check if a custom click
* event has been created and if not, display a InfoWindow.
*
* @param markerView that the click event occurred.
* @param markerView that the click event occurred
* @return true if the marker view click has been handled, false if not
*/
public boolean onClickMarkerView(MarkerView markerView) {
boolean clickHandled = false;
@@ -560,9 +579,9 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
* Handles the {@link MarkerView}'s info window offset.
* Handles the MarkerView info window offset.
*
* @param marker that we are ensuring info window offset.
* @param marker that we are ensuring info window offset
*/
public void ensureInfoWindowOffset(MarkerView marker) {
View view = null;
@@ -612,7 +631,7 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
* Default MarkerViewAdapter used for base class of {@link MarkerView} to adapt a MarkerView to
* Default MarkerViewAdapter used for base class of MarkerView to adapt a MarkerView to
* an ImageView.
*/
private static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> {

View File

@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.camera;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -166,14 +167,14 @@ public final class CameraPosition implements Parcelable {
private double zoom = -1;
/**
* Creates an empty builder.
* Create an empty builder.
*/
public Builder() {
super();
}
/**
* Create Builder with an existing CameraPosition data.
* Create a builder with an existing CameraPosition data.
*
* @param previous Existing CameraPosition values to use
*/
@@ -188,7 +189,7 @@ public final class CameraPosition implements Parcelable {
}
/**
* Create Builder with an existing CameraPosition data.
* Create a builder with an existing CameraPosition data.
*
* @param typedArray TypedArray containing attribute values
*/
@@ -205,7 +206,7 @@ public final class CameraPosition implements Parcelable {
}
/**
* Create Builder from an existing CameraPositionUpdate update.
* Create a builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
@@ -220,7 +221,7 @@ public final class CameraPosition implements Parcelable {
}
/**
* Create Builder from an existing CameraPositionUpdate update.
* Create builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
@@ -235,7 +236,7 @@ public final class CameraPosition implements Parcelable {
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
*
* @param bearing Bearing
* @return Builder
* @return this
*/
public Builder bearing(double bearing) {
double direction = bearing;
@@ -252,19 +253,10 @@ public final class CameraPosition implements Parcelable {
}
/**
* Builds a CameraPosition.
* Sets the location where the camera is pointing at.
*
* @return CameraPosition
*/
public CameraPosition build() {
return new CameraPosition(target, zoom, tilt, bearing);
}
/**
* Sets the location that the camera is pointing at.
*
* @param location Location
* @return Builder
* @param location target of the camera
* @return this
*/
public Builder target(LatLng location) {
this.target = location;
@@ -272,28 +264,42 @@ public final class CameraPosition implements Parcelable {
}
/**
* Set the tilt in degrees
* Set the tilt of the camera in degrees
* <p>
* value is clamped to 0 and 60.
* value is clamped to {@link MapboxConstants#MINIMUM_TILT} and {@link MapboxConstants#MAXIMUM_TILT}.
* </p>
*
* @param tilt Tilt value
* @return Builder
* @param tilt Tilt value of the camera
* @return this
*/
public Builder tilt(double tilt) {
public Builder tilt(@FloatRange(from = MapboxConstants.MINIMUM_TILT,
to = MapboxConstants.MAXIMUM_TILT) double tilt) {
this.tilt = MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT);
return this;
}
/**
* Set the zoom
* Set the zoom of the camera
* <p>
* Zoom ranges from {@link MapboxConstants#MINIMUM_ZOOM} to {@link MapboxConstants#MAXIMUM_ZOOM}
* </p>
*
* @param zoom Zoom value
* @return Builder
* @param zoom Zoom value of the camera
* @return this
*/
public Builder zoom(double zoom) {
public Builder zoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
this.zoom = zoom;
return this;
}
/**
* Builds the CameraPosition.
*
* @return CameraPosition
*/
public CameraPosition build() {
return new CameraPosition(target, zoom, tilt, bearing);
}
}
}

View File

@@ -1,14 +1,22 @@
package com.mapbox.mapboxsdk.camera;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
* Interface definition for camera position changes.
* Interface definition for camera updates.
*/
public interface CameraUpdate {
/**
* Get the camera position from the camera update.
*
* @param mapboxMap Map object to build the position from
* @return the camera position from the implementing camera update
*/
@Nullable
CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);
}

View File

@@ -42,7 +42,7 @@ public final class CameraUpdateFactory {
}
/**
* Returns a {@link CameraUpdate} that transforms the camera such that the specified
* Returns a CameraUpdate that transforms the camera such that the specified
* latitude/longitude bounds are centered on screen at the greatest possible zoom level.
* You can specify padding, in order to inset the bounding box from the map view's edges.
* The returned CameraUpdate has a bearing of 0 and a tilt of 0.
@@ -56,7 +56,7 @@ public final class CameraUpdateFactory {
}
/**
* Returns a {@link CameraUpdate} that transforms the camera such that the specified
* Returns a CameraUpdate that transforms the camera such that the specified
* latitude/longitude bounds are centered on screen at the greatest possible zoom level.
* You can specify padding, in order to inset the bounding box from the map view's edges.
* The returned CameraUpdate has a bearing of 0 and a tilt of 0.

View File

@@ -133,5 +133,6 @@ public class MapboxConstants {
public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "mapbox_attrMarginRight";
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom";
public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled";
public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled";
public static final String STATE_USING_CUSTOM_LOCATION_SOURCE = "mapbox_usingCustomLocationSource";
}

View File

@@ -2,23 +2,27 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* MyBearingTracking exposes different types bearing tracking modes.
* MyBearingTracking exposes different types of bearing tracking modes.
* <p>
* These modes visualise the user direction by extracting the direction from either sensor or location data.
* </p>
* <p>
* Required to enable showing the user location first through {@link MapboxMap#setMyLocationEnabled(boolean)}.
* </p>
*
* @see com.mapbox.mapboxsdk.maps.TrackingSettings#setMyBearingTrackingMode(int)
* @see MyLocationView#setMyBearingTrackingMode(int)
*/
public class MyBearingTracking {
/**
* Indicates that the parameter accepts one of the values from MyBearingTracking.
*/
@IntDef( {NONE, COMPASS, GPS, /**COMBINED**/})
@IntDef( {NONE, COMPASS, GPS})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}

View File

@@ -3,29 +3,34 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* MyLocationTracking exposes different types of locational tracking modes.
* MyLocationTracking exposes types of location tracking modes.
* * <p>
* This allows tracking the user location on screen by updating the camera position when a location update occurs.
* </p>
* <p>
* Required to enable showing the user location first through {@link MapboxMap#setMyLocationEnabled(boolean)}.
* </p>
*
* @see com.mapbox.mapboxsdk.maps.TrackingSettings#setMyLocationTrackingMode(int)
* @see MyLocationView#setMyLocationTrackingMode(int)
* @see MapboxMap#setMyLocationEnabled(boolean)
* @see TrackingSettings#setMyLocationTrackingMode(int)
*/
public class MyLocationTracking {
/**
* Indicates the parameter accepts one of the values from MyLocationTracking.
*/
@IntDef( {TRACKING_NONE, TRACKING_FOLLOW})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}
/**
* Location tracking is disabled.
* Tracking the location of the user is disabled.
*/
public static final int TRACKING_NONE = 0x00000000;

View File

@@ -17,7 +17,6 @@ import java.lang.annotation.RetentionPolicy;
*/
public class Style {
/**
* Indicates the parameter accepts one of the values from Style. Using one of these
* constants means your map style will always use the latest version and may change as we

View File

@@ -1,15 +1,13 @@
package com.mapbox.mapboxsdk.exceptions;
import android.graphics.Bitmap;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.maps.MapView;
/**
* <p>
* A {@code IconBitmapChangedException} is thrown by {@link MapView} when a {@link Marker} is added
* that has a {@link Icon} with a {@link Bitmap} that has been modified since the creation of the Icon.
* An IconBitmapChangedException is thrown by MapView when a Marker is added
* that has an Icon with a Bitmap that has been modified since the creation of the Icon.
* </p>
* You cannot modify a {@code Icon} after it has been added to the map in a {@code Marker}
*

View File

@@ -1,8 +1,8 @@
package com.mapbox.mapboxsdk.exceptions;
/**
* A InvalidLatLngBoundsException is thrown by {@link com.mapbox.mapboxsdk.geometry.LatLngBounds}
* when there aren't enough {@link com.mapbox.mapboxsdk.geometry.LatLng} to create a bounds.
* An InvalidLatLngBoundsException is thrown by LatLngBounds
* when there aren't enough LatLng to create a bounds.
*/
public class InvalidLatLngBoundsException extends RuntimeException {

View File

@@ -5,6 +5,9 @@ package com.mapbox.mapboxsdk.exceptions;
*/
public class InvalidMarkerPositionException extends RuntimeException {
/**
* Creates a invalid marker position exception thrown when a Marker object is created with an invalid LatLng position.
*/
public InvalidMarkerPositionException() {
super("Adding an invalid Marker to a Map. "
+ "Missing the required position field. "

View File

@@ -8,10 +8,14 @@ import android.content.Context;
* This occurs either when {@link com.mapbox.mapboxsdk.Mapbox} is not correctly initialised or the provided access token
* through {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)} isn't valid.
* </p>
*
* @see com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)
*/
public class MapboxConfigurationException extends RuntimeException {
/**
* Creates a Mapbox configuration exception thrown by MapboxMap when the SDK hasn't been properly initialised.
*/
public MapboxConfigurationException() {
super("\nUsing MapView requires setting a valid access token. Use Mapbox.getInstance(Context context, "
+ "String accessToken) to provide one. "

View File

@@ -1,12 +1,11 @@
package com.mapbox.mapboxsdk.exceptions;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
/**
* <p>
* A {@code TooManyIconsException} is thrown by {@link IconFactory} when it
* cannot create a {@link Icon} because there are already too many icons created.
* A TooManyIconsException is thrown by IconFactory when it
* cannot create a Icon because there are already too many icons created.
* </p>
* You should try to reuse Icon objects whenever possible.
*

View File

@@ -1,12 +1,28 @@
package com.mapbox.mapboxsdk.geometry;
/**
* Describes a latitude, longitude point.
* Describes a latitude, longitude, and altitude tuple.
*/
public interface ILatLng {
/**
* Get the latitude, in degrees.
*
* @return the latitude value in degrees
*/
double getLatitude();
/**
* Get the longitude, in degrees.
*
* @return the longitude value in degrees
*/
double getLongitude();
/**
* Get the altitude, in meters.
*
* @return the altitude value in meters
*/
double getAltitude();
}

View File

@@ -4,7 +4,19 @@ package com.mapbox.mapboxsdk.geometry;
* Describes a projection in Mercator meters.
*/
public interface IProjectedMeters {
/**
* Get the north projection, in meters.
*
* @return the projected meters in north direction
*/
double getNorthing();
/**
* Get the east projection, in meters.
*
* @return the projected meters in east direction
*/
double getEasting();
}

View File

@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.geometry;
import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
import com.mapbox.services.android.telemetry.utils.MathUtils;
@@ -21,6 +22,9 @@ import com.mapbox.services.android.telemetry.utils.MathUtils;
*/
public class LatLng implements ILatLng, Parcelable {
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Parcelable.Creator<LatLng> CREATOR = new Parcelable.Creator<LatLng>() {
public LatLng createFromParcel(Parcel in) {
return new LatLng(in);
@@ -44,7 +48,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
* Construct a new latitude, longitude point given float arguments
* Construct a new latitude, longitude point given double arguments
*
* @param latitude Latitude in degrees
* @param longitude Longitude in degrees
@@ -55,7 +59,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
* Construct a new latitude, longitude, altitude point given float arguments
* Construct a new latitude, longitude, altitude point given double arguments
*
* @param latitude Latitude in degrees
* @param longitude Longitude in degress
@@ -68,7 +72,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
* Transform a Location into a LatLng point
* Construct a new latitude, longitude, altitude point given location argument
*
* @param location Android Location
*/
@@ -77,23 +81,40 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
* Clone an existing latitude longitude point
* Construct a new latitude, longitude, altitude point given another latitude, longitude, altitude point.
*
* @param aLatLng LatLng
* @param latLng LatLng to be cloned.
*/
public LatLng(LatLng aLatLng) {
this.latitude = aLatLng.latitude;
this.longitude = aLatLng.longitude;
this.altitude = aLatLng.altitude;
public LatLng(LatLng latLng) {
this.latitude = latLng.latitude;
this.longitude = latLng.longitude;
this.altitude = latLng.altitude;
}
/**
* Constructs a new latitude, longitude, altitude tuple given a parcel.
*
* @param in the parcel containing the latitude, longitude, altitude values
*/
protected LatLng(Parcel in) {
setLatitude(in.readDouble());
setLongitude(in.readDouble());
setAltitude(in.readDouble());
}
public void setLatitude(double latitude) {
/**
* Set the latitude, in degrees.
* <p>
* This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
* {@link GeoConstants#MAX_LATITUDE}
* </p>
*
* @param latitude the latitude value in degrees
* @see GeoConstants#MIN_LATITUDE
* @see GeoConstants#MAX_LATITUDE
*/
public void setLatitude(
@FloatRange(from = GeoConstants.MIN_LATITUDE, to = GeoConstants.MAX_LATITUDE) double latitude) {
if (Double.isNaN(latitude)) {
throw new IllegalArgumentException("latitude must not be NaN");
}
@@ -103,12 +124,35 @@ public class LatLng implements ILatLng, Parcelable {
this.latitude = latitude;
}
/**
* Get the latitude, in degrees.
* <p>
* This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
* {@link GeoConstants#MAX_LATITUDE}
* </p>
*
* @return the latitude value in degrees
* @see GeoConstants#MIN_LATITUDE
* @see GeoConstants#MAX_LATITUDE
*/
@Override
public double getLatitude() {
return latitude;
}
public void setLongitude(double longitude) {
/**
* Set the longitude, in degrees.
* <p>
* This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
* {@link GeoConstants#MAX_LONGITUDE}
* </p>
*
* @param longitude the longitude value in degrees
* @see GeoConstants#MIN_LONGITUDE
* @see GeoConstants#MAX_LONGITUDE
*/
public void setLongitude(@FloatRange(from = GeoConstants.MIN_LONGITUDE, to = GeoConstants.MAX_LONGITUDE)
double longitude) {
if (Double.isNaN(longitude)) {
throw new IllegalArgumentException("longitude must not be NaN");
}
@@ -118,15 +162,36 @@ public class LatLng implements ILatLng, Parcelable {
this.longitude = longitude;
}
/**
* Get the longitude, in degrees.
* <p>
* This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
* {@link GeoConstants#MAX_LONGITUDE}
* </p>
*
* @return the longitude value in degrees
* @see GeoConstants#MIN_LONGITUDE
* @see GeoConstants#MAX_LONGITUDE
*/
@Override
public double getLongitude() {
return longitude;
}
/**
* Set the altitude, in meters.
*
* @param altitude the altitude in meters
*/
public void setAltitude(double altitude) {
this.altitude = altitude;
}
/**
* Get the altitude, in meters.
*
* @return the altitude value in meters
*/
@Override
public double getAltitude() {
return altitude;
@@ -136,13 +201,19 @@ public class LatLng implements ILatLng, Parcelable {
* Return a new LatLng object with a wrapped Longitude. This allows original data object
* to remain unchanged.
*
* @return New LatLng object with wrapped Longitude
* @return new LatLng object with wrapped Longitude
*/
public LatLng wrap() {
longitude = MathUtils.wrap(longitude, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE);
return this;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param object The object to compare
* @return True if equal, false if not
*/
@Override
public boolean equals(Object object) {
if (this == object) {
@@ -158,6 +229,11 @@ public class LatLng implements ILatLng, Parcelable {
&& Double.compare(latLng.longitude, longitude) == 0;
}
/**
* Returns a hash code value for the object.
*
* @return the hash code value
*/
@Override
public int hashCode() {
int result;
@@ -171,16 +247,32 @@ public class LatLng implements ILatLng, Parcelable {
return result;
}
/**
* Returns a string representation of the object.
*
* @return the string representation
*/
@Override
public String toString() {
return "LatLng [latitude=" + latitude + ", longitude=" + longitude + ", altitude=" + altitude + "]";
}
/**
* Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0;
}
/**
* Flatten this object in to a Parcel.
*
* @param out The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written
*/
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);

View File

@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
@@ -18,10 +19,10 @@ import java.util.List;
*/
public class LatLngBounds implements Parcelable {
private final double mLatNorth;
private final double mLatSouth;
private final double mLonEast;
private final double mLonWest;
private final double latitudeNorth;
private final double latitudeSouth;
private final double longitudeEast;
private final double longitudeWest;
/**
* Construct a new LatLngBounds based on its corners, given in NESW
@@ -34,10 +35,10 @@ public class LatLngBounds implements Parcelable {
*/
LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude,
final double westLongitude) {
this.mLatNorth = northLatitude;
this.mLonEast = eastLongitude;
this.mLatSouth = southLatitude;
this.mLonWest = westLongitude;
this.latitudeNorth = northLatitude;
this.longitudeEast = eastLongitude;
this.latitudeSouth = southLatitude;
this.longitudeWest = westLongitude;
}
/**
@@ -59,8 +60,8 @@ public class LatLngBounds implements Parcelable {
* @return LatLng center of this LatLngBounds
*/
public LatLng getCenter() {
return new LatLng((this.mLatNorth + this.mLatSouth) / 2,
(this.mLonEast + this.mLonWest) / 2);
return new LatLng((this.latitudeNorth + this.latitudeSouth) / 2,
(this.longitudeEast + this.longitudeWest) / 2);
}
/**
@@ -69,7 +70,7 @@ public class LatLngBounds implements Parcelable {
* @return double latitude value for north
*/
public double getLatNorth() {
return this.mLatNorth;
return this.latitudeNorth;
}
/**
@@ -78,7 +79,7 @@ public class LatLngBounds implements Parcelable {
* @return double latitude value for south
*/
public double getLatSouth() {
return this.mLatSouth;
return this.latitudeSouth;
}
/**
@@ -87,7 +88,7 @@ public class LatLngBounds implements Parcelable {
* @return double longitude value for east
*/
public double getLonEast() {
return this.mLonEast;
return this.longitudeEast;
}
/**
@@ -96,7 +97,7 @@ public class LatLngBounds implements Parcelable {
* @return double longitude value for west
*/
public double getLonWest() {
return this.mLonWest;
return this.longitudeWest;
}
/**
@@ -105,7 +106,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the south west corner
*/
public LatLng getSouthWest() {
return new LatLng(mLatSouth, mLonWest);
return new LatLng(latitudeSouth, longitudeWest);
}
/**
@@ -114,7 +115,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the north east corner
*/
public LatLng getNorthEast() {
return new LatLng(mLatNorth, mLonEast);
return new LatLng(latitudeNorth, longitudeEast);
}
/**
@@ -123,7 +124,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the south east corner
*/
public LatLng getSouthEast() {
return new LatLng(mLatSouth, mLonEast);
return new LatLng(latitudeSouth, longitudeEast);
}
/**
@@ -132,7 +133,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the north west corner
*/
public LatLng getNorthWest() {
return new LatLng(mLatNorth, mLonWest);
return new LatLng(latitudeNorth, longitudeWest);
}
/**
@@ -151,7 +152,7 @@ public class LatLngBounds implements Parcelable {
* @return Span distance
*/
public double getLatitudeSpan() {
return Math.abs(this.mLatNorth - this.mLatSouth);
return Math.abs(this.latitudeNorth - this.latitudeSouth);
}
/**
@@ -161,7 +162,7 @@ public class LatLngBounds implements Parcelable {
* @return Span distance
*/
public double getLongitudeSpan() {
return Math.abs(this.mLonEast - this.mLonWest);
return Math.abs(this.longitudeEast - this.longitudeWest);
}
@@ -174,9 +175,15 @@ public class LatLngBounds implements Parcelable {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
/**
* Returns a string representaton of the object.
*
* @return the string representation
*/
@Override
public String toString() {
return "N:" + this.mLatNorth + "; E:" + this.mLonEast + "; S:" + this.mLatSouth + "; W:" + this.mLonWest;
return "N:" + this.latitudeNorth + "; E:" + this.longitudeEast + "; S:" + this.latitudeSouth
+ "; W:" + this.longitudeWest;
}
/**
@@ -241,10 +248,10 @@ public class LatLngBounds implements Parcelable {
}
if (o instanceof LatLngBounds) {
LatLngBounds other = (LatLngBounds) o;
return mLatNorth == other.getLatNorth()
&& mLatSouth == other.getLatSouth()
&& mLonEast == other.getLonEast()
&& mLonWest == other.getLonWest();
return latitudeNorth == other.getLatNorth()
&& latitudeSouth == other.getLatSouth()
&& longitudeEast == other.getLonEast()
&& longitudeWest == other.getLonWest();
}
return false;
}
@@ -258,10 +265,10 @@ public class LatLngBounds implements Parcelable {
public boolean contains(final ILatLng latLng) {
final double latitude = latLng.getLatitude();
final double longitude = latLng.getLongitude();
return ((latitude <= this.mLatNorth)
&& (latitude >= this.mLatSouth))
&& ((longitude <= this.mLonEast)
&& (longitude >= this.mLonWest));
return ((latitude <= this.latitudeNorth)
&& (latitude >= this.latitudeSouth))
&& ((longitude <= this.longitudeEast)
&& (longitude >= this.longitudeWest));
}
/**
@@ -295,10 +302,10 @@ public class LatLngBounds implements Parcelable {
* @return BoundingBox
*/
public LatLngBounds union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) {
return new LatLngBounds((this.mLatNorth < lonNorth) ? lonNorth : this.mLatNorth,
(this.mLonEast < latEast) ? latEast : this.mLonEast,
(this.mLatSouth > lonSouth) ? lonSouth : this.mLatSouth,
(this.mLonWest > latWest) ? latWest : this.mLonWest);
return new LatLngBounds((this.latitudeNorth < lonNorth) ? lonNorth : this.latitudeNorth,
(this.longitudeEast < latEast) ? latEast : this.longitudeEast,
(this.latitudeSouth > lonSouth) ? lonSouth : this.latitudeSouth,
(this.longitudeWest > latWest) ? latWest : this.longitudeWest);
}
/**
@@ -307,6 +314,7 @@ public class LatLngBounds implements Parcelable {
* @param box LatLngBounds to intersect with
* @return LatLngBounds
*/
@Nullable
public LatLngBounds intersect(LatLngBounds box) {
double minLatWest = Math.max(getLonWest(), box.getLonWest());
double maxLatEast = Math.min(getLonEast(), box.getLonEast());
@@ -334,6 +342,9 @@ public class LatLngBounds implements Parcelable {
return intersect(new LatLngBounds(northLatitude, eastLongitude, southLatitude, westLongitude));
}
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Parcelable.Creator<LatLngBounds> CREATOR =
new Parcelable.Creator<LatLngBounds>() {
@Override
@@ -347,25 +358,41 @@ public class LatLngBounds implements Parcelable {
}
};
/**
* Returns a hash code value for the object.
*
* @return the hash code
*/
@Override
public int hashCode() {
return (int) ((mLatNorth + 90)
+ ((mLatSouth + 90) * 1000)
+ ((mLonEast + 180) * 1000000)
+ ((mLonEast + 180) * 1000000000));
return (int) ((latitudeNorth + 90)
+ ((latitudeSouth + 90) * 1000)
+ ((longitudeEast + 180) * 1000000)
+ ((longitudeEast + 180) * 1000000000));
}
/**
* Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0;
}
/**
* Flatten this object in to a Parcel.
*
* @param out The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written
*/
@Override
public void writeToParcel(final Parcel out, final int arg1) {
out.writeDouble(this.mLatNorth);
out.writeDouble(this.mLonEast);
out.writeDouble(this.mLatSouth);
out.writeDouble(this.mLonWest);
public void writeToParcel(final Parcel out, final int flags) {
out.writeDouble(this.latitudeNorth);
out.writeDouble(this.longitudeEast);
out.writeDouble(this.latitudeSouth);
out.writeDouble(this.longitudeWest);
}
private static LatLngBounds readFromParcel(final Parcel in) {
@@ -381,28 +408,51 @@ public class LatLngBounds implements Parcelable {
*/
public static final class Builder {
private List<LatLng> mLatLngList;
private List<LatLng> latLngList;
/**
* Constructs a builder to compose LatLng objects to a LatLngBounds.
*/
public Builder() {
mLatLngList = new ArrayList<>();
latLngList = new ArrayList<>();
}
/**
* Builds a new LatLngBounds.
* <p>
* Throws an {@link InvalidLatLngBoundsException} when no LatLngBounds can be created.
* </p>
*
* @return the build LatLngBounds
*/
public LatLngBounds build() {
if (mLatLngList.size() < 2) {
throw new InvalidLatLngBoundsException(mLatLngList.size());
if (latLngList.size() < 2) {
throw new InvalidLatLngBoundsException(latLngList.size());
}
return LatLngBounds.fromLatLngs(mLatLngList);
return LatLngBounds.fromLatLngs(latLngList);
}
/**
* Adds a LatLng object to the LatLngBounds.Builder.
*
* @param latLngs the List of LatLng objects to be added
* @return this
*/
public Builder includes(List<LatLng> latLngs) {
for (LatLng point : latLngs) {
mLatLngList.add(point);
latLngList.add(point);
}
return this;
}
/**
* Adds a LatLng object to the LatLngBounds.Builder.
*
* @param latLng the LatLng to be added
* @return this
*/
public Builder include(@NonNull LatLng latLng) {
mLatLngList.add(latLng);
latLngList.add(latLng);
return this;
}
}

View File

@@ -64,19 +64,28 @@ public class LatLngSpan implements Parcelable {
mLongitudeSpan = longitudeSpan;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param object The object to compare
* @return True if equal, false if not
*/
@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (o instanceof LatLngSpan) {
LatLngSpan other = (LatLngSpan) o;
if (object instanceof LatLngSpan) {
LatLngSpan other = (LatLngSpan) object;
return mLongitudeSpan == other.getLongitudeSpan()
&& mLatitudeSpan == other.getLatitudeSpan();
}
return false;
}
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Parcelable.Creator<LatLngSpan> CREATOR =
new Parcelable.Creator<LatLngSpan>() {
@Override
@@ -90,14 +99,41 @@ public class LatLngSpan implements Parcelable {
}
};
/**
* Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0;
}
/**
* Flatten this object in to a Parcel.
*
* @param out Parcel in which the object should be written
* @param flags Additional flags about how the object should be written
*/
@Override
public void writeToParcel(Parcel out, int arg1) {
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(mLatitudeSpan);
out.writeDouble(mLongitudeSpan);
}
/**
* Returns a hash code value for the object.
*
* @return hash code value of this
*/
@Override
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(mLatitudeSpan);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(mLongitudeSpan);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
}

View File

@@ -13,6 +13,9 @@ import android.os.Parcelable;
*/
public class ProjectedMeters implements IProjectedMeters, Parcelable {
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Creator<ProjectedMeters> CREATOR = new Creator<ProjectedMeters>() {
public ProjectedMeters createFromParcel(Parcel in) {
return new ProjectedMeters(in);
@@ -47,6 +50,12 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
this.easting = projectedMeters.easting;
}
/**
* Creates a ProjectedMeters from a Parcel.
*
* @param in The parcel to create from
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
private ProjectedMeters(Parcel in) {
northing = in.readDouble();
easting = in.readDouble();
@@ -72,22 +81,32 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
return easting;
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param other The object to compare this to
* @return true if equal, false if not
*/
@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (other == null || getClass() != other.getClass()) {
return false;
}
ProjectedMeters projectedMeters = (ProjectedMeters) o;
ProjectedMeters projectedMeters = (ProjectedMeters) other;
return Double.compare(projectedMeters.easting, easting) == 0
&& Double.compare(projectedMeters.northing, northing) == 0;
}
/**
* Returns a hash code value for the object.
*
* @return the hash code of this
*/
@Override
public int hashCode() {
int result;
@@ -99,16 +118,32 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
return result;
}
/**
* Returns a string representation of the object.
*
* @return the string representation of this
*/
@Override
public String toString() {
return "ProjectedMeters [northing=" + northing + ", easting=" + easting + "]";
}
/**
* Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0;
}
/**
* Flatten this object in to a Parcel.
*
* @param out The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written
*/
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(northing);

View File

@@ -37,6 +37,11 @@ public class VisibleRegion implements Parcelable {
*/
public final LatLngBounds latLngBounds;
/**
* Creates a VisibleRegion from a Parcel.
*
* @param in The Parcel to create this from
*/
private VisibleRegion(Parcel in) {
this.farLeft = in.readParcelable(LatLng.class.getClassLoader());
this.farRight = in.readParcelable(LatLng.class.getClassLoader());
@@ -46,7 +51,7 @@ public class VisibleRegion implements Parcelable {
}
/**
* Creates a new VisibleRegion given the four corners of the camera.
* Creates a VisibleRegion given the four corners of the camera.
*
* @param farLeft A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param farRight A LatLng object containing the latitude and longitude of the near left corner of the region.
@@ -88,12 +93,22 @@ public class VisibleRegion implements Parcelable {
&& latLngBounds.equals(visibleRegion.latLngBounds);
}
/**
* The string representation of the object.
*
* @return the string representation of this
*/
@Override
public String toString() {
return "[farLeft [" + farLeft + "], farRight [" + farRight + "], nearLeft [" + nearLeft + "], nearRight ["
+ nearRight + "], latLngBounds [" + latLngBounds + "]]";
}
/**
* Returns a hash code value for the object.
*
* @return the hash code
*/
@Override
public int hashCode() {
return ((farLeft.hashCode() + 90)
@@ -102,11 +117,22 @@ public class VisibleRegion implements Parcelable {
+ ((nearRight.hashCode() + 180) * 1000000000));
}
/**
* Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
*
* @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
*/
@Override
public int describeContents() {
return 0;
}
/**
* Flatten this object in to a Parcel.
*
* @param out The Parcel in which the object should be written.
* @param flags Additional flags about how the object should be written
*/
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(farLeft, flags);
@@ -116,6 +142,9 @@ public class VisibleRegion implements Parcelable {
out.writeParcelable(latLngBounds, flags);
}
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Parcelable.Creator<VisibleRegion> CREATOR =
new Parcelable.Creator<VisibleRegion>() {
public VisibleRegion createFromParcel(Parcel in) {

View File

@@ -2,7 +2,7 @@ package com.mapbox.mapboxsdk.location;
import android.content.Context;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
@@ -13,10 +13,6 @@ import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LocationServices;
import com.mapzen.android.lost.api.LostApiClient;
import java.lang.ref.WeakReference;
import timber.log.Timber;
/**
* Manages locational updates. Contains methods to register and unregister location listeners.
* <ul>
@@ -32,34 +28,20 @@ import timber.log.Timber;
* in the history stack.
* </p>
*/
public class LocationSource extends LocationEngine implements
LostApiClient.ConnectionCallbacks, LocationListener {
public class LocationSource extends LocationEngine implements LocationListener {
private static LocationEngine instance;
private WeakReference<Context> context;
private Context context;
private LostApiClient lostApiClient;
private LocationSource(Context context) {
super();
this.context = new WeakReference<>(context);
lostApiClient = new LostApiClient.Builder(this.context.get())
.addConnectionCallbacks(this)
.build();
}
/**
* Get the LocationEngine instance.
* Constructs a location source instance.
*
* @param context a Context from which the application context is derived
* @return the LocationEngine instance
* @param context the context from which the Application context will be derived.
*/
public static synchronized LocationEngine getLocationEngine(@NonNull Context context) {
if (instance == null) {
instance = new LocationSource(context.getApplicationContext());
}
return instance;
public LocationSource(Context context) {
super();
this.context = context.getApplicationContext();
lostApiClient = new LostApiClient.Builder(this.context).build();
}
/**
@@ -68,9 +50,12 @@ public class LocationSource extends LocationEngine implements
*/
@Override
public void activate() {
if (lostApiClient != null && !lostApiClient.isConnected()) {
if (!lostApiClient.isConnected()) {
lostApiClient.connect();
}
for (LocationEngineListener listener : locationListeners) {
listener.onConnected();
}
}
/**
@@ -80,7 +65,7 @@ public class LocationSource extends LocationEngine implements
*/
@Override
public void deactivate() {
if (lostApiClient != null && lostApiClient.isConnected()) {
if (lostApiClient.isConnected()) {
lostApiClient.disconnect();
}
}
@@ -96,36 +81,18 @@ public class LocationSource extends LocationEngine implements
return lostApiClient.isConnected();
}
/**
* Invoked when the location provider has connected.
*/
@Override
public void onConnected() {
for (LocationEngineListener listener : locationListeners) {
listener.onConnected();
}
}
/**
* Invoked when the location provider connection has been suspended.
*/
@Override
public void onConnectionSuspended() {
Timber.d("Connection suspended.");
}
/**
* Returns the Last known location is the location provider is connected and location permissions are granted.
*
* @return the last known location
*/
@Override
@Nullable
public Location getLastLocation() {
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
return LocationServices.FusedLocationApi.getLastLocation();
}
return null;
}
@@ -151,9 +118,9 @@ public class LocationSource extends LocationEngine implements
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
LocationServices.FusedLocationApi.requestLocationUpdates(request, this);
}
}
@@ -163,7 +130,7 @@ public class LocationSource extends LocationEngine implements
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
LocationServices.FusedLocationApi.removeLocationUpdates(this);
}
}

View File

@@ -2,8 +2,8 @@ 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;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener,
MapboxMap.OnCameraMoveCanceledListener, OnCameraIdleListener {
@@ -59,9 +59,11 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
@Override
public void onCameraIdle() {
if (onCameraIdleListener != null && !idle) {
if (!idle) {
idle = true;
onCameraIdleListener.onCameraIdle();
if (onCameraIdleListener != null) {
onCameraIdleListener.onCameraIdle();
}
}
}
}

View File

@@ -57,6 +57,7 @@ final class MapGestureDetector {
private boolean quickZoom = false;
private boolean scrollInProgress = false;
private boolean scaleGestureOccurred = false;
private boolean recentScaleGestureOccurred = false;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -148,7 +149,7 @@ final class MapGestureDetector {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// First pointer down, reset scaleGestureOccurred, used to avoid triggering a fling after a scale gesture #7666
scaleGestureOccurred = false;
recentScaleGestureOccurred = false;
transform.setGestureInProgress(true);
break;
@@ -274,7 +275,7 @@ final class MapGestureDetector {
break;
case MotionEvent.ACTION_UP:
if (quickZoom) {
// insert here?
cameraChangeDispatcher.onCameraIdle();
quickZoom = false;
break;
}
@@ -341,12 +342,11 @@ final class MapGestureDetector {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || scaleGestureOccurred) {
if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || recentScaleGestureOccurred) {
// don't allow a fling is scroll is disabled
// and ignore when a scale gesture has occurred
return false;
}
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
float screenDensity = uiSettings.getPixelRatio();
@@ -362,6 +362,8 @@ final class MapGestureDetector {
// cancel any animation
transform.cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
// tilt results in a bigger translation, limiting input for #5281
double tilt = transform.getTilt();
double tiltFactor = 1 + ((tilt != 0) ? (tilt / 10) : 0); /* 1 -> 7 */
@@ -391,12 +393,17 @@ final class MapGestureDetector {
return false;
}
if (scaleGestureOccurred) {
return false;
}
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));
@@ -431,6 +438,7 @@ final class MapGestureDetector {
}
scaleGestureOccurred = true;
recentScaleGestureOccurred = true;
beginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
@@ -441,9 +449,11 @@ final class MapGestureDetector {
// Called when fingers leave screen
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
scaleGestureOccurred = false;
beginTime = 0;
scaleFactor = 1.0f;
zoomStarted = false;
cameraChangeDispatcher.onCameraIdle();
}
// Called each time a finger moves
@@ -479,6 +489,9 @@ final class MapGestureDetector {
}
// Gesture is a quickzoom if there aren't two fingers
if (!quickZoom && !twoTap) {
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
}
quickZoom = !twoTap;
// make an assumption here; if the zoom center is specified by the gesture, it's NOT going
@@ -491,6 +504,7 @@ final class MapGestureDetector {
// arround user provided focal point
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
cameraChangeDispatcher.onCameraMove();
// clamp scale factors we feed to core #7514
float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
@@ -552,7 +566,7 @@ final class MapGestureDetector {
// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
totalAngle += detector.getRotationDegreesDelta();
if (!zoomStarted && ((totalAngle > 20.0f) || (totalAngle < -20.0f))) {
if (totalAngle > 20.0f || totalAngle < -20.0f) {
started = true;
}

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -204,7 +205,7 @@ final class MapKeyListener {
currentTrackballLongPressTimeOut = null;
}
currentTrackballLongPressTimeOut = new TrackballLongPressTimeOut();
new Handler().postDelayed(currentTrackballLongPressTimeOut,
new Handler(Looper.getMainLooper()).postDelayed(currentTrackballLongPressTimeOut,
ViewConfiguration.getLongPressTimeout());
return true;

View File

@@ -1,7 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
@@ -28,7 +26,6 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ZoomButtonsController;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
@@ -187,14 +184,14 @@ public class MapView extends FrameLayout {
/**
* <p>
* You must call this method from the parent's {@link android.app.Activity#onCreate(Bundle)} or
* {@link android.app.Fragment#onCreate(Bundle)}.
* You must call this method from the parent's Activity#onCreate(Bundle)} or
* Fragment#onCreate(Bundle).
* </p>
* You must set a valid access token with {@link Mapbox#getInstance(Context, String)}) before you call this method
* or an exception will be thrown.
* You must set a valid access token with {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)}
* before you call this method or an exception will be thrown.
*
* @param savedInstanceState Pass in the parent's savedInstanceState.
* @see Mapbox#getInstance(Context, String)
* @see com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)
*/
@UiThread
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -223,12 +220,11 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link android.app.Activity#onSaveInstanceState(Bundle)}
* or {@link android.app.Fragment#onSaveInstanceState(Bundle)}.
* You must call this method from the parent's Activity#onSaveInstanceState(Bundle)
* or Fragment#onSaveInstanceState(Bundle).
*
* @param outState Pass in the parent's outState.
*/
@UiThread
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
@@ -236,7 +232,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}
* You must call this method from the parent's Activity#onStart() or Fragment#onStart()
*/
@UiThread
public void onStart() {
@@ -245,7 +241,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}.
* You must call this method from the parent's Activity#onResume() or Fragment#onResume().
*/
@UiThread
public void onResume() {
@@ -253,7 +249,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onPause()} or {@link Fragment#onPause()}.
* You must call this method from the parent's Activity#onPause() or Fragment#onPause().
*/
@UiThread
public void onPause() {
@@ -261,7 +257,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.
* You must call this method from the parent's Activity#onStop() or Fragment#onStop().
*/
@UiThread
public void onStop() {
@@ -270,7 +266,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}.
* You must call this method from the parent's Activity#onDestroy() or Fragment#onDestroy().
*/
@UiThread
public void onDestroy() {
@@ -334,7 +330,7 @@ public class MapView extends FrameLayout {
}
/**
* You must call this method from the parent's {@link Activity#onLowMemory()} or {@link Fragment#onLowMemory()}.
* You must call this method from the parent's Activity#onLowMemory() or Fragment#onLowMemory().
*/
@UiThread
public void onLowMemory() {
@@ -783,7 +779,7 @@ public class MapView extends FrameLayout {
public static final int DID_FINISH_LOADING_STYLE = 14;
/**
* This {@link MapChange} is triggered when a source attribution changes.
* This {@link MapChange} is triggered when a source changes.
* <p>
* Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
* </p>

View File

@@ -37,7 +37,6 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.style.layers.Filter;
import com.mapbox.mapboxsdk.style.layers.Layer;
@@ -141,12 +140,20 @@ public final class MapboxMap {
*/
void onRestoreInstanceState(Bundle savedInstanceState) {
final CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION);
if (cameraPosition != null) {
moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(cameraPosition).build()));
}
uiSettings.onRestoreInstanceState(savedInstanceState);
trackingSettings.onRestoreInstanceState(savedInstanceState);
if (cameraPosition != null) {
easeCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder(cameraPosition).build()),
0,
false,
null,
!trackingSettings.isLocationTrackingDisabled()
);
}
nativeMapView.setDebug(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
final String styleUrl = savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL);
@@ -729,8 +736,8 @@ public final class MapboxMap {
* will return the current location of the camera in flight.
* <p>
* Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
* {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
* method and calling it with true in the {@link CancelableCallback#onFinish()}.
* {@link com.mapbox.mapboxsdk.maps.TrackingSettings#setDismissLocationTrackingOnGesture(boolean)} with false before
* invoking this method and calling it with true in the {@link CancelableCallback#onFinish()}.
* </p>
*
* @param update The change that should be applied to the camera.
@@ -756,8 +763,8 @@ public final class MapboxMap {
* will return the current location of the camera in flight.
* <p>
* Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
* {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
* method and calling it with true in the {@link CancelableCallback#onFinish()}.
* {@link com.mapbox.mapboxsdk.maps.TrackingSettings#setDismissLocationTrackingOnGesture(boolean)} with false before
* invoking this method and calling it with true in the {@link CancelableCallback#onFinish()}.
* </p>
*
* @param update The change that should be applied to the camera.
@@ -880,7 +887,12 @@ public final class MapboxMap {
}
/**
* Set focal bearing.
* Transform the map bearing given a bearing, focal point coordinates, and a duration.
*
* @param bearing The bearing of the Map to be transformed to
* @param focalX The x coordinate of the focal point
* @param focalY The y coordinate of the focal point
* @param duration The duration of the transformation
*/
public void setFocalBearing(double bearing, float focalX, float focalY, long duration) {
transform.setBearing(bearing, focalX, focalY, duration);
@@ -1052,7 +1064,7 @@ public final class MapboxMap {
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
* sent.
*
* @param style The bundled style. Accepts one of the values from {@link Style}.
* @param style The bundled style.
* @see Style
*/
@UiThread
@@ -1068,7 +1080,8 @@ public final class MapboxMap {
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
* sent.
*
* @param style The bundled style. Accepts one of the values from {@link Style}.
* @param style The bundled style.
* @param callback The callback to be invoked when the style has finished loading
* @see Style
*/
@UiThread
@@ -1569,9 +1582,11 @@ public final class MapboxMap {
}
/**
* Gets a camera position that would fit a bounds.
* Get a camera position that fits a provided bounds and padding.
*
* @param latLngBounds the bounds to constrain the map with
* @param padding the padding to apply to the bounds
* @return the camera position that fits the bounds and padding
*/
public CameraPosition getCameraForLatLngBounds(@Nullable LatLngBounds latLngBounds, int[] padding) {
// calculate and set additional bounds padding
@@ -1864,8 +1879,6 @@ public final class MapboxMap {
* Replaces the location source of the my-location layer.
*
* @param locationSource A {@link LocationEngine} location source to use in the my-location layer.
* Set to null to use the default {@link LocationSource}
* location source.
*/
@UiThread
public void setLocationSource(@Nullable LocationEngine locationSource) {
@@ -2405,11 +2418,13 @@ public final class MapboxMap {
}
/**
* Interface definintion for a callback to be invoked when the style has finished loading.
* Interface definition for a callback to be invoked when the style has finished loading.
*/
public interface OnStyleLoadedListener {
/**
* Invoked when the style has finished loading.
* Invoked when the style has finished loading
*
* @param style the style that has been loaded
*/
void onStyleLoaded(String style);
}

View File

@@ -378,7 +378,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of mapbox_compass_icon for a map view.
*
* @param gravity see {@link android.view.Gravity}
* @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions compassGravity(int gravity) {
@@ -439,7 +439,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of logo for a map view.
*
* @param gravity see {@link android.view.Gravity}
* @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions logoGravity(int gravity) {
@@ -472,7 +472,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of attribution for a map view.
*
* @param gravity see {@link android.view.Gravity}
* @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions attributionGravity(int gravity) {

View File

@@ -6,11 +6,11 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
@@ -29,6 +29,8 @@ public final class TrackingSettings {
private final CameraZoomInvalidator zoomInvalidator;
private LocationEngine locationSource;
private LocationEngineListener myLocationListener;
private boolean locationChangeAnimationEnabled = true;
private boolean isCustomLocationSource;
private boolean myLocationEnabled;
private boolean dismissLocationTrackingOnGesture = true;
@@ -46,7 +48,7 @@ public final class TrackingSettings {
}
void initialise(MapboxMapOptions options) {
locationSource = LocationSource.getLocationEngine(myLocationView.getContext());
locationSource = Mapbox.getLocationSource();
setMyLocationEnabled(options.getLocationEnabled());
}
@@ -56,11 +58,16 @@ public final class TrackingSettings {
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, isDismissLocationTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, isDismissBearingTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
outState.putBoolean(MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, isLocationChangeAnimationEnabled());
outState.putBoolean(MapboxConstants.STATE_USING_CUSTOM_LOCATION_SOURCE, isCustomLocationSource());
}
void onRestoreInstanceState(Bundle savedInstanceState) {
try {
setMyLocationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED));
setMyLocationEnabled(
savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED),
savedInstanceState.getBoolean(MapboxConstants.STATE_USING_CUSTOM_LOCATION_SOURCE)
);
} catch (SecurityException ignore) {
// User did not accept location permissions
}
@@ -74,6 +81,8 @@ public final class TrackingSettings {
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
setLocationChangeAnimationEnabled(savedInstanceState.getBoolean(
MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, true));
}
/**
@@ -91,6 +100,7 @@ public final class TrackingSettings {
*/
@UiThread
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
myLocationView.setLocationChangeAnimationEnabled(isLocationChangeAnimationEnabled());
myLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
@@ -253,6 +263,26 @@ public final class TrackingSettings {
|| myLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE);
}
/**
* Returns whether location change animation is applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
*
* @return True if animation is applied, false otherwise.
*/
public boolean isLocationChangeAnimationEnabled() {
return locationChangeAnimationEnabled;
}
/**
* Set whether location change animation should be applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
*
* @param locationChangeAnimationEnabled True if animation should be applied, false otherwise.
*/
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
myLocationView.setLocationChangeAnimationEnabled(locationChangeAnimationEnabled);
}
/**
* Reset the tracking modes as necessary. Location tracking is reset if the map center is changed and not from
* location, bearing tracking if there is a rotation.
@@ -314,6 +344,10 @@ public final class TrackingSettings {
}
}
public boolean isCustomLocationSource() {
return isCustomLocationSource;
}
void setOnMyLocationTrackingModeChangeListener(MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
this.onMyLocationTrackingModeChangeListener = listener;
}
@@ -332,16 +366,30 @@ public final class TrackingSettings {
}
void setMyLocationEnabled(boolean locationEnabled) {
setMyLocationEnabled(locationEnabled, isCustomLocationSource());
}
private void setMyLocationEnabled(boolean locationEnabled, boolean isCustomLocationSource) {
if (!PermissionsManager.areLocationPermissionsGranted(myLocationView.getContext())) {
Timber.e("Could not activate user location tracking: "
+ "user did not accept the permission or permissions were not requested.");
return;
}
myLocationEnabled = locationEnabled;
myLocationView.setEnabled(locationEnabled);
this.isCustomLocationSource = isCustomLocationSource;
myLocationView.setEnabled(locationEnabled, isCustomLocationSource);
}
void setLocationSource(LocationEngine locationSource) {
if (this.locationSource != null && this.locationSource.equals(locationSource)) {
// this source is already active
return;
}
this.isCustomLocationSource = locationSource != null;
if (locationSource == null) {
locationSource = Mapbox.getLocationSource();
}
this.locationSource = locationSource;
myLocationView.setLocationSource(locationSource);
}

View File

@@ -79,7 +79,7 @@ final class Transform implements MapView.OnMapChangedListener {
@Override
public void onMapChanged(@MapView.MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) {
if (change == REGION_DID_CHANGE_ANIMATED) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onFinish();
@@ -93,7 +93,7 @@ final class Transform implements MapView.OnMapChangedListener {
@UiThread
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
@@ -109,15 +109,15 @@ final class Transform implements MapView.OnMapChangedListener {
final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator,
final MapboxMap.CancelableCallback callback, boolean isDismissable) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, isDismissable);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
if (callback != null) {
cameraCancelableCallback = callback;
mapView.addOnMapChangedListener(this);
}
mapView.addOnMapChangedListener(this);
mapView.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom, easingInterpolator);
}
@@ -127,21 +127,24 @@ final class Transform implements MapView.OnMapChangedListener {
final void animateCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs,
final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
if (callback != null) {
cameraCancelableCallback = callback;
mapView.addOnMapChangedListener(this);
}
mapView.addOnMapChangedListener(this);
mapView.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom);
}
}
private boolean isValidCameraPosition(@Nullable CameraPosition cameraPosition) {
return cameraPosition != null && !cameraPosition.equals(this.cameraPosition);
}
@UiThread
@Nullable
CameraPosition invalidateCameraPosition() {
@@ -151,6 +154,10 @@ final class Transform implements MapView.OnMapChangedListener {
cameraChangeDispatcher.onCameraMove();
}
if (isComponentUpdateRequired(cameraPosition)) {
updateCameraPosition(cameraPosition);
}
this.cameraPosition = cameraPosition;
if (onCameraChangeListener != null) {
onCameraChangeListener.onCameraChange(this.cameraPosition);
@@ -159,6 +166,11 @@ final class Transform implements MapView.OnMapChangedListener {
return cameraPosition;
}
private boolean isComponentUpdateRequired(@NonNull CameraPosition cameraPosition) {
return this.cameraPosition != null && (this.cameraPosition.tilt != cameraPosition.tilt
|| this.cameraPosition.bearing != cameraPosition.bearing);
}
void cancelTransitions() {
// notify user about cancel
cameraChangeDispatcher.onCameraMoveCanceled();
@@ -203,6 +215,9 @@ final class Transform implements MapView.OnMapChangedListener {
if (cameraPosition != null) {
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
setZoom(newZoom, focalPoint, MapboxConstants.ANIMATION_DURATION);
} else {
// we are not transforming, notify about being idle
cameraChangeDispatcher.onCameraIdle();
}
}
@@ -215,8 +230,8 @@ final class Transform implements MapView.OnMapChangedListener {
@Override
public void onMapChanged(int change) {
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
mapView.removeOnMapChangedListener(this);
cameraChangeDispatcher.onCameraIdle();
mapView.removeOnMapChangedListener(this);
}
}
});
@@ -315,7 +330,7 @@ final class Transform implements MapView.OnMapChangedListener {
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
@Override
public void onMapChanged(int change) {
if (change == MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED) {
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
mapView.removeOnMapChangedListener(this);
cameraChangeDispatcher.onCameraIdle();
}

View File

@@ -16,7 +16,6 @@ import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -315,8 +314,7 @@ public final class UiSettings {
* </p>
* By default, the compass is in the top right corner.
*
* @param gravity One of the values from {@link Gravity}.
* @see Gravity
* @param gravity Android SDK Gravity.
*/
@UiThread
public void setCompassGravity(int gravity) {
@@ -460,8 +458,7 @@ public final class UiSettings {
* </p>
* By default, the logo is in the bottom left corner.
*
* @param gravity One of the values from {@link Gravity}.
* @see Gravity
* @param gravity Android SDK Gravity.
*/
public void setLogoGravity(int gravity) {
setWidgetGravity(logoView, gravity);
@@ -552,8 +549,7 @@ public final class UiSettings {
* </p>
* By default, the attribution is in the bottom left corner next to the Mapbox logo.
*
* @param gravity One of the values from {@link Gravity}.
* @see Gravity
* @param gravity Android SDK Gravity.
*/
public void setAttributionGravity(int gravity) {
setWidgetGravity(attributionsView, gravity);

View File

@@ -26,6 +26,7 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
@@ -40,8 +41,13 @@ import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import java.lang.ref.WeakReference;
import timber.log.Timber;
/**
* UI element overlaid on a map to show the user's location.
* <p>
* Use {@link MyLocationViewSettings} to manipulate the state of this view.
* </p>
*/
public class MyLocationView extends View {
@@ -68,6 +74,7 @@ public class MyLocationView extends View {
private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
private ValueAnimator directionAnimator;
private boolean locationChangeAnimationEnabled;
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
new ValueAnimator.AnimatorUpdateListener() {
@@ -147,6 +154,16 @@ public class MyLocationView extends View {
compassListener = new CompassListener(context);
}
public void init(LocationSource locationSource) {
this.locationSource = locationSource;
}
/**
* Set the foreground drawable, for internal use only.
*
* @param defaultDrawable The drawable shown when showing this view
* @param bearingDrawable The drawable shown when tracking of bearing is enabled
*/
public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
if (defaultDrawable == null) {
return;
@@ -175,6 +192,11 @@ public class MyLocationView extends View {
invalidateBounds();
}
/**
* Set the foreground drawable tint, for internal use only.
*
* @param color The color to tint the drawable with
*/
public final void setForegroundDrawableTint(@ColorInt int color) {
if (foregroundDrawable != null) {
foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
@@ -185,10 +207,24 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Set the shadow drawable, for internal use only.
*
* @param drawable The drawable shown as shadow
*/
public final void setShadowDrawable(Drawable drawable) {
setShadowDrawable(drawable, 0, 0, 0, 0);
}
/**
* Set the shadow drawable with some additional offset.
*
* @param drawable The drawable shown as shadow
* @param left The left offset margin
* @param top The top offset margin
* @param right The right offset margin
* @param bottom The bottom offset margin
*/
public final void setShadowDrawable(Drawable drawable, int left, int top, int right, int bottom) {
if (drawable != null) {
backgroundDrawable = drawable;
@@ -202,6 +238,11 @@ public class MyLocationView extends View {
invalidateBounds();
}
/**
* Set the shadow drawable tint color, for internal use only.
*
* @param color The tint color to apply
*/
public final void setShadowDrawableTint(@ColorInt int color) {
if (backgroundDrawable == null) {
return;
@@ -210,6 +251,11 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Set the accuracy tint color, for internal use only.
*
* @param color The tint color to apply
*/
public final void setAccuracyTint(@ColorInt int color) {
int alpha = accuracyPaint.getAlpha();
accuracyPaint.setColor(color);
@@ -217,6 +263,11 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Set the accuracy alpha value, for internal use only.
*
* @param alpha The alpha accuracy value to apply
*/
public final void setAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
accuracyPaint.setAlpha(alpha);
invalidate();
@@ -297,15 +348,25 @@ public class MyLocationView extends View {
}
// draw foreground
if (myBearingTrackingMode == MyBearingTracking.NONE || !compassListener.isSensorAvailable()) {
if (myBearingTrackingMode == MyBearingTracking.NONE) {
if (foregroundDrawable != null) {
foregroundDrawable.draw(canvas);
}
} else if (foregroundBearingDrawable != null && foregroundBounds != null) {
foregroundBearingDrawable.draw(canvas);
if (myBearingTrackingMode == MyBearingTracking.GPS || compassListener.isSensorAvailable()) {
foregroundBearingDrawable.draw(canvas);
} else {
// We are tracking MyBearingTracking.COMPASS, but sensor is not available.
foregroundDrawable.draw(canvas);
}
}
}
/**
* Set the tilt value, for internal use only.
*
* @param tilt The tilt to apply
*/
public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) {
this.tilt = tilt;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
@@ -314,6 +375,11 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Set the bearing value, for internal use only.
*
* @param bearing The bearing to apply
*/
public void setBearing(double bearing) {
this.bearing = bearing;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
@@ -327,6 +393,11 @@ public class MyLocationView extends View {
}
}
/**
* Set the bearing and tilt from a camera position, for internal use only.
*
* @param position The camera position to extract bearing and tilt from
*/
public void setCameraPosition(CameraPosition position) {
if (position != null) {
setBearing(position.bearing);
@@ -334,6 +405,9 @@ public class MyLocationView extends View {
}
}
/**
* Called when the hosting activity is starting, for internal use only.
*/
public void onStart() {
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
compassListener.onResume();
@@ -343,6 +417,9 @@ public class MyLocationView extends View {
}
}
/**
* Called when the hosting activity is stopping, for internal use only.
*/
public void onStop() {
compassListener.onPause();
toggleGps(false);
@@ -374,6 +451,9 @@ public class MyLocationView extends View {
}
}
/**
* Update current locationstate.
*/
public void update() {
if (isEnabled()) {
myLocationBehavior.invalidate();
@@ -388,13 +468,33 @@ public class MyLocationView extends View {
this.projection = mapboxMap.getProjection();
}
/**
* Set the enabled state, for internal use only.
*
* @param enabled The value to set the state to
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
toggleGps(enabled);
setEnabled(enabled, false);
}
/**
* Set the enabled state, for internal use only.
*
* @param enabled The value to set the state to
* @param isCustomLocationSource Flag handling for handling user provided custom location source
*/
public void setEnabled(boolean enabled, boolean isCustomLocationSource) {
super.setEnabled(enabled);
setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
toggleGps(enabled, isCustomLocationSource);
}
/**
* Save the view instance state, for internal use only.
*
* @return the marshaled representation of the view state
*/
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
@@ -403,6 +503,11 @@ public class MyLocationView extends View {
return bundle;
}
/**
* Restore the view instance state, for internal use only.
*
* @param state the marshalled representation of the state to restore
*/
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
@@ -413,22 +518,23 @@ public class MyLocationView extends View {
super.onRestoreInstanceState(state);
}
private void toggleGps(boolean enableGps) {
toggleGps(enableGps, mapboxMap != null && mapboxMap.getTrackingSettings().isCustomLocationSource());
}
/**
* Enabled / Disable GPS location updates along with updating the UI
* Enabled / Disable GPS location updates along with updating the UI, for internal use only.
*
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
*/
private void toggleGps(boolean enableGps) {
if (locationSource == null) {
locationSource = LocationSource.getLocationEngine(this.getContext());
}
private void toggleGps(boolean enableGps, boolean isCustomLocationSource) {
if (enableGps) {
// Set an initial location if one available
Location lastLocation = locationSource.getLastLocation();
if (lastLocation != null) {
setLocation(lastLocation);
if (locationSource == null) {
if (!isCustomLocationSource) {
locationSource = Mapbox.getLocationSource();
} else {
return;
}
}
if (userLocationListener == null) {
@@ -436,22 +542,34 @@ public class MyLocationView extends View {
}
locationSource.addLocationEngineListener(userLocationListener);
locationSource.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationSource.activate();
} else {
if (locationSource == null) {
return;
}
// Disable location and user dot
location = null;
locationSource.removeLocationUpdates();
locationSource.removeLocationEngineListener(userLocationListener);
locationSource.removeLocationUpdates();
locationSource.deactivate();
}
locationSource.setPriority(LocationEnginePriority.HIGH_ACCURACY);
}
/**
* Get the current location.
*
* @return the current location
*/
public Location getLocation() {
return location;
}
/**
* Set the current location, for internal use only.
*
* @param location The current location
*/
public void setLocation(Location location) {
if (location == null) {
this.location = null;
@@ -460,8 +578,27 @@ public class MyLocationView extends View {
this.location = location;
myLocationBehavior.updateLatLng(location);
if (mapboxMap != null && myBearingTrackingMode == MyBearingTracking.GPS
&& myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
setBearing(mapboxMap.getCameraPosition().bearing);
}
}
/**
* Set location change animation enabled, for internal use only.
*
* @param locationChangeAnimationEnabled True if location changes are animated
*/
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
}
/**
* Set the bearing tracking mode, for internal use only.
*
* @param myBearingTrackingMode The bearing tracking mode
*/
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
this.myBearingTrackingMode = myBearingTrackingMode;
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
@@ -478,6 +615,11 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Set the location tracking mode, for internla use only.
*
* @param myLocationTrackingMode The location tracking mode
*/
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
MyLocationBehaviorFactory factory = new MyLocationBehaviorFactory();
myLocationBehavior = factory.getBehavioralModel(myLocationTrackingMode);
@@ -498,17 +640,32 @@ public class MyLocationView extends View {
invalidate();
}
/**
* Get the location tracking mode, for internal use only.
*
* @return The location tracking mode
*/
@MyLocationTracking.Mode
public int getMyLocationTrackingMode() {
return myLocationTrackingMode;
}
/**
* Get the bearing tracking mode, for internal use only.
*
* @return the bearing tracking mode
*/
@MyBearingTracking.Mode
public int getMyBearingTrackingMode() {
return myBearingTrackingMode;
}
/**
* Set the compass bearing value, for internal use only.
*
* @param bearing The compas bearing value
*/
private void setCompass(double bearing) {
setCompass(bearing, 0 /* no animation */);
}
@@ -536,14 +693,29 @@ public class MyLocationView extends View {
directionAnimator.start();
}
/**
* Get the center of this view in screen coordinates.
*
* @return the center of the view
*/
public PointF getCenter() {
return new PointF(getCenterX(), getCenterY());
}
/**
* Get the x value of the center of this view.
*
* @return the x value of the center of the view
*/
private float getCenterX() {
return (getX() + getMeasuredWidth()) / 2 + contentPaddingX - projectedX;
}
/**
* Get the y value of the center of this view.
*
* @return the y value of the center of the view
*/
private float getCenterY() {
return (getY() + getMeasuredHeight()) / 2 + contentPaddingY - projectedY;
}
@@ -553,8 +725,16 @@ public class MyLocationView extends View {
contentPaddingY = (padding[1] - padding[3]) / 2;
}
/**
* Set the location source from which location updates are received, for internal use only.
*
* @param locationSource The location source to receive updates from
*/
public void setLocationSource(LocationEngine locationSource) {
toggleGps(false);
this.locationSource = locationSource;
this.userLocationListener = null;
setEnabled(isEnabled(), locationSource != null);
}
private static class GpsLocationListener implements LocationEngineListener {
@@ -570,10 +750,12 @@ public class MyLocationView extends View {
@Override
public void onConnected() {
MyLocationView locationView = userLocationView.get();
if (locationView != null) {
LocationEngine locationEngine = locationSource.get();
Location location = locationEngine.getLastLocation();
locationView.setLocation(location);
LocationEngine locationEngine = locationSource.get();
if (locationView != null && locationEngine != null) {
Location lastKnownLocation = locationEngine.getLastLocation();
if (lastKnownLocation != null) {
locationView.setLocation(lastKnownLocation);
}
locationEngine.requestLocationUpdates();
}
}
@@ -597,9 +779,9 @@ public class MyLocationView extends View {
private final SensorManager sensorManager;
private Sensor rotationVectorSensor;
float[] matrix = new float[9];
float[] orientation = new float[3];
private float[] matrix = new float[9];
private float[] orientation = new float[3];
private boolean reportMissingSensor = true;
// Compass data
private long compassUpdateNextTimestamp = 0;
@@ -617,6 +799,10 @@ public class MyLocationView extends View {
}
public boolean isSensorAvailable() {
if (rotationVectorSensor == null && reportMissingSensor) {
reportMissingSensor = false;
Timber.e("Sensor.TYPE_ROTATION_VECTOR is missing from this device. Unable to use MyBearingTracking.COMPASS.");
}
return rotationVectorSensor != null;
}
@@ -701,6 +887,12 @@ public class MyLocationView extends View {
private abstract class MyLocationBehavior {
MyLocationBehavior() {
if (latLng != null) {
locationUpdateTimestamp = SystemClock.elapsedRealtime();
}
}
void updateLatLng(@NonNull Location newLocation) {
location = newLocation;
}
@@ -767,9 +959,14 @@ public class MyLocationView extends View {
// accuracy
updateAccuracy(location);
// ease to new camera position with a linear interpolator
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
true);
if (locationChangeAnimationEnabled) {
// ease to new camera position with a linear interpolator
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
true);
} else {
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), 0, false, null,
true);
}
}
@Override
@@ -811,7 +1008,11 @@ public class MyLocationView extends View {
}
locationChangeAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
locationChangeAnimator.setDuration(locationUpdateDuration);
if (locationChangeAnimationEnabled) {
locationChangeAnimator.setDuration(locationUpdateDuration);
} else {
locationChangeAnimator.setDuration(0);
}
locationChangeAnimator.addUpdateListener(new MarkerCoordinateAnimatorListener(this,
latLng, newLocation
));

View File

@@ -5,9 +5,9 @@ import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.FocalPointChangeListener;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.Projection;
@@ -77,6 +77,11 @@ public class MyLocationViewSettings {
this.focalPointChangeListener = focalPointChangedListener;
}
/**
* Initialise this with MapboxMapOptions.
*
* @param options the options to initialise this class from
*/
public void initialise(@NonNull MapboxMapOptions options) {
CameraPosition position = options.getCamera();
if (position != null && !position.equals(CameraPosition.DEFAULT)) {

View File

@@ -24,7 +24,10 @@ public class ConnectivityReceiver extends BroadcastReceiver {
private static ConnectivityReceiver INSTANCE;
/**
* Get or create the singleton instance
* Get a single instance of ConnectivityReceiver.
*
* @param context the context to extract the application context from
* @return single instance of ConnectivityReceiver
*/
public static synchronized ConnectivityReceiver instance(Context context) {
if (INSTANCE == null) {
@@ -74,7 +77,7 @@ public class ConnectivityReceiver extends BroadcastReceiver {
}
/**
* @see BroadcastReceiver#onReceive(Context, Intent)
* {@inheritDoc}
*/
@Override
public void onReceive(Context context, Intent intent) {

View File

@@ -116,6 +116,12 @@ public class OfflineManager {
}).start();
}
/**
* Get the single instance of offline manager.
*
* @param context the context used to host the offline manager
* @return the single instance of offline manager
*/
public static synchronized OfflineManager getInstance(Context context) {
if (instance == null) {
instance = new OfflineManager(context);

View File

@@ -394,6 +394,7 @@ public class OfflineRegion {
* After you call this method, you may not call any additional methods on this object.
* </p>
*
* @param bytes the metadata in bytes
* @param callback the callback to be invoked
*/
public void updateMetadata(@NonNull final byte[] bytes, @NonNull final OfflineRegionUpdateMetadataCallback callback) {

View File

@@ -7,6 +7,7 @@ package com.mapbox.mapboxsdk.offline;
* <p>
* Note that the total required size in bytes is not currently available. A
* future API release may provide an estimate of this number.
* </p>
*/
public class OfflineRegionStatus {
@@ -51,6 +52,7 @@ public class OfflineRegionStatus {
* Specifically, it is false during early phases of an offline download. Once
* style and tile sources have been downloaded, it is possible to calculate the
* precise number of required resources, at which point it is set to true.
* </p>
*/
private boolean requiredResourceCountIsPrecise = true;
@@ -73,37 +75,93 @@ public class OfflineRegionStatus {
}
/**
* Is the region complete?
* Validates if the region download has completed
*
* @return true if download is complete, false if not
*/
public boolean isComplete() {
return (completedResourceCount == requiredResourceCount);
}
/**
* Returns the download state.
* <p>
* State is defined as
* </p>
* <ul>
* <li>{@link OfflineRegion#STATE_ACTIVE}</li>
* <li>{@link OfflineRegion#STATE_INACTIVE}</li>
* </ul>
*
* @return the download state.
*/
@OfflineRegion.DownloadState
public int getDownloadState() {
return downloadState;
}
/**
* Get the number of resources (inclusive of tiles) that have been fully downloaded
* and are ready for offline access.
*
* @return the amount of resources that have finished downloading.
*/
public long getCompletedResourceCount() {
return completedResourceCount;
}
/**
* The cumulative size, in bytes, of all resources (inclusive of tiles) that have
* been fully downloaded.
*
* @return the size of the resources that have finished downloading
*/
public long getCompletedResourceSize() {
return completedResourceSize;
}
/**
* Get the number of tiles that have been fully downloaded and are ready for
* offline access.
*
* @return the completed tile count
*/
public long getCompletedTileCount() {
return completedTileCount;
}
/**
* Get the cumulative size, in bytes, of all tiles that have been fully downloaded.
*
* @return the completed tile size
*/
public long getCompletedTileSize() {
return completedTileSize;
}
/**
* Get the number of resources that are known to be required for this region. See the
* documentation for `requiredResourceCountIsPrecise` for an important caveat
* about this number.
*
* @return the amount of resources that are required
*/
public long getRequiredResourceCount() {
return requiredResourceCount;
}
/**
* Returns when the value of requiredResourceCount is a precise
* count of the number of required resources, and false when it is merely a lower
* bound.
* <p>
* Specifically, it is false during early phases of an offline download. Once
* style and tile sources have been downloaded, it is possible to calculate the
* precise number of required resources, at which point it is set to true.
* </p>
*
* @return True if the required resource count is precise, false if not
*/
public boolean isRequiredResourceCountPrecise() {
return requiredResourceCountIsPrecise;
}

View File

@@ -3,9 +3,9 @@ package com.mapbox.mapboxsdk.storage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.content.res.AssetManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -28,8 +28,9 @@ public class FileSource {
/**
* Called whenever a URL needs to be transformed.
*
* @param kind The kind of URL to be transformed.
* @return A URL that will now be downloaded.
* @param kind the kind of URL to be transformed.
* @param url the URL to be transformed
* @return a URL that will now be downloaded.
*/
String onURL(@Resource.Kind int kind, String url);
@@ -38,6 +39,12 @@ public class FileSource {
// File source instance is kept alive after initialization
private static FileSource INSTANCE;
/**
* Get the single instance of FileSource.
*
* @param context the context to derive the cache path from
* @return the single instance of FileSource
*/
public static synchronized FileSource getInstance(Context context) {
if (INSTANCE == null) {
String cachePath = getCachePath(context);
@@ -47,6 +54,12 @@ public class FileSource {
return INSTANCE;
}
/**
* Get the cache path for a context.
*
* @param context the context to derive the cache path from
* @return the cache path
*/
public static String getCachePath(Context context) {
// Default value
boolean setStorageExternal = MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL;

View File

@@ -30,14 +30,29 @@ public class PropertyValue<T> {
this.value = value;
}
/**
* Returns if this is null
*
* @return true if this is null, false if not
*/
public boolean isNull() {
return value == null;
}
/**
* Returns if this is a function.
*
* @return true if is a function, false if not
*/
public boolean isFunction() {
return !isNull() && value instanceof Function;
}
/**
* Returns if this is a value.
*
* @return true if is a value, false if not
*/
public boolean isValue() {
return !isNull() && !isFunction();
}
@@ -53,6 +68,11 @@ public class PropertyValue<T> {
}
}
/**
* Get the value of the property.
*
* @return the property value
*/
@Nullable
public T getValue() {
if (isValue()) {
@@ -64,6 +84,11 @@ public class PropertyValue<T> {
}
}
/**
* Get the color int value of the property if the value is a color.
*
* @return the color int value of the property, null if not a color value
*/
@ColorInt
@Nullable
public Integer getColorInt() {
@@ -80,6 +105,11 @@ public class PropertyValue<T> {
}
}
/**
* Get the string representation of a property value.
*
* @return the string representation
*/
@Override
public String toString() {
return String.format("%s: %s", name, value);

View File

@@ -13,7 +13,7 @@ import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
/**
* The global light source.
*
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#light>">The online documentation</a>
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#light">The online documentation</a>
*/
@UiThread
public class Light {
@@ -43,7 +43,8 @@ public class Light {
*
* @return anchor as String
*/
@Property.ANCHOR public String getAnchor() {
@Property.ANCHOR
public String getAnchor() {
return nativeGetAnchor();
}
@@ -106,7 +107,7 @@ public class Light {
*
* @return color as String
*/
public String getColor() {
public String getColor() {
return nativeGetColor();
}
@@ -142,7 +143,7 @@ public class Light {
*
* @return intensity as Float
*/
public float getIntensity() {
public float getIntensity() {
return nativeGetIntensity();
}
@@ -165,17 +166,30 @@ public class Light {
}
private native void nativeSetAnchor(String anchor);
private native String nativeGetAnchor();
private native void nativeSetPosition(Position position);
private native Position nativeGetPosition();
private native TransitionOptions nativeGetPositionTransition();
private native void nativeSetPositionTransition(long duration, long delay);
private native void nativeSetColor(String color);
private native String nativeGetColor();
private native TransitionOptions nativeGetColorTransition();
private native void nativeSetColorTransition(long duration, long delay);
private native void nativeSetIntensity(float intensity);
private native float nativeGetIntensity();
private native TransitionOptions nativeGetIntensityTransition();
private native void nativeSetIntensityTransition(long duration, long delay);
}

View File

@@ -18,7 +18,7 @@ public class Position {
private float polarAngle;
/**
* Creates a Position from a radial coordinate, an azimuthal angle & a polar angle.
* Creates a Position from a radial coordinate, an azimuthal angle and a polar angle.
*
* @param radialCoordinate the distance from the center of the base of an object to its light
* @param azimuthalAngle the position of the light relative to 0°
@@ -31,7 +31,7 @@ public class Position {
}
/**
* Returns a Position from a radial coordinate, an azimuthal angle & a polar angle
* Returns a Position from a radial coordinate, an azimuthal angle and a polar angle
*
* @param radialCoordinate the radial coordinate
* @param azimuthalAngle the azimuthal angle

View File

@@ -17,7 +17,7 @@ import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
/**
* The global light source.
*
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#light>">The online documentation</a>
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#light">The online documentation</a>
*/
@UiThread
public class Light {

View File

@@ -5,8 +5,17 @@ import android.graphics.Canvas;
import android.support.annotation.NonNull;
import android.view.View;
/**
* Utility class for creating bitmaps
*/
public class BitmapUtils {
/**
* Convert a view to a bitmap.
*
* @param view the view to convert
* @return the converted bitmap
*/
public static Bitmap createBitmapFromView(@NonNull View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
@@ -22,6 +31,13 @@ public class BitmapUtils {
return snapshot;
}
/**
* Create a bitmap from a background and a foreground bitmap
*
* @param background The bitmap placed in the background
* @param foreground The bitmap placed in the foreground
* @return the merged bitmap
*/
public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) {
Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());
Canvas canvas = new Canvas(result);

View File

@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
public class ColorUtils {
/**
* Returns a color integer associated as primary color from a theme based on a {@link Context}.
* Returns a color integer associated as primary color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The primary color value of current theme in the form 0xAARRGGBB.
@@ -37,7 +37,7 @@ public class ColorUtils {
}
/**
* Returns a color integer associated as primary dark color from a theme based on a {@link Context}.
* Returns a color integer associated as primary dark color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The primary dark color value of current theme in the form 0xAARRGGBB.
@@ -51,7 +51,7 @@ public class ColorUtils {
}
/**
* Returns a color integer associated as accent color from a theme based on a {@link Context}.
* Returns a color integer associated as accent color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The accent color value of current theme in the form 0xAARRGGBB.
@@ -65,7 +65,7 @@ public class ColorUtils {
}
/**
* Returns a color state list associated with a theme based on a {@link Context}
* Returns a color state list associated with a theme based on a Context.
*
* @param color The color used for tinting.
* @return A ColorStateList object containing the primary color of a theme
@@ -85,7 +85,7 @@ public class ColorUtils {
}
/**
* Set a color tint list to the {@link Drawable} of an {@link ImageView}.
* Set a color tint list to the Drawable of an ImageView.
*
* @param imageView The view to set the default tint list.
* @param tintColor The color to tint.

View File

@@ -18,12 +18,25 @@ import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
*/
public class MapFragmentUtils {
/**
* Convert MapboxMapOptions to a bundle of fragment arguments.
*
* @param options The MapboxMapOptions to convert
* @return a bundle of converted fragment arguments
*/
public static Bundle createFragmentArgs(MapboxMapOptions options) {
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, options);
return bundle;
}
/**
* Convert a bundle of fragment arguments to MapboxMapOptions.
*
* @param context The context of the activity hosting the fragment
* @param args The fragment arguments
* @return converted MapboxMapOptions
*/
public static MapboxMapOptions resolveArgs(Context context, Bundle args) {
MapboxMapOptions options;
if (args != null && args.containsKey(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS)) {