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