public HorizontalDividerItemDecoration(Drawable divider) { this.divider=divider.mutate(); }
private void applyColorMod() { // Only mutate and apply when modifications have occurred. This should // not reset the mColorMod flag, since these filters need to be // re-applied if the Drawable is changed. if (mDrawable != null && mColorMod) { mDrawable = mDrawable.mutate(); if (mHasColorFilter) { mDrawable.setColorFilter(mColorFilter); } // TODO: support, eventually... //mDrawable.setXfermode(mXfermode); //mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8); } }
Drawable drawable = menuItem.getIcon(); if (drawable != null) { // If we don't mutate the drawable, then all drawable's with this id will have a color // filter applied to it. drawable.mutate(); drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); drawable.setAlpha(alpha); }
public static void changeIconDrawableToGray(Context context, Drawable drawable) { if (drawable != null) { drawable.mutate(); drawable.setColorFilter(ContextCompat .getColor(context, R.color.dark_gray), PorterDuff.Mode.SRC_ATOP); } } }
private void setViewColor(View view, int color) { if (view.getBackground() instanceof GradientDrawable) { GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate(); drawable.setColor(color); } }
private void setViewColor(View view, int color) { if (view.getBackground() instanceof GradientDrawable) { GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate(); drawable.setColor(color); } }
@Override public void setBackground(Drawable background) { if (background != null) { background.mutate(); } super.setBackground(background); } }
@Override public Drawable mutate() { Drawable wrapped = mDrawable; Drawable mutated = wrapped.mutate(); if (mutated != wrapped) { // If mutate() returned a new instance, update our reference setWrappedDrawable(mutated); } // We return ourselves, since only the wrapped drawable needs to mutate return this; }
MenuItem favoriteItem = menu.findItem(R.id.action_favorite); Drawable newIcon = (Drawable)favoriteItem.getIcon(); newIcon.mutate().setColorFilter(Color.argb(255, 200, 200, 200), PorterDuff.Mode.SRC_IN); favoriteItem.setIcon(newIcon);
private void setCryptoStatusView(RecipientTokenHolder holder, @DrawableRes int cryptoStatusRes, @AttrRes int cryptoStatusColorAttr) { Resources resources = context.getResources(); Drawable drawable = resources.getDrawable(cryptoStatusRes); // noinspection ConstantConditions, we know the resource exists! drawable.mutate(); int cryptoStatusColor = ThemeUtils.getStyledColor(context, cryptoStatusColorAttr); drawable.setColorFilter(cryptoStatusColor, Mode.SRC_ATOP); holder.itemCryptoStatusIcon.setImageDrawable(drawable); holder.itemCryptoStatus.setVisibility(View.VISIBLE); }
public PressedEffectStateListDrawable(Drawable drawable, int color, int selectionColor) { super(); drawable = drawable.mutate(); addState(new int[]{android.R.attr.state_selected}, drawable); addState(new int[]{}, drawable); this.color = color; this.selectionColor = selectionColor; }
public boolean onPrepareOptionsMenu(Menu menu) { boolean menusEnabled = reachedEndOfSlidehow(); // enable or disable? MenuItem item = menu.findItem(R.id.menu_next_slide); Drawable resIcon = getResources().getDrawable(R.drawable.ic_next_slide); if (!menusEnabled) resIcon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN); item.setEnabled(menusEnabled); // any text will be automatically disabled item.setIcon(resIcon); }
public static Drawable tintDrawable(Drawable drawable, @ColorInt int color, PorterDuff.Mode mode) { if (drawable == null) return null; Drawable wrapper = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTint(wrapper, color); DrawableCompat.setTintMode(drawable, mode); return wrapper; }
@SuppressLint("NewApi") @Override public void setValue(ForegroundFrame layout, int value) { if (layout.getForeground() instanceof ColorDrawable) { ((ColorDrawable) layout.getForeground().mutate()).setColor(value); } else { layout.setForeground(new ColorDrawable(value)); } }
public static Drawable tintDrawable(Drawable drawable, ColorStateList cls, PorterDuff.Mode mode) { if (drawable == null) return null; Drawable wrapper = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintList(wrapper, cls); DrawableCompat.setTintMode(drawable, mode); return wrapper; }
@UiThread // Implicit synchronization for use of shared resource VALUE. public static Drawable getTintedDrawable(Context context, @DrawableRes int id, @AttrRes int tintAttrId) { boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true); if (!attributeFound) { throw new Resources.NotFoundException("Required tint color attribute with name " + context.getResources().getResourceEntryName(tintAttrId) + " and attribute ID " + tintAttrId + " was not found."); } Drawable drawable = ContextCompat.getDrawable(context, id); drawable = DrawableCompat.wrap(drawable.mutate()); int color = ContextCompat.getColor(context, VALUE.resourceId); DrawableCompat.setTint(drawable, color); return drawable; }
@OnMount static void onMount( ComponentContext c, ProgressBar progressBar, @Prop(optional = true, resType = ResType.COLOR) int color, @FromPrepare Drawable resolvedIndeterminateDrawable) { if (resolvedIndeterminateDrawable != null) { progressBar.setIndeterminateDrawable(resolvedIndeterminateDrawable); } if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) { progressBar.getIndeterminateDrawable().mutate().setColorFilter( color, PorterDuff.Mode.MULTIPLY); } }
@OnUnmount static void onUnmount( ComponentContext c, ProgressBar progressBar, @Prop(optional = true, resType = ResType.COLOR) int color, @FromPrepare Drawable resolvedIndeterminateDrawable) { // restore the color first, since it acts on the indeterminateDrawable if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) { progressBar.getIndeterminateDrawable().mutate().clearColorFilter(); } progressBar.setIndeterminateDrawable(null); }
public StateListDrawable build(Context ctx) { StateListDrawable stateListDrawable = new StateListDrawable(); GradientDrawable normal = (GradientDrawable) AppCompatResources.getDrawable(ctx, mStyle.getGradientDrawable()); GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate(); ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, normal); if (mStyle.getColorPressed() == null) { ColorHolder.applyToOrTransparent(mStyle.getColor(), ctx, selected); } else { ColorHolder.applyToOrTransparent(mStyle.getColorPressed(), ctx, selected); } if (mStyle.getCorners() != null) { normal.setCornerRadius(mStyle.getCorners().asPixel(ctx)); selected.setCornerRadius(mStyle.getCorners().asPixel(ctx)); } stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected); stateListDrawable.addState(StateSet.WILD_CARD, normal); return stateListDrawable; } }