From c9962ab13957000df9c547227fd400b376142010 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Fri, 23 Feb 2018 10:01:42 +0100 Subject: [PATCH 1/5] Clean up and javadoc --- .../locationlayer/LocationLayerTest.java | 4 +- .../locationlayer/LocationLayerOptions.java | 20 +- .../locationlayer/LocationLayerPlugin.java | 475 +++++++++++------- .../OnLocationStaleListener.java | 10 + .../locationlayer/StaleStateRunnable.java | 6 +- .../locationlayer/modes/CameraMode.java | 21 +- .../locationlayer/modes/RenderMode.java | 9 +- .../src/main/res/values/attrs.xml | 2 +- .../src/main/res/values/styles.xml | 2 +- 9 files changed, 330 insertions(+), 219 deletions(-) diff --git a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java index f08c4bcca..d8f98e783 100644 --- a/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java +++ b/app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java @@ -180,7 +180,7 @@ public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, Mapbo SymbolLayer symbolLayer = mapboxMap.getLayerAs(FOREGROUND_LAYER); assert symbolLayer != null; assertThat(symbolLayer.getIconImage().getValue(), equalTo(FOREGROUND_ICON)); - locationLayerPlugin.applyStyle(context, LocationLayerOptions.builder(context).staleStateDelay(400).build()); + locationLayerPlugin.applyStyle(context, LocationLayerOptions.builder(context).staleStateTimeout(400).build()); locationLayerPlugin.forceLocationUpdate(location); uiController.loopMainThreadForAtLeast(500); assertThat(symbolLayer.getIconImage().getValue(), equalTo(FOREGROUND_STALE_ICON)); @@ -195,7 +195,7 @@ public void whenDrawableChanged_continuesUsingStaleIcons() throws Exception { public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, MapboxMap mapboxMap, UiController uiController, Context context) { locationLayerPlugin.setLocationLayerMode(RenderMode.NORMAL); - locationLayerPlugin.applyStyle(context, LocationLayerOptions.builder(context).staleStateDelay(100).build()); + locationLayerPlugin.applyStyle(context, LocationLayerOptions.builder(context).staleStateTimeout(100).build()); locationLayerPlugin.forceLocationUpdate(location); uiController.loopMainThreadForAtLeast(200); rule.getActivity().toggleStyle(); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java index 9c554159f..89b071e2d 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java @@ -100,9 +100,9 @@ public static LocationLayerOptions createFromAttributes(@NonNull Context context builder.enableStaleState(typedArray.getBoolean( R.styleable.LocationLayer_enableStaleState, true)); } - if (typedArray.hasValue(R.styleable.LocationLayer_staleStateDelay)) { - builder.staleStateDelay(typedArray.getInteger( - R.styleable.LocationLayer_staleStateDelay, (int) STALE_STATE_DELAY_MS)); + if (typedArray.hasValue(R.styleable.LocationLayer_staleStateTimeout)) { + builder.staleStateTimeout(typedArray.getInteger( + R.styleable.LocationLayer_staleStateTimeout, (int) STALE_STATE_DELAY_MS)); } builder.gpsDrawable(typedArray.getResourceId( R.styleable.LocationLayer_navigationDrawable, -1)); @@ -148,7 +148,7 @@ public static Builder builder(Context context) { private static Builder builder() { return new AutoValue_LocationLayerOptions.Builder() .enableStaleState(true) - .staleStateDelay(STALE_STATE_DELAY_MS); + .staleStateTimeout(STALE_STATE_DELAY_MS); } /** @@ -317,7 +317,7 @@ private static Builder builder() { * @attr ref R.styleable#LocationLayer_staleStateDelay * @since 0.4.0 */ - public abstract long staleStateDelay(); + public abstract long staleStateTimeout(); /** * Builder class for constructing a new instance of {@link LocationLayerOptions}. @@ -481,17 +481,17 @@ public abstract static class Builder { public abstract Builder enableStaleState(boolean enabled); /** - * Set the delay before the location icon becomes stale. The timer begins approximately when a + * Set the timeout before the location icon becomes stale. The timer begins approximately when a * new location update comes in and using this defined time, if an update hasn't occurred by the * end, the location is considered stale. * - * @param delay the duration in milliseconds which it should take before the location layer is - * considered stale + * @param timeout the duration in milliseconds which it should take before the location layer is + * considered stale * @return this builder for chaining options together - * @attr ref R.styleable#LocationLayer_staleStateDelay + * @attr ref R.styleable#LocationLayer_staleStateTimeout * @since 0.4.0 */ - public abstract Builder staleStateDelay(long delay); + public abstract Builder staleStateTimeout(long timeout); abstract LocationLayerOptions autoBuild(); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index de56b11a1..72712f435 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -25,8 +25,6 @@ import java.util.concurrent.CopyOnWriteArrayList; -import timber.log.Timber; - import static android.Manifest.permission.ACCESS_COARSE_LOCATION; import static android.Manifest.permission.ACCESS_FINE_LOCATION; @@ -34,11 +32,15 @@ * The Location layer plugin provides location awareness to your mobile application. Enabling this * plugin provides a contextual experience to your users by showing an icon representing the users * current location. A few different modes are offered to provide the right context to your users at - * the correct time. {@link LocationLayerMode#NORMAL} simply shows the users location on the map - * represented as a dot. {@link LocationLayerMode#COMPASS} mode allows you to display an arrow icon + * the correct time. {@link RenderMode#NORMAL} simply shows the users location on the map + * represented as a dot. {@link RenderMode#COMPASS} mode allows you to display an arrow icon * (by default) that points in the direction the device is pointing in. - * {@link LocationLayerMode#NAVIGATION} can be used in conjunction with our Navigation SDK to - * display a larger icon we call the user puck. + * {@link RenderMode#GPS} can be used in conjunction with our Navigation SDK to + * display a larger icon (customized with {@link LocationLayerOptions#gpsDrawable()}) we call the user puck. + *

+ * This plugin also offers the ability to set a map camera behavior for tracking the user + * location. These different {@link CameraMode}s will track, stop tracking the location based on the + * mode set with {@link LocationLayerPlugin#setCameraMode(int)}. *

* Lastly, {@link LocationLayerPlugin#setLocationLayerEnabled(boolean)} can be used * to disable the Location Layer but keep the instance around till the activity is destroyed. @@ -50,9 +52,7 @@ * * @since 0.1.0 */ -public final class LocationLayerPlugin implements LocationEngineListener, CompassListener, - OnMapChangedListener, LifecycleObserver, OnCameraMoveListener, OnMapClickListener, - OnLocationStaleListener { +public final class LocationLayerPlugin implements LifecycleObserver { private final MapboxMap mapboxMap; private final MapView mapView; @@ -74,10 +74,10 @@ public final class LocationLayerPlugin implements LocationEngineListener, Compas = new CopyOnWriteArrayList<>(); /** - * Construct a {@code LocationLayerPlugin} + * Construct a LocationLayerPlugin * - * @param mapView the MapView to apply the My Location layer plugin to - * @param mapboxMap the MapboxMap to apply the My Location layer plugin with + * @param mapView the MapView to apply the LocationLayerPlugin to + * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with * @param locationEngine the {@link LocationEngine} this plugin should use to update * @since 0.1.0 */ @@ -88,10 +88,10 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa } /** - * Construct a {@code LocationLayerPlugin} + * Construct a LocationLayerPlugin * - * @param mapView the MapView to apply the My Location layer plugin to - * @param mapboxMap the MapboxMap to apply the My Location layer plugin with + * @param mapView the MapView to apply the LocationLayerPlugin to + * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with * @param locationEngine the {@link LocationEngine} this plugin should use to update * @param styleRes customize the user location icons inside your apps {@code style.xml} * @since 0.1.0 @@ -102,6 +102,15 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa LocationLayerOptions.createFromAttributes(mapView.getContext(), styleRes)); } + /** + * Construct a LocationLayerPlugin + * + * @param mapView the MapView to apply the LocationLayerPlugin to + * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with + * @param locationEngine the {@link LocationEngine} this plugin should use to update + * @param options to customize the user location icons inside your apps + * @since 0.3.0 + */ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @Nullable LocationEngine locationEngine, LocationLayerOptions options) { @@ -112,25 +121,13 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa initialize(); } - private void initialize() { - AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); - - mapView.addOnMapChangedListener(this); - mapboxMap.addOnMapClickListener(this); - - compassManager = new CompassManager(mapView.getContext()); - compassManager.addCompassListener(this); - staleStateRunnable = new StaleStateRunnable(this, options.staleStateDelay()); - - locationLayer = new LocationLayer(mapView, mapboxMap, options); - locationLayerCamera = new LocationLayerCamera(mapboxMap); - locationLayerAnimator = new LocationLayerAnimator(); - locationLayerAnimator.addListener(locationLayer); - locationLayerAnimator.addListener(locationLayerCamera); - - enableLocationLayerPlugin(); - } - + /** + * This method will show or hide the location icon and enable or disable the camera + * tracking the location. + * + * @param isEnabled true to show layers and enable camera, false otherwise + * @since 0.5.0 + */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public void setLocationLayerEnabled(boolean isEnabled) { if (isEnabled) { @@ -140,110 +137,128 @@ public void setLocationLayerEnabled(boolean isEnabled) { } } - private void enableLocationLayerPlugin() { - isEnabled = true; - - if (locationEngine != null) { - locationEngine.addLocationEngineListener(this); - } - setLastLocation(); - setLastCompassHeading(); - locationLayer.show(); - } - - private void disableLocationLayerPlugin() { - isEnabled = false; - - if (locationEngine != null) { - locationEngine.removeLocationEngineListener(this); - } - locationLayer.hide(); - } - /** - * After creating an instance of this plugin, you can use this API to enable the location mode of - * your choice. These modes can be found in the {@link LocationLayerMode} class and the parameter - * only accepts one of those modes. Note that before enabling the My Location layer, you will need - * to ensure that you have the requested the required user location permissions. + * Sets the camera mode, which determines how the map camera will track the rendered location. *

*

* - * @param locationLayerMode one of the modes found in {@link LocationLayerMode} - * @since 0.1.0 + * @param cameraMode one of the modes found in {@link CameraMode} + * @since 0.5.0 */ public void setCameraMode(@CameraMode.Mode int cameraMode) { locationLayerCamera.setCameraMode(cameraMode); } + /** + * Provides the current camera mode being used to track + * the location or compass updates. + * + * @return the current camera mode + * @since 0.5.0 + */ @CameraMode.Mode public int getCameraMode() { return locationLayerCamera.getCameraMode(); } + /** + * Sets the render mode, which determines how the location updates will be rendered on the map. + *

+ *

+ * + * @param renderMode one of the modes found in {@link RenderMode} + * @since 0.5.0 + */ public void setRenderMode(@RenderMode.Mode int renderMode) { locationLayer.setRenderMode(renderMode); } + + /** + * Provides the current render mode being used to show + * the location and/or compass updates on the map. + * + * @return the current render mode + * @since 0.5.0 + */ @RenderMode.Mode public int getRenderMode() { return locationLayer.getRenderMode(); } /** - * Returns the current location mode being used with this plugin. + * Returns the current location options being used. * - * @return on of the {@link LocationLayerMode} values - * @since 0.1.0 + * @return the current {@link LocationLayerOptions} + * @since 0.4.0 */ public LocationLayerOptions getLocationLayerOptions() { return options; } - @Override - public void onMapChanged(int change) { - if (change == MapView.WILL_START_LOADING_MAP) { - locationLayerAnimator.cancelAllAnimations(); - } else if (change == MapView.DID_FINISH_LOADING_STYLE) { - mapStyleFinishedLoading(); - } - } - - @Override - public void onStaleStateChange(boolean isStale) { - locationLayer.setLocationsStale(isStale); - - for (OnLocationStaleListener listener : onLocationStaleListeners) { - listener.onStaleStateChange(isStale); - } - } - /** - * Apply a new Location Layer style after the {@link LocationLayerPlugin} has been constructed. + * Apply a new LocationLayer style with a style resource. * * @param styleRes a XML style overriding some or all the options - * @since 0.1.0 + * @since 0.4.0 */ public void applyStyle(@StyleRes int styleRes) { applyStyle(LocationLayerOptions.createFromAttributes(mapView.getContext(), styleRes)); } + /** + * Apply a new LocationLayer style with location layer options. + * + * @param options to update the current style + * @since 0.4.0 + */ public void applyStyle(LocationLayerOptions options) { locationLayer.applyStyle(options); if (!options.enableStaleState()) { staleStateRunnable.onStop(); } - staleStateRunnable.setDelayTime(options.staleStateDelay()); + staleStateRunnable.setDelayTime(options.staleStateTimeout()); + } + + /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + *

+ *

+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *

+ * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + * @since 0.5.0 + */ + public void setPadding(int left, int top, int right, int bottom) { + mapboxMap.setPadding(left, top, right, bottom); } /** * Use to either force a location update or to manually control when the user location gets * updated. * - * @param location where you'd like the location icon to be placed on the map + * @param location where the location icon is placed on the map * @since 0.1.0 */ public void forceLocationUpdate(@Nullable Location location) { @@ -251,8 +266,9 @@ public void forceLocationUpdate(@Nullable Location location) { } /** - * The {@link LocationEngine} the plugin will use to update it's position. If {@code null} is - * passed in, all updates will occur through the + * Set the location engine to update the current user location. + *

+ * If {@code null} is passed in, all updates will occur through the * {@link LocationLayerPlugin#forceLocationUpdate(Location)} method. * * @param locationEngine a {@link LocationEngine} this plugin should use to handle updates @@ -263,7 +279,7 @@ public void setLocationEngine(@Nullable LocationEngine locationEngine) { if (locationEngine != null) { this.locationEngine = locationEngine; } else if (this.locationEngine != null) { - this.locationEngine.removeLocationEngineListener(this); + this.locationEngine.removeLocationEngineListener(locationEngineListener); this.locationEngine = null; } } @@ -280,46 +296,15 @@ public LocationEngine getLocationEngine() { } /** - * Required to place inside your activities {@code onStart} method. You'll also most likely want - * to check that this Location Layer plugin instance inside your activity is null or not. - * - * @since 0.1.0 - */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) - @OnLifecycleEvent(Lifecycle.Event.ON_START) - public void onStart() { - if (isEnabled) { - if (locationEngine != null) { - locationEngine.addLocationEngineListener(this); - } - setLastLocation(); - setLastCompassHeading(); - } - if (mapboxMap != null) { - mapboxMap.addOnCameraMoveListener(this); - } - if (options.enableStaleState()) { - staleStateRunnable.onStart(); - } - compassManager.onStart(); - } - - /** - * Required to place inside your activities {@code onStop} method. + * Get the last know location of the location layer plugin. * - * @since 0.1.0 + * @return the last known location + * @since 0.4.0 */ - @OnLifecycleEvent(Lifecycle.Event.ON_STOP) - public void onStop() { - staleStateRunnable.onStop(); - compassManager.onStop(); - locationLayerAnimator.cancelAllAnimations(); - if (locationEngine != null) { - locationEngine.removeLocationEngineListener(this); - } - if (mapboxMap != null) { - mapboxMap.removeOnCameraMoveListener(this); - } + @SuppressLint("MissingPermission") + @Nullable + public Location getLastKnownLocation() { + return locationEngine != null ? locationEngine.getLastLocation() : null; } /** @@ -355,93 +340,117 @@ public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener loc onLocationLayerClickListeners.add(locationClickListener); } + /** + * Removes the passed listener from the current list of location click listeners. + * + * @param locationClickListener to be removed + * @since 0.3.0 + */ public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) { onLocationLayerClickListeners.remove(locationClickListener); } + /** + * Adds the passed listener that gets invoked when user updates have stopped long enough for the last update + * to be considered stale. + * + * @param listener invoked when last update is considered stale + * @since 0.5.0 + */ public void addOnLocationStaleListener(@NonNull OnLocationStaleListener listener) { onLocationStaleListeners.add(listener); } + /** + * Removes the passed listener from the current list of stale listeners. + * + * @param listener to be removed from the list + * @since 0.5.0 + */ public void removeOnLocationStaleListener(@NonNull OnLocationStaleListener listener) { onLocationStaleListeners.remove(listener); } - @Override - public void onMapClick(@NonNull LatLng point) { - if (!onLocationLayerClickListeners.isEmpty() && locationLayer.onMapClick(point)) { - for (OnLocationLayerClickListener listener : onLocationLayerClickListeners) { - listener.onLocationLayerClick(); + /** + * Required to place inside your activities {@code onStart} method. You'll also most likely want + * to check that this Location Layer plugin instance inside your activity is null or not. + * + * @since 0.1.0 + */ + @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @OnLifecycleEvent(Lifecycle.Event.ON_START) + public void onStart() { + if (isEnabled) { + if (locationEngine != null) { + locationEngine.addLocationEngineListener(locationEngineListener); } + setLastLocation(); + setLastCompassHeading(); } + if (mapboxMap != null) { + mapboxMap.addOnCameraMoveListener(onCameraMoveListener); + } + if (options.enableStaleState()) { + staleStateRunnable.onStart(); + } + compassManager.onStart(); } - @Override - @SuppressWarnings( {"MissingPermission"}) - public void onConnected() { + /** + * Required to place inside your activities {@code onStop} method. + * + * @since 0.1.0 + */ + @OnLifecycleEvent(Lifecycle.Event.ON_STOP) + public void onStop() { + staleStateRunnable.onStop(); + compassManager.onStop(); + locationLayerAnimator.cancelAllAnimations(); if (locationEngine != null) { - locationEngine.requestLocationUpdates(); + locationEngine.removeLocationEngineListener(locationEngineListener); + } + if (mapboxMap != null) { + mapboxMap.removeOnCameraMoveListener(onCameraMoveListener); } } - @Override - public void onLocationChanged(Location location) { - updateLocation(location); - } + private void initialize() { + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); - @Override - public void onCompassChanged(float userHeading) { - updateCompassHeading(userHeading); - } + mapView.addOnMapChangedListener(onMapChangedListener); + mapboxMap.addOnMapClickListener(onMapClickListener); - @Override - public void onCompassAccuracyChange(int compassStatus) { - // Currently don't handle this inside SDK - } + compassManager = new CompassManager(mapView.getContext()); + compassManager.addCompassListener(compassListener); + staleStateRunnable = new StaleStateRunnable(onLocationStaleListener, options.staleStateTimeout()); - /** - * If the locationEngine contains a last location value, we use it for the initial location layer - * position. - */ - @SuppressWarnings( {"MissingPermission"}) - private void setLastLocation() { - if (locationEngine != null) { - updateLocation(locationEngine.getLastLocation()); - } - } + locationLayer = new LocationLayer(mapView, mapboxMap, options); + locationLayerCamera = new LocationLayerCamera(mapboxMap); + locationLayerAnimator = new LocationLayerAnimator(); + locationLayerAnimator.addListener(locationLayer); + locationLayerAnimator.addListener(locationLayerCamera); - private void setLastCompassHeading() { - updateCompassHeading(compassManager.getLastHeading()); + enableLocationLayerPlugin(); } - /** - * Get the last know location of the location layer plugin. - * - * @return the last known location - */ - @SuppressLint("MissingPermission") - @Nullable - public Location getLastKnownLocation() { - return locationEngine != null ? locationEngine.getLastLocation() : null; - } + private void enableLocationLayerPlugin() { + isEnabled = true; - /** - * If the location layer was being displayed before the style change, it will need to be displayed - * in the new style. - */ - @SuppressWarnings( {"MissingPermission"}) - private void mapStyleFinishedLoading() { - // recreate runtime style components - locationLayer = new LocationLayer(mapView, mapboxMap, options); + if (locationEngine != null) { + locationEngine.addLocationEngineListener(locationEngineListener); + } setLastLocation(); setLastCompassHeading(); + locationLayer.show(); } - @Override - public void onCameraMove() { - CameraPosition position = mapboxMap.getCameraPosition(); - locationLayer.updateAccuracyRadius(getLastKnownLocation()); - locationLayer.updateForegroundOffset(position.tilt); + private void disableLocationLayerPlugin() { + isEnabled = false; + + if (locationEngine != null) { + locationEngine.removeLocationEngineListener(locationEngineListener); + } + locationLayer.hide(); } /** @@ -466,4 +475,100 @@ private void updateLocation(final Location location) { private void updateCompassHeading(float heading) { locationLayerAnimator.feedNewCompassBearing(compassManager.getLastHeading(), heading); } + + /** + * If the location layer was being displayed before the style change, it will need to be displayed + * in the new style. + */ + @SuppressWarnings( {"MissingPermission"}) + private void mapStyleFinishedLoading() { + // recreate runtime style components + locationLayer = new LocationLayer(mapView, mapboxMap, options); + setLastLocation(); + setLastCompassHeading(); + } + + /** + * If the locationEngine contains a last location value, we use it for the initial location layer + * position. + */ + @SuppressWarnings( {"MissingPermission"}) + private void setLastLocation() { + if (locationEngine != null) { + updateLocation(locationEngine.getLastLocation()); + } + } + + private void setLastCompassHeading() { + updateCompassHeading(compassManager.getLastHeading()); + } + + private OnCameraMoveListener onCameraMoveListener = new OnCameraMoveListener() { + @Override + public void onCameraMove() { + CameraPosition position = mapboxMap.getCameraPosition(); + locationLayer.updateAccuracyRadius(getLastKnownLocation()); + locationLayer.updateForegroundOffset(position.tilt); + } + }; + + private OnMapClickListener onMapClickListener = new OnMapClickListener() { + @Override + public void onMapClick(@NonNull LatLng point) { + if (!onLocationLayerClickListeners.isEmpty() && locationLayer.onMapClick(point)) { + for (OnLocationLayerClickListener listener : onLocationLayerClickListeners) { + listener.onLocationLayerClick(); + } + } + } + }; + + private OnLocationStaleListener onLocationStaleListener = new OnLocationStaleListener() { + @Override + public void onStaleStateChange(boolean isStale) { + locationLayer.setLocationsStale(isStale); + + for (OnLocationStaleListener listener : onLocationStaleListeners) { + listener.onStaleStateChange(isStale); + } + } + }; + + private OnMapChangedListener onMapChangedListener = new OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + if (change == MapView.WILL_START_LOADING_MAP) { + locationLayerAnimator.cancelAllAnimations(); + } else if (change == MapView.DID_FINISH_LOADING_STYLE) { + mapStyleFinishedLoading(); + } + } + }; + + private CompassListener compassListener = new CompassListener() { + @Override + public void onCompassChanged(float userHeading) { + updateCompassHeading(userHeading); + } + + @Override + public void onCompassAccuracyChange(int compassStatus) { + // Currently don't handle this inside SDK + } + }; + + private LocationEngineListener locationEngineListener = new LocationEngineListener() { + @Override + @SuppressWarnings( {"MissingPermission"}) + public void onConnected() { + if (locationEngine != null) { + locationEngine.requestLocationUpdates(); + } + } + + @Override + public void onLocationChanged(Location location) { + updateLocation(location); + } + }; } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java index 99a1a6d2e..7389dd945 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java @@ -1,5 +1,15 @@ package com.mapbox.mapboxsdk.plugins.locationlayer; +/** + * Listener that can be added as a callback when the last location update + * is considered stale. + *

+ * The time from the last location update that determines if a location update + * is stale or not is provided by {@link LocationLayerOptions#staleStateTimeout()}. + * + * @since 0.5.0 + */ public interface OnLocationStaleListener { + void onStaleStateChange(boolean isStale); } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java index 0f288a36d..3b91d11f4 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java @@ -1,14 +1,10 @@ package com.mapbox.mapboxsdk.plugins.locationlayer; import android.os.Handler; -import android.support.annotation.NonNull; - -import java.util.ArrayList; -import java.util.List; /** * Class controls the location layer stale state when the {@link android.location.Location} hasn't - * been updated in 'x' amount of time. {@link LocationLayerOptions#staleStateDelay()} can be used to + * been updated in 'x' amount of time. {@link LocationLayerOptions#staleStateTimeout()} can be used to * control the amount of time before the locations considered stale. * {@link LocationLayerOptions#enableStaleState()} is available for disabling this behaviour. * diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java index 6672ea2e8..68692a429 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java @@ -9,9 +9,10 @@ import java.lang.annotation.RetentionPolicy; /** - * Contains the variety of Location Layer modes which shape the behavior of the plugin. + * Contains the variety of camera modes which determine how the camera will track + * the user location. * - * @since 0.1.0 + * @since 0.5.0 */ public final class CameraMode { @@ -22,7 +23,7 @@ private CameraMode() { /** * Determine the camera tracking behavior in the {@link LocationLayerPlugin}. * - * @since 0.4.0 + * @since 0.5.0 */ @IntDef( {NONE, NONE_COMPASS, NONE_GPS, TRACKING, TRACKING_COMPASS, TRACKING_GPS, TRACKING_GPS_NORTH}) @Retention(RetentionPolicy.SOURCE) @@ -32,28 +33,28 @@ private CameraMode() { /** * No camera tracking. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int NONE = 0x00000000; /** * Camera does not track location, but does track compass bearing. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int NONE_COMPASS = 0x00000010; /** * Camera does not track location, but does track GPS {@link Location} bearing. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int NONE_GPS = 0x00000016; /** * Camera tracks the user location. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int TRACKING = 0x00000018; @@ -61,7 +62,7 @@ private CameraMode() { * Camera tracks the user location, with bearing * provided by a compass. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int TRACKING_COMPASS = 0x00000020; @@ -69,7 +70,7 @@ private CameraMode() { * Camera tracks the user location, with bearing * provided by a normalized {@link Location#getBearing()}. * - * @since 0.4.0 + * @since 0.5.0 */ public static final int TRACKING_GPS = 0x00000022; @@ -78,7 +79,7 @@ private CameraMode() { * Camera tracks the user location, with bearing * always set to north (0). * - * @since 0.4.0 + * @since 0.5.0 */ public static final int TRACKING_GPS_NORTH = 0x00000024; } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java index a7326410f..3928689b6 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java @@ -8,9 +8,9 @@ import java.lang.annotation.RetentionPolicy; /** - * Contains the variety of Location Layer modes which shape the behavior of the plugin. + * Contains the variety of ways the user location can be rendered on the map. * - * @since 0.1.0 + * @since 0.5.0 */ public final class RenderMode { @@ -19,9 +19,8 @@ private RenderMode() { } /** - * One of these constants should be used when - * {@link LocationLayerPlugin#setLocationLayerMode(int)}'s called. The - * mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing + * One of these constants should be used with {@link LocationLayerPlugin#setRenderMode(int)}. + *mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing * in the new mode you'd like the location layer to be in. * * @since 0.1.0 diff --git a/plugin-locationlayer/src/main/res/values/attrs.xml b/plugin-locationlayer/src/main/res/values/attrs.xml index 475feeb4e..5623ba972 100644 --- a/plugin-locationlayer/src/main/res/values/attrs.xml +++ b/plugin-locationlayer/src/main/res/values/attrs.xml @@ -20,7 +20,7 @@ - + diff --git a/plugin-locationlayer/src/main/res/values/styles.xml b/plugin-locationlayer/src/main/res/values/styles.xml index fd67e3c18..7b17ef9ff 100644 --- a/plugin-locationlayer/src/main/res/values/styles.xml +++ b/plugin-locationlayer/src/main/res/values/styles.xml @@ -16,6 +16,6 @@ 12dp true - 10000 + 10000 \ No newline at end of file From 77b472ee098a5fc952dbcb4c133ba2a75deb6c66 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Fri, 23 Feb 2018 16:28:50 +0100 Subject: [PATCH 2/5] Add long click listener --- .../locationlayer/LocationLayerPlugin.java | 49 ++++++++++++++++--- .../OnLocationLayerClickListener.java | 1 - .../OnLocationLayerLongClickListener.java | 13 +++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerLongClickListener.java diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 72712f435..1f626b7b1 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -72,6 +72,8 @@ public final class LocationLayerPlugin implements LifecycleObserver { = new CopyOnWriteArrayList<>(); private final CopyOnWriteArrayList onLocationLayerClickListeners = new CopyOnWriteArrayList<>(); + private final CopyOnWriteArrayList onLocationLayerLongClickListeners + = new CopyOnWriteArrayList<>(); /** * Construct a LocationLayerPlugin @@ -332,22 +334,43 @@ public void removeCompassListener(@NonNull CompassListener compassListener) { /** * Adds a listener that gets invoked when the user clicks the location layer. * - * @param locationClickListener The location layer click listener that is invoked when the - * location layer is clicked + * @param listener The location layer click listener that is invoked when the + * location layer is clicked * @since 0.3.0 */ - public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) { - onLocationLayerClickListeners.add(locationClickListener); + public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener listener) { + onLocationLayerClickListeners.add(listener); } /** * Removes the passed listener from the current list of location click listeners. * - * @param locationClickListener to be removed + * @param listener to be removed * @since 0.3.0 */ - public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) { - onLocationLayerClickListeners.remove(locationClickListener); + public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener listener) { + onLocationLayerClickListeners.remove(listener); + } + + /** + * Adds a listener that gets invoked when the user long clicks the location layer. + * + * @param listener The location layer click listener that is invoked when the + * location layer is clicked + * @since 0.5.0 + */ + public void addOnLocationClickListener(@NonNull OnLocationLayerLongClickListener listener) { + onLocationLayerLongClickListeners.add(listener); + } + + /** + * Removes the passed listener from the current list of location long click listeners. + * + * @param listener to be removed + * @since 0.5.0 + */ + public void removeOnLocationClickListener(@NonNull OnLocationLayerLongClickListener listener) { + onLocationLayerLongClickListeners.remove(listener); } /** @@ -419,6 +442,7 @@ private void initialize() { mapView.addOnMapChangedListener(onMapChangedListener); mapboxMap.addOnMapClickListener(onMapClickListener); + mapboxMap.addOnMapLongClickListener(onMapLongClickListener); compassManager = new CompassManager(mapView.getContext()); compassManager.addCompassListener(compassListener); @@ -523,6 +547,17 @@ public void onMapClick(@NonNull LatLng point) { } }; + private MapboxMap.OnMapLongClickListener onMapLongClickListener = new MapboxMap.OnMapLongClickListener() { + @Override + public void onMapLongClick(@NonNull LatLng point) { + if (!onLocationLayerLongClickListeners.isEmpty() && locationLayer.onMapClick(point)) { + for (OnLocationLayerLongClickListener listener : onLocationLayerLongClickListeners) { + listener.onLocationLayerLongClick(); + } + } + } + }; + private OnLocationStaleListener onLocationStaleListener = new OnLocationStaleListener() { @Override public void onStaleStateChange(boolean isStale) { diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerClickListener.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerClickListener.java index ec811319b..7cfb79502 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerClickListener.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerClickListener.java @@ -10,5 +10,4 @@ public interface OnLocationLayerClickListener { void onLocationLayerClick(); - } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerLongClickListener.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerLongClickListener.java new file mode 100644 index 000000000..cebcf3e8d --- /dev/null +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationLayerLongClickListener.java @@ -0,0 +1,13 @@ +package com.mapbox.mapboxsdk.plugins.locationlayer; + +/** + * The Location Layer Plugin exposes an API for listening to when the user long clicks on the location + * layer icon visible on the map. when this event occurs, the {@link #onLocationLayerLongClick()} method + * gets invoked. + * + * @since 0.5.0 + */ +public interface OnLocationLayerLongClickListener { + + void onLocationLayerLongClick(); +} From 4ac32fa34725cc06fd200a3dd6d5590e7dbb930f Mon Sep 17 00:00:00 2001 From: danesfeder Date: Fri, 23 Feb 2018 16:52:30 +0100 Subject: [PATCH 3/5] Add max / min zoom and padding APIs --- .../locationlayer/LocationLayerOptions.java | 66 +++++++++++++++++++ .../locationlayer/LocationLayerPlugin.java | 35 ++++++++++ 2 files changed, 101 insertions(+) diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java index 89b071e2d..a01ea3709 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java @@ -319,6 +319,39 @@ private static Builder builder() { */ public abstract long staleStateTimeout(); + /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + *

+ *

+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *

+ * + * @return integer array of padding values + * @since 0.5.0 + */ + public abstract int[] padding(); + + /** + * The maximum zoom level the map can be displayed at. + * + * @return the maximum zoom level + * @since 0.5.0 + */ + public abstract double maxZoom(); + + /** + * The minimum zoom level the map can be displayed at. + * + * @return the minimum zoom level + * @since 0.5.0 + */ + public abstract double minZoom(); + /** * Builder class for constructing a new instance of {@link LocationLayerOptions}. * @@ -493,6 +526,39 @@ public abstract static class Builder { */ public abstract Builder staleStateTimeout(long timeout); + /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + *

+ *

+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *

+ * + * @param padding The margins for the map in pixels (left, top, right, bottom). + * @since 0.5.0 + */ + public abstract Builder setPadding(int[] padding); + + /** + * Sets the maximum zoom level the map can be displayed at. + *

+ * The default maximum zoomn level is 22. The upper bound for this value is 25.5. + * + * @param maxZoom The new maximum zoom level. + * @since 0.5.0 + */ + public abstract Builder setMaxZoom(double maxZoom); + + /** + * Sets the minimum zoom level the map can be displayed at. + * + * @param minZoom The new minimum zoom level. + */ + public abstract Builder setMinZoom(double minZoom); abstract LocationLayerOptions autoBuild(); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 1f626b7b1..c4ca3f750 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -256,6 +256,27 @@ public void setPadding(int left, int top, int right, int bottom) { mapboxMap.setPadding(left, top, right, bottom); } + /** + * Sets the maximum zoom level the map can be displayed at. + *

+ * The default maximum zoom level is 22. The upper bound for this value is 25.5. + * + * @param maxZoom The new maximum zoom level. + * @since 0.5.0 + */ + public void setMaxZoom(double maxZoom) { + mapboxMap.setMaxZoomPreference(maxZoom); + } + + /** + * Sets the minimum zoom level the map can be displayed at. + * + * @param minZoom The new minimum zoom level. + */ + public void setMinZoom(double minZoom) { + mapboxMap.setMinZoomPreference(minZoom); + } + /** * Use to either force a location update or to manually control when the user location gets * updated. @@ -443,6 +464,7 @@ private void initialize() { mapView.addOnMapChangedListener(onMapChangedListener); mapboxMap.addOnMapClickListener(onMapClickListener); mapboxMap.addOnMapLongClickListener(onMapLongClickListener); + updateMapWithOptions(options); compassManager = new CompassManager(mapView.getContext()); compassManager.addCompassListener(compassListener); @@ -477,6 +499,19 @@ private void disableLocationLayerPlugin() { locationLayer.hide(); } + private void updateMapWithOptions(LocationLayerOptions options) { + int[] padding = options.padding(); + if (options.padding() != null && options.padding().length == 4) { + setPadding(options.padding()[0], padding[1], padding[2], padding[3]); + } + if (options.maxZoom() > 0) { + setMaxZoom(options.maxZoom()); + } + if (options.minZoom() > 0) { + setMinZoom(options.minZoom()); + } + } + /** * Updates the user location icon. * From 2d2952475b1259356ccaa986bdaa0d094b11c979 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Tue, 27 Feb 2018 11:48:18 -0500 Subject: [PATCH 4/5] Fix javadoc --- .../plugins/locationlayer/LocationLayerPlugin.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 1d8d2ae5f..844bd7b44 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -176,15 +176,9 @@ public int getCameraMode() { * Sets the render mode, which determines how the location updates will be rendered on the map. *

*

* * @param renderMode one of the modes found in {@link RenderMode} @@ -326,12 +320,10 @@ public LocationEngine getLocationEngine() { } /** - * <<<<<<< HEAD * Get the last know location of the location layer plugin. * * @return the last known location * @since 0.1.0 - * >>>>>>> map-location-animators */ @SuppressLint("MissingPermission") @Nullable From 31a5b699a109d2f31d5ed56d1518774572e8563d Mon Sep 17 00:00:00 2001 From: danesfeder Date: Tue, 27 Feb 2018 13:47:21 -0500 Subject: [PATCH 5/5] Add default values to options --- .../locationlayer/LocationLayerOptions.java | 21 ++++++++++++++++++- .../locationlayer/LocationLayerPlugin.java | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java index 7e1afbe22..6687f5932 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java @@ -42,6 +42,21 @@ public abstract class LocationLayerOptions implements Parcelable { */ private static final float ACCURACY_ALPHA_DEFAULT = 0.15f; + /** + * Default max map zoom + */ + private static final float MAX_ZOOM_DEFAULT = 20; + + /** + * Default min map zoom + */ + private static final float MIN_ZOOM_DEFAULT = 2; + + /** + * Default map padding + */ + private static final int[] PADDING_DEFAULT = {0, 0, 0, 0}; + /** * The default value which is used when the stale state is enabled */ @@ -148,7 +163,10 @@ public static Builder builder(Context context) { private static Builder builder() { return new AutoValue_LocationLayerOptions.Builder() .enableStaleState(true) - .staleStateTimeout(STALE_STATE_DELAY_MS); + .staleStateTimeout(STALE_STATE_DELAY_MS) + .maxZoom(MAX_ZOOM_DEFAULT) + .minZoom(MIN_ZOOM_DEFAULT) + .padding(PADDING_DEFAULT); } /** @@ -334,6 +352,7 @@ private static Builder builder() { * @return integer array of padding values * @since 0.5.0 */ + @SuppressWarnings("mutable") public abstract int[] padding(); /** diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 844bd7b44..07ad567c2 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -467,6 +467,7 @@ private void initialize() { mapView.addOnMapChangedListener(onMapChangedListener); mapboxMap.addOnMapClickListener(onMapClickListener); + updateMapWithOptions(options); locationLayer = new LocationLayer(mapView, mapboxMap, options); locationLayerCamera = new LocationLayerCamera(mapboxMap); @@ -496,7 +497,7 @@ private void disableLocationLayerPlugin() { private void updateMapWithOptions(LocationLayerOptions options) { int[] padding = options.padding(); - if (options.padding() != null && options.padding().length == 4) { + if (padding != null && padding.length == 4) { setPadding(options.padding()[0], padding[1], padding[2], padding[3]); } if (options.maxZoom() > 0) {