[android] - rename style component URL api to URI

This commit is contained in:
tobrun
2019-06-04 10:10:50 +02:00
committed by Tobrun
parent a5f7f73dfe
commit 36361192b1
40 changed files with 215 additions and 92 deletions

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();

View File

@@ -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() {

View File

@@ -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,13 +198,27 @@ 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;
return this;
}
/**
* 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
*/
@@ -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);
}