Example usage for android.support.v4.graphics.drawable DrawableCompat setTint

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setTint.

Prototype

public static void setTint(Drawable drawable, int i) 

Source Link

Usage

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static void tintView(ImageView view, int color) {
    Drawable bg = view.getBackground();/* w w w  .j a  v  a  2 s  .  c o m*/
    if (bg != null) {
        bg = DrawableCompat.wrap(bg);
        DrawableCompat.setTint(bg, color);
        view.setBackground(bg);
    }

    Drawable img = view.getDrawable();
    if (img != null) {
        img = DrawableCompat.wrap(img);
        DrawableCompat.setTint(img, color);
        view.setImageDrawable(img);
    }
}

From source file:com.grarak.kerneladiutor.activities.EditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_save);
    DrawableCompat.setTint(drawable, Color.WHITE);
    menu.add(0, Menu.FIRST, Menu.FIRST, getString(R.string.save)).setIcon(drawable)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return super.onCreateOptionsMenu(menu);
}

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

private void setColorTint() {
    DrawableCompat.setTint(mDrawable, Color.MAGENTA);
}

From source file:uk.ac.horizon.artcodes.fragment.ExperienceLibraryFragment.java

private Drawable getTintedDrawable(@DrawableRes int drawable, @ColorInt int color) {
    final Drawable original = ContextCompat.getDrawable(getContext(), drawable);
    if (original != null) {
        final Drawable wrapDrawable = DrawableCompat.wrap(original);
        DrawableCompat.setTint(wrapDrawable, color);
        return wrapDrawable;
    }//from  w  ww .  jav a 2s . c o m
    return null;
}

From source file:com.patloew.countries.ui.detail.DetailActivity.java

private static void tintMenuIcon(MenuItem menuItem) {
    Drawable favoriteIcon = DrawableCompat.wrap(menuItem.getIcon().mutate());
    DrawableCompat.setTint(favoriteIcon, 0xFFFFFFFF);
    menuItem.setIcon(favoriteIcon);/*from   w  w w .j  a  v  a  2s.  c om*/
}

From source file:org.mozilla.focus.session.ui.SessionViewHolder.java

private void updateDrawable(boolean isCurrentSession, int actionColor, int darkColor) {
    final Drawable drawable = AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_link);
    if (drawable == null) {
        return;/* w  w  w  .  j  a  v a 2s  . co m*/
    }

    final Drawable wrapDrawable = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTint(wrapDrawable, isCurrentSession ? actionColor : darkColor);

    textView.setCompoundDrawablesWithIntrinsicBounds(wrapDrawable, null, null, null);
}

From source file:arun.com.chromer.settings.widgets.PreferenceIconLayoutHelper.java

/**
 * Finds the icon view and attempts to tint it based on the checked state of the preference
 *
 * @param imageView The image view of icon
 * @param checked   Whether the preference is enabled
 *//* w w w  .ja  v  a  2s .c  om*/
private static void applyIconTint(@NonNull ImageView imageView, boolean checked) {
    final Drawable drawable = imageView.getDrawable();
    if (drawable != null) {
        if (drawable instanceof IconicsDrawable) {
            // Just redraw with the correct color
            imageView.setImageDrawable(
                    ((IconicsDrawable) drawable).color(checked ? CHECKED_COLOR : UNCHECKED_COLOR));
        } else {
            final Drawable wrap = DrawableCompat.wrap(drawable);
            DrawableCompat.setTint(wrap, checked ? CHECKED_COLOR : UNCHECKED_COLOR);
            imageView.setImageDrawable(drawable);
        }
    }
}

From source file:com.jameswolfeoliver.pigeon.Utilities.DrawableHelper.java

public DrawableHelper tint() {
    if (mDrawable == null) {
        throw new NullPointerException();
    }/*from   w  w  w  .  j  a  v  a 2  s .  c om*/

    if (mColor == 0) {
        throw new IllegalStateException();
    }

    mWrappedDrawable = mDrawable.mutate();
    mWrappedDrawable = DrawableCompat.wrap(mWrappedDrawable);
    DrawableCompat.setTint(mWrappedDrawable, mColor);
    DrawableCompat.setTintMode(mWrappedDrawable, PorterDuff.Mode.SRC_IN);

    return this;
}

From source file:arun.com.chromer.browsing.article.util.ArticleUtil.java

/**
 * Changes the progress bar's color./*from   w w  w  . j av a  2 s  .  c  o  m*/
 */
public static void changeProgressBarColors(ProgressBar progressBar, int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
        DrawableCompat.setTint(wrapDrawable, color);
        progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
    } else {
        progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
    }
}

From source file:com.schedjoules.eventdiscovery.framework.microfragments.eventdetails.fragments.views.EventHeaderView.java

@Override
public void update(Event event) {
    Glide.with(mActivity).load(new SchedJoulesLinks(event.links()).bannerUri())
            .into(mHeader.schedjoulesEventDetailBanner);

    mHeader.schedjoulesEventDetailToolbarLayout.setTitle(event.title());
    // the expanded title is always white
    mHeader.schedjoulesEventDetailToolbarLayout
            .setExpandedTitleColor(ContextCompat.getColor(mActivity, R.color.schedjoules_white));
    mHeader.schedjoulesEventDetailToolbarCollapsed.setTitle("");

    mDateTimeView.update(event);/*from   w ww .  j  av a  2 s  .c  o m*/

    // set home icon of the collapsed toolbar
    Drawable arrow = DrawableCompat
            .wrap(ContextCompat.getDrawable(mActivity, R.drawable.abc_ic_ab_back_material)).mutate();
    DrawableCompat.setTint(arrow, new AttributeColor(mActivity, R.attr.schedjoules_appBarIconColor).argb());
    mHeader.schedjoulesEventDetailToolbarCollapsed.setNavigationIcon(arrow);
}