diff options
author | Tobrun <tobrun@mapbox.com> | 2016-04-26 09:00:56 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-04-26 12:28:36 +0200 |
commit | 3602fdc040de9dfd700e9130d8db68e045f133db (patch) | |
tree | 965b77296b30ae5cb6fe733831313bd555df7ab3 /platform/android/MapboxGLAndroidSDK/src/main | |
parent | 4770a9eb21450bbc002201de81b2310287935d67 (diff) | |
download | qtlocation-mapboxgl-3602fdc040de9dfd700e9130d8db68e045f133db.tar.gz |
[android] #3231 - added support for automatic tinting ui components used the client developer material colors
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main')
4 files changed, 113 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index c9878f8751..e0bd4eef38 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -19,6 +19,7 @@ import android.graphics.Canvas; import android.graphics.PointF; import android.graphics.RectF; import android.graphics.SurfaceTexture; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.location.Location; import android.net.ConnectivityManager; @@ -86,6 +87,7 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; import com.mapbox.mapboxsdk.maps.widgets.UserLocationView; import com.mapbox.mapboxsdk.telemetry.MapboxEvent; import com.mapbox.mapboxsdk.telemetry.MapboxEventManager; +import com.mapbox.mapboxsdk.utils.ColorUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -311,6 +313,7 @@ public class MapView extends FrameLayout { } // Attribution + ColorUtils.setTintList(mAttributionsView); uiSettings.setAttributionEnabled(options.getAttributionEnabled()); uiSettings.setAttributionGravity(options.getAttributionGravity()); int[] attributionMargins = options.getAttributionMargins(); @@ -2561,7 +2564,8 @@ public class MapView extends FrameLayout { AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); builder.setTitle(R.string.attributionsDialogTitle); builder.setAdapter(new ArrayAdapter<>(context, R.layout.attribution_list_item, items), this); - builder.show(); + AlertDialog dialog = builder.show(); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(ColorUtils.getPrimaryColor(context))); } // Called when someone selects an attribution, 'Improve this map' adds location data to the url diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java index 4c09402924..931c799d10 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/UserLocationView.java @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.maps.widgets; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.PointF; import android.graphics.PorterDuff; @@ -36,6 +37,7 @@ import com.mapbox.mapboxsdk.location.LocationServices; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Projection; import com.mapbox.mapboxsdk.maps.UiSettings; +import com.mapbox.mapboxsdk.utils.ColorUtils; import java.lang.ref.WeakReference; @@ -112,8 +114,12 @@ public class UserLocationView extends View { // default implementation setShadowDrawable(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_shadow)); + setShadowDrawableTint(ColorUtils.getPrimaryDarkColor(context)); + setForegroundDrawables(ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_normal), ContextCompat.getDrawable(context, R.drawable.ic_userlocationview_bearing)); - accuracyPaint.setColor(ContextCompat.getColor(context, R.color.mapbox_blue)); + setForegroundDrawableTint(ColorUtils.getPrimaryColor(context)); + + accuracyPaint.setColor(ColorUtils.getAccentColor(context)); accuracyPaint.setAlpha(100); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java new file mode 100644 index 0000000000..972011b7f9 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java @@ -0,0 +1,101 @@ +package com.mapbox.mapboxsdk.utils; + +import android.content.Context; +import android.content.res.ColorStateList; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.util.TypedValue; +import android.widget.ImageView; + +import com.mapbox.mapboxsdk.R; + +public class ColorUtils { + + /** + * Returns a color integer associated as primary color from a theme based on a {@link Context}. + * + * @param context The context used to style the color attributes. + * @return The primary color value of current theme in the form 0xAARRGGBB. + */ + @ColorInt + public static int getPrimaryColor(@NonNull Context context) { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + theme.resolveAttribute(R.attr.colorPrimary, typedValue, true); + return typedValue.data; + } + + /** + * Returns a color integer associated as primary dark color from a theme based on a {@link Context}. + * + * @param context The context used to style the color attributes. + * @return The primary dark color value of current theme in the form 0xAARRGGBB. + */ + @ColorInt + public static int getPrimaryDarkColor(@NonNull Context context) { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); + return typedValue.data; + } + + /** + * Returns a color integer associated as accent color from a theme based on a {@link Context}. + * + * @param context The context used to style the color attributes. + * @return The accent color value of current theme in the form 0xAARRGGBB. + */ + @ColorInt + public static int getAccentColor(@NonNull Context context) { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = context.getTheme(); + theme.resolveAttribute(R.attr.colorAccent, typedValue, true); + return typedValue.data; + } + + /** + * Returns a color state list associated with a theme based on a {@link Context} + * + * @param context The context used to style the color attributes. + * @return A ColorStateList object containing the primary color of a theme + */ + @NonNull + public static ColorStateList getSelector(@NonNull Context context) { + return new ColorStateList( + new int[][]{ + new int[]{android.R.attr.state_pressed}, + new int[]{} + }, + new int[]{ + getPrimaryColor(context), + getPrimaryColor(context) + } + ); + } + + /** + * Set a primary color tint list to the {@link Drawable} of an {@link ImageView}. + * + * @param imageView The view to set the default tint list. + */ + public static void setTintList(@NonNull ImageView imageView) { + Drawable originalDrawable = imageView.getDrawable(); + Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); + DrawableCompat.setTintList(wrappedDrawable, getSelector(imageView.getContext())); + } + + /** + * Set a primary color tint to a {@link Drawable}. + * + * @param context The context used to style the color attributes. + * @param drawable The drawable to tint. + */ + public static void setTint(@NonNull Context context, @NonNull Drawable drawable) { + Drawable wrappedDrawable = DrawableCompat.wrap(drawable); + DrawableCompat.setTint(wrappedDrawable, ColorUtils.getPrimaryColor(context)); + } + +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml index 9ad12f76ad..a46f58ae80 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml @@ -4,7 +4,6 @@ <!-- these are public --> <style name="AttributionAlertDialogStyle" parent="Theme.AppCompat.Dialog.Alert"> <item name="android:textColorPrimary">@android:color/white</item> - <item name="android:background">@color/mapbox_blue</item> </style> </resources>
\ No newline at end of file |