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

Commit

Permalink
initial additions to add pulsing locationcomponent circle
Browse files Browse the repository at this point in the history
  • Loading branch information
Langston Smith committed Feb 4, 2020
1 parent b15e9f8 commit 5808c0f
Show file tree
Hide file tree
Showing 28 changed files with 1,852 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -108,4 +109,18 @@ Layer generateAccuracyLayer() {
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
);
}

/**
* 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 @@ -30,6 +30,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 @@ -150,6 +151,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);
PulsingLocationCircleAnimator pulsingLocationCircleAnimator = animatorProvider.pulsingCircleAnimator(
listener,
maxAnimationFps,
options.pulseSingleDuration(),
options.pulseMaxRadius(),
options.pulseInterpolator());
if (listener != null) {
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 @@ -292,6 +315,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 @@ -383,6 +418,13 @@ void cancelTiltAnimation() {
cancelAnimator(ANIMATOR_TILT);
}

/**
* Cancel's the pulsing circle location animator.
*/
void cancelPulsingCircleAnimation() {
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 @@ -716,10 +716,20 @@ public void applyStyle(@NonNull final LocationComponentOptions options) {
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
locationAnimatorCoordinator.setCompassAnimationEnabled(options.compassAnimationEnabled());
locationAnimatorCoordinator.setAccuracyAnimationEnabled(options.accuracyAnimationEnabled());
if (options.pulseEnabled()) {
startPulsingLocationCircle();
}
updateMapWithOptions(options);
}
}

/**
* Starts the LocationComponent's pulsing circle UI.
*/
public void startPulsingLocationCircle() {
locationAnimatorCoordinator.startLocationComponentCirclePulsing(options);
}

/**
* 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 @@ -1179,6 +1189,14 @@ public void onFinishLoadingStyle() {
}
}

/**
* Available to cancel the specific pulsing circle animation.
*/
public void cancelPulsingLocationCircle() {
locationAnimatorCoordinator.cancelPulsingCircleAnimation();
locationLayerController.adjustPulsingCircleLayerVisibility(false);
}

@SuppressLint("MissingPermission")
private void onLocationLayerStart() {
if (!isComponentInitialized || !isComponentStarted || mapboxMap.getStyle() == null) {
Expand All @@ -1204,6 +1222,9 @@ private void onLocationLayerStart() {
}
}
setCameraMode(locationCameraController.getCameraMode());
if (options.pulseEnabled()) {
startPulsingLocationCircle();
}
setLastLocation();
updateCompassListenerState(true);
setLastCompassHeading();
Expand All @@ -1220,6 +1241,7 @@ private void onLocationLayerStop() {
if (compassEngine != null) {
updateCompassListenerState(false);
}
cancelPulsingLocationCircle();
locationAnimatorCoordinator.cancelAllAnimations();
if (locationEngine != null) {
locationEngine.removeLocationUpdates(currentLocationEngineListener);
Expand Down Expand Up @@ -1371,6 +1393,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

0 comments on commit 5808c0f

Please sign in to comment.