diff options
author | Tobrun <tobrun@mapbox.com> | 2016-04-25 12:31:07 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-04-26 22:24:17 +0200 |
commit | e2510fce79d9a90bad71bcfc5a73c248a9c7c3d1 (patch) | |
tree | 92b6a4bba2516a4accf686b7f849b8905c30097d /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java | |
parent | ba9703351d6bfc9bfa9bcf54553d62961e42c723 (diff) | |
download | qtlocation-mapboxgl-e2510fce79d9a90bad71bcfc5a73c248a9c7c3d1.tar.gz |
[android] #4800 - default location view from start: introduced attributes, update MapboxMapOptions, added tests. updated MockParcel
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java | 259 |
1 files changed, 254 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 764a901d8b..c6b9aa7bfc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -2,17 +2,25 @@ package com.mapbox.mapboxsdk.maps; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.ColorInt; +import android.support.annotation.IntRange; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.util.AttributeSet; +import android.util.Log; import android.view.Gravity; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.utils.ColorUtils; + +import java.util.Arrays; /** * Defines configuration MapboxMapMapOptions for a MapboxMap. These options can be used when adding a @@ -56,7 +64,15 @@ public class MapboxMapOptions implements Parcelable { private boolean zoomGesturesEnabled = true; private boolean zoomControlsEnabled = false; - private boolean locationEnabled; + private boolean myLocationEnabled; + private Drawable myLocationForegroundDrawable; + private Drawable myLocationForegroundBearingDrawable; + private Drawable myLocationBackgroundDrawable; + private int myLocationForegroundTintColor = -1; + private int myLocationBackgroundTintColor = -1; + private int[] myLocationBackgroundPadding; + private int myLocationAccuracyTintColor; + private int myLocationAccuracyAlpha; private String style; private String accessToken; @@ -93,7 +109,15 @@ public class MapboxMapOptions implements Parcelable { zoomControlsEnabled = in.readByte() != 0; zoomGesturesEnabled = in.readByte() != 0; - locationEnabled = in.readByte() != 0; + myLocationEnabled = in.readByte() != 0; + //myLocationForegroundDrawable; + //myLocationForegroundBearingDrawable; + //myLocationBackgroundDrawable; + myLocationForegroundTintColor = in.readInt(); + myLocationBackgroundTintColor = in.readInt(); + myLocationBackgroundPadding = in.createIntArray(); + myLocationAccuracyAlpha = in.readInt(); + myLocationAccuracyTintColor = in.readInt(); style = in.readString(); accessToken = in.readString(); @@ -150,6 +174,18 @@ public class MapboxMapOptions implements Parcelable { , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * screenDensity)}); mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false)); + mapboxMapOptions.myLocationForegroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground)); + mapboxMapOptions.myLocationForegroundBearingDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground_bearing)); + mapboxMapOptions.myLocationBackgroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_background)); + mapboxMapOptions.myLocationForegroundDrawable(typedArray.getDrawable(R.styleable.MapView_my_location_foreground)); + mapboxMapOptions.myLocationForegroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_foreground_tint, -1)); + mapboxMapOptions.myLocationBackgroundTintColor(typedArray.getColor(R.styleable.MapView_my_location_background_tint, -1)); + mapboxMapOptions.myLocationBackgroundPadding(new int[]{(int) (typedArray.getDimension(R.styleable.MapView_my_location_background_left, 0) * screenDensity) + , (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_top, 0) * screenDensity) + , (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_right, 0) * screenDensity) + , (int) (typedArray.getDimension(R.styleable.MapView_my_location_background_bottom, 0) * screenDensity)}); + mapboxMapOptions.myLocationAccuracyAlpha(typedArray.getInt(R.styleable.MapView_my_location_accuracy_alpha, 100)); + mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(R.styleable.MapView_my_location_accuracy_tint, ColorUtils.getAccentColor(context))); } finally { typedArray.recycle(); } @@ -394,7 +430,79 @@ public class MapboxMapOptions implements Parcelable { * @return This */ public MapboxMapOptions locationEnabled(boolean locationEnabled) { - this.locationEnabled = locationEnabled; + this.myLocationEnabled = locationEnabled; + return this; + } + + /** + * @param myLocationForegroundDrawable + * @return This + */ + public MapboxMapOptions myLocationForegroundDrawable(Drawable myLocationForegroundDrawable) { + this.myLocationForegroundDrawable = myLocationForegroundDrawable; + return this; + } + + /** + * @param myLocationBearingDrawable + * @return This + */ + public MapboxMapOptions myLocationForegroundBearingDrawable(Drawable myLocationBearingDrawable) { + this.myLocationForegroundBearingDrawable = myLocationBearingDrawable; + return this; + } + + /** + * @param myLocationBackgroundDrawable + * @return This + */ + public MapboxMapOptions myLocationBackgroundDrawable(Drawable myLocationBackgroundDrawable) { + this.myLocationBackgroundDrawable = myLocationBackgroundDrawable; + return this; + } + + /** + * @param myLocationForegroundTintColor + * @return This + */ + public MapboxMapOptions myLocationForegroundTintColor(@ColorInt int myLocationForegroundTintColor) { + this.myLocationForegroundTintColor = myLocationForegroundTintColor; + return this; + } + + /** + * @param myLocationBackgroundTintColor + * @return This + */ + public MapboxMapOptions myLocationBackgroundTintColor(@ColorInt int myLocationBackgroundTintColor) { + this.myLocationBackgroundTintColor = myLocationBackgroundTintColor; + return this; + } + + /** + * @param myLocationBackgroundPadding + * @return This + */ + public MapboxMapOptions myLocationBackgroundPadding(int[] myLocationBackgroundPadding) { + this.myLocationBackgroundPadding = myLocationBackgroundPadding; + return this; + } + + /** + * @param myLocationAccuracyTintColor + * @return This + */ + public MapboxMapOptions myLocationAccuracyTint(@ColorInt int myLocationAccuracyTintColor) { + this.myLocationAccuracyTintColor = myLocationAccuracyTintColor; + return this; + } + + /** + * @param alpha + * @return This + */ + public MapboxMapOptions myLocationAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) { + this.myLocationAccuracyAlpha = alpha; return this; } @@ -580,7 +688,63 @@ public class MapboxMapOptions implements Parcelable { * @return True and user location will be shown */ public boolean getLocationEnabled() { - return locationEnabled; + return myLocationEnabled; + } + + /** + * @return + */ + public Drawable getMyLocationForegroundDrawable() { + return myLocationForegroundDrawable; + } + + /** + * @return + */ + public Drawable getMyLocationForegroundBearingDrawable() { + return myLocationForegroundBearingDrawable; + } + + /** + * @return + */ + public Drawable getMyLocationBackgroundDrawable() { + return myLocationBackgroundDrawable; + } + + /** + * @return + */ + public int getMyLocationForegroundTintColor() { + return myLocationForegroundTintColor; + } + + /** + * @return + */ + public int getMyLocationBackgroundTintColor() { + return myLocationBackgroundTintColor; + } + + /** + * @return + */ + public int[] getMyLocationBackgroundPadding() { + return myLocationBackgroundPadding; + } + + /** + * @return + */ + public int getMyLocationAccuracyTintColor() { + return myLocationAccuracyTintColor; + } + + /** + * @return + */ + public int getMyLocationAccuracyAlpha() { + return myLocationAccuracyAlpha; } /** @@ -635,9 +799,94 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (zoomControlsEnabled ? 1 : 0)); dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0)); - dest.writeByte((byte) (locationEnabled ? 1 : 0)); + dest.writeByte((byte) (myLocationEnabled ? 1 : 0)); + //myLocationForegroundDrawable; + //myLocationForegroundBearingDrawable; + //myLocationBackgroundDrawable; + dest.writeInt(myLocationForegroundTintColor); + dest.writeInt(myLocationBackgroundTintColor); + dest.writeIntArray(myLocationBackgroundPadding); + dest.writeInt(myLocationAccuracyAlpha); + dest.writeInt(myLocationAccuracyTintColor); dest.writeString(style); dest.writeString(accessToken); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MapboxMapOptions options = (MapboxMapOptions) o; + + if (debugActive != options.debugActive) return false; + if (compassEnabled != options.compassEnabled) return false; + if (compassGravity != options.compassGravity) return false; + if (logoEnabled != options.logoEnabled) return false; + if (logoGravity != options.logoGravity) return false; + if (attributionEnabled != options.attributionEnabled) return false; + if (attributionGravity != options.attributionGravity) return false; + if (Float.compare(options.minZoom, minZoom) != 0) return false; + if (Float.compare(options.maxZoom, maxZoom) != 0) return false; + if (rotateGesturesEnabled != options.rotateGesturesEnabled) return false; + if (scrollGesturesEnabled != options.scrollGesturesEnabled) return false; + if (tiltGesturesEnabled != options.tiltGesturesEnabled) return false; + if (zoomGesturesEnabled != options.zoomGesturesEnabled) return false; + if (zoomControlsEnabled != options.zoomControlsEnabled) return false; + if (myLocationEnabled != options.myLocationEnabled) return false; + if (myLocationForegroundTintColor != options.myLocationForegroundTintColor) return false; + if (myLocationBackgroundTintColor != options.myLocationBackgroundTintColor) return false; + if (myLocationAccuracyTintColor != options.myLocationAccuracyTintColor) return false; + if (myLocationAccuracyAlpha != options.myLocationAccuracyAlpha) return false; + if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null) + return false; + if (!Arrays.equals(compassMargins, options.compassMargins)) return false; + if (!Arrays.equals(logoMargins, options.logoMargins)) return false; + if (!Arrays.equals(attributionMargins, options.attributionMargins)) return false; + if (myLocationForegroundDrawable != null ? !myLocationForegroundDrawable.equals(options.myLocationForegroundDrawable) : options.myLocationForegroundDrawable != null) + return false; + if (myLocationForegroundBearingDrawable != null ? !myLocationForegroundBearingDrawable.equals(options.myLocationForegroundBearingDrawable) : options.myLocationForegroundBearingDrawable != null) + return false; + if (myLocationBackgroundDrawable != null ? !myLocationBackgroundDrawable.equals(options.myLocationBackgroundDrawable) : options.myLocationBackgroundDrawable != null) + return false; + if (!Arrays.equals(myLocationBackgroundPadding, options.myLocationBackgroundPadding)) + return false; + if (style != null ? !style.equals(options.style) : options.style != null) return false; + return accessToken != null ? accessToken.equals(options.accessToken) : options.accessToken == null; + } + + @Override + public int hashCode() { + int result = cameraPosition != null ? cameraPosition.hashCode() : 0; + result = 31 * result + (debugActive ? 1 : 0); + result = 31 * result + (compassEnabled ? 1 : 0); + result = 31 * result + compassGravity; + result = 31 * result + Arrays.hashCode(compassMargins); + result = 31 * result + (logoEnabled ? 1 : 0); + result = 31 * result + logoGravity; + result = 31 * result + Arrays.hashCode(logoMargins); + result = 31 * result + (attributionEnabled ? 1 : 0); + result = 31 * result + attributionGravity; + result = 31 * result + Arrays.hashCode(attributionMargins); + result = 31 * result + (minZoom != +0.0f ? Float.floatToIntBits(minZoom) : 0); + result = 31 * result + (maxZoom != +0.0f ? Float.floatToIntBits(maxZoom) : 0); + result = 31 * result + (rotateGesturesEnabled ? 1 : 0); + result = 31 * result + (scrollGesturesEnabled ? 1 : 0); + result = 31 * result + (tiltGesturesEnabled ? 1 : 0); + result = 31 * result + (zoomGesturesEnabled ? 1 : 0); + result = 31 * result + (zoomControlsEnabled ? 1 : 0); + result = 31 * result + (myLocationEnabled ? 1 : 0); + result = 31 * result + (myLocationForegroundDrawable != null ? myLocationForegroundDrawable.hashCode() : 0); + result = 31 * result + (myLocationForegroundBearingDrawable != null ? myLocationForegroundBearingDrawable.hashCode() : 0); + result = 31 * result + (myLocationBackgroundDrawable != null ? myLocationBackgroundDrawable.hashCode() : 0); + result = 31 * result + myLocationForegroundTintColor; + result = 31 * result + myLocationBackgroundTintColor; + result = 31 * result + Arrays.hashCode(myLocationBackgroundPadding); + result = 31 * result + myLocationAccuracyTintColor; + result = 31 * result + myLocationAccuracyAlpha; + result = 31 * result + (style != null ? style.hashCode() : 0); + result = 31 * result + (accessToken != null ? accessToken.hashCode() : 0); + return result; + } } |