[android] #3231 - added support for automatic tinting ui components used the client developer material colors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user