Example usage for android.graphics.drawable Drawable mutate

List of usage examples for android.graphics.drawable Drawable mutate

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable mutate.

Prototype

public @NonNull Drawable mutate() 

Source Link

Document

Make this drawable mutable.

Usage

From source file:Main.java

public static void doGray(Drawable d) {
    //Make this drawable mutable.     
    //A mutable drawable is guaranteed to not share its state with any other drawable.     
    d.mutate();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);/*from ww  w .j a  v a  2  s .c  om*/
    ColorMatrixColorFilter cf = new ColorMatrixColorFilter(cm);
    d.setColorFilter(cf);

}

From source file:com.example.madiba.venu_alpha.utils.ColorUtils.java

public static Drawable colorDrawable(Resources res, @DrawableRes int drawableResId, @ColorRes int colorResId,
        Context context) {/*from www  .j  a  v  a 2  s.  c  o  m*/

    Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
    int color = res.getColor(colorResId);
    drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
    return drawable;
}

From source file:com.danimahardhika.android.helpers.core.DrawableHelper.java

@Nullable
public static Drawable getTintedDrawable(@NonNull Drawable drawable, @ColorInt int color) {
    try {/*from w ww  . j a  v  a 2 s  .c om*/
        DrawableCompat.setTint(drawable, color);
        return drawable.mutate();
    } catch (OutOfMemoryError e) {
        return null;
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java

public static void populateAutoTextViews(TextView autoTextView, String autoText, int drawableId,
        Resources res) {/*from   w w  w.j  a  v  a 2s.c o  m*/
    autoTextView.setText(autoText);
    autoTextView
            .setContentDescription(res.getString(R.string.trigger_label_icon_content_description, autoText));
    Drawable drawable = res.getDrawable(drawableId);
    DrawableCompat.setTint(drawable.mutate(), res.getColor(R.color.text_color_light_grey));
    autoTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
}

From source file:com.popdeem.sdk.uikit.utils.PDUIColorUtils.java

public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableRes, @ColorRes int colorRes,
        boolean mutate) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableRes);
    if (drawable == null) {
        return null;
    }/*from   w  ww.ja  v  a  2  s .  c om*/

    if (mutate) {
        drawable = drawable.mutate();
    }
    drawable.setColorFilter(ContextCompat.getColor(context, colorRes), PorterDuff.Mode.SRC_IN);
    return drawable;
}

From source file:Main.java

private static void downEffect(View v) {

    /*ColorMatrix cm = new ColorMatrix(
          new float[] {//from  ww  w .ja va 2s  .  c  o m
                  -1, 0, 0, 0, 255,
                  0, -1, 0, 0, 255,
                  0, 0, -1, 0, 255,
                  0, 0, 0, 1, 0 }
      );
                
      v.getBackground().mutate().setColorFilter(new ColorMatrixColorFilter(cm));*/

    Drawable drwb;
    if (v instanceof ImageView) {
        drwb = ((ImageView) v).getDrawable();
    } else {
        drwb = v.getBackground();
    }

    if (drwb == null)
        return;
    drwb.mutate().setColorFilter(0xffaaaaaa, PorterDuff.Mode.MULTIPLY);

    v.invalidate();
}

From source file:com.dm.material.dashboard.candybar.helpers.DrawableHelper.java

@Nullable
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int res) {
    try {//from   www.j ava 2  s  . c o m
        Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res);
        return drawable.mutate();
    } catch (OutOfMemoryError e) {
        return null;
    }
}

From source file:com.achep.acdisplay.graphics.IconFactory.java

@NonNull
private static Bitmap createIcon(@NonNull Drawable drawable, int size) {
    Bitmap icon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(icon);

    drawable = drawable.mutate();
    drawable.setBounds(0, 0, size, size);
    drawable.draw(canvas);/*w ww  . j  av  a2s  .  co  m*/

    return icon;
}

From source file:com.kaliturin.blacklist.utils.Utils.java

/**
 * Tints menu icon//from   w  ww  .  ja v a  2s .co  m
 **/
public static void setMenuIconTint(Context context, MenuItem item, @AttrRes int colorAttrRes) {
    Drawable drawable = DrawableCompat.wrap(item.getIcon());
    drawable.mutate();
    setDrawableTint(context, drawable, colorAttrRes);
}

From source file:com.pranavpandey.smallapp.theme.DynamicTheme.java

/**
 * Colorize and return the mutated drawable so that, all other references
 * do not change./*from ww w  .ja v a2 s  .  c o  m*/
 *
 * @param drawable to be colorized.
 * @param color to colorize the drawable.
 *
 * @return Colorized drawable.
 */
public static Drawable colorizeDrawable(Drawable drawable, @ColorInt int color) {
    drawable.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    return drawable;
}