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

Commit

Permalink
[android] - feature - location accuracy indicator threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
paczos authored and tobrun committed Jul 14, 2017
1 parent 3b26177 commit 83395c2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class MapboxMapOptions implements Parcelable {
private int[] myLocationBackgroundPadding;
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
private float myLocationAccuracyThreshold;

private String apiBaseUrl;

Expand Down Expand Up @@ -148,6 +149,7 @@ private MapboxMapOptions(Parcel in) {
myLocationBackgroundPadding = in.createIntArray();
myLocationAccuracyAlpha = in.readInt();
myLocationAccuracyTintColor = in.readInt();
myLocationAccuracyThreshold = in.readFloat();

style = in.readString();
apiBaseUrl = in.readString();
Expand Down Expand Up @@ -291,6 +293,8 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
mapboxMapOptions.myLocationAccuracyTint(
typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyTintColor,
ColorUtils.getPrimaryColor(context)));
mapboxMapOptions.myLocationAccuracyThreshold(
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
mapboxMapOptions.textureMode(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
} finally {
Expand Down Expand Up @@ -680,6 +684,17 @@ public MapboxMapOptions myLocationAccuracyAlpha(@IntRange(from = 0, to = 255) in
return this;
}

/**
* Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
*
* @param myLocationAccuracyThreshold Value of accuracy (in meters), below which circle won't be displayed
* @return This
*/
public MapboxMapOptions myLocationAccuracyThreshold(float myLocationAccuracyThreshold) {
this.myLocationAccuracyThreshold = myLocationAccuracyThreshold;
return this;
}

/**
* Enable TextureView as rendered surface.
* <p>
Expand Down Expand Up @@ -987,6 +1002,15 @@ public int getMyLocationAccuracyAlpha() {
return myLocationAccuracyAlpha;
}

/**
* Returns current accuracy threshold value (in meters).
*
* @return Value of accuracy threshold (in meters), below which circle won't be displayed
*/
public float getMyLocationAccuracyThreshold() {
return myLocationAccuracyThreshold;
}

/**
* Get the current configured debug state for a map view.
*
Expand Down Expand Up @@ -1065,6 +1089,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeIntArray(myLocationBackgroundPadding);
dest.writeInt(myLocationAccuracyAlpha);
dest.writeInt(myLocationAccuracyTintColor);
dest.writeFloat(myLocationAccuracyThreshold);

dest.writeString(style);
dest.writeString(apiBaseUrl);
Expand Down Expand Up @@ -1153,6 +1178,9 @@ public boolean equals(Object o) {
if (myLocationAccuracyAlpha != options.myLocationAccuracyAlpha) {
return false;
}
if (myLocationAccuracyThreshold != options.myLocationAccuracyThreshold) {
return false;
}
if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null) {
return false;
}
Expand Down Expand Up @@ -1230,6 +1258,8 @@ public int hashCode() {
result = 31 * result + Arrays.hashCode(myLocationBackgroundPadding);
result = 31 * result + myLocationAccuracyTintColor;
result = 31 * result + myLocationAccuracyAlpha;
result = 31 * result + (myLocationAccuracyThreshold != +0.0f
? Float.floatToIntBits(myLocationAccuracyThreshold) : 0);
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class MyLocationView extends View {

private float accuracy;
private Paint accuracyPaint;
private float accuracyThreshold;

private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
Expand Down Expand Up @@ -591,6 +592,16 @@ public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEna
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
}

/**
* Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
* For internal use only.
*
* @param accuracyThreshold Value below which circle won't be displayed
*/
public void setAccuracyThreshold(float accuracyThreshold) {
this.accuracyThreshold = accuracyThreshold;
}

/**
* Set the bearing tracking mode, for internal use only.
*
Expand Down Expand Up @@ -928,10 +939,11 @@ void updateAccuracy(@NonNull Location location) {
accuracyAnimator.end();
}

accuracyAnimator = ValueAnimator.ofFloat(accuracy, location.getAccuracy());
float newAccuracy = location.getAccuracy() >= accuracyThreshold ? location.getAccuracy() : 0f;
accuracyAnimator = ValueAnimator.ofFloat(accuracy, newAccuracy);
accuracyAnimator.setDuration(750);
accuracyAnimator.start();
accuracy = location.getAccuracy();
accuracy = newAccuracy;
}

abstract void invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MyLocationViewSettings {
//

private int accuracyAlpha;
private float accuracyThreshold = 0f;

@ColorInt
private int accuracyTintColor;
Expand Down Expand Up @@ -93,6 +94,7 @@ public void initialise(@NonNull MapboxMapOptions options) {
setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
setAccuracyAlpha(options.getMyLocationAccuracyAlpha());
setAccuracyTintColor(options.getMyLocationAccuracyTintColor());
setAccuracyThreshold(options.getMyLocationAccuracyThreshold());
}

/**
Expand Down Expand Up @@ -293,6 +295,25 @@ public void setAccuracyTintColor(@ColorInt int accuracyTintColor) {
myLocationView.setAccuracyTint(accuracyTintColor);
}

/**
* Returns current accuracy threshold value (in meters).
*
* @return Value of accuracy threshold (in meters), below which circle won't be displayed
*/
public float getAccuracyThreshold() {
return accuracyThreshold;
}

/**
* Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
*
* @param accuracyThreshold Value of accuracy (in meters), below which circle won't be displayed
*/
public void setAccuracyThreshold(float accuracyThreshold) {
this.accuracyThreshold = accuracyThreshold;
myLocationView.setAccuracyThreshold(accuracyThreshold);
}

public void setTilt(double tilt) {
myLocationView.setTilt(tilt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<attr name="mapbox_myLocationBackgroundMarginBottom" format="dimension"/>
<attr name="mapbox_myLocationAccuracyTintColor" format="color"/>
<attr name="mapbox_myLocationAccuracyAlpha" format="integer"/>
<attr name="mapbox_myLocationAccuracyThreshold" format="float"/>

<!--Compass-->
<attr name="mapbox_uiCompass" format="boolean"/>
Expand Down

0 comments on commit 83395c2

Please sign in to comment.