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()); }
@SuppressLint("RestrictedApi") private static void setTintMode(Drawable drawable, PorterDuff.Mode mode) { if (drawable instanceof TintAwareDrawable) { ((TintAwareDrawable) drawable).setTintMode(mode); } else { DrawableCompat.setTintMode(drawable, mode); } }
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)); } }
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)); } }
public static void setTintMode(Drawable drawable, PorterDuff.Mode mode) { if (drawable instanceof TintAwareDrawable) ((TintAwareDrawable) drawable).setTintMode(mode); }