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, boolean inverted) {
if (baseDrawable == null) {
return null;
}
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
int baseColor;
if (!inverted) {
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);
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 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.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredStateListDrawableWithThemeType.
/**
* 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 getColoredStateListDrawableWithThemeType(Context context, int baseDrawableResId, @ThemeUtils.ThemeType int themeType) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
int baseColor;
if ((themeType == ThemeUtils.ThemeType.TYPE_DARK) || (themeType == ThemeUtils.ThemeType.TYPE_SOLID_DARK) || (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);
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 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.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getBlackBitmap.
/**
* Takes a drawable resource and turns it black
*
* @param baseDrawableResId the resource id of the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Bitmap getBlackBitmap(Context context, int baseDrawableResId) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter colorFilter = new LightingColorFilter(context.getResources().getColor(R.color.black), 0);
baseDrawable.mutate().setColorFilter(colorFilter);
Bitmap bitmap = Bitmap.createBitmap(baseDrawable.getIntrinsicWidth(), baseDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
baseDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
baseDrawable.draw(canvas);
return bitmap;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredDrawable.
/**
* Takes a drawable and applies the current theme highlight color to it
*
* @param baseDrawable the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getColoredDrawable(Context context, Drawable baseDrawable) {
if (baseDrawable == null) {
return null;
}
baseDrawable = baseDrawable.getConstantState().newDrawable();
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 0);
baseDrawable.mutate().setColorFilter(highlightColorFilter);
return baseDrawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredAccentFABDrawable.
/**
* Takes a drawable and applies the current theme accent color to it
*
* @param baseDrawable the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getColoredAccentFABDrawable(Context context, Drawable baseDrawable) {
if (baseDrawable == null) {
return null;
}
baseDrawable = baseDrawable.getConstantState().newDrawable();
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getFloatingActionIconColor(context), 0);
baseDrawable.mutate().setColorFilter(highlightColorFilter);
return baseDrawable;
}
Aggregations