use of android.graphics.LightingColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredStateListDrawableWithThemeColor.
/**
* Returns a {@link FilterableStateListDrawable}, coloring the passed in
* drawable according to the theme and the passed in highlight color
*
* @param baseDrawable the drawable to use
* @return an {@link FilterableStateListDrawable}, coloring the passed in
* drawable according to the theme and the passed in highlight color
*/
public static Drawable getColoredStateListDrawableWithThemeColor(Context context, Drawable baseDrawable, @ThemeUtils.ThemeColor int color) {
if (baseDrawable == null) {
return null;
}
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
int baseColor;
if (color == ThemeUtils.WHITE) {
baseColor = context.getResources().getColor(R.color.drawable_base_color_dark);
} else {
baseColor = context.getResources().getColor(R.color.drawable_base_color_light);
}
ColorFilter baseColorFilter = new LightingColorFilter(baseColor, 0);
int accentColor = ColorUtils.getAccentColor();
if (accentColor == ColorUtils.getPrimaryColor()) {
accentColor = Color.WHITE;
}
ColorFilter highlightColorFilter = new LightingColorFilter(accentColor, 0);
FilterableStateListDrawable filterableStateListDrawable = new FilterableStateListDrawable();
filterableStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, baseDrawable, highlightColorFilter);
filterableStateListDrawable.addState(StateSet.WILD_CARD, highlightDrawable, baseColorFilter);
return filterableStateListDrawable;
}
use of android.graphics.LightingColorFilter in project Shuttle by timusus.
the class ThemeUtils method setFastscrollDrawable.
/**
* Uses reflection to find the FastScroll drawable and themes it
*
* @param listView the {@link android.widget.AbsListView} to theme
*/
public static void setFastscrollDrawable(Context context, AbsListView listView) {
try {
Object object;
java.lang.reflect.Field field;
if (ShuttleUtils.hasAndroidLPreview()) {
field = AbsListView.class.getDeclaredField("mFastScroll");
} else {
field = AbsListView.class.getDeclaredField("mFastScroller");
}
field.setAccessible(true);
object = field.get(listView);
//Theme the fastscroll thumb
if (ShuttleUtils.hasKitKat()) {
Field thumbField = field.getType().getDeclaredField("mThumbImage");
thumbField.setAccessible(true);
ImageView imageView = (ImageView) thumbField.get(object);
Drawable drawable = DrawableUtils.getColoredFastScrollDrawable(context, false);
imageView.setImageDrawable(drawable);
thumbField.set(object, imageView);
} else {
Field thumbField = field.getType().getDeclaredField("mThumbDrawable");
thumbField.setAccessible(true);
Drawable drawable = DrawableUtils.getColoredFastScrollDrawable(context, false);
thumbField.set(object, drawable);
}
//Theme the SectionIndexer overlay ('Preview Image')
if (ShuttleUtils.hasLollipop()) {
Field previewImageField = field.getType().getDeclaredField("mPreviewImage");
previewImageField.setAccessible(true);
View view = (View) previewImageField.get(object);
Drawable drawable = CompatUtils.getDrawableCompat(context, R.drawable.fastscroll_label_right_material);
drawable.setColorFilter(new LightingColorFilter((ColorUtils.getAccentColor()), 0));
view.setBackground(drawable);
previewImageField.set(object, view);
}
} catch (Exception ignored) {
}
}
use of android.graphics.LightingColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredStateListDrawableWithThemeColor.
/**
* Returns a {@link FilterableStateListDrawable}, coloring the passed in
* drawable according to the theme and the passed in highlight color
*
* @param baseDrawableResId the drawable to use
* @return an {@link FilterableStateListDrawable}, coloring the passed in
* drawable according to the theme and the passed in highlight color
*/
public static Drawable getColoredStateListDrawableWithThemeColor(Context context, int baseDrawableResId, @ThemeUtils.ThemeColor int color) {
if (context == null) {
return null;
}
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
int baseColor;
if (color == ThemeUtils.WHITE) {
baseColor = context.getResources().getColor(R.color.drawable_base_color_dark);
} else {
baseColor = context.getResources().getColor(R.color.drawable_base_color_light);
}
ColorFilter baseColorFilter = new LightingColorFilter(baseColor, 0);
int accentColor = ColorUtils.getAccentColor();
if (accentColor == ColorUtils.getPrimaryColor()) {
accentColor = Color.WHITE;
}
ColorFilter highlightColorFilter = new LightingColorFilter(accentColor, 0);
FilterableStateListDrawable filterableStateListDrawable = new FilterableStateListDrawable();
filterableStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, baseDrawable, highlightColorFilter);
filterableStateListDrawable.addState(StateSet.WILD_CARD, highlightDrawable, baseColorFilter);
return filterableStateListDrawable;
}
use of android.graphics.LightingColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredDrawable.
/**
* Takes a drawable and applies the passed in color to it
*
* @param baseDrawable the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getColoredDrawable(Drawable baseDrawable, int color) {
if (baseDrawable == null) {
return null;
}
ColorFilter colorFilter = new LightingColorFilter(color, 0);
baseDrawable.mutate().setColorFilter(colorFilter);
return baseDrawable;
}
use of android.graphics.LightingColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredDrawable.
/**
* Takes a drawable resource and applies the current theme highlight color to it
*
* @param baseDrawableResId the resource id of the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getColoredDrawable(Context context, int baseDrawableResId) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 0);
baseDrawable.mutate().setColorFilter(highlightColorFilter);
return baseDrawable;
}
Aggregations