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 | 52 |
1 files changed, 44 insertions, 8 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 bc1049d146..b67b6e96f2 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 @@ -1,6 +1,6 @@ package com.mapbox.mapboxsdk; -import android.app.Application; +import android.annotation.SuppressLint; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -15,22 +15,27 @@ import com.mapbox.mapboxsdk.net.ConnectivityReceiver; import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEnginePriority; +import com.mapbox.services.android.telemetry.location.LocationEngineProvider; + +import timber.log.Timber; /** - * The entry point of the Mapbox Android SDK. + * The entry point to initialize the Mapbox Android SDK. * <p> * Obtain a reference by calling {@link #getInstance(Context, String)}. Usually this class is configured in - * {@link Application#onCreate()} and is responsible for the active access token, application context, and + * Application#onCreate() and is responsible for the active access token, application context, and * connectivity state. * </p> */ @UiThread public final class Mapbox { + @SuppressLint("StaticFieldLeak") private static Mapbox INSTANCE; private Context context; private String accessToken; private Boolean connected; + private LocationEngine locationEngine; /** * Get an instance of Mapbox. @@ -46,19 +51,27 @@ public final class Mapbox { public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull String accessToken) { if (INSTANCE == null) { Context appContext = context.getApplicationContext(); - INSTANCE = new Mapbox(appContext, accessToken); - LocationEngine locationEngine = LocationSource.getLocationEngine(appContext); + LocationEngineProvider locationEngineProvider = new LocationEngineProvider(context); + LocationEngine locationEngine = locationEngineProvider.obtainBestLocationEngineAvailable(); + INSTANCE = new Mapbox(appContext, accessToken, locationEngine); locationEngine.setPriority(LocationEnginePriority.NO_POWER); - MapboxTelemetry.getInstance().initialize( - appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); + + try { + MapboxTelemetry.getInstance().initialize( + appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); + } catch (Exception exception) { + Timber.e(exception, "Unable to instantiate Mapbox telemetry"); + } + ConnectivityReceiver.instance(appContext); } return INSTANCE; } - Mapbox(@NonNull Context context, @NonNull String accessToken) { + Mapbox(@NonNull Context context, @NonNull String accessToken, LocationEngine locationEngine) { this.context = context; this.accessToken = accessToken; + this.locationEngine = locationEngine; } /** @@ -96,6 +109,8 @@ public final class Mapbox { /** * Application context + * + * @return the application context */ public static Context getApplicationContext() { return INSTANCE.context; @@ -129,4 +144,25 @@ public final class Mapbox { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return (activeNetwork != null && activeNetwork.isConnected()); } + + /** + * Returns a location source instance with empty methods. + * + * @return an empty location source implementation + * @deprecated Replaced by {@link Mapbox#getLocationEngine()} + */ + @Deprecated + public static LocationSource getLocationSource() { + return new EmptyLocationSource(); + } + + + /** + * Returns the location engine used by the SDK. + * + * @return the location engine configured + */ + public static LocationEngine getLocationEngine() { + return INSTANCE.locationEngine; + } } |