diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src')
3 files changed, 85 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java index 27ecb7520b..d321c3ec59 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java @@ -4,14 +4,18 @@ import android.app.Fragment; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; + import com.mapbox.mapboxsdk.MapboxAccountManager; +import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException; @@ -59,6 +63,7 @@ public final class MapFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + Context context = inflater.getContext(); MapboxMapOptions options = null; // Get bundle @@ -84,6 +89,23 @@ public final class MapFragment extends Fragment { options.accessToken(token); } } + + Drawable foregroundDrawable = options.getMyLocationForegroundDrawable(); + Drawable foregroundBearingDrawable = options.getMyLocationForegroundBearingDrawable(); + if (foregroundDrawable == null || foregroundBearingDrawable == null) { + if (foregroundDrawable == null) { + foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_normal); + } + if (foregroundBearingDrawable == null) { + foregroundBearingDrawable = ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_bearing); + } + options.myLocationForegroundDrawables(foregroundDrawable, foregroundBearingDrawable); + } + + if (options.getMyLocationBackgroundDrawable() == null) { + options.myLocationBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_background)); + } + return mMap = new MapView(inflater.getContext(), options); } 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); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java index 3d96727758..9fb97cce1f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java @@ -3,15 +3,19 @@ package com.mapbox.mapboxsdk.maps; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; + import com.mapbox.mapboxsdk.MapboxAccountManager; +import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException; @@ -68,6 +72,7 @@ public class SupportMapFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + Context context = inflater.getContext(); MapboxMapOptions options = null; // Get bundle @@ -93,6 +98,23 @@ public class SupportMapFragment extends Fragment { options.accessToken(token); } } + + Drawable foregroundDrawable = options.getMyLocationForegroundDrawable(); + Drawable foregroundBearingDrawable = options.getMyLocationForegroundBearingDrawable(); + if (foregroundDrawable == null || foregroundBearingDrawable == null) { + if (foregroundDrawable == null) { + foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_normal); + } + if (foregroundBearingDrawable == null) { + foregroundBearingDrawable = ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_bearing); + } + options.myLocationForegroundDrawables(foregroundDrawable, foregroundBearingDrawable); + } + + if (options.getMyLocationBackgroundDrawable() == null) { + options.myLocationBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ic_mylocationview_background)); + } + return mMap = new MapView(inflater.getContext(), options); } |