Search in sources :

Example 16 with ColorFilter

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;
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 17 with ColorFilter

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;
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 18 with ColorFilter

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;
}
Also used : Bitmap(android.graphics.Bitmap) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) Canvas(android.graphics.Canvas) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 19 with ColorFilter

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;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LightingColorFilter(android.graphics.LightingColorFilter)

Example 20 with ColorFilter

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;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LightingColorFilter(android.graphics.LightingColorFilter)

Aggregations

ColorFilter (android.graphics.ColorFilter)50 LightingColorFilter (android.graphics.LightingColorFilter)21 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)17 Drawable (android.graphics.drawable.Drawable)17 FilterableStateListDrawable (com.simplecity.amp_library.ui.views.FilterableStateListDrawable)16 Paint (android.graphics.Paint)14 LayerDrawable (android.graphics.drawable.LayerDrawable)14 Path (android.graphics.Path)5 RectF (android.graphics.RectF)5 Test (org.junit.Test)5 Bitmap (android.graphics.Bitmap)4 Canvas (android.graphics.Canvas)4 Rect (android.graphics.Rect)3 Shader (android.graphics.Shader)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 FilterableStateListDrawable (com.bilibili.magicasakura.drawables.FilterableStateListDrawable)2