diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index bc6794900..c5f752071 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -6,12 +6,16 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C * Add your pull request... -## 10.0.0 - February 10, 2023 +## 10.0.0 - February 14, 2023 ### ✨ Features and improvements -* Breaking: Changed resourcePrefix to `maplibre_` from `mapbox_` [647](https://github.com/maplibre/maplibre-gl-native/pull/647) and renamed resources accordingly. Note that this is a breaking change since the names of public resources were renamed as well. Replaced Mapbox logo with MapLibre logo. -* GMS location: Replace new LocationRequest() with LocationRequest.Builder, and LocationRequest.PRIORITY_X with Priority.PRIORITY_X ([620](https://github.com/maplibre/maplibre-gl-native/pull/620)) +* Breaking: Changed resourcePrefix to `maplibre_` from `mapbox_` ([#647](https://github.com/maplibre/maplibre-gl-native/pull/647)) and renamed resources accordingly. Note that this is a breaking change since the names of public resources were renamed as well. Replaced Mapbox logo with MapLibre logo. +* Breaking: several deprecated overloads of `LocationComponent.activateLocationComponent` were removed. Use `LocationComponentActivationOptions.Builder` instead. +* Breaking: the `LocationEngine` implemented with Google Location Services has been removed to make MapLibre GL Native for Android fully FLOSS ([#379](https://github.com/maplibre/maplibre-gl-native/issues/379)). To migrate: + * Include the source code of the removed [`GoogleLocationEngineImpl`](https://github.com/maplibre/maplibre-gl-native/blob/4a34caab7593f4f1b6d8c09c06a5e25d7c6cfc43/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/GoogleLocationEngineImpl.java) in your source tree. + * Pass an instance of `LocationEngine` based on `GoogleLocationEngineImpl` to `LocationComponentActivationOptions.Builder.locationEngine`. Refer to how this was done in the now-removed [`LocationEngineProvider`](https://github.com/maplibre/maplibre-gl-native/blob/68d58d6f6f453d5c6cc0fa92fcc6c6cfe0cf967f/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/LocationEngineProvider.java#L59). + * The static `LocationEngineResult.extractResult` can no longer extract a `LocationEngineResult` from a Google Play intent. To migrate, include and use the [previous implementation](https://github.com/maplibre/maplibre-gl-native/blob/ea234edf67bb3aec75f077e15c1c30c99756b926/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/LocationEngineResult.java#L97) in your source tree. ### 🐞 Bug fixes diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index 1dc8b50dd..aecd63cb0 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -17,7 +17,6 @@ dependencies { implementation dependenciesList.supportAnnotations implementation dependenciesList.supportFragmentV4 implementation dependenciesList.okhttp3 - implementation dependenciesList.gmsLocation implementation dependenciesList.timber implementation dependenciesList.interpolator diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.kt b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.kt index 4fa897182..ae1bf1ea2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.kt +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.kt @@ -40,7 +40,8 @@ class LatLng : Parcelable { @Keep var latitude = 0.0 set( - @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) latitude) { + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) latitude + ) { require(!latitude.isNaN()) { "latitude must not be NaN" } require(abs(latitude) <= GeometryConstants.MAX_LATITUDE) { "latitude must be between -90 and 90" } field = latitude diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index 072a029b2..cc654df57 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -20,7 +20,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdate; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.engine.LocationEngine; import com.mapbox.mapboxsdk.location.engine.LocationEngineCallback; -import com.mapbox.mapboxsdk.location.engine.LocationEngineProvider; +import com.mapbox.mapboxsdk.location.engine.LocationEngineDefault; import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest; import com.mapbox.mapboxsdk.location.engine.LocationEngineResult; import com.mapbox.mapboxsdk.location.modes.CameraMode; @@ -66,7 +66,7 @@ import static com.mapbox.mapboxsdk.location.modes.RenderMode.GPS; *
* * To get the component object use {@link MapboxMap#getLocationComponent()} and activate it with - * {@link #activateLocationComponent(Context, Style)} or one of the overloads. + * {@link #activateLocationComponent(LocationComponentActivationOptions)}. * Then, manage its visibility with {@link #setLocationComponentEnabled(boolean)}. * The component will not process location updates right after activation, but only after being enabled. * @@ -76,19 +76,17 @@ import static com.mapbox.mapboxsdk.location.modes.RenderMode.GPS; * {@code ACCESS_COARSE_LOCATION} or {@code ACCESS_FINE_LOCATION} permissions can be requested for * this component to work as expected. *
- * This component offers a default, built-in {@link LocationEngine} with some of the activation methods. - * This engine will be obtained by {@link LocationEngineProvider#getBestLocationEngine(Context, boolean)} which defaults - * to the {@link com.mapbox.mapboxsdk.location.engine.MapboxFusedLocationEngineImpl}. If you'd like to utilize Google - * Play Services - * for more precise location updates, simply add the Google Play Location Services dependency in your build script. - * This will make the default engine the {@link com.mapbox.mapboxsdk.location.engine.GoogleLocationEngineImpl} instead. + * This component offers a default, built-in {@link LocationEngine} called + * {@link com.mapbox.mapboxsdk.location.engine.MapboxFusedLocationEngineImpl}. + * If you'd like to utilize the previously available Google Play Services for more precise location updates, + * refer to the migration guide of 10.0.0 in the changelog. * After a custom engine is passed to the component, or the built-in is initialized, * the location updates are going to be requested with the {@link LocationEngineRequest}, either a default one, * or the one passed during the activation. * When using any engine, requesting/removing the location updates is going to be managed internally. *
* You can also push location updates to the component without any internal engine management. - * To achieve that, use {@link #activateLocationComponent(Context, Style, boolean)} with false. + * To achieve that, set `useDefaultLocationEngine` in {@link LocationComponentActivationOptions} to false. * No engine is going to be initialized and you can push location updates with {@link #forceLocationUpdate(Location)}. *
* For location puck animation purposes, like navigation, @@ -105,8 +103,6 @@ public final class LocationComponent { private final Transform transform; private Style style; private LocationComponentOptions options; - @NonNull - private InternalLocationEngineProvider internalLocationEngineProvider = new InternalLocationEngineProvider(); @Nullable private LocationEngine locationEngine; @NonNull @@ -218,7 +214,6 @@ public final class LocationComponent { @NonNull LocationAnimatorCoordinator locationAnimatorCoordinator, @NonNull StaleStateManager staleStateManager, @NonNull CompassEngine compassEngine, - @NonNull InternalLocationEngineProvider internalLocationEngineProvider, boolean useSpecializedLocationLayer) { this.mapboxMap = mapboxMap; this.transform = transform; @@ -230,242 +225,10 @@ public final class LocationComponent { this.locationAnimatorCoordinator = locationAnimatorCoordinator; this.staleStateManager = staleStateManager; this.compassEngine = compassEngine; - this.internalLocationEngineProvider = internalLocationEngineProvider; this.useSpecializedLocationLayer = useSpecializedLocationLayer; isComponentInitialized = true; } - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - *
- * Note: This method will initialize and use an internal {@link LocationEngine} when enabled. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style) { - activateLocationComponent(context, style, - LocationComponentOptions.createFromAttributes(context, R.style.maplibre_LocationComponent)); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if - * there should be no location engine initialized - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - boolean useDefaultLocationEngine) { - if (useDefaultLocationEngine) { - activateLocationComponent(context, style, R.style.maplibre_LocationComponent); - } else { - activateLocationComponent(context, style, null, R.style.maplibre_LocationComponent); - } - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if - * there should be no location engine initialized - * @param locationEngineRequest the location request - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - boolean useDefaultLocationEngine, - @NonNull LocationEngineRequest locationEngineRequest) { - setLocationEngineRequest(locationEngineRequest); - if (useDefaultLocationEngine) { - activateLocationComponent(context, style, R.style.maplibre_LocationComponent); - } else { - activateLocationComponent(context, style, null, R.style.maplibre_LocationComponent); - } - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if - * there should be no location engine initialized - * @param locationEngineRequest the location request - * @param options the options - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - boolean useDefaultLocationEngine, - @NonNull LocationEngineRequest locationEngineRequest, - @NonNull LocationComponentOptions options) { - setLocationEngineRequest(locationEngineRequest); - if (useDefaultLocationEngine) { - activateLocationComponent(context, style, options); - } else { - activateLocationComponent(context, style, null, options); - } - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - *
- * Note: This method will initialize and use an internal {@link LocationEngine} when enabled. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param styleRes the LocationComponent style res - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @StyleRes int styleRes) { - activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, styleRes)); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - *
- * Note: This method will initialize and use an internal {@link LocationEngine} when enabled. - *
- * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param options the options - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @NonNull LocationComponentOptions options) { - initialize(context, style, false, options); - initializeLocationEngine(context); - applyStyle(options); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param locationEngine the engine, or null if you'd like to only force location updates - * @param styleRes the LocationComponent style res - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine, @StyleRes int styleRes) { - activateLocationComponent(context, style, locationEngine, - LocationComponentOptions.createFromAttributes(context, styleRes)); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param locationEngine the engine, or null if you'd like to only force location updates - * @param locationEngineRequest the location request - * @param styleRes the LocationComponent style res - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine, - @NonNull LocationEngineRequest locationEngineRequest, @StyleRes int styleRes) { - activateLocationComponent(context, style, locationEngine, locationEngineRequest, - LocationComponentOptions.createFromAttributes(context, styleRes)); - } - - /** - * This method will show the location icon and enable the camera tracking the location. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param locationEngine the engine - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine) { - activateLocationComponent(context, style, locationEngine, R.style.maplibre_LocationComponent); - } - - /** - * This method will show the location icon and enable the camera tracking the location. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param locationEngine the engine - * @param locationEngineRequest the location request - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine, - @NonNull LocationEngineRequest locationEngineRequest) { - activateLocationComponent( - context, - style, - locationEngine, - locationEngineRequest, - R.style.maplibre_LocationComponent); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param locationEngine the engine, or null if you'd like to only force location updates - * @param style the proxy object for current map style. More info at {@link Style} - * @param options the options - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine, - @NonNull LocationComponentOptions options) { - initialize(context, style, false, options); - setLocationEngine(locationEngine); - applyStyle(options); - } - - /** - * This method initializes the component and needs to be called before any other operations are performed. - * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. - * - * @param context the context - * @param style the proxy object for current map style. More info at {@link Style} - * @param locationEngine the engine, or null if you'd like to only force location updates - * @param locationEngineRequest the location request - * @param options the options - * @deprecated use {@link LocationComponentActivationOptions.Builder} instead - */ - @Deprecated - public void activateLocationComponent(@NonNull Context context, @NonNull Style style, - @Nullable LocationEngine locationEngine, - @NonNull LocationEngineRequest locationEngineRequest, - @NonNull LocationComponentOptions options) { - initialize(context, style, false, options); - setLocationEngineRequest(locationEngineRequest); - setLocationEngine(locationEngine); - applyStyle(options); - } - /** * This method initializes the component and needs to be called before any other operations are performed. * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. @@ -503,7 +266,7 @@ public final class LocationComponent { setLocationEngine(locationEngine); } else { if (activationOptions.useDefaultLocationEngine()) { - initializeLocationEngine(activationOptions.context()); + setLocationEngine(LocationEngineDefault.INSTANCE.getDefaultLocationEngine(activationOptions.context())); } else { setLocationEngine(null); } @@ -1354,13 +1117,6 @@ public final class LocationComponent { onLocationLayerStart(); } - private void initializeLocationEngine(@NonNull Context context) { - if (this.locationEngine != null) { - this.locationEngine.removeLocationUpdates(currentLocationEngineListener); - } - setLocationEngine(internalLocationEngineProvider.getBestLocationEngine(context, false)); - } - private void updateCompassListenerState(boolean canListen) { if (compassEngine != null) { if (!canListen) { @@ -1712,12 +1468,6 @@ public final class LocationComponent { } }; - static class InternalLocationEngineProvider { - LocationEngine getBestLocationEngine(@NonNull Context context, boolean background) { - return LocationEngineProvider.getBestLocationEngine(context, background); - } - } - private void checkActivationState() { if (!isComponentInitialized) { throw new LocationComponentNotInitializedException(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/GoogleLocationEngineImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/GoogleLocationEngineImpl.java deleted file mode 100644 index b6e6afb23..000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/engine/GoogleLocationEngineImpl.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.mapbox.mapboxsdk.location.engine; - -import android.annotation.SuppressLint; -import android.app.PendingIntent; -import android.content.Context; -import android.location.Location; -import android.os.Looper; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; - -import com.google.android.gms.location.FusedLocationProviderClient; -import com.google.android.gms.location.LocationCallback; -import com.google.android.gms.location.LocationRequest; -import com.google.android.gms.location.LocationResult; -import com.google.android.gms.location.LocationServices; -import com.google.android.gms.location.Priority; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; - -import java.util.Collections; -import java.util.List; - -/** - * Wraps implementation of Fused Location Provider - */ -class GoogleLocationEngineImpl implements LocationEngineImpl
@@ -23,8 +19,6 @@ import static com.mapbox.mapboxsdk.location.engine.Utils.isOnClasspath;
* @since 1.0.0
*/
public final class LocationEngineResult {
- private static final String GOOGLE_PLAY_LOCATION_RESULT = "com.google.android.gms.location.LocationResult";
-
private final List