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:de.grobox.liberario.utils.TransportrUtils.java

static public Drawable getTintedDrawable(Context context, boolean dark, Drawable drawable) {
    if (dark) {// w w w. j a  v a  2s. c o m
        drawable.setColorFilter(ContextCompat.getColor(context, R.color.drawableTintDark),
                PorterDuff.Mode.SRC_IN);
    } else {
        drawable.setColorFilter(ContextCompat.getColor(context, R.color.drawableTintLight),
                PorterDuff.Mode.SRC_IN);
    }
    return drawable.mutate();
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void wrapMenuItemIcon(@NonNull MenuItem item, int itemColor, int... excludeGroups) {
    if (ArrayUtils.contains(excludeGroups, item.getGroupId()))
        return;// w  ww.j  av a 2 s.  co m
    final Drawable icon = item.getIcon();
    if (icon == null)
        return;
    icon.mutate();
    final Drawable.Callback callback = icon.getCallback();
    final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor);
    newIcon.setCallback(callback);
    item.setIcon(newIcon);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

private static Drawable applyActionBarDrawable(final Context context, final Drawable d,
        final boolean applyAlpha) {
    if (d == null)
        return null;
    d.mutate();
    if (d instanceof LayerDrawable) {
        final Drawable colorLayer = ((LayerDrawable) d).findDrawableByLayerId(R.id.color_layer);
        if (colorLayer != null) {
            final int color = getActionBarColor(context);
            colorLayer.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }//from w w w  .j  a  v a  2s.c o m
    }
    if (applyAlpha) {
        d.setAlpha(getThemeAlpha(context));
    }
    return d;
}

From source file:com.rks.musicx.ui.adapters.PlaylistListAdapter.java

@Override
public void onBindViewHolder(PlaylistViewHolder holder, int position) {
    Playlist playlist = getItem(position);
    holder.PlaylistName.setText(playlist.getName());
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlist.getId());
    int songCount = PlaylistHelper.getSongCount(getContext().getContentResolver(), uri);
    holder.SongCount.setText(String.valueOf(songCount) + " " + getContext().getString(R.string.titles));
    holder.deletePlaylist.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_menu));
    Drawable drawable = holder.deletePlaylist.getDrawable();
    drawable.mutate();
    if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
        drawable.setTint(Color.WHITE);
        holder.PlaylistName.setTextColor(Color.WHITE);
        holder.SongCount.setTextColor(Color.WHITE);
    } else {//  w  ww. j  a  va 2 s.c  om
        drawable.setTint(ContextCompat.getColor(getContext(), R.color.MaterialGrey));
        holder.SongCount.setTextColor(ContextCompat.getColor(getContext(), R.color.MaterialGrey));
        holder.PlaylistName.setTextColor(ContextCompat.getColor(getContext(), R.color.MaterialGrey));
    }
}

From source file:org.michaelbel.bottomsheet.BottomSheetGrid.java

public BottomSheetGrid setIcon(@DrawableRes int resId, @ColorInt int color) {
    Drawable icon = ContextCompat.getDrawable(getContext(), resId);
    icon.clearColorFilter();//w w  w. j  a v a 2  s .  com
    icon.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);

    iconView.setImageDrawable(icon);
    return this;
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyBackground(final View view, final int color) {
    if (view == null)
        return;//  w  w w . j a  v  a  2 s.c o m
    try {
        final Drawable bg = view.getBackground();
        if (bg == null)
            return;
        final Drawable mutated = bg.mutate();
        if (mutated == null)
            return;
        mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.invalidate();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.supportv4.graphics.DrawableCompatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drawable_compat);

    mImageView = (ImageView) findViewById(R.id.image);

    Drawable d = ContextCompat.getDrawable(this, IMAGE_RES);
    mDrawable = DrawableCompat.wrap(d.mutate());

    mImageView.setImageDrawable(mDrawable);

    RadioGroup rg = (RadioGroup) findViewById(R.id.drawable_compat_options);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override// w  w  w  . j a  va  2  s . c  om
        public void onCheckedChanged(RadioGroup radioGroup, int id) {
            switch (id) {
            case R.id.drawable_compat_no_tint:
                clearTint();
                break;
            case R.id.drawable_compat_color:
                setColorTint();
                break;
            case R.id.drawable_compat_state_list:
                setColorStateListTint();
                break;
            }
        }
    });
}

From source file:com.android.contacts.model.account.FallbackAccountType.java

@Override
public Drawable getDisplayIcon(Context context) {
    final Drawable icon = ResourcesCompat.getDrawable(context.getResources(), iconRes, null);
    icon.mutate().setColorFilter(ContextCompat.getColor(context, R.color.actionbar_icon_color_grey),
            PorterDuff.Mode.SRC_ATOP);/*from w w w . ja v  a  2s.  c  om*/
    return icon;
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

private static Drawable applyActionBarDrawable(final Context context, final Drawable d,
        final boolean applyAlpha) {
    if (d == null)
        return null;
    d.mutate();
    //        DrawableCompat.setTint(d, getUserAccentColor(context));
    if (applyAlpha) {
        d.setAlpha(getThemeAlpha(context));
    }// ww w . j  a  v a  2  s  . c  o  m
    return d;
}

From source file:io.github.hidroh.materialistic.widget.IconButton.java

private Drawable tint(Drawable drawable) {
    if (drawable == null) {
        return null;
    }//from w w  w.  j a v a 2s  .  co  m
    Drawable tintDrawable = DrawableCompat.wrap(mTinted ? drawable.mutate() : drawable);
    DrawableCompat.setTintList(tintDrawable, mColorStateList);
    return tintDrawable;
}