diff options
author | langsmith <langstonlmcs@gmail.com> | 2019-02-18 13:51:59 -0800 |
---|---|---|
committer | langsmith <langstonlmcs@gmail.com> | 2019-03-05 09:46:57 -0800 |
commit | 28ee0b35e3835d8d6fa7289b2ede979d7714d2d4 (patch) | |
tree | 9a7481edff75a9e6ad9695d774bb23a6bb48c8eb | |
parent | b29704cd1f19f03ac71ee7d308669135c6cfddcc (diff) | |
download | qtlocation-mapboxgl-28ee0b35e3835d8d6fa7289b2ede979d7714d2d4.tar.gz |
initial additions of activation builder
7 files changed, 425 insertions, 0 deletions
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 ddb211f8f6..b559b36bd0 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 @@ -11,6 +11,7 @@ import android.support.annotation.Nullable; import android.support.annotation.RequiresPermission; import android.support.annotation.StyleRes; import android.support.annotation.VisibleForTesting; +import android.util.Log; import android.view.WindowManager; import com.mapbox.android.core.location.LocationEngine; @@ -217,8 +218,11 @@ public final class LocationComponent { * * @param context the context * @param style the proxy object for current map style. More info at {@link Style} + * @deprecated As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style) { activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, R.style.mapbox_LocationComponent)); @@ -232,8 +236,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine) { if (useDefaultLocationEngine) { @@ -252,8 +259,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine, @NonNull LocationEngineRequest locationEngineRequest) { @@ -275,8 +285,11 @@ public final class LocationComponent { * there should be no location engine initialized * @param locationEngineRequest the location request * @param options the options + * @deprecated As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, boolean useDefaultLocationEngine, @NonNull LocationEngineRequest locationEngineRequest, @@ -298,8 +311,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @StyleRes int styleRes) { activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, styleRes)); } @@ -314,8 +330,11 @@ public final class LocationComponent { * @param context the context * @param style the proxy object for current map style. More info at {@link Style} * @param options the options + * @deprecated As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @NonNull LocationComponentOptions options) { initialize(context, style, options); @@ -331,8 +350,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @StyleRes int styleRes) { activateLocationComponent(context, style, locationEngine, @@ -348,8 +370,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @NonNull LocationEngineRequest locationEngineRequest, @StyleRes int styleRes) { @@ -363,8 +388,11 @@ public final class LocationComponent { * @param context the context * @param style the proxy object for current map style. More info at {@link Style} * @param locationEngine the engine + * @deprecated As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine) { activateLocationComponent(context, style, locationEngine, R.style.mapbox_LocationComponent); @@ -377,8 +405,11 @@ public final class LocationComponent { * @param style the proxy object for current map style. More info at {@link Style} * @param locationEngine the engine * @param locationEngineRequest the location request + * @deprecated As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @NonNull LocationEngineRequest locationEngineRequest) { @@ -392,8 +423,11 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @NonNull LocationComponentOptions options) { @@ -411,7 +445,10 @@ public final class LocationComponent { * @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 As of 7.2.0, + * use {@link LocationComponentActivationOptions.Builder} instead */ + @Deprecated public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, @NonNull LocationEngineRequest locationEngineRequest, @@ -422,6 +459,55 @@ public final class LocationComponent { applyStyle(options); } + public void activateLocationComponent(@NonNull LocationComponentActivationOptions + locationComponentActivationOptions) { + + Log.d(TAG, "locationComponentActivationOptions context packageName = " + locationComponentActivationOptions.context().getPackageName()); + Log.d(TAG, "locationComponentActivationOptions style URL = " + locationComponentActivationOptions.style().getUrl()); + Log.d(TAG, "locationComponentActivationOptions styleRes = " + locationComponentActivationOptions.styleRes()); + + if (locationComponentActivationOptions.context() != null + && locationComponentActivationOptions.style() != null + && locationComponentActivationOptions.locationComponentOptions() != null) { + initialize(locationComponentActivationOptions.context(), locationComponentActivationOptions.style(), + locationComponentActivationOptions.locationComponentOptions()); + } + + if (locationComponentActivationOptions.locationEngineRequest() != null) { + setLocationEngineRequest(locationComponentActivationOptions.locationEngineRequest()); + } + + if (locationComponentActivationOptions.locationEngine() != null) { + setLocationEngine(locationEngine); + } else if (locationComponentActivationOptions.useDefaultLocationEngine()) { + initializeLocationEngine(locationComponentActivationOptions.context()); + } else { + setLocationEngine(null); + } + + // TODO: How to do some sort of null check on an int for locationComponentActivationOptions.styleRes() ? + if (locationComponentActivationOptions.styleRes() <0 && + locationComponentActivationOptions.locationComponentOptions() == null + && locationComponentActivationOptions.context() != null) { + + applyStyle(LocationComponentOptions.createFromAttributes(locationComponentActivationOptions.context(), + R.style.mapbox_LocationComponent)); + + } else if (locationComponentActivationOptions.styleRes() <0 + && locationComponentActivationOptions.locationComponentOptions() == null + && locationComponentActivationOptions.context() != null) { + + applyStyle(LocationComponentOptions.createFromAttributes(locationComponentActivationOptions.context(), + locationComponentActivationOptions.styleRes())); + } else if (locationComponentActivationOptions.styleRes() < 0 + && locationComponentActivationOptions.locationComponentOptions() != null + && locationComponentActivationOptions.context() != null) { + + applyStyle(locationComponentActivationOptions.locationComponentOptions()); + } + } + + /** * Manage component's visibility after activation. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java new file mode 100644 index 0000000000..6e8529bc18 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java @@ -0,0 +1,170 @@ +package com.mapbox.mapboxsdk.location; + +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.mapbox.android.core.location.LocationEngine; +import com.mapbox.android.core.location.LocationEngineRequest; +import com.mapbox.mapboxsdk.maps.Style; + +/** + * since 7.2.0 + */ +public class LocationComponentActivationOptions { + + private Context context; + private Style style; + private LocationEngine locationEngine; + private LocationEngineRequest locationEngineRequest; + private LocationComponentOptions locationComponentOptions; + private int styleRes; + private boolean useDefaultLocationEngine; + + LocationComponentActivationOptions(@NonNull Context context, @NonNull Style style, + @Nullable LocationEngine locationEngine, + @Nullable LocationEngineRequest locationEngineRequest, + @Nullable LocationComponentOptions locationComponentOptions, + int styleRes, + boolean useDefaultLocationEngine) { + this.context = context; + this.style = style; + this.locationEngine = locationEngine; + this.locationEngineRequest = locationEngineRequest; + this.locationComponentOptions = locationComponentOptions; + this.styleRes = styleRes; + this.useDefaultLocationEngine = useDefaultLocationEngine; + } + + /** + * Convenience method to retrieve a {@link LocationComponentActivationOptions} object which is ready to build with + * + * @return a builder object + */ + @NonNull + public static Builder builder(@NonNull Context context, @NonNull Style fullyLoadedMapStyle) { + return new LocationComponentActivationOptions.Builder(context, fullyLoadedMapStyle); + } + + /** + * The application's current context + * + * @return the application's current context + */ + @Nullable + public Context context() { + return context; + } + + /** + * The proxy object for current map style. More info at {@link Style} + * + * @return the map's fully loaded Style object + */ + @Nullable + public Style style() { + return style; + } + + /** + * The {@link LocationEngine} which the {@link LocationComponent} should use + * + * @return the engine, or null if you'd like to only force location updates + */ + @Nullable + public LocationEngine locationEngine() { + return locationEngine; + } + + /** + * The location request which the {@link LocationComponent} should use + * @return + */ + @Nullable + public LocationEngineRequest locationEngineRequest() { + return locationEngineRequest; + } + + /** + * A built {@link LocationComponentOptions} object, which holds the various {@link LocationComponent} styling options + * @return the options for styling the actual LocationComponent + */ + @Nullable + public LocationComponentOptions locationComponentOptions() { + return locationComponentOptions; + } + + /** + * the LocationComponent style res + * + * @return + */ + @Nullable + public int styleRes() { + return styleRes; + } + + /** + * true if you want to initialize and use the built-in location engine or false if there should be no + * location engine initialized + * @return whether the default LocationEngine is used + */ + @Nullable + public boolean useDefaultLocationEngine() { + return useDefaultLocationEngine; + } + + /** + * Builder class for constructing a new instance of {@link LocationComponentActivationOptions}. + * + * since 7.2.0 + */ + public static class Builder { + private Context context; + private Style style; + private LocationEngine locationEngine; + private LocationEngineRequest locationEngineRequest; + private LocationComponentOptions locationComponentOptions; + private int styleRes; + private boolean useDefaultLocationEngine; + + public Builder(Context context, Style style) { + this.context = context; + this.style = style; + } + + public Builder() { + + } + + public Builder locationEngine(LocationEngine locationEngine) { + this.locationEngine = locationEngine; + return this; + } + + public Builder locationEngineRequest(LocationEngineRequest locationEngineRequest) { + this.locationEngineRequest = locationEngineRequest; + return this; + } + + public Builder locationComponentOptions(LocationComponentOptions locationComponentOptions) { + this.locationComponentOptions = locationComponentOptions; + return this; + } + + public Builder styleRes(int styleRes) { + this.styleRes = styleRes; + return this; + } + + public Builder useDefaultLocationEngine(boolean useDefaultLocationEngine) { + this.useDefaultLocationEngine = useDefaultLocationEngine; + return this; + } + + public LocationComponentActivationOptions build() { + return new LocationComponentActivationOptions(context, style, locationEngine, locationEngineRequest, + locationComponentOptions, styleRes, useDefaultLocationEngine); + } + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 22ae7f9824..a113fe1d6b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -862,6 +862,17 @@ android:value=".activity.FeatureOverviewActivity" /> </activity> <activity + android:name=".activity.location.LocationComponentActivationActivity" + android:description="@string/description_location_activation_builder" + android:label="@string/activity_location_activation_builder"> + <meta-data + android:name="@string/category" + android:value="@string/category_location" /> + <meta-data + android:name="android.support.PARENT_ACTIVITY" + android:value=".activity.FeatureOverviewActivity" /> + </activity> + <activity android:name=".activity.maplayout.RecyclerViewActivity" android:description="@string/description_recyclerview" android:label="@string/activity_recyclerview"> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java new file mode 100644 index 0000000000..90b13c5338 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java @@ -0,0 +1,139 @@ +package com.mapbox.mapboxsdk.testapp.activity.location; + +import android.annotation.SuppressLint; +import android.graphics.Color; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.widget.Toast; + +import com.mapbox.android.core.permissions.PermissionsListener; +import com.mapbox.android.core.permissions.PermissionsManager; +import com.mapbox.mapboxsdk.location.LocationComponent; +import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions; +import com.mapbox.mapboxsdk.location.LocationComponentOptions; +import com.mapbox.mapboxsdk.location.modes.RenderMode; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.maps.Style; +import com.mapbox.mapboxsdk.testapp.R; + +import java.util.List; + +public class LocationComponentActivationActivity extends AppCompatActivity implements OnMapReadyCallback { + + private MapView mapView; + private MapboxMap mapboxMap; + private PermissionsManager permissionsManager; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_location_layer_activation_builder); + + mapView = findViewById(R.id.mapView); + + mapView.onCreate(savedInstanceState); + + if (PermissionsManager.areLocationPermissionsGranted(this)) { + mapView.getMapAsync(this); + } else { + permissionsManager = new PermissionsManager(new PermissionsListener() { + @Override + public void onExplanationNeeded(List<String> permissionsToExplain) { + Toast.makeText(LocationComponentActivationActivity.this, "You need to accept location permissions.", + Toast.LENGTH_SHORT).show(); + } + + @Override + public void onPermissionResult(boolean granted) { + if (granted) { + mapView.getMapAsync(LocationComponentActivationActivity.this); + } else { + finish(); + } + } + }); + permissionsManager.requestLocationPermissions(this); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults); + } + + @Override + public void onMapReady(@NonNull MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + mapboxMap.setStyle(Style.DARK, + style -> activateLocationComponent(style)); + } + + @SuppressLint("MissingPermission") + private void activateLocationComponent(@NonNull Style style) { + LocationComponent locationComponent = mapboxMap.getLocationComponent(); + + LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(this) + .elevation(5) + .accuracyAlpha(.6f) + .accuracyColor(Color.GREEN) + .foregroundDrawable(R.drawable.mapbox_marker_icon_default) + .build(); + + LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions + .builder(this, style) + .locationComponentOptions(locationComponentOptions) + .useDefaultLocationEngine(true) + .build(); + + locationComponent.activateLocationComponent(locationComponentActivationOptions); + locationComponent.setLocationComponentEnabled(true); + locationComponent.setRenderMode(RenderMode.COMPASS); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + protected void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml new file mode 100644 index 0000000000..daae10ad03 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.design.widget.CoordinatorLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/coordinator_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <com.mapbox.mapboxsdk.maps.MapView + android:id="@+id/mapView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginBottom="0dp" + app:mapbox_uiAttribution="false"/> + +</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index 7fdc4c1bea..14eb678795 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -75,6 +75,7 @@ <string name="description_location_modes">Showcases location render and tracking modes</string> <string name="description_location_fragment">Uses LocationComponent in a Fragment</string> <string name="description_location_manual">Force location updates and don\'t rely on the engine</string> + <string name="description_location_activation_builder">Use LocationComponentActivationOptions to set options</string> <string name="description_recyclerview">Show a MapView as a recyclerView item</string> <string name="description_nested_viewpager">Show a MapView inside a viewpager inside a recyclerView</string> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index 3345c8db4e..dc4fd89deb 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -75,6 +75,7 @@ <string name="activity_location_modes">Location Modes Activity</string> <string name="activity_location_fragment">Location Fragment</string> <string name="activity_location_manual">Manual Location updates</string> + <string name="activity_location_activation_builder">Build Location Activation</string> <string name="activity_recyclerview">RecyclerView</string> <string name="activity_nested_viewpager">Nested ViewPager</string> </resources>
\ No newline at end of file |