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 = ContextCompat.getDrawable(context, baseDrawableResId).getConstantState().newDrawable();
ColorFilter colorFilter = new LightingColorFilter(ContextCompat.getColor(context, 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 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 = ContextCompat.getDrawable(context, baseDrawableResId).getConstantState().newDrawable();
ColorFilter highlightColorFilter = new LightingColorFilter(Aesthetic.get(context).colorPrimary().blockingFirst(), 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;
}
use of android.graphics.ColorFilter in project remusic by aa112901.
the class StateListDrawableUtils method inflateDrawable.
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
StateListDrawable sd = null;
ArrayList<int[]> states = new ArrayList<>();
ArrayList<Drawable> drawables = new ArrayList<>();
SparseArray<ColorFilter> mColorFilterMap = null;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
Drawable dr = getAttrDrawable(context, attrs, android.R.attr.drawable);
states.add(extractStateSet(attrs));
// attributes and extracting states.
if (dr == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
dr = createFromXmlInner(context, parser, attrs);
} else {
ColorFilter colorFilter = getAttrColorFilter(context, attrs, R.attr.drawableTint, R.attr.drawableTintMode);
if (colorFilter != null) {
if (mColorFilterMap == null) {
mColorFilterMap = new SparseArray<>();
}
mColorFilterMap.put(drawables.size(), colorFilter);
}
}
drawables.add(dr);
}
if (states.size() >= 1) {
if (mColorFilterMap != null) {
sd = new FilterableStateListDrawable();
for (int i = 0; i < states.size(); i++) {
((FilterableStateListDrawable) sd).addState(states.get(i), drawables.get(i), mColorFilterMap.get(i));
}
} else {
sd = new StateListDrawable();
for (int i = 0; i < states.size(); i++) {
sd.addState(states.get(i), drawables.get(i));
}
}
}
return sd;
}
use of android.graphics.ColorFilter in project Shuttle by timusus.
the class DrawableUtils method getBaseDrawable.
/**
* 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 getBaseDrawable(Context context, int baseDrawableResId) {
Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
ColorFilter colorFilter = new LightingColorFilter(ThemeUtils.getBaseColor(context), 0);
baseDrawable.mutate().setColorFilter(colorFilter);
return baseDrawable;
}
use of android.graphics.ColorFilter 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;
}
Aggregations