Java 类android.support.v4.graphics.drawable.TintAwareDrawable 实例源码

项目:tenor-android-demo-search    文件:SearchSuggestionVH.java   
public void render(@Nullable final SearchSuggestionRVItem item,
                   @Nullable final OnClickListener listener) {
    if (!hasContext() || item == null) {
        return;
    }

    mItem = item;
    if (listener != null) {
        mListener = listener;
    }

    mSuggestionField.setText(item.getSuggestion());

    if (mSuggestionField instanceof TintableBackgroundView) {
        // "AppCompatTextView" and "com.android.support:appcompat-v7" are used, tint all states
        ViewCompat.setBackgroundTintList(mSuggestionField,
                new ColorStateList(STATES, new int[]{
                        AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
                        AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
        return;
    }

    // "com.android.support:appcompat-v7" is likely not being used, and thus "TextView" is used
    Drawable background = mSuggestionField.getBackground();
    if (background instanceof TintAwareDrawable) {
        // tint all states of the given drawable
        DrawableCompat.setTintList(background,
                new ColorStateList(STATES, new int[]{
                        AbstractColorUtils.getColor(getContext(), item.getPlaceholder()),
                        AbstractColorUtils.getColor(getContext(), R.color.tenor_sdk_primary_color)}));
        return;
    }

    // last option, tint only the background individually
    AbstractDrawableUtils.setDrawableTint(getContext(), background, item.getPlaceholder());
}
项目:vehicle-keyboard-android    文件:DrawableTint.java   
@SuppressLint("RestrictedApi")
private static void setTintMode(Drawable drawable, PorterDuff.Mode mode) {
    if (drawable instanceof TintAwareDrawable) {
        ((TintAwareDrawable) drawable).setTintMode(mode);
    } else {
        DrawableCompat.setTintMode(drawable, mode);
    }
}
项目:Carbon    文件:Carbon.java   
public static void setTint(Drawable drawable, int tint) {
    if (drawable instanceof TintAwareDrawable) {
        ((TintAwareDrawable) drawable).setTint(tint);
    } else {
        drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
    }
}
项目:Carbon    文件:Carbon.java   
public static void setTintList(Drawable drawable, ColorStateList tint) {
    if (drawable instanceof TintAwareDrawable) {
        ((TintAwareDrawable) drawable).setTintList(tint);
    } else {
        drawable.setColorFilter(tint == null ? null : new PorterDuffColorFilter(tint.getColorForState(drawable.getState(), tint.getDefaultColor()), PorterDuff.Mode.MULTIPLY));
    }
}
项目:Carbon    文件:Carbon.java   
public static void setTintMode(Drawable drawable, PorterDuff.Mode mode) {
    if (drawable instanceof TintAwareDrawable)
        ((TintAwareDrawable) drawable).setTintMode(mode);
}