[core] [android] - public api configurable base endpoint (#6309)
add runloop to test
This commit is contained in:
@@ -56,7 +56,7 @@ class HTTPRequest implements Callback {
|
||||
|
||||
HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
|
||||
final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
|
||||
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com")) {
|
||||
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn") || host.endsWith(".mapbox.cn")) {
|
||||
if (httpUrl.querySize() == 0) {
|
||||
resourceUrl = resourceUrl + "?";
|
||||
} else {
|
||||
|
||||
@@ -260,6 +260,12 @@ public class MapView extends FrameLayout {
|
||||
mMyLocationView.setTilt(position.tilt);
|
||||
}
|
||||
|
||||
// api base url
|
||||
String apiBaseUrl = options.getApiBaseUrl();
|
||||
if (!TextUtils.isEmpty(apiBaseUrl)) {
|
||||
setApiBaseUrl(apiBaseUrl);
|
||||
}
|
||||
|
||||
// access token
|
||||
String accessToken = options.getAccessToken();
|
||||
if (!TextUtils.isEmpty(accessToken)) {
|
||||
@@ -877,6 +883,15 @@ public class MapView extends FrameLayout {
|
||||
return mStyleUrl;
|
||||
}
|
||||
|
||||
//
|
||||
// API Base URL
|
||||
//
|
||||
|
||||
@UiThread
|
||||
void setApiBaseUrl(@NonNull String baseUrl) {
|
||||
mNativeMapView.setApiBaseUrl(baseUrl);
|
||||
}
|
||||
|
||||
//
|
||||
// Access token
|
||||
//
|
||||
|
||||
@@ -7,15 +7,12 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
@@ -79,6 +76,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private int myLocationAccuracyTintColor;
|
||||
private int myLocationAccuracyAlpha;
|
||||
|
||||
private String apiBaseUrl;
|
||||
private String style;
|
||||
@Deprecated
|
||||
private String accessToken;
|
||||
@@ -123,12 +121,12 @@ public class MapboxMapOptions implements Parcelable {
|
||||
}
|
||||
|
||||
Bitmap foregroundBearingBitmap = in.readParcelable(getClass().getClassLoader());
|
||||
if(foregroundBearingBitmap!=null) {
|
||||
if (foregroundBearingBitmap != null) {
|
||||
myLocationForegroundBearingDrawable = new BitmapDrawable(foregroundBearingBitmap);
|
||||
}
|
||||
|
||||
Bitmap backgroundBitmap = in.readParcelable(getClass().getClassLoader());
|
||||
if(backgroundBitmap!=null){
|
||||
if (backgroundBitmap != null) {
|
||||
myLocationBackgroundDrawable = new BitmapDrawable(backgroundBitmap);
|
||||
}
|
||||
|
||||
@@ -140,6 +138,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
style = in.readString();
|
||||
accessToken = in.readString();
|
||||
apiBaseUrl = in.readString();
|
||||
}
|
||||
|
||||
public static Bitmap getBitmapFromDrawable(Drawable drawable) {
|
||||
@@ -172,6 +171,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
mapboxMapOptions.accessToken(typedArray.getString(R.styleable.MapView_access_token));
|
||||
mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.MapView_style_url));
|
||||
mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.MapView_api_base_url));
|
||||
|
||||
mapboxMapOptions.zoomGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true));
|
||||
mapboxMapOptions.scrollGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_scroll_enabled, true));
|
||||
@@ -237,6 +237,17 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the URL used for API endpoint.
|
||||
*
|
||||
* @param apiBaseUrl The base of our API endpoint
|
||||
* @return This
|
||||
*/
|
||||
public MapboxMapOptions apiBaseUrl(String apiBaseUrl) {
|
||||
this.apiBaseUrl = apiBaseUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies a the initial camera position for the map view.
|
||||
*
|
||||
@@ -583,6 +594,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured API endpoint base URL.
|
||||
*
|
||||
* @return Base URL to be used API endpoint.
|
||||
*/
|
||||
public String getApiBaseUrl() {
|
||||
return apiBaseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured initial camera position for a map view.
|
||||
*
|
||||
@@ -914,6 +934,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
dest.writeString(style);
|
||||
dest.writeString(accessToken);
|
||||
dest.writeString(apiBaseUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -957,6 +978,8 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (!Arrays.equals(myLocationBackgroundPadding, options.myLocationBackgroundPadding))
|
||||
return false;
|
||||
if (style != null ? !style.equals(options.style) : options.style != null) return false;
|
||||
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null)
|
||||
return false;
|
||||
return accessToken != null ? accessToken.equals(options.accessToken) : options.accessToken == null;
|
||||
|
||||
}
|
||||
@@ -993,6 +1016,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
result = 31 * result + myLocationAccuracyAlpha;
|
||||
result = 31 * result + (style != null ? style.hashCode() : 0);
|
||||
result = 31 * result + (accessToken != null ? accessToken.hashCode() : 0);
|
||||
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,6 +526,10 @@ final class NativeMapView {
|
||||
nativeScheduleTakeSnapshot(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
public void setApiBaseUrl(String baseUrl) {
|
||||
nativeSetAPIBaseURL(mNativeMapViewPtr, baseUrl);
|
||||
}
|
||||
|
||||
//
|
||||
// Callbacks
|
||||
//
|
||||
@@ -721,4 +725,6 @@ final class NativeMapView {
|
||||
private native Feature[] nativeQueryRenderedFeaturesForPoint(long nativeMapViewPtr, float x, float y, String[] layerIds);
|
||||
|
||||
private native Feature[] nativeQueryRenderedFeaturesForBox(long mNativeMapViewPtr, float left, float top, float right, float bottom, String[] layerIds);
|
||||
|
||||
private native void nativeSetAPIBaseURL(long nativeMapViewPtr, String baseUrl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user