diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main')
8 files changed, 161 insertions, 32 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index fa34e5b1f7..ea06856e9e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -704,7 +704,7 @@ public final class MapboxMap { moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); setMinZoomPreference(minZoom); setMaxZoomPreference(maxZoom); - setStyle(new Style.Builder().fromUrl(definition.getStyleURL()), callback); + setStyle(new Style.Builder().fromUri(definition.getStyleURL()), callback); } // @@ -793,7 +793,7 @@ public final class MapboxMap { * @see Style */ public void setStyle(@Style.StyleUrl String style, final Style.OnStyleLoaded callback) { - this.setStyle(new Style.Builder().fromUrl(style), callback); + this.setStyle(new Style.Builder().fromUri(style), callback); } /** @@ -831,8 +831,8 @@ public final class MapboxMap { } style = builder.build(nativeMapView); - if (!TextUtils.isEmpty(builder.getUrl())) { - nativeMapView.setStyleUrl(builder.getUrl()); + if (!TextUtils.isEmpty(builder.getUri())) { + nativeMapView.setStyleUri(builder.getUri()); } else if (!TextUtils.isEmpty(builder.getJson())) { nativeMapView.setStyleJson(builder.getJson()); } else { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 389cb0a0a9..cc2124c6c7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -11,9 +11,9 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.res.ResourcesCompat; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.Gravity; - import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.MapboxConstants; @@ -70,7 +70,7 @@ public class MapboxMapOptions implements Parcelable { private boolean zMediaOverlay = false; private String localIdeographFontFamily = "sans-serif"; - private String apiBaseUrl; + private String apiBaseUri; private boolean textureMode; private boolean translucentTextureSurface; @@ -84,6 +84,7 @@ public class MapboxMapOptions implements Parcelable { /** * Creates a new MapboxMapOptions object. + * * @deprecated Use {@link #createFromAttributes(Context, AttributeSet)} instead. */ @Deprecated @@ -123,7 +124,7 @@ public class MapboxMapOptions implements Parcelable { doubleTapGesturesEnabled = in.readByte() != 0; quickZoomGesturesEnabled = in.readByte() != 0; - apiBaseUrl = in.readString(); + apiBaseUri = in.readString(); textureMode = in.readByte() != 0; translucentTextureSurface = in.readByte() != 0; prefetchesTiles = in.readByte() != 0; @@ -148,8 +149,16 @@ public class MapboxMapOptions implements Parcelable { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.mapbox_MapView, 0, 0); try { mapboxMapOptions.camera(new CameraPosition.Builder(typedArray).build()); + + // deprecated mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_apiBaseUrl)); + String baseUri = typedArray.getString(R.styleable.mapbox_MapView_mapbox_apiBaseUri); + if (!TextUtils.isEmpty(baseUri)) { + // override deprecated property if a value of the new type was provided + mapboxMapOptions.apiBaseUri(baseUri); + } + mapboxMapOptions.zoomGesturesEnabled( typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiZoomGestures, true)); mapboxMapOptions.scrollGesturesEnabled( @@ -246,10 +255,24 @@ public class MapboxMapOptions implements Parcelable { * * @param apiBaseUrl The base of our API endpoint * @return This + * @deprecated use {@link #apiBaseUri} instead */ + @Deprecated @NonNull public MapboxMapOptions apiBaseUrl(String apiBaseUrl) { - this.apiBaseUrl = apiBaseUrl; + this.apiBaseUri = apiBaseUrl; + return this; + } + + /** + * Specifies the URI used for API endpoint. + * + * @param apiBaseUri The base of our API endpoint + * @return This + */ + @NonNull + public MapboxMapOptions apiBaseUri(String apiBaseUri) { + this.apiBaseUri = apiBaseUri; return this; } @@ -660,9 +683,20 @@ public class MapboxMapOptions implements Parcelable { * Get the current configured API endpoint base URL. * * @return Base URL to be used API endpoint. + * @deprecated use {@link #getApiBaseUri()} instead */ + @Deprecated public String getApiBaseUrl() { - return apiBaseUrl; + return apiBaseUri; + } + + /** + * Get the current configured API endpoint base URI. + * + * @return Base URI to be used API endpoint. + */ + public String getApiBaseUri() { + return apiBaseUri; } /** @@ -953,7 +987,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (quickZoomGesturesEnabled ? 1 : 0)); - dest.writeString(apiBaseUrl); + dest.writeString(apiBaseUri); dest.writeByte((byte) (textureMode ? 1 : 0)); dest.writeByte((byte) (translucentTextureSurface ? 1 : 0)); dest.writeByte((byte) (prefetchesTiles ? 1 : 0)); @@ -1044,7 +1078,7 @@ public class MapboxMapOptions implements Parcelable { return false; } - if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) { + if (apiBaseUri != null ? !apiBaseUri.equals(options.apiBaseUri) : options.apiBaseUri != null) { return false; } if (prefetchesTiles != options.prefetchesTiles) { @@ -1095,7 +1129,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (zoomGesturesEnabled ? 1 : 0); result = 31 * result + (doubleTapGesturesEnabled ? 1 : 0); result = 31 * result + (quickZoomGesturesEnabled ? 1 : 0); - result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0); + result = 31 * result + (apiBaseUri != null ? apiBaseUri.hashCode() : 0); result = 31 * result + (textureMode ? 1 : 0); result = 31 * result + (translucentTextureSurface ? 1 : 0); result = 31 * result + (prefetchesTiles ? 1 : 0); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index 66038e4d45..7692c1a9f2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -102,10 +102,10 @@ interface NativeMap { // Style API // - void setStyleUrl(String url); + void setStyleUri(String url); @NonNull - String getStyleUrl(); + String getStyleUri(); void setStyleJson(String newStyleJson); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 3980790fd1..7f93b9ad04 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -171,8 +171,8 @@ final class NativeMapView implements NativeMap { } @Override - public void setStyleUrl(String url) { - if (checkState("setStyleUrl")) { + public void setStyleUri(String url) { + if (checkState("setStyleUri")) { return; } nativeSetStyleUrl(url); @@ -180,8 +180,8 @@ final class NativeMapView implements NativeMap { @Override @NonNull - public String getStyleUrl() { - if (checkState("getStyleUrl")) { + public String getStyleUri() { + if (checkState("getStyleUri")) { return ""; } return nativeGetStyleUrl(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java index 84efe6a4af..e1a5c8926c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -59,11 +59,24 @@ public class Style { * Returns the current style url. * * @return the style url + * @deprecated use {@link #getUri()} instead */ @NonNull + @Deprecated public String getUrl() { validateState("getUrl"); - return nativeMap.getStyleUrl(); + return nativeMap.getStyleUri(); + } + + /** + * Returns the current style uri. + * + * @return the style uri + */ + @NonNull + public String getUri() { + validateState("getUri"); + return nativeMap.getStyleUri(); } /** @@ -600,7 +613,7 @@ public class Style { private final List<ImageWrapper> images = new ArrayList<>(); private TransitionOptions transitionOptions; - private String styleUrl; + private String styleUri; private String styleJson; /** @@ -637,17 +650,60 @@ public class Style { * @param url The URL of the map style * @return this * @see Style + * @deprecated use {@link #fromUri(String)} instead */ + @Deprecated @NonNull public Builder fromUrl(@NonNull String url) { - this.styleUrl = url; + this.styleUri = url; + return this; + } + + /** + * <p> + * Will loads a new map style asynchronous from the specified URI. + * </p> + * {@code uri} can take the following forms: + * <ul> + * <li>{@code Style#StyleUrl}: load one of the bundled styles in {@link Style}.</li> + * <li>{@code mapbox://styles/<user>/<style>}: + * loads the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a> + * {@code user} is your username. {@code style} is the ID of your custom + * style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li> + * <li>{@code http://...} or {@code https://...}: + * loads the style over the Internet from any web server.</li> + * <li>{@code asset://...}: + * loads the style from the APK {@code assets/} directory. + * This is used to load a style bundled with your app.</li> + * <li>{@code file://...}: + * loads the style from a file path. This is used to load a style from disk. + * </li> + * </li> + * <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li> + * </ul> + * <p> + * This method is asynchronous and will return before the style finishes loading. + * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener} + * callback or use {@link MapboxMap#setStyle(String, OnStyleLoaded)} instead. + * </p> + * If the style fails to load or an invalid style URI is set, the map view will become blank. + * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback + * will be triggered. + * + * @param uri The URI of the map style + * @return this + * @see Style + */ + @NonNull + public Builder fromUri(@NonNull String uri) { + this.styleUri = uri; return this; } /** * Will load a new map style from a json string. * <p> - * If the style fails to load or an invalid style URL is set, the map view will become blank. + * If the style fails to load or an invalid style URI is set, the map view will become blank. * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback * will be triggered. * </p> @@ -876,8 +932,8 @@ public class Style { return this; } - String getUrl() { - return styleUrl; + String getUri() { + return styleUri; } String getJson() { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java index 586234a0c2..e8e38c4f4e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java @@ -93,7 +93,7 @@ public class MapSnapshotter { private float pixelRatio = 1; private int width; private int height; - private String styleUrl = Style.MAPBOX_STREETS; + private String styleUri = Style.MAPBOX_STREETS; private String styleJson; private LatLngBounds region; private CameraPosition cameraPosition; @@ -114,12 +114,12 @@ public class MapSnapshotter { } /** - * @param url The style URL to use + * @param uri The style URI to use * @return the mutated {@link Options} */ @NonNull - public Options withStyle(String url) { - this.styleUrl = url; + public Options withStyle(String uri) { + this.styleUri = uri; return this; } @@ -198,7 +198,9 @@ public class MapSnapshotter { * * @param apiBaseUrl The base of our API endpoint * @return the mutated {@link Options} + * @deprecated use {@link #withApiBaseUri(String)} instead */ + @Deprecated @NonNull public Options withApiBaseUrl(String apiBaseUrl) { this.apiBaseUrl = apiBaseUrl; @@ -206,6 +208,18 @@ public class MapSnapshotter { } /** + * Specifies the URI used for API endpoint. + * + * @param apiBaseUri The base of our API endpoint + * @return the mutated {@link Options} + */ + @NonNull + public Options withApiBaseUri(String apiBaseUri) { + this.apiBaseUrl = apiBaseUrl; + return this; + } + + /** * @return the width of the image */ public int getWidth() { @@ -236,9 +250,18 @@ public class MapSnapshotter { /** * @return the style url + * @deprecated use {@link #getStyleUri()} instead */ + @Deprecated public String getStyleUrl() { - return styleUrl; + return styleUri; + } + + /** + * @return the style uri + */ + public String getStyleUri() { + return styleUri; } /** @@ -259,11 +282,21 @@ public class MapSnapshotter { /** * @return The base of our API endpoint + * @deprecated use {@link #getApiBaseUri()} instead */ @Nullable + @Deprecated public String getApiBaseUrl() { return apiBaseUrl; } + + /** + * @return The base of our API endpoint + */ + @Nullable + public String getApiBaseUri() { + return apiBaseUrl; + } } /** @@ -289,7 +322,7 @@ public class MapSnapshotter { String programCacheDir = FileSource.getInternalCachePath(context); nativeInitialize(this, fileSource, options.pixelRatio, options.width, - options.height, options.styleUrl, options.styleJson, options.region, options.cameraPosition, + options.height, options.styleUri, options.styleJson, options.region, options.cameraPosition, options.showLogo, programCacheDir, options.localIdeographFontFamily); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 0a7397da6e..60a1efc771 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -7,9 +7,12 @@ <public name="mapbox_AlertDialogStyle" type="style" /> + <!--DEPRECATED--> + <public name="mapbox_apiBaseUrl" type="attr" /> + <!-- Exposed attrs.xml --> <!--Configuration--> - <public name="mapbox_apiBaseUrl" type="attr" /> + <public name="mapbox_apiBaseUri" type="attr" /> <public name="mapbox_localIdeographFontFamily" type="attr" /> <public name="mapbox_cross_source_collisions" type="attr" /> <public name="mapbox_pixelRatio" type="float" /> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index a7182d6e4b..3e7124a414 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -2,8 +2,11 @@ <!-- these are public --> <declare-styleable name="mapbox_MapView"> - <!--Configuration--> + <!--DEPRECATED use mapbox_apiBaseUri instead --> <attr name="mapbox_apiBaseUrl" format="string"/> + + <!--Configuration--> + <attr name="mapbox_apiBaseUri" format="string"/> <attr name="mapbox_localIdeographFontFamily" format="string"/> <attr name="mapbox_cross_source_collisions" format="boolean"/> |