From 9f88e373665124464351424e1efc95fe3a1fc05d Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 9 Jun 2017 10:00:00 +0200 Subject: [PATCH] Custom location source fix (#9142) * [android] - custom location engine fixes (#9139) * Update to latest LOST dependency, fixup internal location source integration --- .../java/com/mapbox/mapboxsdk/Mapbox.java | 12 +- .../mapboxsdk/constants/MapboxConstants.java | 2 +- .../mapboxsdk/location/LocationSource.java | 40 +--- .../com/mapbox/mapboxsdk/maps/MapboxMap.java | 3 - .../mapboxsdk/maps/TrackingSettings.java | 31 ++- .../maps/widgets/MyLocationView.java | 58 ++++-- .../maps/widgets/MyLocationViewTest.java | 4 +- .../activity/FeatureOverviewActivity.java | 52 ++--- .../userlocation/BaseLocationActivity.java | 46 +++-- .../CustomLocationEngineActivity.java | 36 +++- .../userlocation/MockLocationEngine.java | 125 ++++++++----- .../MyLocationDrawableActivity.java | 48 ++--- .../userlocation/MyLocationTintActivity.java | 3 - .../MyLocationToggleActivity.java | 65 ++----- .../MyLocationTrackingModeActivity.java | 177 ++++++++++++------ .../layout/activity_my_location_tracking.xml | 2 +- .../main/res/menu/menu_location_engine.xml | 20 ++ .../src/main/res/values/strings.xml | 3 + .../java/com/mapbox/mapboxsdk/MapboxTest.java | 5 +- platform/android/dependencies.gradle | 4 +- 20 files changed, 444 insertions(+), 292 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_location_engine.xml 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 81134e9497d..17cd4e0dce5 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 @@ -30,6 +30,7 @@ public final class Mapbox { private Context context; private String accessToken; private Boolean connected; + private LocationSource locationSource; /** * Get an instance of Mapbox. @@ -45,8 +46,8 @@ 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); + INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext)); + LocationEngine locationEngine = new LocationSource(appContext); locationEngine.setPriority(LocationEnginePriority.NO_POWER); MapboxTelemetry.getInstance().initialize( appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine); @@ -55,9 +56,10 @@ public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull return INSTANCE; } - Mapbox(@NonNull Context context, @NonNull String accessToken) { + Mapbox(@NonNull Context context, @NonNull String accessToken, LocationSource locationSource) { this.context = context; this.accessToken = accessToken; + this.locationSource = locationSource; } /** @@ -128,4 +130,8 @@ public static synchronized Boolean isConnected() { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return (activeNetwork != null && activeNetwork.isConnected()); } + + public static LocationSource getLocationSource() { + return INSTANCE.locationSource; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java index 0396defe74f..1ee59057d23 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java @@ -134,5 +134,5 @@ public class MapboxConstants { public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom"; public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled"; public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled"; - + public static final String STATE_USING_CUSTOM_LOCATION_SOURCE = "mapbox_usingCustomLocationSource"; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java index 4e934fa3ccb..8416bd5b6cf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java @@ -2,7 +2,7 @@ import android.content.Context; import android.location.Location; -import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEngineListener; @@ -13,10 +13,6 @@ import com.mapzen.android.lost.api.LocationServices; import com.mapzen.android.lost.api.LostApiClient; -import java.lang.ref.WeakReference; - -import timber.log.Timber; - /** * Manages locational updates. Contains methods to register and unregister location listeners. *