use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method themeLightOrDark.
/**
* Sets a drawable to the appropriate base color(light or dark) according to the theme
*
* @param drawable the drawable to theme
* @return a colored drawable
*/
public static Drawable themeLightOrDark(Context context, Drawable drawable) {
int baseColor;
if ((ThemeUtils.getInstance().themeType == ThemeUtils.ThemeType.TYPE_DARK) || (ThemeUtils.getInstance().themeType == ThemeUtils.ThemeType.TYPE_SOLID_DARK) || (ThemeUtils.getInstance().themeType == ThemeUtils.ThemeType.TYPE_SOLID_BLACK)) {
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);
drawable.setColorFilter(baseColorFilter);
return drawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredFastScrollDrawable.
/**
* @return an {@link FilterableStateListDrawable} representing the themed FastScroll thumb
*/
public static Drawable getColoredFastScrollDrawable(Context context, boolean dontTint) {
ColorFilter highlightColorFilter;
if (dontTint) {
highlightColorFilter = new LightingColorFilter(context.getResources().getColor(R.color.white), 0);
} else {
highlightColorFilter = new LightingColorFilter(ColorUtils.getAccentColor(), 0);
}
FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
if (ShuttleUtils.hasLollipopMR1()) {
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, CompatUtils.getDrawableCompat(context, R.drawable.fastscroll_thumb_material), highlightColorFilter);
stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_material)), highlightColorFilter);
} else if (ShuttleUtils.hasLollipop()) {
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(R.drawable.fastscroll_thumb_mtrl_alpha), highlightColorFilter);
stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_mtrl_alpha)), highlightColorFilter);
} else {
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(R.drawable.fastscroll_thumb_pressed), highlightColorFilter);
stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_default)), highlightColorFilter);
}
return stateListDrawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getWhiteDrawable.
/**
* Takes a drawable resource and turns it white
*
* @param baseDrawableResId the resource id of the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getWhiteDrawable(Context context, int baseDrawableResId) {
if (context == null) {
return null;
}
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter colorFilter = new LightingColorFilter(context.getResources().getColor(R.color.white), 0);
baseDrawable.mutate().setColorFilter(colorFilter);
return baseDrawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class ThemeUtils method themeSearchView.
@SuppressLint("InlinedApi")
public static void themeSearchView(Context context, SearchView searchView) {
FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
NinePatchDrawable disabledDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_default_mtrl_alpha);
NinePatchDrawable otherDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_activated_mtrl_alpha);
int accentColor = ColorUtils.getAccentColor();
ColorFilter colorFilter = new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_activated }, otherDrawable, colorFilter);
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, otherDrawable, colorFilter);
stateListDrawable.addState(StateSet.WILD_CARD, disabledDrawable);
View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
searchPlate.setBackground(stateListDrawable);
EditText searchTextView = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
try {
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(searchTextView, 0);
} catch (final Exception | NoClassDefFoundError ignored) {
}
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredStateListDrawable.
/**
* 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 getColoredStateListDrawable(Context context, Drawable baseDrawable, int highlightColor) {
if (baseDrawable == null) {
return null;
}
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
ColorFilter baseColorFilter = new LightingColorFilter(highlightColor, 0);
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getAccentColor(), 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;
}
Aggregations