List of usage examples for android.graphics.drawable Drawable setColorFilter
public abstract void setColorFilter(@Nullable ColorFilter colorFilter);
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static void converToGrayscale(Drawable drawable) { ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0);/*from www .ja v a 2 s . c o m*/ ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); drawable.setColorFilter(filter); }
From source file:xyz.berial.textinputlayout.TintManager.java
public static void tintViewBackground(View view, TintInfo tint) { final Drawable background = view.getBackground(); if (tint.mHasTintList || tint.mHasTintMode) { background.setColorFilter(createTintFilter(tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } else {//w ww .j a v a2s. com background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 10) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation view.invalidate(); } }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private static void setPorterDuffColorFilter(Drawable d, int color, PorterDuff.Mode mode) { d.setColorFilter(getPorterDuffColorFilter(color, mode == null ? DEFAULT_MODE : mode)); }
From source file:org.deviceconnect.android.manager.core.util.DConnectUtil.java
/** * ??Drawable??.//from w w w. ja va 2s . com * * @param drawable ??Drawable * @return ??Drawable */ public static Drawable convertToGrayScale(final Drawable drawable) { Drawable clone = drawable.getConstantState().newDrawable().mutate(); ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0.2f); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); clone.setColorFilter(filter); return clone; }
From source file:com.bilibili.magicasakura.utils.TintManager.java
public static void tintViewDrawable(View view, Drawable drawable, TintInfo tint) { if (view == null || drawable == null) return;/*from w ww. j ava2s. c o m*/ if (tint.mHasTintList || tint.mHasTintMode) { drawable.mutate(); if (drawable instanceof ColorDrawable) { ((ColorDrawable) drawable).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { drawable.setColorFilter( createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation drawable.invalidateSelf(); } }
From source file:com.bilibili.magicasakura.utils.TintManager.java
public static void tintViewBackground(View view, com.bilibili.magicasakura.utils.TintInfo tint) { Drawable background; if (view == null || (background = view.getBackground()) == null) return;//from www .j av a 2 s . com if (tint.mHasTintList || tint.mHasTintMode) { background.mutate(); if (background instanceof ColorDrawable) { ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { background.setColorFilter( createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation background.invalidateSelf(); } }
From source file:poche.fm.potunes.utils.TintManager.java
public static void tintViewBackground(View view, TintInfo tint) { Drawable background; if (view == null || (background = view.getBackground()) == null) return;/*from www .j a v a 2 s . c om*/ if (tint.mHasTintList || tint.mHasTintMode) { background.mutate(); if (background instanceof ColorDrawable) { ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { background.setColorFilter( createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation background.invalidateSelf(); } }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private static void setPorterDuffColorFilter(Drawable d, int color, PorterDuff.Mode mode) { if (DrawableUtils.canSafelyMutateDrawable(d)) { d = d.mutate();/*from w ww. j a v a2 s . c o m*/ } d.setColorFilter(getPorterDuffColorFilter(color, mode == null ? DEFAULT_MODE : mode)); }
From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java
/** * Sets the color filter and/or the alpha transparency on a {@link MenuItem}'s icon. * * @param menuItem The {@link MenuItem} to theme. * @param color The color to set for the color filter or {@code null} for no changes. * @param alpha The alpha value (0...255) to set on the icon or {@code null} for no changes. *//*from w w w. java 2s.com*/ public static void colorMenuItem(MenuItem menuItem, Integer color, Integer alpha) { if (color == null && alpha == null) { return; // nothing to do. } Drawable drawable = menuItem.getIcon(); if (drawable != null) { // If we don't mutate the drawable, then all drawables with this id will have the ColorFilter drawable.mutate(); if (color != null) { drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); } if (alpha != null) { drawable.setAlpha(alpha); } } }
From source file:android.support.v7.internal.widget.TintManager.java
private static void tintDrawableUsingColorFilter(Drawable drawable, int color, PorterDuff.Mode mode) { // First, lets see if the cache already contains the color filter PorterDuffColorFilter filter = COLOR_FILTER_CACHE.get(color, mode); if (filter == null) { // Cache miss, so create a color filter and add it to the cache filter = new PorterDuffColorFilter(color, mode); COLOR_FILTER_CACHE.put(color, mode, filter); }/*from ww w . j a v a2s . com*/ drawable.setColorFilter(filter); }