Search in sources :

Example 26 with LightingColorFilter

use of android.graphics.LightingColorFilter 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;
}
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 27 with LightingColorFilter

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

the class ThemeUtils method setFastscrollDrawable.

/**
     * Uses reflection to find the FastScroll drawable and themes it
     *
     * @param listView the {@link android.widget.AbsListView} to theme
     */
public static void setFastscrollDrawable(Context context, AbsListView listView) {
    try {
        Object object;
        java.lang.reflect.Field field;
        if (ShuttleUtils.hasAndroidLPreview()) {
            field = AbsListView.class.getDeclaredField("mFastScroll");
        } else {
            field = AbsListView.class.getDeclaredField("mFastScroller");
        }
        field.setAccessible(true);
        object = field.get(listView);
        //Theme the fastscroll thumb
        if (ShuttleUtils.hasKitKat()) {
            Field thumbField = field.getType().getDeclaredField("mThumbImage");
            thumbField.setAccessible(true);
            ImageView imageView = (ImageView) thumbField.get(object);
            Drawable drawable = DrawableUtils.getColoredFastScrollDrawable(context, false);
            imageView.setImageDrawable(drawable);
            thumbField.set(object, imageView);
        } else {
            Field thumbField = field.getType().getDeclaredField("mThumbDrawable");
            thumbField.setAccessible(true);
            Drawable drawable = DrawableUtils.getColoredFastScrollDrawable(context, false);
            thumbField.set(object, drawable);
        }
        //Theme the SectionIndexer overlay ('Preview Image')
        if (ShuttleUtils.hasLollipop()) {
            Field previewImageField = field.getType().getDeclaredField("mPreviewImage");
            previewImageField.setAccessible(true);
            View view = (View) previewImageField.get(object);
            Drawable drawable = CompatUtils.getDrawableCompat(context, R.drawable.fastscroll_label_right_material);
            drawable.setColorFilter(new LightingColorFilter((ColorUtils.getAccentColor()), 0));
            view.setBackground(drawable);
            previewImageField.set(object, view);
        }
    } catch (Exception ignored) {
    }
}
Also used : Field(java.lang.reflect.Field) ColorDrawable(android.graphics.drawable.ColorDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LightingColorFilter(android.graphics.LightingColorFilter) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) Field(java.lang.reflect.Field) 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)

Example 28 with LightingColorFilter

use of android.graphics.LightingColorFilter 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 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 getColoredStateListDrawableWithThemeColor(Context context, int baseDrawableResId, @ThemeUtils.ThemeColor int color) {
    if (context == null) {
        return null;
    }
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
    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;
}
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 29 with LightingColorFilter

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

the class DrawableUtils method getColoredDrawable.

/**
     * Takes a drawable and applies the passed in color to it
     *
     * @param baseDrawable the drawable to theme
     * @return a themed {@link android.graphics.drawable.Drawable}
     */
public static Drawable getColoredDrawable(Drawable baseDrawable, int color) {
    if (baseDrawable == null) {
        return null;
    }
    ColorFilter colorFilter = new LightingColorFilter(color, 0);
    baseDrawable.mutate().setColorFilter(colorFilter);
    return baseDrawable;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LightingColorFilter(android.graphics.LightingColorFilter)

Example 30 with LightingColorFilter

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

the class DrawableUtils method getColoredDrawable.

/**
     * 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 Drawable getColoredDrawable(Context context, int baseDrawableResId) {
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).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) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Aggregations

LightingColorFilter (android.graphics.LightingColorFilter)32 ColorFilter (android.graphics.ColorFilter)20 Drawable (android.graphics.drawable.Drawable)18 LayerDrawable (android.graphics.drawable.LayerDrawable)17 FilterableStateListDrawable (com.simplecity.amp_library.ui.views.FilterableStateListDrawable)16 ImageView (android.widget.ImageView)5 View (android.view.View)4 Canvas (android.graphics.Canvas)3 TextView (android.widget.TextView)3 Bitmap (android.graphics.Bitmap)2 SearchView (android.support.v7.widget.SearchView)2 LayoutInflater (android.view.LayoutInflater)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1