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

Commit

Permalink
[android] initial additions to add a pulsing locationComponent circle
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov authored and langsmith committed Feb 19, 2019
1 parent 4540f80 commit 55a49db
Show file tree
Hide file tree
Showing 21 changed files with 1,010 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.location;

import android.support.annotation.NonNull;

import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
import com.mapbox.mapboxsdk.style.layers.Layer;
Expand All @@ -27,6 +28,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.PROPERTY_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 +110,12 @@ Layer generateAccuracyLayer() {
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
);
}

@NonNull
Layer generatePulsingCircleLayer() {
return new CircleLayer(PROPERTY_PULSING_CIRCLE_LAYER, LOCATION_SOURCE)
.withProperties(
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.util.SparseArray;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.modes.PulseMode;
import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
Expand Down Expand Up @@ -51,6 +56,7 @@ final class LocationAnimatorCoordinator {
private final MapboxAnimatorSetProvider animatorSetProvider;
private boolean compassAnimationEnabled;
private boolean accuracyAnimationEnabled;
private PulsingLocationCircleAnimator pulsingLocationCircleAnimator;

@VisibleForTesting
int maxAnimationFps = Integer.MAX_VALUE;
Expand Down Expand Up @@ -147,6 +153,16 @@ void feedNewTilt(double targetTilt, @NonNull CameraPosition currentCameraPositio
playAnimators(animationDuration, ANIMATOR_TILT);
}

void startLocationCirclePulsing(LocationComponentOptions options, MapboxMap mapboxMap) {
pulsingLocationCircleAnimator = new PulsingLocationCircleAnimator();
pulsingLocationCircleAnimator.animatePulsingCircleRadius(
retrievePulseInterpolator(options.pulseInterpolator()), mapboxMap, options);
}

void stopPulsingAnimation() {
pulsingLocationCircleAnimator.stopPulsingAnimation();
}

private LatLng getPreviousLayerLatLng() {
LatLng previousLatLng;
MapboxAnimator latLngAnimator = animatorArray.get(ANIMATOR_LAYER_LATLNG);
Expand Down Expand Up @@ -381,11 +397,26 @@ void setAccuracyAnimationEnabled(boolean accuracyAnimationEnabled) {
this.accuracyAnimationEnabled = accuracyAnimationEnabled;
}

void setMaxAnimationFps(int maxAnimationFps) {
if (maxAnimationFps <= 0) {
Logger.e(TAG, "Max animation FPS cannot be less or equal to 0.");
return;
void setMaxAnimationFps(int maxAnimationFps){
if (maxAnimationFps <= 0) {
Logger.e(TAG, "Max animation FPS cannot be less or equal to 0.");
return;
}
this.maxAnimationFps = maxAnimationFps;
}

private Interpolator retrievePulseInterpolator(String interpolatorAnimationType) {
switch(interpolatorAnimationType) {
case PulseMode.LINEAR:
return new LinearInterpolator();
case PulseMode.ACCELERATE:
return new AccelerateInterpolator();
case PulseMode.DECELERATE:
return new DecelerateInterpolator();
case PulseMode.BOUNCE:
return new BounceInterpolator();
default:
return new DecelerateInterpolator();
}
this.maxAnimationFps = maxAnimationFps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -587,6 +588,7 @@ public void applyStyle(@NonNull Context context, @StyleRes int styleRes) {
*
* @param options to update the current style
*/
@SuppressLint("MissingPermission")
public void applyStyle(@NonNull final LocationComponentOptions options) {
LocationComponent.this.options = options;
if (mapboxMap.getStyle() != null) {
Expand All @@ -597,6 +599,9 @@ public void applyStyle(@NonNull final LocationComponentOptions options) {
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
locationAnimatorCoordinator.setCompassAnimationEnabled(options.compassAnimationEnabled());
locationAnimatorCoordinator.setAccuracyAnimationEnabled(options.accuracyAnimationEnabled());
if (options.pulseEnabled()) {
locationAnimatorCoordinator.startLocationCirclePulsing(options, mapboxMap);
}
updateMapWithOptions(options);
}
}
Expand Down Expand Up @@ -1056,6 +1061,10 @@ private void onLocationLayerStop() {
if (locationEngine != null) {
locationEngine.removeLocationUpdates(currentLocationEngineListener);
}
if (options.pulseEnabled()) {
Log.d(TAG, "onLocationLayerStop: about to stop animation ");
locationAnimatorCoordinator.stopPulsingAnimation();
}
mapboxMap.removeOnCameraMoveListener(onCameraMoveListener);
mapboxMap.removeOnCameraIdleListener(onCameraIdleListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class LocationComponentConstants {
static final String BACKGROUND_LAYER = "mapbox-location-stroke-layer";
static final String ACCURACY_LAYER = "mapbox-location-accuracy-layer";
static final String BEARING_LAYER = "mapbox-location-bearing-layer";
static final String PROPERTY_PULSING_CIRCLE_LAYER = "mapbox-location-pulsing-circle-layer";

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

0 comments on commit 55a49db

Please sign in to comment.