Search in sources :

Example 6 with ColorFilter

use of android.graphics.ColorFilter in project Shuttle by timusus.

the class DrawableUtils method themeLightOrDark.

/**
     * Sets a drawable to the appropriate base color(light or dark) according to the theme
     *
     * @param drawable the drawable to theme
     * @return a colored drawable
     */
public static Drawable themeLightOrDark(Context context, Drawable drawable) {
    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);
    drawable.setColorFilter(baseColorFilter);
    return drawable;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LightingColorFilter(android.graphics.LightingColorFilter)

Example 7 with ColorFilter

use of android.graphics.ColorFilter in project Shuttle by timusus.

the class DrawableUtils method getColoredFastScrollDrawable.

/**
     * @return an {@link FilterableStateListDrawable} representing the themed FastScroll thumb
     */
public static Drawable getColoredFastScrollDrawable(Context context, boolean dontTint) {
    ColorFilter highlightColorFilter;
    if (dontTint) {
        highlightColorFilter = new LightingColorFilter(context.getResources().getColor(R.color.white), 0);
    } else {
        highlightColorFilter = new LightingColorFilter(ColorUtils.getAccentColor(), 0);
    }
    FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
    if (ShuttleUtils.hasLollipopMR1()) {
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, CompatUtils.getDrawableCompat(context, R.drawable.fastscroll_thumb_material), highlightColorFilter);
        stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_material)), highlightColorFilter);
    } else if (ShuttleUtils.hasLollipop()) {
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(R.drawable.fastscroll_thumb_mtrl_alpha), highlightColorFilter);
        stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_mtrl_alpha)), highlightColorFilter);
    } else {
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(R.drawable.fastscroll_thumb_pressed), highlightColorFilter);
        stateListDrawable.addState(StateSet.WILD_CARD, CompatUtils.getDrawableCompat(context, (R.drawable.fastscroll_thumb_default)), highlightColorFilter);
    }
    return stateListDrawable;
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LightingColorFilter(android.graphics.LightingColorFilter)

Example 8 with ColorFilter

use of android.graphics.ColorFilter in project Shuttle by timusus.

the class DrawableUtils method getWhiteDrawable.

/**
     * Takes a drawable resource and turns it white
     *
     * @param baseDrawableResId the resource id of the drawable to theme
     * @return a themed {@link android.graphics.drawable.Drawable}
     */
public static Drawable getWhiteDrawable(Context context, int baseDrawableResId) {
    if (context == null) {
        return null;
    }
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
    ColorFilter colorFilter = new LightingColorFilter(context.getResources().getColor(R.color.white), 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 9 with ColorFilter

use of android.graphics.ColorFilter in project Shuttle by timusus.

the class ThemeUtils method themeSearchView.

@SuppressLint("InlinedApi")
public static void themeSearchView(Context context, SearchView searchView) {
    FilterableStateListDrawable stateListDrawable = new FilterableStateListDrawable();
    NinePatchDrawable disabledDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_default_mtrl_alpha);
    NinePatchDrawable otherDrawable = (NinePatchDrawable) CompatUtils.getDrawableCompat(context, R.drawable.abc_textfield_search_activated_mtrl_alpha);
    int accentColor = ColorUtils.getAccentColor();
    ColorFilter colorFilter = new PorterDuffColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_activated }, otherDrawable, colorFilter);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, otherDrawable, colorFilter);
    stateListDrawable.addState(StateSet.WILD_CARD, disabledDrawable);
    View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    searchPlate.setBackground(stateListDrawable);
    EditText searchTextView = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    try {
        Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
        mCursorDrawableRes.setAccessible(true);
        mCursorDrawableRes.set(searchTextView, 0);
    } catch (final Exception | NoClassDefFoundError ignored) {
    }
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) AppCompatEditText(android.support.v7.widget.AppCompatEditText) EditText(android.widget.EditText) Field(java.lang.reflect.Field) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) HmsView(com.doomonafireball.betterpickers.hmspicker.HmsView) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) SuppressLint(android.annotation.SuppressLint)

Example 10 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, int highlightColor) {
    if (baseDrawable == null) {
        return null;
    }
    Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
    ColorFilter baseColorFilter = new LightingColorFilter(highlightColor, 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)

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