Search in sources :

Example 11 with ColorFilter

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;
}
Also used : 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 12 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) {
    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;
}
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 13 with ColorFilter

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

Example 14 with ColorFilter

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;
}
Also used : 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 15 with ColorFilter

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;
}
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)

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