Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Adding pulsing circle to LocationComponent options #172

Merged
merged 22 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a9fa0e7
[location] added pulsing locationcomponent circle
Feb 4, 2020
131f5d4
adjusting style switching to roll through all styles
Mar 31, 2020
9a028ee
refactored methods and variables for prefix continuity
Mar 31, 2020
4d8e3d1
refactoring to after making start and stop private methods
Mar 31, 2020
0df00f2
refactoring to stop pulsing when LocationComponent is disabled and co…
Mar 31, 2020
6a4f038
refactoring to swap interpolator string paramete for interpolator int…
Mar 31, 2020
4b93fc6
LocationLayerControllerTest adjustments
Apr 1, 2020
2096cbd
removing unneeded test
Apr 1, 2020
02e5dc0
more rebase adjustments
Apr 22, 2020
206fc07
[location] added pulsing locationcomponent circle
Feb 4, 2020
0ea0ac6
refactoring to swap interpolator string paramete for interpolator int…
Mar 31, 2020
dfd9c63
consolidating pulse ui update methods
Apr 1, 2020
0b3bc9f
gl-native vendor bump
Apr 23, 2020
e7848ab
refactor to check for activation with locationcomponent
Apr 23, 2020
7a681b5
Update MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location…
Apr 27, 2020
6008acd
Update MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location…
Apr 27, 2020
cabcb4a
Update MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location…
Apr 27, 2020
12e411c
Update MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location…
Apr 27, 2020
0082d69
Update MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location…
Apr 27, 2020
3c051b6
Added incompatibility docs
Apr 27, 2020
ed5d513
Added pulse alpha range explanation
Apr 27, 2020
07ec52f
Do not wrap pulsing circle animator with an animator set to avoid leaks
LukasPaczos Apr 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.graphics.Bitmap;

import androidx.annotation.Nullable;

import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.Style;
Expand All @@ -12,6 +10,8 @@
import com.mapbox.mapboxsdk.utils.BitmapUtils;
import com.mapbox.mapboxsdk.utils.ColorUtils;

import androidx.annotation.Nullable;

import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_ICON;
Expand Down Expand Up @@ -181,6 +181,30 @@ private void setLayerBearing(double bearing) {
lastBearing = bearing;
}

/**
* Adjust the visibility of the pulsing LocationComponent circle.
*/
@Override
public void adjustPulsingCircleLayerVisibility(boolean visible) {
// not supported at this time
}

/**
* Adjust the the pulsing LocationComponent circle based on the set options.
*/
@Override
public void stylePulsingCircle(LocationComponentOptions options) {
// not supported at this time
}

/**
* Adjust the visual appearance of the pulsing LocationComponent circle.
*/
@Override
public void updatePulsingUi(float radius, @Nullable Float opacity) {
// not supported at this time
}

private void setImages(@RenderMode.Mode int renderMode, boolean isStale) {
String topImage = "";
String bearingImage = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_LOCATION_STALE;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PULSING_CIRCLE_LAYER;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER;
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
Expand Down Expand Up @@ -131,9 +132,23 @@ Layer generateLocationComponentLayer() {
LocationIndicatorLayer layer = new LocationIndicatorLayer(FOREGROUND_LAYER);
layer.setLocationTransition(new TransitionOptions(0, 0));
layer.setProperties(
LocationPropertyFactory.perspectiveCompensation(0.9f),
LocationPropertyFactory.imageTiltDisplacement(4f)
LocationPropertyFactory.perspectiveCompensation(0.9f),
LocationPropertyFactory.imageTiltDisplacement(4f)
);
return layer;
}

/**
* Adds a {@link CircleLayer} to the map to support the {@link LocationComponent} pulsing UI functionality.
*
* @return a {@link CircleLayer} with the correct data-driven styling. Tilting the map will keep the pulsing
* layer aligned with the map plane.
*/
@NonNull
Layer generatePulsingCircleLayer() {
return new CircleLayer(PULSING_CIRCLE_LAYER, LOCATION_SOURCE)
.withProperties(
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.location.Location;
import android.os.SystemClock;
import android.util.SparseArray;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -32,6 +33,7 @@
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_COMPASS_BEARING;
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_GPS_BEARING;
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_LATLNG;
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_PULSING_CIRCLE;
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_TILT;
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_ZOOM;
import static com.mapbox.mapboxsdk.location.Utils.immediateAnimation;
Expand Down Expand Up @@ -186,6 +188,28 @@ void feedNewAccuracyRadius(float targetAccuracyRadius, boolean noAnimation) {
this.previousAccuracyRadius = targetAccuracyRadius;
}

/**
* Initializes the {@link PulsingLocationCircleAnimator}, which is a type of {@link MapboxAnimator}.
* This method also adds the animator to this class' animator array.
*
* @param options the {@link LocationComponentOptions} passed to this class upstream from the
* {@link LocationComponent}.
*/
void startLocationComponentCirclePulsing(LocationComponentOptions options) {
cancelAnimator(ANIMATOR_PULSING_CIRCLE);
MapboxAnimator.AnimationsValueChangeListener listener = listeners.get(ANIMATOR_PULSING_CIRCLE);
if (listener != null) {
PulsingLocationCircleAnimator pulsingLocationCircleAnimator = animatorProvider.pulsingCircleAnimator(
listener,
maxAnimationFps,
options.pulseSingleDuration(),
options.pulseMaxRadius(),
options.pulseInterpolator() == null ? new DecelerateInterpolator() : options.pulseInterpolator());
animatorArray.put(ANIMATOR_PULSING_CIRCLE, pulsingLocationCircleAnimator);
playPulsingAnimator();
}
}

void feedNewZoomLevel(double targetZoomLevel, @NonNull CameraPosition currentCameraPosition, long animationDuration,
@Nullable MapboxMap.CancelableCallback callback) {
updateZoomAnimator((float) targetZoomLevel, (float) currentCameraPosition.zoom, callback);
Expand Down Expand Up @@ -349,6 +373,18 @@ private void playAnimators(long duration, @MapboxAnimator.Type int... animatorTy
animatorSetProvider.startAnimation(animators, new LinearInterpolator(), duration);
}

/**
* Starts the {@link PulsingLocationCircleAnimator} in the animator array. This method is separate
* from {@link #playAnimators(long, int...)} because the MapboxAnimatorSetProvider has many more
* customizable animation parameters than the other {@link MapboxAnimator}s.
*/
private void playPulsingAnimator() {
Animator animator = animatorArray.get(ANIMATOR_PULSING_CIRCLE);
if (animator != null) {
animatorSetProvider.startSingleAnimation(animator);
}
}

void resetAllCameraAnimations(@NonNull CameraPosition currentCameraPosition, boolean isGpsNorth) {
resetCameraCompassAnimation(currentCameraPosition);
boolean snap = resetCameraLocationAnimations(currentCameraPosition, isGpsNorth);
Expand Down Expand Up @@ -446,6 +482,13 @@ void cancelTiltAnimation() {
cancelAnimator(ANIMATOR_TILT);
}

/**
* Cancel the pulsing circle location animator.
*/
void stopPulsingCircleAnimation() {
cancelAnimator(ANIMATOR_PULSING_CIRCLE);
}

void cancelAllAnimations() {
for (int i = 0; i < animatorArray.size(); i++) {
@MapboxAnimator.Type int animatorType = animatorArray.keyAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,25 @@ public void applyStyle(@NonNull final LocationComponentOptions options) {
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
locationAnimatorCoordinator.setCompassAnimationEnabled(options.compassAnimationEnabled());
locationAnimatorCoordinator.setAccuracyAnimationEnabled(options.accuracyAnimationEnabled());
if (options.pulseEnabled()) {
startPulsingLocationCircle();
} else {
stopPulsingLocationCircle();
}
updateMapWithOptions(options);
}
}

/**
* Starts the LocationComponent's pulsing circle UI.
*/
private void startPulsingLocationCircle() {
if (isEnabled) {
langsmith marked this conversation as resolved.
Show resolved Hide resolved
locationAnimatorCoordinator.startLocationComponentCirclePulsing(options);
locationLayerController.adjustPulsingCircleLayerVisibility(true);
}
}

/**
* Zooms to the desired zoom level.
* This API can only be used in pair with camera modes other than {@link CameraMode#NONE}.
Expand Down Expand Up @@ -1215,6 +1230,14 @@ public void onFinishLoadingStyle() {
}
}

/**
* Stop the LocationComponent's pulsing circle animation.
*/
private void stopPulsingLocationCircle() {
locationAnimatorCoordinator.stopPulsingCircleAnimation();
locationLayerController.adjustPulsingCircleLayerVisibility(false);
}

@SuppressLint("MissingPermission")
private void onLocationLayerStart() {
if (!isComponentInitialized || !isComponentStarted || mapboxMap.getStyle() == null) {
Expand All @@ -1240,6 +1263,11 @@ private void onLocationLayerStart() {
}
}
setCameraMode(locationCameraController.getCameraMode());
if (options.pulseEnabled()) {
startPulsingLocationCircle();
} else {
stopPulsingLocationCircle();
}
setLastLocation();
updateCompassListenerState(true);
setLastCompassHeading();
Expand All @@ -1256,6 +1284,8 @@ private void onLocationLayerStop() {
if (compassEngine != null) {
updateCompassListenerState(false);
}

stopPulsingLocationCircle();
locationAnimatorCoordinator.cancelAllAnimations();
if (locationEngine != null) {
locationEngine.removeLocationUpdates(currentLocationEngineListener);
Expand Down Expand Up @@ -1430,6 +1460,9 @@ private void showLocationLayerIfHidden() {
boolean isLocationLayerHidden = locationLayerController.isHidden();
if (isEnabled && isComponentStarted && isLocationLayerHidden) {
locationLayerController.show();
if (options.pulseEnabled()) {
locationLayerController.adjustPulsingCircleLayerVisibility(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public final class LocationComponentConstants {
static final String PROPERTY_FOREGROUND_STALE_ICON = "mapbox-property-foreground-stale-icon";
static final String PROPERTY_BACKGROUND_STALE_ICON = "mapbox-property-background-stale-icon";
static final String PROPERTY_BEARING_ICON = "mapbox-property-shadow-icon";
static final String PROPERTY_PULSING_RADIUS = "mapbox-property-pulsing-circle-radius";
static final String PROPERTY_PULSING_OPACITY = "mapbox-property-pulsing-circle-opacity";

// Layers

Expand Down Expand Up @@ -80,6 +82,11 @@ public final class LocationComponentConstants {
*/
public static final String BEARING_LAYER = "mapbox-location-bearing-layer";

/**
* Layer ID of the location pulsing circle.
*/
public static final String PULSING_CIRCLE_LAYER = "mapbox-location-pulsing-circle-layer";

// Icons
static final String FOREGROUND_ICON = "mapbox-location-icon";
static final String BACKGROUND_ICON = "mapbox-location-stroke-icon";
Expand Down
Loading