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

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

Introduction

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

Prototype

public static void setTintMode(Drawable drawable, Mode mode) 

Source Link

Usage

From source file:com.vinidsl.googleioextended.helper.TintHelper.java

public static Drawable tint(Drawable drawable, int colorResource) {
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, colorResource);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    return drawable;
}

From source file:com.vinidsl.googleioextended.helper.TintHelper.java

public static Drawable tint(Drawable drawable, ColorStateList stateList) {
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTintList(drawable, stateList);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    return drawable;
}

From source file:com.mytwitter.Utils.Utils.java

public static Drawable tintMyDrawable(Drawable drawable, int color) {
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, color);
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    return drawable;
}

From source file:me.henrytao.mdcore.core.MdCompat.java

public static Drawable createDrawableTint(Drawable drawable, int[] drawableState, ColorStateList tintList,
        PorterDuff.Mode tintMode) {/*from   w  w w  .  j  a  va  2  s .com*/
    if (drawable != null && (tintList != null || tintMode != null)) {
        drawable = DrawableCompat.wrap(drawable).mutate();
        if (tintList != null) {
            DrawableCompat.setTintList(drawable, tintList);
        }
        if (tintMode != null) {
            DrawableCompat.setTintMode(drawable, tintMode);
        }
        if (drawable.isStateful() && drawableState != null) {
            drawable.setState(drawableState);
        }
    }
    return drawable;
}

From source file:android.support.design.widget.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor,
        int borderWidth) {
    // Now we need to tint the shape background with the tint
    mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }//from w  w  w  .ja va 2s.co  m

    final Drawable rippleContent;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        rippleContent = new LayerDrawable(new Drawable[] { mBorderDrawable, mShapeDrawable });
    } else {
        mBorderDrawable = null;
        rippleContent = mShapeDrawable;
    }

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mContentBackground = mRippleDrawable;

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.IconUtils.java

@CheckResult
@Nullable//from w  w  w . ja v  a  2 s .co  m
public static Drawable getTintedIcon(Drawable drawable, int color) {
    if (drawable != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (drawable instanceof VectorDrawable) {
                drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            }
            drawable = DrawableCompat.wrap(drawable.mutate());
        } else {
            drawable = DrawableCompat.wrap(drawable);
        }
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
        DrawableCompat.setTint(drawable, color);
        return drawable;
    } else {
        return null;
    }
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonLollipop.java

@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
        PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the original background with the tint
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }// w  ww.j av a  2 s. c om

    final Drawable rippleContent;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        rippleContent = new LayerDrawable(new Drawable[] { mBorderDrawable, mShapeDrawable });
    } else {
        mBorderDrawable = null;
        rippleContent = mShapeDrawable;
    }

    mRippleDrawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), rippleContent, null);

    mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
    mShadowViewDelegate.setShadowPadding(0, 0, 0, 0);
}

From source file:com.bilibili.magicasakura.widgets.TintCheckedTextView.java

public void tintCheckTextView(@DrawableRes int resId, int tintId) {
    Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(resId));
    DrawableCompat.setTintList(drawable, TintManager.get(getContext()).getColorStateList(tintId));
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    //android-sdk-23 material layout is deprecate android.R.styleable#CheckedTextView_checkMark
    //follow android native style, check position is left when version is above 5.0
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
        setCheckMarkDrawable(null);/*from w w  w .ja  v  a 2s.com*/
    } else {
        setCheckMarkDrawable(drawable);
        setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
}

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

public DrawableHelper tint() {
    if (mDrawable == null) {
        throw new NullPointerException();
    }//from w  w w. ja  v a 2  s .com

    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:com.bilibili.magicasakura.utils.ThemeUtils.java

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;
}