diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-08-29 13:43:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-29 13:43:22 +0200 |
commit | 1d66eda14b221496d9bf687e45e37f704f0778c7 (patch) | |
tree | d2a9d462a1a3a3906d42fbbbdbd50ef6b7c56001 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java | |
parent | 7af5542226e908989f2ded7eab46d4b09ec22f18 (diff) | |
download | qtlocation-mapboxgl-1d66eda14b221496d9bf687e45e37f704f0778c7.tar.gz |
[android] #5875 - MapboxMap options not parceling drawables (#5984)
* [android] #5875 - MapboxMap options not parceling the MyLocationView drawables
* [android] #5875 - disabled parceable test for bitmaps
* [android] #5876 - correct restoration of bitmapdrawable for unit test
* disable check for drawable type
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 | 47 |
1 files changed, 41 insertions, 6 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 42609b8265..14c3a4da79 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,14 +2,20 @@ package com.mapbox.mapboxsdk.maps; import android.content.Context; import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.VectorDrawable; 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.graphics.drawable.VectorDrawableCompat; import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import android.view.Gravity; @@ -110,9 +116,22 @@ public class MapboxMapOptions implements Parcelable { zoomGesturesEnabled = in.readByte() != 0; myLocationEnabled = in.readByte() != 0; - //myLocationForegroundDrawable; - //myLocationForegroundBearingDrawable; - //myLocationBackgroundDrawable; + + Bitmap foregroundBitmap = in.readParcelable(getClass().getClassLoader()); + if (foregroundBitmap != null) { + myLocationForegroundDrawable = new BitmapDrawable(foregroundBitmap); + } + + Bitmap foregroundBearingBitmap = in.readParcelable(getClass().getClassLoader()); + if(foregroundBearingBitmap!=null) { + myLocationForegroundBearingDrawable = new BitmapDrawable(foregroundBearingBitmap); + } + + Bitmap backgroundBitmap = in.readParcelable(getClass().getClassLoader()); + if(backgroundBitmap!=null){ + myLocationBackgroundDrawable = new BitmapDrawable(backgroundBitmap); + } + myLocationForegroundTintColor = in.readInt(); myLocationBackgroundTintColor = in.readInt(); myLocationBackgroundPadding = in.createIntArray(); @@ -123,6 +142,18 @@ public class MapboxMapOptions implements Parcelable { accessToken = in.readString(); } + public static Bitmap getBitmapFromDrawable(Drawable drawable) { + if (drawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap(); + } else { + Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + return bitmap; + } + } + /** * Creates a MapboxMapsOptions from the attribute set.s * @@ -871,9 +902,10 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (myLocationEnabled ? 1 : 0)); - //myLocationForegroundDrawable; - //myLocationForegroundBearingDrawable; - //myLocationBackgroundDrawable; + + dest.writeParcelable(myLocationForegroundDrawable != null ? getBitmapFromDrawable(myLocationForegroundDrawable) : null, flags); + dest.writeParcelable(myLocationForegroundBearingDrawable != null ? getBitmapFromDrawable(myLocationForegroundBearingDrawable) : null, flags); + dest.writeParcelable(myLocationBackgroundDrawable != null ? getBitmapFromDrawable(myLocationBackgroundDrawable) : null, flags); dest.writeInt(myLocationForegroundTintColor); dest.writeInt(myLocationBackgroundTintColor); dest.writeIntArray(myLocationBackgroundPadding); @@ -896,6 +928,7 @@ public class MapboxMapOptions implements Parcelable { if (compassGravity != options.compassGravity) return false; if (logoEnabled != options.logoEnabled) return false; if (logoGravity != options.logoGravity) return false; + if (attributionTintColor != options.attributionTintColor) return false; if (attributionEnabled != options.attributionEnabled) return false; if (attributionGravity != options.attributionGravity) return false; if (Float.compare(options.minZoom, minZoom) != 0) return false; @@ -925,6 +958,7 @@ public class MapboxMapOptions implements Parcelable { 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 @@ -937,6 +971,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (logoEnabled ? 1 : 0); result = 31 * result + logoGravity; result = 31 * result + Arrays.hashCode(logoMargins); + result = 31 * result + attributionTintColor; result = 31 * result + (attributionEnabled ? 1 : 0); result = 31 * result + attributionGravity; result = 31 * result + Arrays.hashCode(attributionMargins); |