Replacing hardcoded configuration with configurable API and removing Mapbox assets (#90)

* Refactoring online file source so that tile server configuration is not hardcoded - part 1

* Added default templates

* Update from master

* Renaming MGLAccountManager to MGLSettings. Passing ResourceOptions and TileServerOptions to relevant classes and method in order to remove mapbox hardocded configuration

* Fixing build

* Addedm missing theme

* Unit tests fixes

* Fixing unit tests, adding factory methods for creating predefined configuration.

* Fixing mapbox unit tests

* Additional unit test fixes

* Making MapboxConfiguration default

* Making get/set resource options available in all classes that inherits from FileSource

* Making get/set resource options available in all classes that inherits from FileSource - part 2

* Fixes for Android

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Disable test coverage reports

* Removing hardcoded configuration in iOS project - part 1

* Fixing wrong file extension, making use of tile server options.

* Use apiKey and MGL_API_KEY everywhere

* Just a rename

* Re-enabling tests and improving MGLSettings init

* Removing mapbox hardcoded configuration, using api key everywhere, implementing JNI conversion for TileServerOptions

* Lint issues.

* Integrating configurable tile server properties into Android SDK - part 2

* Removing mabox accounts

* Exposing multiple configurations to Android SDK - bug fixes

* Removing TileServerOptions from public interface - native methods dont work before mapbox-gl library is loaded

* Adding support for configurable predefined styles

* Migrating predefined styles in test app + cleanup

* Parameter fix

* Bug fixes

* Fixing render test build

* Fixing offline tester

* Fixing benchmark tool

* Fix: typo in method name

* Adding code for public access to TileServerOptions

* Bug fixes and debug code removal

* Fixes for macOS, adding unit tests from MapLibre, removing redundant members from OnlineFileSource

* Unit test fixes

* MacOS test app - migrating to configurable tile server options, part 1

* Fixing offline maps

* Migrating macOS test app to MapTiler

* Minor improvements

* Putting back apiKey test

* Added unit tests for MapTiler configuration

* Migrating test resources to MapTiler

* minor fix

* A few fixes

* Fixing macOS tests, removing feedback functionality

* Migrating ios test app to MapTiler

* Migrating ui tests

* UI tests fix

* Benchmarking app fix

* Cleanup and strings updates

* Migrating benchmark app to maptiler

* API key injection in benchmark app

* Putting back release configuration

* Additional tests and fixing issues identified by thread sanitizer.

* Removing test filters

* Fixes and addressing lint issues

* More Maptiler tests + minro fix

* Android instrumentation test migration to MapTiler. Exposing missing TileServerOptions in Android SDK. Minor fixes.

* No requirements on API key format.

* Fixing offline cache test tool

* Adding configurable domain name for sources, adding source domain int MapTiler configuration, cleanup

* Migrating tests to MapTiler, adding code for canonicalizing URLs, removing mapbox stuff from comments, cleanup

* More tests

* Updated database size

* Lint issues

* Fixed test

* Updating developer config API key

* Fixes for Android, propagaing updated tileServerOptions to native file sources, more tests

* Just a few more fixes

* Propagating updated settings to file sources + additional unit test

* Lint issues

* Removing test filter and fixing incorrect uri

* Release preparation

* macos release notes
This commit is contained in:
Petr Pokorny
2021-06-29 12:44:51 +02:00
committed by GitHub
parent 9a49fa16c9
commit d62ff400c6
398 changed files with 107907 additions and 184517 deletions

View File

@@ -1,107 +0,0 @@
package com.mapbox.mapboxsdk;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.mapbox.android.accounts.v1.MapboxAccounts;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.log.Logger;
/**
* REMOVAL OR MODIFICATION OF THE FOLLOWING CODE VIOLATES THE MAPBOX TERMS
* OF SERVICE
* <p>
* The following code is used to access Mapbox's Mapping APIs.
* <p>
* Removal or modification of this code when used with Mapbox's Mapping APIs
* can result in termination of your agreement and/or your account with
* Mapbox.
* <p>
* Using this code to access Mapbox Mapping APIs from outside the Mapbox Maps
* SDK also violates the Mapbox Terms of Service. On Android, Mapping APIs
* should be accessed using the methods documented at
* https://www.mapbox.com/android.
* <p>
* You can access the Mapbox Terms of Service at https://www.mapbox.com/tos/
*/
class AccountsManager {
private static final String TAG = "Mbgl-AccountsManager";
private static final String PREFERENCE_USER_ID = "com.mapbox.mapboxsdk.accounts.userid";
private static final String PREFERENCE_TIMESTAMP = "com.mapbox.mapboxsdk.accounts.timestamp";
private SharedPreferences sharedPreferences;
private String userId;
private long timestamp;
AccountsManager() {
initialize();
}
@VisibleForTesting
AccountsManager(SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
initialize();
}
private void initialize() {
}
private ApplicationInfo retrieveApplicationInfo() throws PackageManager.NameNotFoundException {
return Mapbox.getApplicationContext().getPackageManager().getApplicationInfo(
Mapbox.getApplicationContext().getPackageName(),
PackageManager.GET_META_DATA);
}
private boolean isExpired() {
return isExpired(getNow(), timestamp);
}
static boolean isExpired(long now, long then) {
return ((now - then) > DateUtils.HOUR_IN_MILLIS);
}
@NonNull
private SharedPreferences getSharedPreferences() {
if (sharedPreferences == null) {
sharedPreferences = Mapbox.getApplicationContext()
.getSharedPreferences(MapboxConstants.MAPBOX_SHARED_PREFERENCES, Context.MODE_PRIVATE);
}
return sharedPreferences;
}
static long getNow() {
return System.currentTimeMillis();
}
private synchronized String getUserId() {
if (!TextUtils.isEmpty(userId)) {
return userId;
}
SharedPreferences sharedPreferences = getSharedPreferences();
userId = sharedPreferences.getString(PREFERENCE_USER_ID, "");
if (TextUtils.isEmpty(userId)) {
userId = generateUserId();
SharedPreferences.Editor editor = getSharedPreferences().edit();
editor.putString(PREFERENCE_USER_ID, userId);
if (!editor.commit()) {
Logger.e(TAG, "Failed to save user id.");
}
}
return userId;
}
@NonNull
private String generateUserId() {
return MapboxAccounts.obtainEndUserId();
}
}

View File

@@ -13,14 +13,16 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.util.DefaultStyle;
import com.mapbox.mapboxsdk.util.TileServerOptions;
import com.mapbox.mapboxsdk.utils.ThreadUtils;
/**
* The entry point to initialize the Mapbox Android SDK.
* The entry point to initialize the MapLibre Android SDK.
* <p>
* Obtain a reference by calling {@link #getInstance(Context, String)}. Usually this class is configured in
* Application#onCreate() and is responsible for the active access token, application context, and
* connectivity state.
* Obtain a reference by calling {@link #getInstance(Context, String, WellKnownTileServer)}.
* Usually this class is configured in Application#onCreate() and is responsible for the
* active API key, application context, and connectivity state.
* </p>
*/
@UiThread
@@ -34,62 +36,149 @@ public final class Mapbox {
private Context context;
@Nullable
private String accessToken;
private String apiKey;
@Nullable
private AccountsManager accounts;
private TileServerOptions tileServerOptions;
/**
* Get an instance of Mapbox.
* <p>
* This class manages the Mapbox access token, application context, and connectivity state.
* This class manages the API key, application context, and connectivity state.
* </p>
*
* @param context Android context which holds or is an application context
* @param accessToken Mapbox access token
* @param context Android context which holds or is an application context
* @return the single instance of Mapbox
*/
@UiThread
@NonNull
public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String accessToken) {
public static synchronized Mapbox getInstance(@NonNull Context context) {
ThreadUtils.init(context);
ThreadUtils.checkThread(TAG);
if (INSTANCE == null) {
Context appContext = context.getApplicationContext();
FileSource.initializeFileDirsPaths(appContext);
INSTANCE = new Mapbox(appContext, accessToken);
if (isAccessTokenValid(accessToken)) {
INSTANCE.accounts = new AccountsManager();
}
INSTANCE = new Mapbox(appContext, null);
ConnectivityReceiver.instance(appContext);
} else {
TileServerOptions tileServerOptions = TileServerOptions.get(WellKnownTileServer.MapLibre);
INSTANCE.tileServerOptions = tileServerOptions;
INSTANCE.apiKey = null;
FileSource fileSource = FileSource.getInstance(context);
fileSource.setTileServerOptions(tileServerOptions);
fileSource.setApiKey(null);
}
return INSTANCE;
}
Mapbox(@NonNull Context context, @Nullable String accessToken) {
/**
* Get an instance of Mapbox.
* <p>
* This class manages the API key, application context, and connectivity state.
* </p>
*
* @param context Android context which holds or is an application context
* @param apiKey api key
* @param tileServer the tile server whose predefined configuration will be used to
* bootstrap the SDK. The predefined configuration includes
* rules for converting resource URLs between normal and canonical forms
* and set of predefined styles available on the server.
* @return the single instance of Mapbox
*/
@UiThread
@NonNull
public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String apiKey,
WellKnownTileServer tileServer) {
ThreadUtils.init(context);
ThreadUtils.checkThread(TAG);
if (INSTANCE == null) {
Context appContext = context.getApplicationContext();
FileSource.initializeFileDirsPaths(appContext);
INSTANCE = new Mapbox(appContext, apiKey);
ConnectivityReceiver.instance(appContext);
} else {
INSTANCE.apiKey = apiKey;
}
TileServerOptions tileServerOptions = TileServerOptions.get(tileServer);
INSTANCE.tileServerOptions = tileServerOptions;
FileSource fileSource = FileSource.getInstance(context);
fileSource.setTileServerOptions(tileServerOptions);
fileSource.setApiKey(apiKey);
return INSTANCE;
}
Mapbox(@NonNull Context context, @Nullable String apiKey) {
this.context = context;
this.accessToken = accessToken;
this.apiKey = apiKey;
}
Mapbox(@NonNull Context context, @Nullable String apiKey, @NonNull TileServerOptions options) {
this.context = context;
this.apiKey = apiKey;
this.tileServerOptions = options;
}
/**
* Get the current active access token for this application.
* Get the current active API key for this application.
*
* @return Mapbox access token
* @return API key
*/
@Nullable
public static String getAccessToken() {
public static String getApiKey() {
validateMapbox();
return INSTANCE.accessToken;
return INSTANCE.apiKey;
}
/**
* Set the current active accessToken.
* Set the current active apiKey.
*/
public static void setAccessToken(String accessToken) {
public static void setApiKey(String apiKey) {
validateMapbox();
throwIfAccessTokenInvalid(accessToken);
INSTANCE.accessToken = accessToken;
INSTANCE.accounts = new AccountsManager();
FileSource.getInstance(getApplicationContext()).setAccessToken(accessToken);
throwIfApiKeyInvalid(apiKey);
INSTANCE.apiKey = apiKey;
FileSource.getInstance(getApplicationContext()).setApiKey(apiKey);
}
/**
* Get tile server configuration.
*/
@Nullable
public static TileServerOptions getTileServerOptions() {
validateMapbox();
return INSTANCE.tileServerOptions;
}
/**
* Get all pre-defined styles
*
* @return List of predefined styles
*/
@Nullable
public static DefaultStyle[] getPredefinedStyles() {
validateMapbox();
if (INSTANCE.tileServerOptions != null) {
return INSTANCE.tileServerOptions.getDefaultStyles();
}
return null;
}
/**
* Get predefined style by name
*
* @return Predefined style if found
*/
@Nullable
public static DefaultStyle getPredefinedStyle(String name) {
validateMapbox();
if (INSTANCE.tileServerOptions != null) {
DefaultStyle[] styles = INSTANCE.tileServerOptions.getDefaultStyles();
for (DefaultStyle style : styles) {
if (style.getName().equalsIgnoreCase(name)) {
return style;
}
}
}
return null;
}
/**
@@ -151,28 +240,25 @@ public final class Mapbox {
/**
* Runtime validation of Mapbox access token
*
* @param accessToken the access token to validate
* @param apiKey the access token to validate
* @return true is valid, false otherwise
*/
static boolean isAccessTokenValid(@Nullable String accessToken) {
if (accessToken == null) {
static boolean isApiKeyValid(@Nullable String apiKey) {
if (apiKey == null) {
return false;
}
accessToken = accessToken.trim().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
return accessToken.length() != 0 && (accessToken.startsWith("pk.") || accessToken.startsWith("sk."));
apiKey = apiKey.trim().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
return apiKey.length() != 0;
}
/**
* Throws exception when access token is invalid
*/
public static void throwIfAccessTokenInvalid(@Nullable String accessToken) {
if (!isAccessTokenValid(accessToken)) {
public static void throwIfApiKeyInvalid(@Nullable String apiKey) {
if (!isApiKeyValid(apiKey)) {
throw new MapboxConfigurationException(
"A valid access token parameter is required when using a Mapbox service."
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens."
+ "Currently provided token is: " + accessToken);
"A valid API key is required, currently provided key is: " + apiKey);
}
}

View File

@@ -0,0 +1,7 @@
package com.mapbox.mapboxsdk;
public enum WellKnownTileServer {
Mapbox,
MapTiler,
MapLibre;
}

View File

@@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
/**
* A MapboxConfigurationException is thrown by MapboxMap when the SDK hasn't been properly initialised.
* <p>
* This occurs either when {@link com.mapbox.mapboxsdk.Mapbox} is not correctly initialised or the provided access token
* This occurs either when {@link com.mapbox.mapboxsdk.Mapbox} is not correctly initialised or the provided apiKey
* through {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)} isn't valid.
* </p>
*
@@ -19,10 +19,8 @@ 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 calling Mapbox.getInstance(Context context, String accessToken) before "
+ "inflating or creating the view. The access token parameter is required when using a Mapbox service."
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.");
super("\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey) before "
+ "inflating or creating the view.");
}
/**

View File

@@ -108,13 +108,13 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
Attribution[] attributions = attributionSet.toArray(new Attribution[attributionSet.size()]);
String url = attributions[which].getUrl();
if (url.contains(MAP_FEEDBACK_URL_OLD) || url.contains(MAP_FEEDBACK_URL)) {
url = buildMapFeedbackMapUrl(Mapbox.getAccessToken());
url = buildMapFeedbackMapUrl(Mapbox.getApiKey());
}
showWebPage(url);
}
@NonNull
String buildMapFeedbackMapUrl(@Nullable String accessToken) {
String buildMapFeedbackMapUrl(@Nullable String apiKey) {
// TODO Add Android Maps SDK version to the query parameter, currently the version API is not available.
// TODO Keep track of this issue at [#15632](https://github.com/mapbox/mapbox-gl-native/issues/15632)
@@ -132,8 +132,9 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
builder.appendQueryParameter("referrer", packageName);
}
if (accessToken != null) {
builder.appendQueryParameter("access_token", accessToken);
if (apiKey != null) {
//TODO:PP
builder.appendQueryParameter("access_token", apiKey);
}
Style style = mapboxMap.getStyle();

View File

@@ -883,7 +883,7 @@ public final class MapboxMap {
* @param style The bundled style
* @see Style
*/
public void setStyle(@Style.StyleUrl String style) {
public void setStyle(String style) {
this.setStyle(style, null);
}
@@ -899,7 +899,7 @@ public final class MapboxMap {
* @param callback The callback to be invoked when the style has loaded
* @see Style
*/
public void setStyle(@Style.StyleUrl String style, final Style.OnStyleLoaded callback) {
public void setStyle(String style, final Style.OnStyleLoaded callback) {
this.setStyle(new Style.Builder().fromUri(style), callback);
}

View File

@@ -9,17 +9,16 @@ import android.util.Pair;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringDef;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.util.DefaultStyle;
import com.mapbox.mapboxsdk.utils.BitmapUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -802,11 +801,6 @@ public class Style {
* </p>
* {@code url} 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://...}:
@@ -816,7 +810,6 @@ public class Style {
* 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.
@@ -845,11 +838,6 @@ public class Style {
* </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://...}:
@@ -859,7 +847,6 @@ public class Style {
* 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.
@@ -1421,70 +1408,25 @@ 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
* improve the style
* Get predefined styles
*
* @return The list of predefined styles
*/
@StringDef( {MAPBOX_STREETS, OUTDOORS, LIGHT, DARK, SATELLITE, SATELLITE_STREETS, TRAFFIC_DAY, TRAFFIC_NIGHT})
@Retention(RetentionPolicy.SOURCE)
public @interface StyleUrl {
public static DefaultStyle[] getPredefinedStyles() {
return Mapbox.getPredefinedStyles();
}
// IMPORTANT: If you change any of these you also need to edit them in strings.xml
/**
* Mapbox Streets: A complete basemap, perfect for incorporating your own data. Using this
* constant means your map style will always use the latest version and may change as we
* improve the style.
* Get predefined style by name
*
* @return The predefined style definition
*/
public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v11";
/**
* Outdoors: A general-purpose style tailored to outdoor activities. Using this constant means
* your map style will always use the latest version and may change as we improve the style.
*/
public static final String OUTDOORS = "mapbox://styles/mapbox/outdoors-v11";
/**
* Light: Subtle light backdrop for data visualizations. Using this constant means your map
* style will always use the latest version and may change as we improve the style.
*/
public static final String LIGHT = "mapbox://styles/mapbox/light-v10";
/**
* Dark: Subtle dark backdrop for data visualizations. Using this constant means your map style
* will always use the latest version and may change as we improve the style.
*/
public static final String DARK = "mapbox://styles/mapbox/dark-v10";
/**
* Satellite: A beautiful global satellite and aerial imagery layer. Using this constant means
* your map style will always use the latest version and may change as we improve the style.
*/
public static final String SATELLITE = "mapbox://styles/mapbox/satellite-v9";
/**
* Satellite Streets: Global satellite and aerial imagery with unobtrusive labels. Using this
* constant means your map style will always use the latest version and may change as we
* improve the style.
*/
public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-streets-v11";
/**
* Traffic Day: Color-coded roads based on live traffic congestion data. Traffic data is currently
* available in
* <a href="https://www.mapbox.com/help/how-directions-work/#traffic-data">these select
* countries</a>. Using this constant means your map style will always use the latest version and
* may change as we improve the style.
*/
public static final String TRAFFIC_DAY = "mapbox://styles/mapbox/traffic-day-v2";
/**
* Traffic Night: Color-coded roads based on live traffic congestion data, designed to maximize
* legibility in low-light situations. Traffic data is currently available in
* <a href="https://www.mapbox.com/help/how-directions-work/#traffic-data">these select
* countries</a>. Using this constant means your map style will always use the latest version and
* may change as we improve the style.
*/
public static final String TRAFFIC_NIGHT = "mapbox://styles/mapbox/traffic-night-v2";
@NonNull
public static String getPredefinedStyle(String name) {
DefaultStyle style = Mapbox.getPredefinedStyle(name);
if (style != null) {
return style.getUrl();
}
throw new IllegalArgumentException("Could not find layer " + name);
}
}

View File

@@ -325,14 +325,14 @@ public class MapSnapshotter {
*/
@Deprecated
public String getStyleUrl() {
return builder == null ? Style.MAPBOX_STREETS : builder.getUri();
return builder == null ? null : builder.getUri();
}
/**
* @return the style uri
*/
public String getStyleUri() {
return builder == null ? Style.MAPBOX_STREETS : builder.getUri();
return builder == null ? null : builder.getUri();
}
/**

View File

@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.MapStrictMode;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.util.TileServerOptions;
import com.mapbox.mapboxsdk.utils.FileUtils;
import com.mapbox.mapboxsdk.utils.ThreadUtils;
@@ -371,9 +372,13 @@ public class FileSource {
private long nativePtr;
private FileSource(String cachePath) {
initialize(Mapbox.getAccessToken(), cachePath);
TileServerOptions options = Mapbox.getTileServerOptions();
initialize(Mapbox.getApiKey(), cachePath, options);
}
@Keep
public native void setTileServerOptions(TileServerOptions tileServerOptions);
@Keep
public native boolean isActivated();
@@ -384,15 +389,19 @@ public class FileSource {
public native void deactivate();
@Keep
public native void setAccessToken(String accessToken);
public native void setApiKey(String apiKey);
@NonNull
@Keep
public native String getAccessToken();
public native String getApiKey();
@Keep
public native void setApiBaseUrl(String baseUrl);
@NonNull
@Keep
public native String getApiBaseUrl();
/**
* Sets a callback for transforming URLs requested from the internet
* <p>
@@ -408,7 +417,7 @@ public class FileSource {
private native void setResourceCachePath(String path, ResourcesCachePathChangeCallback callback);
@Keep
private native void initialize(String accessToken, String cachePath);
private native void initialize(String apiKey, String cachePath, TileServerOptions options);
@Override
@Keep

View File

@@ -9,7 +9,7 @@ import java.net.URI;
import java.net.URL;
/**
* A raster DEM source. Currently only supports Mapbox Terrain RGB (mapbox://mapbox.terrain-rgb)
* A raster DEM source.
*
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-raster-dem">The style specification</a>
*/

View File

@@ -0,0 +1,110 @@
package com.mapbox.mapboxsdk.util;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
/**
* Default style definition
*/
public class DefaultStyle implements Parcelable {
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Creator<DefaultStyle> CREATOR = new Creator<DefaultStyle>() {
public DefaultStyle createFromParcel(@NonNull Parcel in) {
return new DefaultStyle(in);
}
public DefaultStyle[] newArray(int size) {
return new DefaultStyle[size];
}
};
@Keep
private String url;
@Keep
private String name;
@Keep
private int version;
/**
* Construct a new Default style definition
*
* @param url canonical style url
* @param name style name
* @param version style version
*/
@Keep
public DefaultStyle(
String url,
String name,
int version
) {
setUrl(url);
setName(name);
setVersion(version);
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setVersion(int version) {
this.version = version;
}
public int getVersion() {
return this.version;
}
/**
* 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;
}
/**
* Constructs a new default style tuple given a parcel.
*
* @param in the parcel containing the tile server options values
*/
protected DefaultStyle(Parcel in) {
setUrl(in.readString());
setName(in.readString());
setVersion(in.readInt());
}
/**
* 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(@NonNull Parcel out, int flags) {
out.writeString(url);
out.writeString(name);
out.writeInt(version);
}
}

View File

@@ -0,0 +1,417 @@
package com.mapbox.mapboxsdk.util;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapbox.mapboxsdk.WellKnownTileServer;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
/**
* Tile server options - baseUrl and similar properties
*/
public class TileServerOptions implements Parcelable {
/**
* Inner class responsible for recreating Parcels into objects.
*/
public static final Creator<TileServerOptions> CREATOR = new Creator<TileServerOptions>() {
public TileServerOptions createFromParcel(@NonNull Parcel in) {
return new TileServerOptions(in);
}
public TileServerOptions[] newArray(int size) {
return new TileServerOptions[size];
}
};
@Keep
private String baseURL;
@Keep
private String uriSchemeAlias;
@Keep
private String sourceTemplate;
@Keep
private String sourceDomainName;
@Keep
@Nullable
private String sourceVersionPrefix;
@Keep
private String styleTemplate;
@Keep
private String styleDomainName;
@Keep
@Nullable
private String styleVersionPrefix;
@Keep
private String spritesTemplate;
@Keep
private String spritesDomainName;
@Keep
@Nullable
private String spritesVersionPrefix;
@Keep
private String glyphsTemplate;
@Keep
private String glyphsDomainName;
@Keep
@Nullable
private String glyphsVersionPrefix;
@Keep
private String tileTemplate;
@Keep
private String tileDomainName;
@Keep
@Nullable
private String tileVersionPrefix;
@Keep
private String apiKeyParameterName;
@Keep
private boolean apiKeyRequired;
@Keep
private String defaultStyle;
@Keep
private DefaultStyle[] defaultStyles;
/**
* Construct a new TileServerOptions given string arguments
*
* @param baseURL tile server base url
* @param uriSchemeAlias scheme alias such as maplibre://
* @param sourceTemplate tile source url template
* @param sourceDomainName tile source domain name
* @param sourceVersionPrefix tile source version prefix
* @param styleTemplate style url template
* @param styleDomainName the name of style domain in canonical url
* @param styleVersionPrefix version prefix
* @param spritesTemplate sprites url template
* @param spritesDomainName the name of the sprites domain in canonical url
* @param spritesVersionPrefix the sprite version prefix
* @param glyphsTemplate glyphs url template
* @param glyphsDomainName the name of the glyphs domain in canonical url
* @param glyphsVersionPrefix the glyphs version prefix
* @param tileTemplate tile url template
* @param tileDomainName the name of the tile domain in canonical url
* @param tileVersionPrefix the tile version prefix
* @param apiKeyParameterName the name of api key parameter
* @param apiKeyRequired indicates if API key is required
* @param defaultStyle the name of the default style
* @param defaultStyles the list of default styles
*/
@Keep
public TileServerOptions(
String baseURL,
String uriSchemeAlias,
String sourceTemplate,
String sourceDomainName,
@Nullable String sourceVersionPrefix,
String styleTemplate,
String styleDomainName,
@Nullable String styleVersionPrefix,
String spritesTemplate,
String spritesDomainName,
@Nullable String spritesVersionPrefix,
String glyphsTemplate,
String glyphsDomainName,
@Nullable String glyphsVersionPrefix,
String tileTemplate,
String tileDomainName,
@Nullable String tileVersionPrefix,
String apiKeyParameterName,
boolean apiKeyRequired,
String defaultStyle,
DefaultStyle[] defaultStyles
) {
setBaseURL(baseURL);
setUriSchemeAlias(uriSchemeAlias);
setSourceTemplate(sourceTemplate);
setSourceDomainName(sourceDomainName);
setSourceVersionPrefix(sourceVersionPrefix);
setStyleTemplate(styleTemplate);
setStyleDomainName(styleDomainName);
setStyleVersionPrefix(styleVersionPrefix);
setSpritesTemplate(spritesTemplate);
setSpritesDomainName(spritesDomainName);
setSpritesVersionPrefix(spritesVersionPrefix);
setGlyphsTemplate(glyphsTemplate);
setGlyphsDomainName(glyphsDomainName);
setGlyphsVersionPrefix(glyphsVersionPrefix);
setTileTemplate(tileTemplate);
setTileDomainName(tileDomainName);
setTileVersionPrefix(tileVersionPrefix);
setApiKeyParameterName(apiKeyParameterName);
setDefaultStyles(defaultStyles);
setDefaultStyle(defaultStyle);
setApiKeyRequired(apiKeyRequired);
}
public void setBaseURL(String baseURL) {
this.baseURL = baseURL;
}
public String getBaseURL() {
return this.baseURL;
}
public void setUriSchemeAlias(String uriSchemeAlias) {
this.uriSchemeAlias = uriSchemeAlias;
}
public String getUriSchemeAlias() {
return this.uriSchemeAlias;
}
public void setSourceTemplate(String sourceTemplate) {
this.sourceTemplate = sourceTemplate;
}
public String getSourceTemplate() {
return this.sourceTemplate;
}
public void setSourceDomainName(String domainName) {
this.sourceDomainName = domainName;
}
public String getSourceDomainName() {
return this.sourceDomainName;
}
public void setSourceVersionPrefix(String sourceVersionPrefix) {
this.sourceVersionPrefix = sourceVersionPrefix;
}
public String getSourceVersionPrefix() {
return this.sourceVersionPrefix;
}
public void setStyleTemplate(String styleTemplate) {
this.styleTemplate = styleTemplate;
}
public String getStyleTemplate() {
return this.styleTemplate;
}
public void setStyleDomainName(String styleDomainName) {
this.styleDomainName = styleDomainName;
}
public String getStyleDomainName() {
return this.styleDomainName;
}
public void setStyleVersionPrefix(String styleVersionPrefix) {
this.styleVersionPrefix = styleVersionPrefix;
}
public String getStyleVersionPrefix() {
return this.styleVersionPrefix;
}
public void setSpritesTemplate(String spritesTemplate) {
this.spritesTemplate = spritesTemplate;
}
public String getSpritesTemplate() {
return this.spritesTemplate;
}
public void setSpritesDomainName(String spritesDomainName) {
this.spritesDomainName = spritesDomainName;
}
public String getSpritesDomainName() {
return this.spritesDomainName;
}
public void setSpritesVersionPrefix(String spritesVersionPrefix) {
this.spritesVersionPrefix = spritesVersionPrefix;
}
public String getSpritesVersionPrefix() {
return this.spritesVersionPrefix;
}
public void setGlyphsTemplate(String glyphsTemplate) {
this.glyphsTemplate = glyphsTemplate;
}
public String getGlyphsTemplate() {
return this.glyphsTemplate;
}
public void setGlyphsDomainName(String glyphsDomainName) {
this.glyphsDomainName = glyphsDomainName;
}
public String getGlyphsDomainName() {
return this.glyphsDomainName;
}
public void setGlyphsVersionPrefix(String glyphsVersionPrefix) {
this.glyphsVersionPrefix = glyphsVersionPrefix;
}
public String getGlyphsVersionPrefix() {
return this.glyphsVersionPrefix;
}
public void setTileTemplate(String tileTemplate) {
this.tileTemplate = tileTemplate;
}
public String getTileTemplate() {
return this.tileTemplate;
}
public void setTileDomainName(String tileDomainName) {
this.tileDomainName = tileDomainName;
}
public String getTileDomainName() {
return this.tileDomainName;
}
public void setTileVersionPrefix(String tileVersionPrefix) {
this.tileVersionPrefix = tileVersionPrefix;
}
public String getTileVersionPrefix() {
return this.tileVersionPrefix;
}
public void setApiKeyParameterName(String apiKeyParameterName) {
this.apiKeyParameterName = apiKeyParameterName;
}
public String getApiKeyParameterName() {
return this.apiKeyParameterName;
}
public void setApiKeyRequired(boolean isRequired) {
this.apiKeyRequired = isRequired;
}
public boolean getApiKeyRequired() {
return this.apiKeyRequired;
}
public void setDefaultStyles(DefaultStyle[] defaultStyles) {
this.defaultStyles = defaultStyles;
}
public DefaultStyle[] getDefaultStyles() {
return this.defaultStyles;
}
public void setDefaultStyle(String defaultStyleName) {
this.defaultStyle = defaultStyleName;
}
public String getDefaultStyle() {
return this.defaultStyle;
}
/**
* 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;
}
/**
* Constructs a new tile server options tuple given a parcel.
*
* @param in the parcel containing the tile server options values
*/
protected TileServerOptions(Parcel in) {
setBaseURL(in.readString());
setUriSchemeAlias(in.readString());
setSourceTemplate(in.readString());
setSourceDomainName(in.readString());
setSourceVersionPrefix(in.readString());
setStyleTemplate(in.readString());
setStyleDomainName(in.readString());
setStyleVersionPrefix(in.readString());
setSpritesTemplate(in.readString());
setSpritesDomainName(in.readString());
setSpritesVersionPrefix(in.readString());
setGlyphsTemplate(in.readString());
setGlyphsDomainName(in.readString());
setGlyphsVersionPrefix(in.readString());
setTileTemplate(in.readString());
setTileDomainName(in.readString());
setTileVersionPrefix(in.readString());
setApiKeyParameterName(in.readString());
setApiKeyRequired(in.readByte() != 0);
setDefaultStyle(in.readString());
in.createTypedArray(DefaultStyle.CREATOR);
}
/**
* 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(@NonNull Parcel out, int flags) {
out.writeString(baseURL);
out.writeString(uriSchemeAlias);
out.writeString(sourceTemplate);
out.writeString(sourceDomainName);
out.writeString(sourceVersionPrefix);
out.writeString(styleTemplate);
out.writeString(styleDomainName);
out.writeString(styleVersionPrefix);
out.writeString(spritesTemplate);
out.writeString(spritesDomainName);
out.writeString(spritesVersionPrefix);
out.writeString(glyphsTemplate);
out.writeString(glyphsDomainName);
out.writeString(glyphsVersionPrefix);
out.writeString(tileTemplate);
out.writeString(tileDomainName);
out.writeString(tileVersionPrefix);
out.writeString(apiKeyParameterName);
out.writeByte((byte) (apiKeyRequired ? 1 : 0));
out.writeString(defaultStyle);
out.writeTypedArray(defaultStyles, 0);
}
public static TileServerOptions get(WellKnownTileServer tileServer) {
switch (tileServer) {
case Mapbox:
return mapboxConfiguration();
case MapTiler:
return mapTilerConfiguration();
case MapLibre:
return mapLibreConfiguration();
default:
throw new MapboxConfigurationException("Unknown tile server");
}
}
@Keep
@NonNull
private static native TileServerOptions defaultConfiguration();
@Keep
@NonNull
private static native TileServerOptions mapboxConfiguration();
@Keep
@NonNull
private static native TileServerOptions mapTilerConfiguration();
@Keep
@NonNull
private static native TileServerOptions mapLibreConfiguration();
}