diff options
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 | 45 |
1 files changed, 44 insertions, 1 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 6467033ead..2fd02c76e5 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 @@ -47,6 +47,7 @@ public class MapboxMapOptions implements Parcelable { private boolean fadeCompassFacingNorth = true; private int compassGravity = Gravity.TOP | Gravity.END; private int[] compassMargins; + private Drawable compassImage; private boolean logoEnabled = true; private int logoGravity = Gravity.BOTTOM | Gravity.START; @@ -100,6 +101,11 @@ public class MapboxMapOptions implements Parcelable { compassMargins = in.createIntArray(); fadeCompassFacingNorth = in.readByte() != 0; + Bitmap compassBitmap = in.readParcelable(getClass().getClassLoader()); + if (compassBitmap != null) { + compassImage = new BitmapDrawable(compassBitmap); + } + logoEnabled = in.readByte() != 0; logoGravity = in.readInt(); logoMargins = in.createIntArray(); @@ -147,7 +153,7 @@ public class MapboxMapOptions implements Parcelable { textureMode = in.readByte() != 0; } - public static Bitmap getBitmapFromDrawable(Drawable drawable) { + static Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } else { @@ -208,6 +214,12 @@ public class MapboxMapOptions implements Parcelable { DIMENSION_TEN_DP * pxlRatio))}); mapboxMapOptions.compassFadesWhenFacingNorth(typedArray.getBoolean( R.styleable.mapbox_MapView_mapbox_uiCompassFadeFacingNorth, true)); + Drawable compassDrawable = typedArray.getDrawable( + R.styleable.mapbox_MapView_mapbox_uiCompassDrawable); + if (compassDrawable == null) { + compassDrawable = ContextCompat.getDrawable(context, R.drawable.mapbox_compass_icon); + } + mapboxMapOptions.compassImage(compassDrawable); mapboxMapOptions.logoEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiLogo, true)); mapboxMapOptions.logoGravity(typedArray.getInt(R.styleable.mapbox_MapView_mapbox_uiLogoGravity, @@ -401,6 +413,20 @@ public class MapboxMapOptions implements Parcelable { } /** + * Specifies the image of the CompassView. + * <p> + * By default this value is R.drawable.mapbox_compass_icon. + * </p> + * + * @param compass the drawable to show as image compass + * @return This + */ + public MapboxMapOptions compassImage(Drawable compass) { + this.compassImage = compass; + return this; + } + + /** * Specifies the visibility state of a logo for a map view. * * @param enabled True and logo is shown @@ -743,6 +769,15 @@ public class MapboxMapOptions implements Parcelable { } /** + * Get the current configured CompassView image. + * + * @return the drawable used as compass image + */ + public Drawable getCompassImage() { + return compassImage; + } + + /** * Get the current configured visibility state for mapbox_compass_icon for a map view. * * @return Visibility state of the mapbox_compass_icon @@ -993,6 +1028,8 @@ public class MapboxMapOptions implements Parcelable { dest.writeInt(compassGravity); dest.writeIntArray(compassMargins); dest.writeByte((byte) (fadeCompassFacingNorth ? 1 : 0)); + dest.writeParcelable(compassImage != null + ? getBitmapFromDrawable(compassImage) : null, flags); dest.writeByte((byte) (logoEnabled ? 1 : 0)); dest.writeInt(logoGravity); @@ -1052,6 +1089,11 @@ public class MapboxMapOptions implements Parcelable { if (fadeCompassFacingNorth != options.fadeCompassFacingNorth) { return false; } + if (compassImage != null + ? !compassImage.equals(options.compassImage) + : options.compassImage != null) { + return false; + } if (compassGravity != options.compassGravity) { return false; } @@ -1157,6 +1199,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (compassEnabled ? 1 : 0); result = 31 * result + (fadeCompassFacingNorth ? 1 : 0); result = 31 * result + compassGravity; + result = 31 * result + (compassImage != null ? compassImage.hashCode() : 0); result = 31 * result + Arrays.hashCode(compassMargins); result = 31 * result + (logoEnabled ? 1 : 0); result = 31 * result + logoGravity; |