Search in sources :

Example 21 with LightingColorFilter

use of android.graphics.LightingColorFilter 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 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 getColoredStateListDrawable(Context context, int baseDrawableResId) {
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
    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 22 with LightingColorFilter

use of android.graphics.LightingColorFilter in project NotificationPeekPort by lzanita09.

the class NotificationHelper method getHighlightTouchListener.

public static View.OnTouchListener getHighlightTouchListener(final int color) {
    return new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            Drawable drawable = ((ImageView) view).getDrawable();
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    LightingColorFilter lighten = new LightingColorFilter(color, color);
                    drawable.setColorFilter(lighten);
                    break;
                case MotionEvent.ACTION_UP:
                    drawable.clearColorFilter();
                    break;
                case MotionEvent.ACTION_MOVE:
                    Rect rect = new Rect();
                    view.getLocalVisibleRect(rect);
                    if (!rect.contains((int) event.getX(), (int) event.getY())) {
                        drawable.clearColorFilter();
                    }
                    break;
                case MotionEvent.ACTION_OUTSIDE:
                case MotionEvent.ACTION_CANCEL:
                    drawable.clearColorFilter();
                    break;
            }
            return false;
        }
    };
}
Also used : Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 23 with LightingColorFilter

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

the class DrawerHeaderFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBackgroundDrawable = getResources().getDrawable(R.drawable.ic_drawer_header_placeholder);
    mBackgroundDrawable.setColorFilter(new LightingColorFilter(ColorUtils.getPrimaryColor(), 0x00222222));
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    mSharedPreferenceChangeListener = (sharedPreferences, key) -> {
        if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
            themeUIComponents();
        }
    };
    mPrefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);
}
Also used : LightingColorFilter(android.graphics.LightingColorFilter)

Example 24 with LightingColorFilter

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

the class NavigationDrawerAdapter method getGroupView.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    final GroupViewHolder viewHolder;
    DrawerGroupItem groupItem = getGroup(groupPosition);
    if (groupItem.type == DrawerGroupItem.Type.DIVIDER) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_drawer_divider, parent, false);
    } else {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_drawer, parent, false);
        viewHolder = new GroupViewHolder(convertView);
        viewHolder.position = groupPosition;
        convertView.setClickable(groupItem.getChildCount() == 0);
        int imageResourceId = isExpanded ? R.drawable.ic_arrow_up : R.drawable.ic_arrow_down;
        viewHolder.expandableIcon.setImageDrawable(parent.getResources().getDrawable(imageResourceId));
        viewHolder.expandableIcon.setVisibility(groupItem.getChildCount() == 0 ? View.GONE : View.VISIBLE);
        if (groupItem.iconResId != -1) {
            viewHolder.icon.setImageDrawable(DrawableUtils.themeLightOrDark(parent.getContext(), parent.getResources().getDrawable(groupItem.iconResId)));
            viewHolder.icon.setVisibility(View.VISIBLE);
        } else {
            viewHolder.icon.setVisibility(View.GONE);
        }
        viewHolder.lineOne.setText(parent.getResources().getString(groupItem.titleResId));
        viewHolder.lineOne.setTypeface(TypefaceManager.getInstance().getTypeface(TypefaceManager.SANS_SERIF_MEDIUM));
        if (mSelectedDrawerGroupItem != null && groupItem.type == mSelectedDrawerGroupItem.type) {
            viewHolder.itemView.setActivated(true);
            if (ColorUtils.isPrimaryColorLowContrast(parent.getContext())) {
                viewHolder.lineOne.setTextColor(ColorUtils.getAccentColor());
                viewHolder.icon.setColorFilter(ColorUtils.getAccentColor(), PorterDuff.Mode.MULTIPLY);
            } else {
                viewHolder.lineOne.setTextColor(ColorUtils.getPrimaryColor());
                viewHolder.icon.setColorFilter(ColorUtils.getPrimaryColor(), PorterDuff.Mode.MULTIPLY);
            }
        } else {
            viewHolder.itemView.setActivated(false);
            viewHolder.lineOne.setTextColor(ColorUtils.getTextColorPrimary());
            viewHolder.icon.setColorFilter(new LightingColorFilter(ThemeUtils.getBaseColor(parent.getContext()), 0));
            viewHolder.icon.setAlpha(0.6f);
        }
        if (groupItem.type == DrawerGroupItem.Type.FOLDERS && !ShuttleUtils.isUpgraded()) {
            viewHolder.itemView.setAlpha(0.4f);
        } else {
            viewHolder.itemView.setAlpha(1.0f);
        }
        if (groupItem.type == DrawerGroupItem.Type.PLAYLISTS) {
            viewHolder.itemView.setAlpha(groupItem.children.isEmpty() ? 0.4f : 1.0f);
            viewHolder.itemView.setEnabled(!groupItem.children.isEmpty());
        }
    }
    return convertView;
}
Also used : LightingColorFilter(android.graphics.LightingColorFilter) DrawerGroupItem(com.simplecity.amp_library.model.DrawerGroupItem)

Example 25 with LightingColorFilter

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