summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java99
1 files changed, 96 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index e9d823ebda..ec7c53e1d0 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -1,19 +1,26 @@
package com.mapbox.mapboxsdk.maps.widgets;
import android.graphics.drawable.Drawable;
+import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.FocalPointChangeListener;
-import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.Projection;
+import com.mapbox.mapboxsdk.utils.BitmapUtils;
/**
* Settings to configure the visual appearance of the MyLocationView.
+ *
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+@Deprecated
public class MyLocationViewSettings {
private Projection projection;
@@ -51,6 +58,7 @@ public class MyLocationViewSettings {
//
private int accuracyAlpha;
+ private float accuracyThreshold = 0f;
@ColorInt
private int accuracyTintColor;
@@ -77,6 +85,11 @@ public class MyLocationViewSettings {
this.focalPointChangeListener = focalPointChangedListener;
}
+ /**
+ * Initialise this with MapboxMapOptions.
+ *
+ * @param options the options to initialise this class from
+ */
public void initialise(@NonNull MapboxMapOptions options) {
CameraPosition position = options.getCamera();
if (position != null && !position.equals(CameraPosition.DEFAULT)) {
@@ -88,6 +101,57 @@ public class MyLocationViewSettings {
setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
setAccuracyAlpha(options.getMyLocationAccuracyAlpha());
setAccuracyTintColor(options.getMyLocationAccuracyTintColor());
+ setAccuracyThreshold(options.getMyLocationAccuracyThreshold());
+ }
+
+ public void onSaveInstanceState(Bundle outState) {
+ outState.putBoolean(MapboxConstants.STATE_LOCATION_VIEW_ENABLED, isEnabled());
+ outState.putByteArray(
+ MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_DRAWABLE,
+ BitmapUtils.getByteArrayFromDrawable(getForegroundDrawable())
+ );
+ outState.putByteArray(
+ MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_BEARING_DRAWABLE,
+ BitmapUtils.getByteArrayFromDrawable(getForegroundBearingDrawable())
+ );
+ outState.putInt(MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_TINT_COLOR, getForegroundTintColor());
+ outState.putByteArray(
+ MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_DRAWABLE,
+ BitmapUtils.getByteArrayFromDrawable(getBackgroundDrawable())
+ );
+ outState.putIntArray(MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_OFFSET, getBackgroundOffset());
+ outState.putInt(MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_TINT_COLOR, getBackgroundTintColor());
+ outState.putInt(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_ALPHA, getAccuracyAlpha());
+ outState.putInt(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_TINT_COLOR, getAccuracyTintColor());
+ outState.putFloat(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_THRESHOLD, getAccuracyThreshold());
+ outState.putIntArray(MapboxConstants.STATE_LOCATION_VIEW_PADDING, getPadding());
+ }
+
+ public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
+ setEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_LOCATION_VIEW_ENABLED));
+ setForegroundDrawable(
+ BitmapUtils.getDrawableFromByteArray(
+ myLocationView.getContext(),
+ savedInstanceState.getByteArray(MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_DRAWABLE)
+ ),
+ BitmapUtils.getDrawableFromByteArray(
+ myLocationView.getContext(),
+ savedInstanceState.getByteArray(MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_BEARING_DRAWABLE)
+ )
+ );
+ setForegroundTintColor(savedInstanceState.getInt(MapboxConstants.STATE_LOCATION_VIEW_FOREGROUND_TINT_COLOR));
+ setBackgroundDrawable(
+ BitmapUtils.getDrawableFromByteArray(
+ myLocationView.getContext(),
+ savedInstanceState.getByteArray(MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_DRAWABLE)
+ ),
+ savedInstanceState.getIntArray(MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_OFFSET)
+ );
+ setBackgroundTintColor(savedInstanceState.getInt(MapboxConstants.STATE_LOCATION_VIEW_BACKGROUND_TINT_COLOR));
+ setAccuracyAlpha(savedInstanceState.getInt(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_ALPHA));
+ setAccuracyTintColor(savedInstanceState.getInt(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_TINT_COLOR));
+ setAccuracyThreshold(savedInstanceState.getFloat(MapboxConstants.STATE_LOCATION_VIEW_ACCURACY_THRESHOLD));
+ setPadding(savedInstanceState.getIntArray(MapboxConstants.STATE_LOCATION_VIEW_PADDING));
}
/**
@@ -114,6 +178,7 @@ public class MyLocationViewSettings {
* <p>
* The foreground drawable is the image visible on screen
* </p>
+ * It's linked with the foreground tint color
*
* @param foregroundDrawable the drawable to show as foreground without bearing
* @param foregroundBearingDrawable the drawable to show as foreground when bearing is enabled
@@ -122,6 +187,7 @@ public class MyLocationViewSettings {
this.foregroundDrawable = foregroundDrawable;
this.foregroundBearingDrawable = foregroundBearingDrawable;
myLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
+ myLocationView.setForegroundDrawableTint(foregroundTintColor);
}
/**
@@ -148,7 +214,8 @@ public class MyLocationViewSettings {
* The color will tint both the foreground and the bearing foreground drawable.
* </p>
*
- * @param foregroundTintColor the color to tint the foreground drawable
+ * @param foregroundTintColor the color to tint the foreground drawable or -1 (undefined color) to remove the
+ * existing foreground tint color
*/
public void setForegroundTintColor(@ColorInt int foregroundTintColor) {
this.foregroundTintColor = foregroundTintColor;
@@ -169,6 +236,7 @@ public class MyLocationViewSettings {
* <p>
* Padding can be added to provide an offset to the background
* </p>
+ * It's linked with the background tint color
*
* @param backgroundDrawable the drawable to show as background
* @param padding the padding added to the background
@@ -181,6 +249,7 @@ public class MyLocationViewSettings {
} else {
myLocationView.setShadowDrawable(backgroundDrawable);
}
+ myLocationView.setShadowDrawableTint(backgroundTintColor);
}
/**
@@ -195,7 +264,8 @@ public class MyLocationViewSettings {
/**
* Set the background tint color.
*
- * @param backgroundTintColor the color to tint the background
+ * @param backgroundTintColor the color to tint the background drawable or -1 (undefined color) to remove the
+ * existing background tint color
*/
public void setBackgroundTintColor(@ColorInt int backgroundTintColor) {
this.backgroundTintColor = backgroundTintColor;
@@ -230,6 +300,10 @@ public class MyLocationViewSettings {
*/
public void setPadding(int left, int top, int right, int bottom) {
padding = new int[] {left, top, right, bottom};
+ setPadding(padding);
+ }
+
+ private void setPadding(int[] padding) {
myLocationView.setContentPadding(padding);
projection.invalidateContentPadding(padding);
invalidateFocalPointForTracking(myLocationView);
@@ -282,6 +356,25 @@ public class MyLocationViewSettings {
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);
}