diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java index b761c85e1c..9c4752b030 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java @@ -10,6 +10,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException; import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.TelemetryDefinition; +import com.mapbox.mapboxsdk.module.ModuleProviderImpl; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; import com.mapbox.mapboxsdk.storage.FileSource; import com.mapbox.mapboxsdk.utils.ThreadUtils; @@ -35,6 +36,8 @@ public final class Mapbox { private String accessToken; @Nullable private TelemetryDefinition telemetry; + @Nullable + private LibraryLoader libraryLoader; /** * Get an instance of Mapbox. @@ -49,14 +52,33 @@ public final class Mapbox { @UiThread @NonNull public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String accessToken) { + return getInstance(context, accessToken, null); + } + + /** + * Get an instance of Mapbox. + * <p> + * This class manages the Mapbox access token, application context, and connectivity state. + * </p> + * + * @param context Android context which holds or is an application context + * @param accessToken Mapbox access token + * @param libraryLoader Library loader used to load the native library + * @return the single instance of Mapbox + */ + @UiThread + @NonNull + public static synchronized Mapbox getInstance(@NonNull Context context, @Nullable String accessToken, + @Nullable LibraryLoader libraryLoader) { ThreadUtils.checkThread("Mapbox"); if (INSTANCE == null) { Context appContext = context.getApplicationContext(); - FileSource.initializeFileDirsPaths(appContext); INSTANCE = new Mapbox(appContext, accessToken); + initializeLibraryLoader(libraryLoader); if (isAccessTokenValid(accessToken)) { initializeTelemetry(); } + FileSource.initializeFileDirsPaths(appContext); ConnectivityReceiver.instance(appContext); } return INSTANCE; @@ -145,7 +167,36 @@ public final class Mapbox { } /** - * Get the module provider + * Initializes library loader. + * + * @param libraryLoader the library loader used to load native libraries + */ + private static void initializeLibraryLoader(LibraryLoader libraryLoader) { + if (libraryLoader != null) { + INSTANCE.libraryLoader = libraryLoader; + } else { + try { + INSTANCE.libraryLoader = getModuleProvider().obtainLibraryLoader(); + } catch (Exception exception) { + String message = "Error occurred while initializing library loader"; + Logger.e(TAG, message, exception); + MapStrictMode.strictModeViolation(message, exception); + } + } + } + + /** + * Get an instance of LibraryLoader if initialised. + * + * @return library loader used to load native libraries + */ + public static LibraryLoader getLibraryLoader() { + return INSTANCE.libraryLoader; + } + + + /** + * Get the module provider, internal use only * * @return moduleProvider */ @@ -157,6 +208,7 @@ public final class Mapbox { return moduleProvider; } + /** * Runtime validation of Mapbox creation. */ |