summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlangsmith <langstonlmcs@gmail.com>2019-02-21 08:23:03 -0800
committerlangsmith <langstonlmcs@gmail.com>2019-04-09 17:25:35 -0700
commit52018dba647c6324ce3a3091531c08372c8a0d1b (patch)
treeeb45e1ea42370cf6877ec77f0301f1c6d44b05f3
parent552643ee8c417c41c68b6f1bc4b72e6357c2a73b (diff)
downloadqtlocation-mapboxgl-52018dba647c6324ce3a3091531c08372c8a0d1b.tar.gz
refactor
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java23
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java9
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java79
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/PulsingLocationCircleAnimator.java144
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java8
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationPulsingCircleActivity.java55
8 files changed, 212 insertions, 118 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java
index c6c9340c06..da612beede 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java
@@ -6,6 +6,7 @@ import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
+import android.util.Log;
import android.util.SparseArray;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.BounceInterpolator;
@@ -154,15 +155,31 @@ final class LocationAnimatorCoordinator {
}
void startLocationCirclePulsing(LocationComponentOptions options, MapboxMap mapboxMap) {
- pulsingLocationCircleAnimator = new PulsingLocationCircleAnimator();
- pulsingLocationCircleAnimator.animatePulsingCircleRadius(
- retrievePulseInterpolator(options.pulseInterpolator()), mapboxMap, options);
+ pulsingLocationCircleAnimator = new PulsingLocationCircleAnimator(retrievePulseInterpolator(
+ options.pulseInterpolator()), mapboxMap, options);
+ pulsingLocationCircleAnimator.startPulsingAnimation();
}
void stopPulsingAnimation() {
pulsingLocationCircleAnimator.stopPulsingAnimation();
}
+ void pausePulsingAnimation() {
+ pulsingLocationCircleAnimator.pausePulsingAnimation();
+ }
+
+ void resumePulsingAnimation() {
+ pulsingLocationCircleAnimator.resumePulsingAnimation();
+ }
+
+ void pulsingAnimationIsRunning() {
+ pulsingLocationCircleAnimator.pulsingAnimationIsRunning();
+ }
+
+ boolean pulsingAnimationIsStarted() {
+ return pulsingLocationCircleAnimator.pulsingAnimationIsStarted();
+ }
+
private LatLng getPreviousLayerLatLng() {
LatLng previousLatLng;
MapboxAnimator latLngAnimator = animatorArray.get(ANIMATOR_LAYER_LATLNG);
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 d43d802140..3b0099af0f 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,7 +11,6 @@ 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;
@@ -667,9 +666,6 @@ public final class LocationComponent {
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
locationAnimatorCoordinator.setCompassAnimationEnabled(options.compassAnimationEnabled());
locationAnimatorCoordinator.setAccuracyAnimationEnabled(options.accuracyAnimationEnabled());
- if (options.pulseEnabled()) {
- locationAnimatorCoordinator.startLocationCirclePulsing(options, mapboxMap);
- }
updateMapWithOptions(options);
}
}
@@ -1063,6 +1059,7 @@ public final class LocationComponent {
*/
public void onStart() {
isComponentStarted = true;
+ Logger.d(TAG, "onStart()");
onLocationLayerStart();
}
@@ -1072,6 +1069,7 @@ public final class LocationComponent {
public void onStop() {
onLocationLayerStop();
isComponentStarted = false;
+ Logger.d(TAG, "onStop()");
}
/**
@@ -1127,6 +1125,9 @@ public final class LocationComponent {
setLastLocation();
updateCompassListenerState(true);
setLastCompassHeading();
+ if (options.pulseEnabled()) {
+ locationAnimatorCoordinator.startLocationCirclePulsing(options, mapboxMap);
+ }
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
index ccb3709120..ce9d0b485d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
@@ -128,12 +128,12 @@ public class LocationComponentOptions implements Parcelable {
private float trackingAnimationDurationMultiplier;
private boolean compassAnimationEnabled;
private boolean accuracyAnimationEnabled;
- private boolean pulsingCircleEnabled;
- private boolean pulsingCircleFadeEnabled;
+ private Boolean pulsingCircleEnabled;
+ private Boolean pulsingCircleFadeEnabled;
private int pulseColor;
private float pulseSingleDuration;
private float pulseFrequency;
- private float pulseAlpha;
+ private Float pulseAlpha;
private String pulseInterpolator;
public LocationComponentOptions(
@@ -169,12 +169,12 @@ public class LocationComponentOptions implements Parcelable {
float trackingAnimationDurationMultiplier,
boolean compassAnimationEnabled,
boolean accuracyAnimationEnabled,
- boolean pulsingCircleEnabled,
- boolean pulsingCircleFadeEnabled,
+ Boolean pulsingCircleEnabled,
+ Boolean pulsingCircleFadeEnabled,
Integer pulsingCircleColor,
- float pulsingCircleDuration,
- float pulsingCircleFrequency,
- float pulsingCircleAlpha,
+ Float pulsingCircleDuration,
+ Float pulsingCircleFrequency,
+ Float pulsingCircleAlpha,
String pulsingCircleInterpolator) {
this.accuracyAlpha = accuracyAlpha;
this.accuracyColor = accuracyColor;
@@ -788,7 +788,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return whether the LocationComponent's pulsing circle is enabled
*/
- public boolean pulseEnabled() {
+ public Boolean pulseEnabled() {
return pulsingCircleEnabled;
}
@@ -799,7 +799,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return whether fading of the LocationComponent's pulsing circle is enabled
*/
- public boolean pulsingCircleFadeEnabled() {
+ public Boolean pulsingCircleFadeEnabled() {
return pulsingCircleFadeEnabled;
}
@@ -835,7 +835,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return the current set opacity of the LocationComponent's circle
*/
- public float pulseAlpha() {
+ public Float pulseAlpha() {
return pulseAlpha;
}
@@ -1225,16 +1225,43 @@ public class LocationComponentOptions implements Parcelable {
// TODO: Finish this logic below
- /*Log.d("LocationComponentOptions", "locationComponentOptions.pulseFrequency() = " + locationComponentOptions.pulseFrequency());
- Log.d("LocationComponentOptions", "locationComponentOptions.pulseSingleDuration() = " + locationComponentOptions.pulseSingleDuration());
+ if (locationComponentOptions.pulseEnabled() == null) {
+
+ Log.d("LCOptions", "autoBuild: this.pulsingCircleFadeEnabled == null ");
+
+ String pulsingSetupError = "";
+
+ if (locationComponentOptions.pulsingCircleFadeEnabled() != null) {
+ pulsingSetupError += " pulsingCircleFadeEnabled";
+ }
+ if (locationComponentOptions.pulseColor() != null) {
+ pulsingSetupError += " pulsingCircleColor";
+ }
+ if ((Float) locationComponentOptions.pulseSingleDuration() == null) {
+
+ pulsingSetupError += " pulsingCircleDuration";
+ }
+ if ((Float) locationComponentOptions.pulseFrequency() != null) {
+ pulsingSetupError += " pulsingCircleFrequency";
+ }
+ if (locationComponentOptions.pulseAlpha() != null) {
+ pulsingSetupError += " accuracyAlpha";
+ }
+ if (locationComponentOptions.pulseInterpolator() != null) {
+ pulsingSetupError += " pulsingCircleInterpolator";
+ }
+ if (!pulsingSetupError.isEmpty()) {
+ throw new IllegalStateException("You've set up the following pulsing circle options but have not enabled" +
+ " the pulsing circle via the LocationComponentOptions builder:" + pulsingSetupError + ". Enable the pulsing" +
+ " circle if you're going to set pulsing options.");
+ }
+ }
if (locationComponentOptions.pulseFrequency() < locationComponentOptions.pulseSingleDuration()) {
-
throw new IllegalArgumentException("Invalid relationship between the LocationComponent " +
"pulsing circle frequency of " + locationComponentOptions.pulseFrequency() + " and duration of " +
locationComponentOptions.pulseSingleDuration() + " . The frequency of the pulsing must be >= to the duration " +
"of a single pulse.");
- }*/
-
+ }
return locationComponentOptions;
}
@@ -1282,12 +1309,12 @@ public class LocationComponentOptions implements Parcelable {
private Float trackingAnimationDurationMultiplier;
private Boolean compassAnimationEnabled;
private Boolean accuracyAnimationEnabled;
- private boolean pulsingCircleEnabled;
- private boolean pulsingCircleFadeEnabled;
- private int pulsingCircleColor;
- private float pulsingCircleDuration;
- private float pulsingCircleFrequency;
- private float pulsingCircleAlpha;
+ private Boolean pulsingCircleEnabled;
+ private Boolean pulsingCircleFadeEnabled;
+ private Integer pulsingCircleColor;
+ private Float pulsingCircleDuration;
+ private Float pulsingCircleFrequency;
+ private Float pulsingCircleAlpha;
private String pulsingCircleInterpolator;
Builder() {
@@ -1824,7 +1851,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return the current set color of the circle
*/
- public LocationComponentOptions.Builder pulsingCircleColor(int pulsingCircleColor) {
+ public LocationComponentOptions.Builder pulsingCircleColor(Integer pulsingCircleColor) {
this.pulsingCircleColor = pulsingCircleColor;
return this;
}
@@ -1834,7 +1861,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return the current set length of time for a single pulse
*/
- public LocationComponentOptions.Builder pulsingCircleDuration(float pulsingCircleDuration) {
+ public LocationComponentOptions.Builder pulsingCircleDuration(Float pulsingCircleDuration) {
this.pulsingCircleDuration = pulsingCircleDuration;
return this;
}
@@ -1844,7 +1871,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return the current set length of time between pulses
*/
- public LocationComponentOptions.Builder pulsingCircleFrequency(float pulsingCircleFrequency) {
+ public LocationComponentOptions.Builder pulsingCircleFrequency(Float pulsingCircleFrequency) {
this.pulsingCircleFrequency = pulsingCircleFrequency;
return this;
}
@@ -1854,7 +1881,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @return the current set opacity of the LocationComponent's circle
*/
- public LocationComponentOptions.Builder pulsingCircleAlpha(float pulsingCircleAlpha) {
+ public LocationComponentOptions.Builder pulsingCircleAlpha(Float pulsingCircleAlpha) {
this.pulsingCircleAlpha = pulsingCircleAlpha;
return this;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
index a8e067c12d..1b3e7dd928 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
@@ -6,7 +6,6 @@ import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
-import android.util.Log;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -48,8 +47,8 @@ import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_STALE_ICON;
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.PROPERTY_SHADOW_ICON_OFFSET;
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.interpolate;
@@ -474,7 +473,6 @@ final class LocationLayerController {
new MapboxAnimator.AnimationsValueChangeListener<Float>() {
@Override
public void onNewAnimationValue(Float value) {
- // TODO: Hide the pulsing circle layer once the accuracy circle is visibile? (i.e. newAnimationValue > 0)
updateAccuracyRadius(value);
}
};
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/PulsingLocationCircleAnimator.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/PulsingLocationCircleAnimator.java
index c8f6260fb1..65cc586a7b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/PulsingLocationCircleAnimator.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/PulsingLocationCircleAnimator.java
@@ -1,11 +1,11 @@
package com.mapbox.mapboxsdk.location;
import android.animation.ValueAnimator;
-import android.os.Handler;
+import android.os.Build;
import android.support.annotation.NonNull;
-import android.util.Log;
import android.view.animation.Interpolator;
+import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.style.layers.Layer;
@@ -16,65 +16,111 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
/**
* Manages the logic of the interpolated animation which is applied to the LocationComponent's pulsing circle
*/
-class PulsingLocationCircleAnimator {
+public class PulsingLocationCircleAnimator {
private static final String TAG = "Mbgl-PulsingLocationCircleAnimator";
private static final float PULSING_CIRCLE_RADIUS = 60;
- private Handler handler;
- private Runnable runnable;
private float opacityCounter;
-
- public PulsingLocationCircleAnimator() {
- this.opacityCounter = 0;
- }
+ private Interpolator interpolatorToUse;
+ private MapboxMap mapboxMap;
+ private LocationComponentOptions locationComponentOptions;
+ private Layer pulsingCircleLayer;
+ private ValueAnimator animator;
/**
* Start the LocationComponent circle pulse animation
*
- * @param interpolatorToUse the type of Android-system interpolator to use
- * @param mapboxMap the MapboxMap object which pulsing circle should be shown on
+ * @param interpolatorToUse the type of Android-system interpolator to use
+ * @param mapboxMap the MapboxMap object which pulsing circle should be shown on
* @param locationComponentOptions the stying options of the LocationComponent pulsing circle
*/
- public void animatePulsingCircleRadius(@NonNull final Interpolator interpolatorToUse,
- @NonNull final MapboxMap mapboxMap,
- @NonNull final LocationComponentOptions locationComponentOptions) {
- handler = new Handler();
- runnable = new Runnable() {
- @Override
- public void run() {
- // Check if we are at the end of the points list, if so we want to stop using
- // the handler.
- if (mapboxMap.getStyle().getLayer(PROPERTY_PULSING_CIRCLE_LAYER) != null) {
-
- opacityCounter = 0;
-
- final Layer pulsingCircleLayer = mapboxMap.getStyle().getLayer(PROPERTY_PULSING_CIRCLE_LAYER);
- ValueAnimator animator = ValueAnimator.ofFloat(0f, PULSING_CIRCLE_RADIUS);
- animator.setDuration((long) locationComponentOptions.pulseSingleDuration());
- animator.setRepeatMode(ValueAnimator.RESTART);
- animator.setInterpolator(interpolatorToUse);
- animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator valueAnimator) {
- pulsingCircleLayer.setProperties(circleRadius((Float) valueAnimator.getAnimatedValue()));
- if (locationComponentOptions.pulsingCircleFadeEnabled()) {
- pulsingCircleLayer.setProperties(circleOpacity(1 - opacityCounter * .01f));
- opacityCounter++;
- }
- }
- });
- animator.start();
- // Once we finish we need to repeat the entire process by executing the
- // handler again once the ValueAnimator is finished.
- handler.postDelayed(this, (long) locationComponentOptions.pulseFrequency());
- }
+ public PulsingLocationCircleAnimator(@NonNull final Interpolator interpolatorToUse,
+ @NonNull final MapboxMap mapboxMap,
+ @NonNull final LocationComponentOptions locationComponentOptions) {
+ Logger.d(TAG,"creating PulsingLocationCircleAnimator()");
+ this.opacityCounter = 0;
+ this.interpolatorToUse = interpolatorToUse;
+ this.mapboxMap = mapboxMap;
+ this.locationComponentOptions = locationComponentOptions;
+ }
+
+ public void startPulsingAnimation() {
+ createValueAnimator();
+ startValueAnimator();
+ }
+
+ private void createValueAnimator() {
+ // handler.postDelayed(runnable, (long) locationComponentOptions.pulseFrequency());
+ if (mapboxMap.getStyle().getLayer(PROPERTY_PULSING_CIRCLE_LAYER) != null) {
+ Logger.d(TAG, "mapboxMap.getStyle().getLayer(PROPERTY_PULSING_CIRCLE_LAYER) != null");
+ pulsingCircleLayer = mapboxMap.getStyle().getLayer(PROPERTY_PULSING_CIRCLE_LAYER);
+
+ if (pulsingCircleLayer != null) {
+ Logger.d(TAG, "pulsingCircleLayer != null");
+ } else {
+ Logger.d(TAG, "pulsingCircleLayer == null");
}
- };
- handler.post(runnable);
+ animator = ValueAnimator.ofFloat(0f, PULSING_CIRCLE_RADIUS);
+ animator.setDuration((long) locationComponentOptions.pulseSingleDuration());
+ animator.setRepeatMode(ValueAnimator.RESTART);
+ animator.setRepeatCount(ValueAnimator.INFINITE);
+ animator.setInterpolator(interpolatorToUse);
+
+ Logger.d(TAG, "animator.getDuration() = " + animator.getDuration());
+ Logger.d(TAG, "animator.getRepeatMode() = " + animator.getRepeatMode());
+
+ animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator valueAnimator) {
+ pulsingCircleLayer.setProperties(circleRadius((Float) valueAnimator.getAnimatedValue()));
+ if (locationComponentOptions.pulsingCircleFadeEnabled()) {
+ pulsingCircleLayer.setProperties(circleOpacity(1 - opacityCounter * .01f));
+ opacityCounter++;
+ }
+ }
+ });
+ }
+ }
+
+ private void startValueAnimator() {
+ if (animator != null) {
+ animator.start();
+ }
+ }
+
+ public boolean pulsingAnimationIsStarted() {
+ if (animator != null) {
+ return animator.isStarted();
+ }
+ return false;
+ }
+
+ public boolean pulsingAnimationIsRunning() {
+ if (animator != null) {
+ return animator.isRunning();
+ }
+ return false;
+ }
+
+ public void pausePulsingAnimation() {
+ if (animator != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ animator.pause();
+ } else {
+ animator.end();
+ }
+ }
+
+ public void resumePulsingAnimation() {
+ if (animator != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ animator.resume();
+// createValueAnimator();
+// startValueAnimator();
+ }
}
public void stopPulsingAnimation() {
- Log.d(TAG, "stopPulsingAnimation: ");
- handler.removeCallbacks(runnable);
+ if (animator != null) {
+ animator.end();
+ }
}
-}
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
index f179586782..49f9a7c43c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
@@ -56,14 +56,6 @@ public final class Utils {
return (float) (location.getAccuracy() * (1 / metersPerPixel));
}
- static float calculatePulsingCircleRadius(@NonNull MapboxMap mapboxMap, @Nullable Location location) {
- if (location == null) {
- return 0;
- }
- double metersPerPixel = mapboxMap.getProjection().getMetersPerPixelAtLatitude(location.getLatitude());
- return (float) (location.getAccuracy() * (1 / metersPerPixel));
- }
-
static boolean immediateAnimation(@NonNull Projection projection, @NonNull LatLng current, @NonNull LatLng target) {
double metersPerPixel = projection.getMetersPerPixelAtLatitude((current.getLatitude() + target.getLatitude()) / 2);
double distance = current.distanceTo(target);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
index 8cb784eb58..8db6ea6b47 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
@@ -34,10 +34,12 @@
<item name="mapbox_trackingMultiFingerMoveThreshold">@dimen/mapbox_locationComponentTrackingMultiFingerMoveThreshold</item>
<!-- Location pulsing circle -->
+ <item name="mapbox_pulsingLocationCircleEnabled">false</item>
+ <item name="mapbox_pulsingLocationCircleFadeEnabled">true</item>
<item name="mapbox_pulsingLocationCircleColor">@color/mapbox_location_layer_blue</item>
- <item name="mapbox_pulsingLocationCircleDuration">2.5</item>
- <item name="mapbox_pulsingLocationCircleFrequency">2</item>
+ <item name="mapbox_pulsingLocationCircleDuration">1700</item>
+ <item name="mapbox_pulsingLocationCircleFrequency">1700</item>
<item name="mapbox_pulsingLocationCircleAlpha">0.4</item>
- <item name="mapbox_pulsingLocationCircleInterpolator">linear</item>
+ <item name="mapbox_pulsingLocationCircleInterpolator">decelerate</item>
</style>
</resources> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationPulsingCircleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationPulsingCircleActivity.java
index 1694b7de5a..b94140ccd0 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationPulsingCircleActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationPulsingCircleActivity.java
@@ -20,6 +20,7 @@ import com.mapbox.android.core.location.LocationEngineRequest;
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.CameraMode;
import com.mapbox.mapboxsdk.location.modes.PulseMode;
@@ -48,10 +49,10 @@ public class LocationPulsingCircleActivity extends AppCompatActivity implements
private static final String SAVED_STATE_LOCATION = "saved_state_location";
// Make sure that the frequency value is equal to or larger than the duration value.
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_FREQUENCY = 1700;
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_DURATION = 1700;
+ private static final float DEFAULT_LOCATION_CIRCLE_PULSE_FREQUENCY = 5000;
+ private static final float DEFAULT_LOCATION_CIRCLE_PULSE_DURATION = 1900;
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA = .4f;
+ private static final float DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA = .6f;
private static final String DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE = PulseMode.DECELERATE;
private static final boolean DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE = false;
@@ -130,17 +131,22 @@ public class LocationPulsingCircleActivity extends AppCompatActivity implements
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
locationComponent = mapboxMap.getLocationComponent();
- locationComponent.activateLocationComponent(this, style, true,
- new LocationEngineRequest.Builder(750)
- .setFastestInterval(750)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
- .build(),
- buildLocationComponentOptions(
- "waterway-label",
- DEFAULT_LOCATION_CIRCLE_PULSE_COLOR,
- DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA,
- DEFAULT_LOCATION_CIRCLE_PULSE_DURATION,
- DEFAULT_LOCATION_CIRCLE_PULSE_FREQUENCY));
+
+ locationComponent.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(this, style)
+ .locationComponentOptions(buildLocationComponentOptions(
+ "waterway-label",
+ DEFAULT_LOCATION_CIRCLE_PULSE_COLOR,
+ DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA,
+ DEFAULT_LOCATION_CIRCLE_PULSE_DURATION,
+ DEFAULT_LOCATION_CIRCLE_PULSE_FREQUENCY))
+ .useDefaultLocationEngine(true)
+ .locationEngineRequest(new LocationEngineRequest.Builder(750)
+ .setFastestInterval(750)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
+ .build())
+ .build());
locationComponent.setLocationComponentEnabled(true);
locationComponent.setCameraMode(CameraMode.TRACKING);
@@ -170,14 +176,19 @@ public class LocationPulsingCircleActivity extends AppCompatActivity implements
private void setNewLocationComponentOptions(@Nullable float newPulsingFrequency,
@Nullable int newPulsingColor) {
if (mapboxMap.getStyle() != null) {
- locationComponent.activateLocationComponent(this, mapboxMap.getStyle(),
- true,
- new LocationEngineRequest.Builder(750)
- .setFastestInterval(750)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
- .build(), buildLocationComponentOptions("waterway-label",
- newPulsingColor, DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA,
- DEFAULT_LOCATION_CIRCLE_PULSE_DURATION, newPulsingFrequency));
+
+ locationComponent.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(this, mapboxMap.getStyle())
+ .locationComponentOptions(buildLocationComponentOptions("waterway-label",
+ newPulsingColor, DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA,
+ DEFAULT_LOCATION_CIRCLE_PULSE_DURATION, newPulsingFrequency))
+ .useDefaultLocationEngine(true)
+ .locationEngineRequest(new LocationEngineRequest.Builder(750)
+ .setFastestInterval(750)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
+ .build())
+ .build());
}
}