use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getBlackDrawable.
/**
* 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 Drawable getBlackDrawable(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);
return baseDrawable;
}
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) {
if (baseDrawable == null) {
return null;
}
Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
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);
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;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredAccentDrawable.
/**
* 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 getColoredAccentDrawable(Context context, Drawable baseDrawable, boolean canFallBackToWhite, boolean usePrimary) {
if (baseDrawable == null) {
return null;
}
baseDrawable = baseDrawable.getConstantState().newDrawable();
int accentColor = ColorUtils.getAccentColor();
if (accentColor == ColorUtils.getPrimaryColor() && canFallBackToWhite) {
accentColor = Color.WHITE;
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (!canFallBackToWhite && sharedPreferences.getBoolean("pref_theme_white_accent", false)) {
accentColor = ColorUtils.getAccentColor(false, true);
}
if (!canFallBackToWhite && usePrimary && sharedPreferences.getBoolean("pref_theme_white_accent", false)) {
accentColor = ColorUtils.getPrimaryColor();
}
ColorFilter highlightColorFilter = new LightingColorFilter(accentColor, 0);
baseDrawable.mutate().setColorFilter(highlightColorFilter);
return baseDrawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getSemiTransparentBaseDrawable.
/**
* Takes a drawable resource and colors it according to the base color of the theme
*
* @param baseDrawableResId the resource id of the drawable to theme
* @return a themed {@link android.graphics.drawable.Drawable}
*/
public static Drawable getSemiTransparentBaseDrawable(Context context, int baseDrawableResId) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter colorFilter = new LightingColorFilter(ThemeUtils.getBaseColor(context), 0);
baseDrawable.mutate().setColorFilter(colorFilter);
baseDrawable.setAlpha(155);
return baseDrawable;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getColoredBitmap.
/**
* 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 Bitmap getColoredBitmap(Context context, int baseDrawableResId) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 0);
baseDrawable.mutate().setColorFilter(highlightColorFilter);
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;
}
Aggregations