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:
@@ -183,7 +183,11 @@ add_library(mapbox-gl SHARED
|
||||
${PROJECT_SOURCE_DIR}/style/transition_options.cpp
|
||||
${PROJECT_SOURCE_DIR}/style/transition_options.hpp
|
||||
${PROJECT_SOURCE_DIR}/style/value.cpp
|
||||
${PROJECT_SOURCE_DIR}/style/value.hpp)
|
||||
${PROJECT_SOURCE_DIR}/style/value.hpp
|
||||
${PROJECT_SOURCE_DIR}/util/default_style.cpp
|
||||
${PROJECT_SOURCE_DIR}/util/tile_server_options.cpp
|
||||
${PROJECT_SOURCE_DIR}/util/default_style.hpp
|
||||
${PROJECT_SOURCE_DIR}/util/tile_server_options.hpp)
|
||||
|
||||
target_include_directories(
|
||||
mapbox-gl
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/platform/settings.hpp>
|
||||
#include <mbgl/storage/file_source_request.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/storage/resource_options.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
#include <mbgl/util/url.hpp>
|
||||
@@ -15,8 +16,9 @@ namespace mbgl {
|
||||
|
||||
class AssetManagerFileSource::Impl {
|
||||
public:
|
||||
Impl(ActorRef<Impl>, AAssetManager* assetManager_) : assetManager(assetManager_) {
|
||||
}
|
||||
Impl(ActorRef<Impl>, AAssetManager* assetManager_, const ResourceOptions options) :
|
||||
resourceOptions(options.clone()),
|
||||
assetManager(assetManager_) {}
|
||||
|
||||
void request(const std::string& url, ActorRef<FileSourceRequest> req) {
|
||||
// Note: AssetManager already prepends "assets" to the filename.
|
||||
@@ -36,17 +38,28 @@ public:
|
||||
req.invoke(&FileSourceRequest::setResponse, response);
|
||||
}
|
||||
|
||||
void setResourceOptions(ResourceOptions options) {
|
||||
resourceOptions = options;
|
||||
}
|
||||
|
||||
ResourceOptions getResourceOptions() {
|
||||
return resourceOptions.clone();
|
||||
}
|
||||
|
||||
private:
|
||||
AAssetManager* assetManager;
|
||||
ResourceOptions resourceOptions;
|
||||
};
|
||||
|
||||
AssetManagerFileSource::AssetManagerFileSource(jni::JNIEnv& env,
|
||||
const jni::Object<android::AssetManager>& assetManager_)
|
||||
const jni::Object<android::AssetManager>& assetManager_,
|
||||
const ResourceOptions options)
|
||||
: assetManager(jni::NewGlobal(env, assetManager_)),
|
||||
impl(std::make_unique<util::Thread<Impl>>(
|
||||
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE),
|
||||
"AssetManagerFileSource",
|
||||
AAssetManager_fromJava(&env, jni::Unwrap(assetManager.get())))) {}
|
||||
AAssetManager_fromJava(&env, jni::Unwrap(assetManager.get())),
|
||||
options.clone())) {}
|
||||
|
||||
AssetManagerFileSource::~AssetManagerFileSource() = default;
|
||||
|
||||
@@ -62,4 +75,11 @@ bool AssetManagerFileSource::canRequest(const Resource& resource) const {
|
||||
return 0 == resource.url.rfind(mbgl::util::ASSET_PROTOCOL, 0);
|
||||
}
|
||||
|
||||
void AssetManagerFileSource::setResourceOptions(ResourceOptions options) {
|
||||
impl->actor().invoke(&Impl::setResourceOptions, options.clone());
|
||||
}
|
||||
|
||||
ResourceOptions AssetManagerFileSource::getResourceOptions() {
|
||||
return impl->actor().ask(&Impl::getResourceOptions).get();
|
||||
}
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource_options.hpp>
|
||||
|
||||
#include "asset_manager.hpp"
|
||||
|
||||
@@ -14,12 +15,15 @@ template <typename T> class Thread;
|
||||
|
||||
class AssetManagerFileSource : public FileSource {
|
||||
public:
|
||||
AssetManagerFileSource(jni::JNIEnv&, const jni::Object<android::AssetManager>&);
|
||||
AssetManagerFileSource(jni::JNIEnv&, const jni::Object<android::AssetManager>&, const ResourceOptions);
|
||||
~AssetManagerFileSource() override;
|
||||
|
||||
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
|
||||
bool canRequest(const Resource&) const override;
|
||||
|
||||
void setResourceOptions(ResourceOptions options) override;
|
||||
ResourceOptions getResourceOptions() override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
||||
|
||||
@@ -19,24 +19,27 @@ namespace android {
|
||||
|
||||
// FileSource //
|
||||
|
||||
FileSource::FileSource(jni::JNIEnv& _env, const jni::String& accessToken, const jni::String& _cachePath)
|
||||
FileSource::FileSource(jni::JNIEnv& _env, const jni::String& apiKey, const jni::String& _cachePath, const jni::Object<TileServerOptions>& _options)
|
||||
:activationCounter( optional<int>(1)) {
|
||||
std::string path = jni::Make<std::string>(_env, _cachePath);
|
||||
mapbox::sqlite::setTempPath(path);
|
||||
|
||||
mbgl::FileSourceManager::get()->registerFileSourceFactory(
|
||||
mbgl::FileSourceType::Asset, [](const mbgl::ResourceOptions&) {
|
||||
mbgl::FileSourceType::Asset, [](const mbgl::ResourceOptions& opts) {
|
||||
auto env{android::AttachEnv()};
|
||||
std::unique_ptr<mbgl::FileSource> assetFileSource;
|
||||
if (android::Mapbox::hasInstance(*env)) {
|
||||
auto assetManager = android::Mapbox::getAssetManager(*env);
|
||||
assetFileSource = std::make_unique<AssetManagerFileSource>(*env, assetManager);
|
||||
assetFileSource = std::make_unique<AssetManagerFileSource>(*env, assetManager, opts.clone());
|
||||
}
|
||||
return assetFileSource;
|
||||
});
|
||||
|
||||
resourceOptions.withAccessToken(accessToken ? jni::Make<std::string>(_env, accessToken) : "")
|
||||
.withCachePath(path + DATABASE_FILE);
|
||||
auto tileServerOptions = TileServerOptions::getTileServerOptions(_env, _options);
|
||||
resourceOptions
|
||||
.withTileServerOptions(tileServerOptions)
|
||||
.withApiKey(apiKey ? jni::Make<std::string>(_env, apiKey) : "")
|
||||
.withCachePath(path + DATABASE_FILE);
|
||||
|
||||
// Create a core file sources
|
||||
// TODO: Split Android FileSource API to smaller interfaces
|
||||
@@ -50,8 +53,16 @@ FileSource::FileSource(jni::JNIEnv& _env, const jni::String& accessToken, const
|
||||
FileSource::~FileSource() {
|
||||
}
|
||||
|
||||
jni::Local<jni::String> FileSource::getAccessToken(jni::JNIEnv& env) {
|
||||
if (auto* token = onlineSource->getProperty(mbgl::ACCESS_TOKEN_KEY).getString()) {
|
||||
void FileSource::setTileServerOptions(jni::JNIEnv& _env, const jni::Object<TileServerOptions>& _options) {
|
||||
auto tileServerOptions = TileServerOptions::getTileServerOptions(_env, _options);
|
||||
resourceOptions.withTileServerOptions(tileServerOptions);
|
||||
resourceLoader->setResourceOptions(resourceOptions.clone());
|
||||
databaseSource->setResourceOptions(resourceOptions.clone());
|
||||
onlineSource->setResourceOptions(resourceOptions.clone());
|
||||
}
|
||||
|
||||
jni::Local<jni::String> FileSource::getApiKey(jni::JNIEnv& env) {
|
||||
if (auto* token = onlineSource->getProperty(mbgl::API_KEY_KEY).getString()) {
|
||||
return jni::Make<jni::String>(env, *token);
|
||||
}
|
||||
|
||||
@@ -59,9 +70,9 @@ jni::Local<jni::String> FileSource::getAccessToken(jni::JNIEnv& env) {
|
||||
return jni::Make<jni::String>(env, "");
|
||||
}
|
||||
|
||||
void FileSource::setAccessToken(jni::JNIEnv& env, const jni::String& token) {
|
||||
void FileSource::setApiKey(jni::JNIEnv& env, const jni::String& token) {
|
||||
if (onlineSource) {
|
||||
onlineSource->setProperty(mbgl::ACCESS_TOKEN_KEY, token ? jni::Make<std::string>(env, token) : "");
|
||||
onlineSource->setProperty(mbgl::API_KEY_KEY, token ? jni::Make<std::string>(env, token) : "");
|
||||
} else {
|
||||
ThrowNew(env, jni::FindClass(env, "java/lang/IllegalStateException"), "Online functionality is disabled.");
|
||||
}
|
||||
@@ -75,6 +86,15 @@ void FileSource::setAPIBaseUrl(jni::JNIEnv& env, const jni::String& url) {
|
||||
}
|
||||
}
|
||||
|
||||
jni::Local<jni::String> FileSource::getAPIBaseUrl(jni::JNIEnv& env) {
|
||||
if (auto* url = onlineSource->getProperty(mbgl::API_BASE_URL_KEY).getString()) {
|
||||
return jni::Make<jni::String>(env, *url);
|
||||
}
|
||||
|
||||
ThrowNew(env, jni::FindClass(env, "java/lang/IllegalStateException"), "Online functionality is disabled.");
|
||||
return jni::Make<jni::String>(env, "");
|
||||
}
|
||||
|
||||
void FileSource::setResourceTransform(jni::JNIEnv& env, const jni::Object<FileSource::ResourceTransformCallback>& transformCallback) {
|
||||
// Core could be built without support for network resource provider.
|
||||
if (!onlineSource) {
|
||||
@@ -214,12 +234,14 @@ void FileSource::registerNative(jni::JNIEnv& env) {
|
||||
jni::RegisterNativePeer<FileSource>(env,
|
||||
javaClass,
|
||||
"nativePtr",
|
||||
jni::MakePeer<FileSource, const jni::String&, const jni::String&>,
|
||||
jni::MakePeer<FileSource, const jni::String&, const jni::String&, const jni::Object<TileServerOptions>&>,
|
||||
"initialize",
|
||||
"finalize",
|
||||
METHOD(&FileSource::getAccessToken, "getAccessToken"),
|
||||
METHOD(&FileSource::setAccessToken, "setAccessToken"),
|
||||
METHOD(&FileSource::setTileServerOptions, "setTileServerOptions"),
|
||||
METHOD(&FileSource::getApiKey, "getApiKey"),
|
||||
METHOD(&FileSource::setApiKey, "setApiKey"),
|
||||
METHOD(&FileSource::setAPIBaseUrl, "setApiBaseUrl"),
|
||||
METHOD(&FileSource::getAPIBaseUrl, "getApiBaseUrl"),
|
||||
METHOD(&FileSource::setResourceTransform, "setResourceTransform"),
|
||||
METHOD(&FileSource::setResourceCachePath, "setResourceCachePath"),
|
||||
METHOD(&FileSource::resume, "activate"),
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "util/tile_server_options.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
template <typename T> class Actor;
|
||||
@@ -42,13 +44,17 @@ public:
|
||||
const jni::String&);
|
||||
};
|
||||
|
||||
FileSource(jni::JNIEnv&, const jni::String&, const jni::String&);
|
||||
FileSource(jni::JNIEnv&, const jni::String&, const jni::String&, const jni::Object<TileServerOptions>&);
|
||||
|
||||
~FileSource();
|
||||
|
||||
jni::Local<jni::String> getAccessToken(jni::JNIEnv&);
|
||||
void setTileServerOptions(jni::JNIEnv& _env, const jni::Object<TileServerOptions>& _options);
|
||||
|
||||
void setAccessToken(jni::JNIEnv&, const jni::String&);
|
||||
jni::Local<jni::String> getApiKey(jni::JNIEnv&);
|
||||
|
||||
void setApiKey(jni::JNIEnv&, const jni::String&);
|
||||
|
||||
jni::Local<jni::String> getAPIBaseUrl(jni::JNIEnv&);
|
||||
|
||||
void setAPIBaseUrl(jni::JNIEnv&, const jni::String&);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/storage/http_file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/storage/resource_options.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
@@ -16,7 +17,15 @@ namespace mbgl {
|
||||
|
||||
class HTTPFileSource::Impl {
|
||||
public:
|
||||
Impl(const ResourceOptions options): resourceOptions(options.clone()){};
|
||||
|
||||
android::UniqueEnv env { android::AttachEnv() };
|
||||
|
||||
void setResourceOptions(ResourceOptions options) {resourceOptions = options;};
|
||||
ResourceOptions getResourceOptions() {return resourceOptions.clone(); };
|
||||
|
||||
private:
|
||||
ResourceOptions resourceOptions;
|
||||
};
|
||||
|
||||
class HTTPRequest : public AsyncRequest {
|
||||
@@ -182,8 +191,8 @@ void HTTPRequest::onFailure(jni::JNIEnv& env, int type, const jni::String& messa
|
||||
async.send();
|
||||
}
|
||||
|
||||
HTTPFileSource::HTTPFileSource()
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
HTTPFileSource::HTTPFileSource(const ResourceOptions& options)
|
||||
: impl(std::make_unique<Impl>(options.clone())) {
|
||||
}
|
||||
|
||||
HTTPFileSource::~HTTPFileSource() = default;
|
||||
@@ -192,4 +201,12 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
|
||||
return std::make_unique<HTTPRequest>(*impl->env, resource, callback);
|
||||
}
|
||||
|
||||
void HTTPFileSource::setResourceOptions(ResourceOptions options) {
|
||||
impl->setResourceOptions(options.clone());
|
||||
}
|
||||
|
||||
ResourceOptions HTTPFileSource::getResourceOptions() {
|
||||
return impl->getResourceOptions();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "map_renderer_runnable.hpp"
|
||||
#include "mapbox.hpp"
|
||||
#include "native_map_view.hpp"
|
||||
#include "util/tile_server_options.hpp"
|
||||
#ifndef MBGL_MODULE_OFFLINE_DISABLE
|
||||
#include "offline/offline_manager.hpp"
|
||||
#include "offline/offline_region.hpp"
|
||||
@@ -162,6 +163,10 @@ void registerNatives(JavaVM *vm) {
|
||||
|
||||
// AssetManager
|
||||
Mapbox::registerNative(env);
|
||||
|
||||
// Util
|
||||
DefaultStyle::registerNative(env);
|
||||
TileServerOptions::registerNative(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "default_style.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Local<jni::Object<DefaultStyle>> DefaultStyle::New(jni::JNIEnv& env, const mbgl::util::DefaultStyle& jDefaultStyle) {
|
||||
static auto& javaClass = jni::Class<DefaultStyle>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<jni::String, jni::String, int>(env);
|
||||
return javaClass.New(
|
||||
env,
|
||||
constructor,
|
||||
jni::Make<jni::String>(env, jDefaultStyle.getUrl()),
|
||||
jni::Make<jni::String>(env, jDefaultStyle.getName()),
|
||||
jDefaultStyle.getCurrentVersion());
|
||||
}
|
||||
|
||||
mbgl::util::DefaultStyle DefaultStyle::getDefaultStyle(jni::JNIEnv& env, const jni::Object<DefaultStyle>& options) {
|
||||
static auto& javaClass = jni::Class<DefaultStyle>::Singleton(env);
|
||||
return mbgl::util::DefaultStyle (
|
||||
jni::Make<std::string>(env, options.Get(env, javaClass.GetField<jni::String>(env, "url"))),
|
||||
jni::Make<std::string>(env, options.Get(env, javaClass.GetField<jni::String>(env, "name"))),
|
||||
options.Get(env, javaClass.GetField<int>(env, "version"))
|
||||
);
|
||||
}
|
||||
|
||||
void DefaultStyle::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<DefaultStyle>::Singleton(env);
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/default_style.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class DefaultStyle : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/util/DefaultStyle"; };
|
||||
|
||||
static jni::Local<jni::Object<DefaultStyle>> New(jni::JNIEnv&, const mbgl::util::DefaultStyle&);
|
||||
static mbgl::util::DefaultStyle getDefaultStyle(jni::JNIEnv&, const jni::Object<DefaultStyle>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,178 @@
|
||||
#include "tile_server_options.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::New(jni::JNIEnv& env, const mbgl::TileServerOptions& tileServerOptions) {
|
||||
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
|
||||
static auto constructor = javaClass.GetConstructor<
|
||||
jni::String, jni::String, jni::String, jni::String, jni::String, jni::String,
|
||||
jni::String, jni::String, jni::String, jni::String, jni::String,
|
||||
jni::String, jni::String, jni::String, jni::String, jni::String,
|
||||
jni::String, jni::String, jni::jboolean, jni::String, jni::Array<jni::Object<DefaultStyle>>>(env);
|
||||
|
||||
optional<std::string> sourceVersionPrefixValue = tileServerOptions.sourceVersionPrefix();
|
||||
optional<std::string> styleVersionPrefixValue = tileServerOptions.styleVersionPrefix();
|
||||
optional<std::string> spritesVersionPrefixValue = tileServerOptions.spritesVersionPrefix();
|
||||
optional<std::string> glyphsVersionPrefixValue = tileServerOptions.glyphsVersionPrefix();
|
||||
optional<std::string> tileVersionPrefixValue = tileServerOptions.tileVersionPrefix();
|
||||
|
||||
return javaClass.New(env, constructor,
|
||||
jni::Make<jni::String>(env, tileServerOptions.baseURL()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.uriSchemeAlias()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.sourceTemplate()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.sourceDomainName()),
|
||||
sourceVersionPrefixValue ? jni::Make<jni::String>(env, *sourceVersionPrefixValue) : jni::Local<jni::String>(),
|
||||
jni::Make<jni::String>(env, tileServerOptions.styleTemplate()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.styleDomainName()),
|
||||
styleVersionPrefixValue ? jni::Make<jni::String>(env, *styleVersionPrefixValue) : jni::Local<jni::String>(),
|
||||
jni::Make<jni::String>(env, tileServerOptions.spritesTemplate()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.spritesDomainName()),
|
||||
spritesVersionPrefixValue ? jni::Make<jni::String>(env, *spritesVersionPrefixValue) : jni::Local<jni::String>(),
|
||||
jni::Make<jni::String>(env, tileServerOptions.glyphsTemplate()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.glyphsDomainName()),
|
||||
glyphsVersionPrefixValue ? jni::Make<jni::String>(env, *glyphsVersionPrefixValue) : jni::Local<jni::String>(),
|
||||
jni::Make<jni::String>(env, tileServerOptions.tileTemplate()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.tileDomainName()),
|
||||
tileVersionPrefixValue ? jni::Make<jni::String>(env, *tileVersionPrefixValue) : jni::Local<jni::String>(),
|
||||
jni::Make<jni::String>(env, tileServerOptions.apiKeyParameterName()),
|
||||
jni::jboolean(tileServerOptions.requiresApiKey()),
|
||||
jni::Make<jni::String>(env, tileServerOptions.defaultStyle()),
|
||||
TileServerOptions::NewStyles(env, tileServerOptions.defaultStyles())
|
||||
);
|
||||
}
|
||||
|
||||
jni::Local<jni::Array<jni::Object<DefaultStyle>>> TileServerOptions::NewStyles(jni::JNIEnv& env, const std::vector<const mbgl::util::DefaultStyle> nativeStyles) {
|
||||
|
||||
auto retVal = jni::Array<jni::Object<DefaultStyle>>::New(env, nativeStyles.size());
|
||||
for (auto it = begin(nativeStyles); it != end(nativeStyles); ++it) {
|
||||
auto converted = DefaultStyle::New(env, *it);
|
||||
retVal.Set(env, it - nativeStyles.begin(), converted);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::DefaultConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
|
||||
auto options = mbgl::TileServerOptions::DefaultConfiguration();
|
||||
return TileServerOptions::New(env, options);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapboxConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
|
||||
auto options = mbgl::TileServerOptions::MapboxConfiguration();
|
||||
return TileServerOptions::New(env, options);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapTilerConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
|
||||
auto options = mbgl::TileServerOptions::MapTilerConfiguration();
|
||||
return TileServerOptions::New(env, options);
|
||||
}
|
||||
|
||||
jni::Local<jni::Object<TileServerOptions>> TileServerOptions::MapLibreConfiguration(jni::JNIEnv& env, const jni::Class<TileServerOptions>& jOptions) {
|
||||
auto options = mbgl::TileServerOptions::MapLibreConfiguration();
|
||||
return TileServerOptions::New(env, options);
|
||||
}
|
||||
|
||||
mbgl::TileServerOptions TileServerOptions::getTileServerOptions(jni::JNIEnv& env, const jni::Object<TileServerOptions>& options) {
|
||||
auto opts = mbgl::TileServerOptions();
|
||||
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
|
||||
|
||||
static auto baseURLField = javaClass.GetField<jni::String>(env, "baseURL");
|
||||
|
||||
static auto uriSchemeAliasField = javaClass.GetField<jni::String>(env, "uriSchemeAlias");
|
||||
|
||||
static auto sourceTemplateField = javaClass.GetField<jni::String>(env, "sourceTemplate");
|
||||
static auto sourceDomainNameField = javaClass.GetField<jni::String>(env, "sourceDomainName");
|
||||
static auto sourceVersionPrefixField = javaClass.GetField<jni::String>(env, "sourceVersionPrefix");
|
||||
|
||||
static auto styleTemplateField = javaClass.GetField<jni::String>(env, "styleTemplate");
|
||||
static auto styleDomainNameField = javaClass.GetField<jni::String>(env, "styleDomainName");
|
||||
static auto styleVersionPrefixField = javaClass.GetField<jni::String>(env, "styleVersionPrefix");
|
||||
|
||||
static auto spritesTemplateField = javaClass.GetField<jni::String>(env, "spritesTemplate");
|
||||
static auto spritesDomainNameField = javaClass.GetField<jni::String>(env, "spritesDomainName");
|
||||
static auto spritesVersionPrefixField = javaClass.GetField<jni::String>(env, "spritesVersionPrefix");
|
||||
|
||||
static auto glyphsTemplateField = javaClass.GetField<jni::String>(env, "glyphsTemplate");
|
||||
static auto glyphsDomainNameField = javaClass.GetField<jni::String>(env, "glyphsDomainName");
|
||||
static auto glyphsVersionPrefixField = javaClass.GetField<jni::String>(env, "glyphsVersionPrefix");
|
||||
|
||||
static auto tileTemplateField = javaClass.GetField<jni::String>(env, "tileTemplate");
|
||||
static auto tileDomainNameField = javaClass.GetField<jni::String>(env, "tileDomainName");
|
||||
static auto tileVersionPrefixField = javaClass.GetField<jni::String>(env, "tileVersionPrefix");
|
||||
|
||||
static auto apiKeyParameterNameField = javaClass.GetField<jni::String>(env, "apiKeyParameterName");
|
||||
static auto apiKeyRequiredField = javaClass.GetField<jni::jboolean>(env, "apiKeyRequired");
|
||||
|
||||
static auto defaultStyleField = javaClass.GetField<jni::String>(env, "defaultStyle");
|
||||
|
||||
static auto defaultStylesField = javaClass.GetField<jni::Array<jni::Object<DefaultStyle>>>(env, "defaultStyles");
|
||||
std::vector<const mbgl::util::DefaultStyle> defaultStyles = TileServerOptions::getDefaultStyles(env, options.Get(env, defaultStylesField));
|
||||
|
||||
auto retVal = mbgl::TileServerOptions()
|
||||
.withBaseURL(jni::Make<std::string>(env, options.Get(env, baseURLField)))
|
||||
.withUriSchemeAlias(jni::Make<std::string>(env, options.Get(env, uriSchemeAliasField)))
|
||||
.withApiKeyParameterName(jni::Make<std::string>(env, options.Get(env, apiKeyParameterNameField)))
|
||||
.setRequiresApiKey(options.Get(env, apiKeyRequiredField));
|
||||
|
||||
auto sourcePrefixValue = options.Get(env, sourceVersionPrefixField);
|
||||
retVal.withSourceTemplate(
|
||||
jni::Make<std::string>(env, options.Get(env, sourceTemplateField)),
|
||||
jni::Make<std::string>(env, options.Get(env, sourceDomainNameField)),
|
||||
sourcePrefixValue ? jni::Make<std::string>(env, sourcePrefixValue): optional<std::string>{});
|
||||
|
||||
auto styleVersionPrefixValue = options.Get(env, styleVersionPrefixField);
|
||||
retVal.withStyleTemplate(
|
||||
jni::Make<std::string>(env, options.Get(env, styleTemplateField)),
|
||||
jni::Make<std::string>(env, options.Get(env, styleDomainNameField)),
|
||||
styleVersionPrefixValue ? jni::Make<std::string>(env, styleVersionPrefixValue): optional<std::string>{});
|
||||
|
||||
auto spritesVersionPrefixValue = options.Get(env, spritesVersionPrefixField);
|
||||
retVal.withSpritesTemplate(
|
||||
jni::Make<std::string>(env, options.Get(env, spritesTemplateField)),
|
||||
jni::Make<std::string>(env, options.Get(env, spritesDomainNameField)),
|
||||
spritesVersionPrefixValue ? jni::Make<std::string>(env, spritesVersionPrefixValue): optional<std::string>{});
|
||||
|
||||
auto glyphsVersionPrefixValue = options.Get(env, glyphsVersionPrefixField);
|
||||
retVal.withGlyphsTemplate(
|
||||
jni::Make<std::string>(env, options.Get(env, glyphsTemplateField)),
|
||||
jni::Make<std::string>(env, options.Get(env, glyphsDomainNameField)),
|
||||
glyphsVersionPrefixValue ? jni::Make<std::string>(env, glyphsVersionPrefixValue) : optional<std::string>{});
|
||||
|
||||
auto tileVersionPrefixValue = options.Get(env, tileVersionPrefixField);
|
||||
retVal.withTileTemplate(
|
||||
jni::Make<std::string>(env, options.Get(env, tileTemplateField)),
|
||||
jni::Make<std::string>(env, options.Get(env, tileDomainNameField)),
|
||||
tileVersionPrefixValue ? jni::Make<std::string>(env, tileVersionPrefixValue): optional<std::string>{});
|
||||
|
||||
retVal.withDefaultStyle(jni::Make<std::string>(env, options.Get(env, defaultStyleField)));
|
||||
retVal.withDefaultStyles(defaultStyles);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
std::vector<const mbgl::util::DefaultStyle> TileServerOptions::getDefaultStyles(jni::JNIEnv& env, const jni::Array<jni::Object<DefaultStyle>>& styles_) {
|
||||
|
||||
std::size_t length = styles_.Length(env);
|
||||
std::vector<const mbgl::util::DefaultStyle> convertedStyles;
|
||||
//convertedStyles.reserve(length);
|
||||
for (std::size_t i = 0; i < length; i++) {
|
||||
const mbgl::util::DefaultStyle converted = DefaultStyle::getDefaultStyle(env, styles_.Get(env, i));
|
||||
convertedStyles.push_back(converted);
|
||||
}
|
||||
|
||||
return convertedStyles;
|
||||
}
|
||||
|
||||
void TileServerOptions::registerNative(jni::JNIEnv& env) {
|
||||
static auto& javaClass = jni::Class<TileServerOptions>::Singleton(env);
|
||||
jni::RegisterNatives(env,
|
||||
*javaClass,
|
||||
jni::MakeNativeMethod<decltype(&TileServerOptions::DefaultConfiguration), &TileServerOptions::DefaultConfiguration>("defaultConfiguration"),
|
||||
jni::MakeNativeMethod<decltype(&TileServerOptions::MapboxConfiguration), &TileServerOptions::MapboxConfiguration>("mapboxConfiguration"),
|
||||
jni::MakeNativeMethod<decltype(&TileServerOptions::MapTilerConfiguration), &TileServerOptions::MapTilerConfiguration>("mapTilerConfiguration"),
|
||||
jni::MakeNativeMethod<decltype(&TileServerOptions::MapLibreConfiguration), &TileServerOptions::MapLibreConfiguration>("mapLibreConfiguration"));
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/tile_server_options.hpp>
|
||||
#include <mbgl/util/default_style.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "default_style.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class TileServerOptions : private mbgl::util::noncopyable {
|
||||
public:
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/util/TileServerOptions"; };
|
||||
|
||||
static jni::Local<jni::Object<TileServerOptions>> New(jni::JNIEnv&, const mbgl::TileServerOptions&);
|
||||
|
||||
static jni::Local<jni::Object<TileServerOptions>> DefaultConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
|
||||
static jni::Local<jni::Object<TileServerOptions>> MapboxConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
|
||||
static jni::Local<jni::Object<TileServerOptions>> MapTilerConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
|
||||
static jni::Local<jni::Object<TileServerOptions>> MapLibreConfiguration(jni::JNIEnv&, const jni::Class<TileServerOptions>&);
|
||||
|
||||
static mbgl::TileServerOptions getTileServerOptions(jni::JNIEnv&, const jni::Object<TileServerOptions>&);
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
static jni::Local<jni::Array<jni::Object<DefaultStyle>>> NewStyles(jni::JNIEnv& env, const std::vector<const mbgl::util::DefaultStyle>);
|
||||
static std::vector<const mbgl::util::DefaultStyle> getDefaultStyles(jni::JNIEnv& env, const jni::Array<jni::Object<DefaultStyle>>& styles_);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
public enum WellKnownTileServer {
|
||||
Mapbox,
|
||||
MapTiler,
|
||||
MapLibre;
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -7,16 +7,4 @@
|
||||
<string name="mapbox_attributionsDialogTitle">Mapbox Maps SDK for Android</string>
|
||||
<string name="mapbox_attributionErrorNoBrowser">No web browser installed on device, can\'t open web page.</string>
|
||||
<string name="mapbox_offline_error_region_definition_invalid">Provided OfflineRegionDefinition doesn\'t fit the world bounds: %s</string>
|
||||
|
||||
<!-- these are public -->
|
||||
<!-- Using one of these constants means your map style will always use the latest version and
|
||||
may change as we improve the style. -->
|
||||
<string name="mapbox_style_mapbox_streets" translatable="false">mapbox://styles/mapbox/streets-v11</string>
|
||||
<string name="mapbox_style_outdoors" translatable="false">mapbox://styles/mapbox/outdoors-v11</string>
|
||||
<string name="mapbox_style_light" translatable="false">mapbox://styles/mapbox/light-v10</string>
|
||||
<string name="mapbox_style_dark" translatable="false">mapbox://styles/mapbox/dark-v10</string>
|
||||
<string name="mapbox_style_satellite" translatable="false">mapbox://styles/mapbox/satellite-v9</string>
|
||||
<string name="mapbox_style_satellite_streets" translatable="false">mapbox://styles/mapbox/satellite-streets-v11</string>
|
||||
<string name="mapbox_style_traffic_day" translatable="false">mapbox://styles/mapbox/traffic-day-v2</string>
|
||||
<string name="mapbox_style_traffic_night" translatable="false">mapbox://styles/mapbox/traffic-night-v2</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccountsManagerTest {
|
||||
@Test
|
||||
public void testIsExpired() {
|
||||
long now = AccountsManager.getNow();
|
||||
|
||||
long defaultValue = 0L;
|
||||
long tooOld = now - DateUtils.HOUR_IN_MILLIS - 1;
|
||||
long futureValue = now + 1;
|
||||
long immediatePast = now - 1;
|
||||
|
||||
assertTrue(AccountsManager.isExpired(now, defaultValue));
|
||||
assertTrue(AccountsManager.isExpired(now, tooOld));
|
||||
|
||||
assertFalse(AccountsManager.isExpired(now, futureValue));
|
||||
assertFalse(AccountsManager.isExpired(now, immediatePast));
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,21 @@ import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import com.mapbox.mapboxsdk.util.TileServerOptions;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class MapboxInjector {
|
||||
|
||||
private static final String FIELD_INSTANCE = "INSTANCE";
|
||||
private static final String FIELD_ACCOUNTS = "accounts";
|
||||
|
||||
public static void inject(@NonNull Context context, @NonNull String accessToken) {
|
||||
Mapbox mapbox = new Mapbox(context, accessToken);
|
||||
public static void inject(@NonNull Context context, @NonNull String apiKey,
|
||||
@NonNull TileServerOptions options) {
|
||||
Mapbox mapbox = new Mapbox(context, apiKey, options);
|
||||
try {
|
||||
Field instance = Mapbox.class.getDeclaredField(FIELD_INSTANCE);
|
||||
instance.setAccessible(true);
|
||||
instance.set(mapbox, mapbox);
|
||||
|
||||
Field accounts = Mapbox.class.getDeclaredField(FIELD_ACCOUNTS);
|
||||
accounts.setAccessible(true);
|
||||
|
||||
AccountsManager manager = mock(AccountsManager.class);
|
||||
accounts.set(mapbox, manager);
|
||||
} catch (Exception exception) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.util.DisplayMetrics;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.utils.ConfigUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -43,43 +44,33 @@ public class MapboxTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccessToken() {
|
||||
final String accessToken = "pk.0000000001";
|
||||
MapboxInjector.inject(context, accessToken);
|
||||
assertSame(accessToken, Mapbox.getAccessToken());
|
||||
public void testGetApiKey() {
|
||||
final String apiKey = "pk.0000000001";
|
||||
MapboxInjector.inject(context, apiKey, ConfigUtils.getMockedOptions());
|
||||
assertSame(apiKey, Mapbox.getApiKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationContext() {
|
||||
MapboxInjector.inject(context, "pk.0000000001");
|
||||
MapboxInjector.inject(context, "pk.0000000001", ConfigUtils.getMockedOptions());
|
||||
assertNotNull(Mapbox.getApplicationContext());
|
||||
assertNotEquals(context, appContext);
|
||||
assertEquals(appContext, appContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPkTokenValid() {
|
||||
assertTrue(Mapbox.isAccessTokenValid("pk.0000000001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkTokenValid() {
|
||||
assertTrue(Mapbox.isAccessTokenValid("sk.0000000001"));
|
||||
public void testPlainTokenValid() {
|
||||
assertTrue(Mapbox.isApiKeyValid("apiKey"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid(""));
|
||||
assertFalse(Mapbox.isApiKeyValid(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlaBlaToken() {
|
||||
assertFalse(Mapbox.isAccessTokenValid("blabla"));
|
||||
assertFalse(Mapbox.isApiKeyValid(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,10 +85,8 @@ public class MapboxTest {
|
||||
|
||||
expectedException.expect(MapboxConfigurationException.class);
|
||||
expectedException.expectMessage(
|
||||
"\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."
|
||||
"\nUsing MapView requires calling Mapbox.getInstance(Context context, String apiKey) before "
|
||||
+ "inflating or creating the view."
|
||||
);
|
||||
new MapView(context);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -14,7 +10,6 @@ import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AttributionDialogManagerTest {
|
||||
@@ -28,72 +23,14 @@ public class AttributionDialogManagerTest {
|
||||
Style style = mock(Style.class);
|
||||
|
||||
private AttributionDialogManager attributionDialogManager;
|
||||
private CameraPosition cameraPosition;
|
||||
|
||||
private static final String ASSERT_MAPBOX_TOKEN = "TestAccessToken";
|
||||
|
||||
private static final String ASSERT_MAPBOX_STYLE_URI = "mapbox://styles/mapbox/streets-v11";
|
||||
private static final String ASSERT_MAPBOX_LOCAL_STYLE_URI = "asset://style.json";
|
||||
|
||||
private static final String ASSERT_MAPBOX_PACKAGE_NAME = "com.mapbox.attributionmanagertest";
|
||||
|
||||
private static final String ASSERT_MAPBOX_FEEDBACK_FINAL_URL =
|
||||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&"
|
||||
+ "access_token=TestAccessToken&owner=mapbox&id=streets-v11"
|
||||
+ "#/22.200001/11.100000/12.000000/24.000000/5";
|
||||
private static final String ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE =
|
||||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&"
|
||||
+ "access_token=TestAccessToken#/22.200001/11.100000/12.000000/24.000000/5";
|
||||
private static final String ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION =
|
||||
"https://apps.mapbox.com/feedback?referrer=com.mapbox.attributionmanagertest&access_token=TestAccessToken";
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
attributionDialogManager = new AttributionDialogManager(context, mapboxMap);
|
||||
cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT)
|
||||
.tilt(5.0f).zoom(12).bearing(24.0f).target(new LatLng(11.1f, 22.2f)).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("AttributionDialogManager should not be null", attributionDialogManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildMapFeedbackMapUrl() {
|
||||
when(context.getApplicationContext()).thenReturn(context);
|
||||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME);
|
||||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_STYLE_URI);
|
||||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition);
|
||||
when(mapboxMap.getStyle()).thenReturn(style);
|
||||
|
||||
Assert.assertEquals(ASSERT_MAPBOX_FEEDBACK_FINAL_URL,
|
||||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildMapFeedbackMapUrlWithLocalStyleJson() {
|
||||
when(context.getApplicationContext()).thenReturn(context);
|
||||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME);
|
||||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI);
|
||||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition);
|
||||
when(mapboxMap.getStyle()).thenReturn(style);
|
||||
|
||||
Assert.assertEquals(ASSERT_MAPBOX_FEEDHACK_FINAL_URL_LOCAL_STYLE,
|
||||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildMapFeedbackMapUrlWithNullCameraPosition() {
|
||||
when(context.getApplicationContext()).thenReturn(context);
|
||||
when(context.getPackageName()).thenReturn(ASSERT_MAPBOX_PACKAGE_NAME);
|
||||
when(style.getUri()).thenReturn(ASSERT_MAPBOX_LOCAL_STYLE_URI);
|
||||
when(mapboxMap.getCameraPosition()).thenReturn(null);
|
||||
when(mapboxMap.getStyle()).thenReturn(style);
|
||||
|
||||
Assert.assertEquals(ASSERT_MAPBOX_FEEDBACL_FINAL_URL_NULL_CAMERA_POSITION,
|
||||
attributionDialogManager.buildMapFeedbackMapUrl(ASSERT_MAPBOX_TOKEN));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.content.Context
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import com.mapbox.mapboxsdk.utils.ConfigUtils
|
||||
import io.mockk.*
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@@ -26,8 +31,15 @@ class MapboxMapTest {
|
||||
|
||||
private lateinit var developerAnimationListener: MapboxMap.OnDeveloperAnimationListener
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
@Mock
|
||||
private lateinit var appContext: Context
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
MapboxInjector.inject(context, "abcdef", ConfigUtils.getMockedOptions())
|
||||
cameraChangeDispatcher = spyk()
|
||||
developerAnimationListener = mockk(relaxed = true)
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
@@ -36,7 +48,7 @@ class MapboxMapTest {
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
every { nativeMapView.nativePtr } returns 5
|
||||
mapboxMap.injectLocationComponent(spyk())
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
mapboxMap.setStyle(Style.getPredefinedStyle("Streets"))
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class StyleBuilderTest {
|
||||
|
||||
@Test
|
||||
fun testFromUrl() {
|
||||
val expected = Style.MAPBOX_STREETS
|
||||
val expected = Style.getPredefinedStyle("Streets")
|
||||
val builder = Style.Builder()
|
||||
builder.fromUrl(expected)
|
||||
assertEquals(expected, builder.uri)
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions
|
||||
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.utils.ConfigUtils
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.spyk
|
||||
@@ -16,6 +19,8 @@ import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@@ -25,8 +30,16 @@ class StyleTest {
|
||||
|
||||
private lateinit var nativeMapView: NativeMap
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var appContext: Context
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
MapboxInjector.inject(context, "abcdef", ConfigUtils.getMockedOptions())
|
||||
nativeMapView = mockk(relaxed = true)
|
||||
mapboxMap = MapboxMap(nativeMapView, null, null, null, null, null, null)
|
||||
every { nativeMapView.isDestroyed } returns false
|
||||
@@ -35,9 +48,9 @@ class StyleTest {
|
||||
|
||||
@Test
|
||||
fun testFromUrl() {
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +74,12 @@ class StyleTest {
|
||||
val builder = Style.Builder().withLayer(layer)
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.onFinishLoadingStyle()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
|
||||
verify(exactly = 1) {
|
||||
nativeMapView.addLayerBelow(
|
||||
layer,
|
||||
MapboxConstants.LAYER_ID_ANNOTATIONS
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,9 +135,10 @@ class StyleTest {
|
||||
fun testWithFromLoadingSource() {
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source)
|
||||
val builder =
|
||||
Style.Builder().fromUrl(Style.getPredefinedStyle("Streets")).withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
}
|
||||
@@ -128,20 +147,26 @@ class StyleTest {
|
||||
fun testWithFromLoadingLayer() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayer(layer)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets")).withLayer(layer)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, MapboxConstants.LAYER_ID_ANNOTATIONS) }
|
||||
verify(exactly = 1) {
|
||||
nativeMapView.addLayerBelow(
|
||||
layer,
|
||||
MapboxConstants.LAYER_ID_ANNOTATIONS
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWithFromLoadingLayerAt() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerAt(layer, 1)
|
||||
val builder =
|
||||
Style.Builder().fromUrl(Style.getPredefinedStyle("Streets")).withLayerAt(layer, 1)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerAt(layer, 1) }
|
||||
}
|
||||
@@ -150,9 +175,10 @@ class StyleTest {
|
||||
fun testWithFromLoadingLayerBelow() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
.withLayerBelow(layer, "below")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
|
||||
}
|
||||
@@ -161,9 +187,10 @@ class StyleTest {
|
||||
fun testWithFromLoadingLayerAbove() {
|
||||
val layer = mockk<SymbolLayer>()
|
||||
every { layer.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withLayerBelow(layer, "below")
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
.withLayerBelow(layer, "below")
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addLayerBelow(layer, "below") }
|
||||
}
|
||||
@@ -171,9 +198,10 @@ class StyleTest {
|
||||
@Test
|
||||
fun testWithFromLoadingTransitionOptions() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
.withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions }
|
||||
}
|
||||
@@ -182,9 +210,9 @@ class StyleTest {
|
||||
fun testFromCallback() {
|
||||
val callback = mockk<Style.OnStyleLoaded>()
|
||||
every { callback.onStyleLoaded(any()) } answers {}
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
mapboxMap.setStyle(builder, callback)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
@@ -237,9 +265,10 @@ class StyleTest {
|
||||
mapboxMap.getStyle(callback)
|
||||
val source = mockk<GeoJsonSource>()
|
||||
every { source.id } returns "1"
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withSource(source)
|
||||
val builder =
|
||||
Style.Builder().fromUrl(Style.getPredefinedStyle("Streets")).withSource(source)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.MAPBOX_STREETS }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Streets") }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addSource(source) }
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
@@ -253,7 +282,8 @@ class StyleTest {
|
||||
@Test
|
||||
fun testGetNullWhileLoading() {
|
||||
val transitionOptions = TransitionOptions(100, 200)
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withTransition(transitionOptions)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
.withTransition(transitionOptions)
|
||||
mapboxMap.setStyle(builder)
|
||||
Assert.assertNull(mapboxMap.style)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
@@ -271,26 +301,27 @@ class StyleTest {
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS)
|
||||
mapboxMap.setStyle(Style.getPredefinedStyle("Streets"))
|
||||
verify(exactly = 1) { callback.onStyleLoaded(any()) }
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun testIllegalStateExceptionWithStyleReload() {
|
||||
val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
val builder = Style.Builder().fromUrl(Style.getPredefinedStyle("Streets"))
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
val style = mapboxMap.style
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.getPredefinedStyle("Bright")))
|
||||
style!!.addLayer(mockk<SymbolLayer>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddImage() {
|
||||
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
||||
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", bitmap)
|
||||
val builder =
|
||||
Style.Builder().fromUrl(Style.getPredefinedStyle("Satellite Hybrid")).withImage("id", bitmap)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Satellite Hybrid") }
|
||||
verify(exactly = 0) { nativeMapView.addImages(any()) }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImages(any()) }
|
||||
@@ -301,9 +332,10 @@ class StyleTest {
|
||||
val drawable = ShapeDrawable()
|
||||
drawable.intrinsicHeight = 10
|
||||
drawable.intrinsicWidth = 10
|
||||
val builder = Style.Builder().fromUrl(Style.SATELLITE).withImage("id", drawable)
|
||||
val builder =
|
||||
Style.Builder().fromUrl(Style.getPredefinedStyle("Satellite Hybrid")).withImage("id", drawable)
|
||||
mapboxMap.setStyle(builder)
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.SATELLITE }
|
||||
verify(exactly = 1) { nativeMapView.styleUri = Style.getPredefinedStyle("Satellite Hybrid") }
|
||||
verify(exactly = 0) { nativeMapView.addImages(any()) }
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
verify(exactly = 1) { nativeMapView.addImages(any()) }
|
||||
@@ -325,7 +357,11 @@ class StyleTest {
|
||||
try {
|
||||
mapboxMap.style!!.addSource(source2)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Source that failed to be added shouldn't be cached", source1, mapboxMap.style!!.getSource("source1"))
|
||||
Assert.assertEquals(
|
||||
"Source that failed to be added shouldn't be cached",
|
||||
source1,
|
||||
mapboxMap.style!!.getSource("source1")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +381,11 @@ class StyleTest {
|
||||
try {
|
||||
mapboxMap.style!!.addLayer(layer2)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
Assert.assertEquals(
|
||||
"Layer that failed to be added shouldn't be cached",
|
||||
layer1,
|
||||
mapboxMap.style!!.getLayer("layer1")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,12 +400,21 @@ class StyleTest {
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayerBelow(any(), "") } throws CannotAddLayerException("Duplicate ID")
|
||||
every {
|
||||
nativeMapView.addLayerBelow(
|
||||
any(),
|
||||
""
|
||||
)
|
||||
} throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayerBelow(layer2, "")
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
Assert.assertEquals(
|
||||
"Layer that failed to be added shouldn't be cached",
|
||||
layer1,
|
||||
mapboxMap.style!!.getLayer("layer1")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,12 +429,21 @@ class StyleTest {
|
||||
mapboxMap.setStyle(builder)
|
||||
mapboxMap.notifyStyleLoaded()
|
||||
|
||||
every { nativeMapView.addLayerAbove(any(), "") } throws CannotAddLayerException("Duplicate ID")
|
||||
every {
|
||||
nativeMapView.addLayerAbove(
|
||||
any(),
|
||||
""
|
||||
)
|
||||
} throws CannotAddLayerException("Duplicate ID")
|
||||
|
||||
try {
|
||||
mapboxMap.style!!.addLayerAbove(layer2, "")
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
Assert.assertEquals(
|
||||
"Layer that failed to be added shouldn't be cached",
|
||||
layer1,
|
||||
mapboxMap.style!!.getLayer("layer1")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +463,11 @@ class StyleTest {
|
||||
try {
|
||||
mapboxMap.style!!.addLayerAt(layer2, 5)
|
||||
} catch (ex: Exception) {
|
||||
Assert.assertEquals("Layer that failed to be added shouldn't be cached", layer1, mapboxMap.style!!.getLayer("layer1"))
|
||||
Assert.assertEquals(
|
||||
"Layer that failed to be added shouldn't be cached",
|
||||
layer1,
|
||||
mapboxMap.style!!.getLayer("layer1")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.module.http
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import com.mapbox.mapboxsdk.http.HttpRequestUrl
|
||||
import com.mapbox.mapboxsdk.utils.ConfigUtils
|
||||
import io.mockk.mockk
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.After
|
||||
@@ -15,7 +16,7 @@ class HttpRequestUrlTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "pk.foobar")
|
||||
MapboxInjector.inject(mockk(relaxed = true), "pk.foobar", ConfigUtils.getMockedOptions())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mapbox.mapboxsdk.module.http
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxInjector
|
||||
import com.mapbox.mapboxsdk.utils.ConfigUtils
|
||||
import io.mockk.mockk
|
||||
import junit.framework.Assert.assertEquals
|
||||
import okhttp3.OkHttpClient
|
||||
@@ -13,7 +14,7 @@ class HttpRequestUtilTest {
|
||||
|
||||
@Test
|
||||
fun replaceHttpClient() {
|
||||
MapboxInjector.inject(mockk(relaxed = true), "")
|
||||
MapboxInjector.inject(mockk(relaxed = true), "", ConfigUtils.getMockedOptions())
|
||||
|
||||
assertEquals(HttpRequestImpl.DEFAULT_CLIENT, HttpRequestImpl.client)
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.mapbox.mapboxsdk.utils
|
||||
|
||||
import com.mapbox.mapboxsdk.util.DefaultStyle
|
||||
import com.mapbox.mapboxsdk.util.TileServerOptions
|
||||
|
||||
class ConfigUtils {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getMockedOptions(): TileServerOptions {
|
||||
val defaultStyles = arrayOf(
|
||||
DefaultStyle("maptiler://maps/streets", "Streets", 1),
|
||||
DefaultStyle("maptiler://maps/outdoor", "Outdoor", 1),
|
||||
DefaultStyle("maptiler://maps/basic", "Basic", 1),
|
||||
DefaultStyle("maptiler://maps/bright", "Bright", 1),
|
||||
DefaultStyle("maptiler://maps/pastel", "Pastel", 1),
|
||||
DefaultStyle("maptiler://maps/hybrid", "Satellite Hybrid", 1),
|
||||
DefaultStyle("maptiler://maps/topo", "Satellite Topo", 1)
|
||||
)
|
||||
val defaultStyle = defaultStyles[0].name
|
||||
|
||||
return TileServerOptions(
|
||||
"https://api.maptiler.com",
|
||||
"maptiler",
|
||||
"{path}",
|
||||
"sources",
|
||||
null,
|
||||
"/maps{path}/style.json",
|
||||
"maps",
|
||||
null,
|
||||
"/maps{path}",
|
||||
"sprites",
|
||||
null,
|
||||
"/fonts{path}",
|
||||
"fonts",
|
||||
null,
|
||||
"{path}",
|
||||
"tiles",
|
||||
null,
|
||||
"key",
|
||||
true,
|
||||
defaultStyle,
|
||||
defaultStyles
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user