Java Code Examples for android.support.v4.graphics.drawable.DrawableCompat#setTintMode()
The following examples show how to use
android.support.v4.graphics.drawable.DrawableCompat#setTintMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppCompatImageHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
private boolean applySupportImageTint() { Drawable image = mView.getDrawable(); if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) { Drawable tintDrawable = image.mutate(); tintDrawable = DrawableCompat.wrap(tintDrawable); if (mImageTintInfo.mHasTintList) { DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList); } if (mImageTintInfo.mHasTintMode) { DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode); } if (tintDrawable.isStateful()) { tintDrawable.setState(mView.getDrawableState()); } setImageDrawable(tintDrawable); if (image == tintDrawable) { tintDrawable.invalidateSelf(); } return true; } return false; }
Example 2
Source File: AppCompatCompoundDrawableHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
private Drawable applySupportCompoundDrawableTint(int position) { Drawable originDrawable = mView.getCompoundDrawables()[position]; Drawable compoundDrawable = originDrawable; TintInfo tintInfo = mCompoundDrawableTintInfos[position]; if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) { compoundDrawable = DrawableCompat.wrap(compoundDrawable); compoundDrawable.mutate(); if (tintInfo.mHasTintList) { DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList); } if (tintInfo.mHasTintMode) { DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode); } if (compoundDrawable.isStateful()) { compoundDrawable.setState(originDrawable.getState()); } return compoundDrawable; } return originDrawable; }
Example 3
Source File: AppCompatCompoundButtonHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
public boolean applySupportButtonDrawableTint() { Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView); if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) { buttonDrawable = DrawableCompat.wrap(buttonDrawable); buttonDrawable = buttonDrawable.mutate(); if (mCompoundButtonTintInfo.mHasTintList) { DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList); } if (mCompoundButtonTintInfo.mHasTintMode) { DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (buttonDrawable.isStateful()) { buttonDrawable.setState(mView.getDrawableState()); } setButtonDrawable(buttonDrawable); return true; } return false; }
Example 4
Source File: AppCompatSwitchHelper.java From timecat with Apache License 2.0 | 6 votes |
private boolean applySupportDrawableTint() { Drawable drawable = mDrawableCallback.getDrawable(); if (drawable != null && mTintInfo != null && mTintInfo.mHasTintList) { Drawable tintDrawable = drawable.mutate(); tintDrawable = DrawableCompat.wrap(tintDrawable); if (mTintInfo.mHasTintList) { DrawableCompat.setTintList(tintDrawable, mTintInfo.mTintList); } if (mTintInfo.mHasTintMode) { DrawableCompat.setTintMode(tintDrawable, mTintInfo.mTintMode); } if (tintDrawable.isStateful()) { tintDrawable.setState(mSwitchCompat.getDrawableState()); } setDrawable(tintDrawable); if (drawable == tintDrawable) { tintDrawable.invalidateSelf(); } return true; } return false; }
Example 5
Source File: AppCompatSwitchHelper.java From MagicaSakura with Apache License 2.0 | 6 votes |
private boolean applySupportDrawableTint() { Drawable drawable = mDrawableCallback.getDrawable(); if (drawable != null && mTintInfo != null && mTintInfo.mHasTintList) { Drawable tintDrawable = drawable.mutate(); tintDrawable = DrawableCompat.wrap(tintDrawable); if (mTintInfo.mHasTintList) { DrawableCompat.setTintList(tintDrawable, mTintInfo.mTintList); } if (mTintInfo.mHasTintMode) { DrawableCompat.setTintMode(tintDrawable, mTintInfo.mTintMode); } if (tintDrawable.isStateful()) { tintDrawable.setState(mSwitchCompat.getDrawableState()); } setDrawable(tintDrawable); if (drawable == tintDrawable) { tintDrawable.invalidateSelf(); } return true; } return false; }
Example 6
Source File: AppCompatBackgroundHelper.java From timecat with Apache License 2.0 | 6 votes |
private boolean applySupportBackgroundTint() { Drawable backgroundDrawable = mView.getBackground(); if (backgroundDrawable != null && mBackgroundTintInfo != null && mBackgroundTintInfo.mHasTintList) { backgroundDrawable = DrawableCompat.wrap(backgroundDrawable); backgroundDrawable = backgroundDrawable.mutate(); if (mBackgroundTintInfo.mHasTintList) { DrawableCompat.setTintList(backgroundDrawable, mBackgroundTintInfo.mTintList); } if (mBackgroundTintInfo.mHasTintMode) { DrawableCompat.setTintMode(backgroundDrawable, mBackgroundTintInfo.mTintMode); } if (backgroundDrawable.isStateful()) { backgroundDrawable.setState(mView.getDrawableState()); } setBackgroundDrawable(backgroundDrawable); return true; } return false; }
Example 7
Source File: AppCompatCompoundDrawableHelper.java From timecat with Apache License 2.0 | 6 votes |
private Drawable applySupportCompoundDrawableTint(int position) { Drawable originDrawable = ((TextView) mView).getCompoundDrawables()[position]; Drawable compoundDrawable = originDrawable; TintInfo tintInfo = mCompoundDrawableTintInfos[position]; if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) { compoundDrawable = DrawableCompat.wrap(compoundDrawable); compoundDrawable.mutate(); if (tintInfo.mHasTintList) { DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList); } if (tintInfo.mHasTintMode) { DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode); } if (compoundDrawable.isStateful()) { compoundDrawable.setState(originDrawable.getState()); } return compoundDrawable; } return originDrawable; }
Example 8
Source File: TintableImageView.java From ImageLetterIcon with Apache License 2.0 | 6 votes |
@Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mTint != null) { if (mTint.isStateful()) setColorFilter(mTint.getColorForState(getDrawableState(), 0)); else setColorFilter(mTint); } Drawable drawable = getBackground(); if (mBackgroundTint != null && drawable != null) { Drawable wrap = DrawableCompat.wrap(drawable); wrap = wrap.mutate(); if (mBackgroundTint.isStateful()) DrawableCompat.setTint(wrap, ContextCompat.getColor(getContext(), mBackgroundTint.getColorForState(getDrawableState(), 0))); else DrawableCompat.setTintList(wrap, mBackgroundTint); DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN); } }
Example 9
Source File: Coloring.java From actual-number-picker with GNU General Public License v3.0 | 6 votes |
/** * Tries to clone and just color filter the drawable. Uses mode SRC_ATOP. * * @param drawable Which drawable to color * @param color Which color to use * @return A colored drawable ready for use */ @SuppressWarnings("RedundantCast") public Drawable colorUnknownDrawable(@Nullable Drawable drawable, int color) { if (drawable instanceof DrawableWrapper || drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, color); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP); drawable = DrawableCompat.unwrap(drawable); return drawable; } else { try { // noinspection ConstantConditions Drawable copy = drawable.getConstantState().newDrawable(); copy.mutate(); copy.setColorFilter(color, SRC_ATOP); return copy; } catch (Exception e) { if (drawable != null) { Log.d(LOG_TAG, "Failed to color unknown drawable: " + drawable.getClass().getSimpleName()); } return drawable; } } }
Example 10
Source File: ThemeUtils.java From timecat with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: LayerDrawable.java From RippleDrawable with MIT License | 5 votes |
@Override public void setTintMode(Mode tintMode) { final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { DrawableCompat.setTintMode(array[i].mDrawable, tintMode); } }
Example 12
Source File: ThemeUtils.java From MagicaSakura with Apache License 2.0 | 5 votes |
public static Drawable tintDrawable(Drawable drawable, ColorStateList cls, PorterDuff.Mode mode) { if (drawable == null) return null; Drawable wrapper = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintList(wrapper, cls); DrawableCompat.setTintMode(drawable, mode); return wrapper; }
Example 13
Source File: DrawMeShapeText.java From DrawMe with Apache License 2.0 | 5 votes |
private Drawable tintDrawable(Drawable drawable, int tintColor, int tintMode) { if (drawable == null || tintColor == 0) return drawable; Drawable wrapDrawable = DrawableCompat.wrap(drawable).mutate(); DrawableCompat.setTint(wrapDrawable, tintColor); PorterDuff.Mode mode = intToMode(tintMode); if (mode != null && mode != PorterDuff.Mode.CLEAR) DrawableCompat.setTintMode(wrapDrawable, mode); return wrapDrawable; }
Example 14
Source File: ThemeUtil.java From talk-android with MIT License | 5 votes |
public static Drawable getThemeDrawable(Resources res, @DrawableRes int drawableResId, String themeColor) { Drawable drawable = DrawableCompat.wrap(res.getDrawable(drawableResId).mutate()); int color = res.getColor(getThemeColorRes(themeColor)); // DrawableCompat.setTint(drawable, color); DrawableCompat.setTint(drawable, res.getColor(R.color.colorPrimary)); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN); return drawable; }
Example 15
Source File: Util.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
@CheckResult @Nullable public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int i) { if (drawable == null) { return null; } Drawable wrap = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintMode(wrap, Mode.SRC_IN); DrawableCompat.setTint(wrap, i); return wrap; }
Example 16
Source File: MdCompat.java From android-md-core with Apache License 2.0 | 5 votes |
public static Drawable createDrawableTint(Drawable drawable, int[] drawableState, ColorStateList tintList, PorterDuff.Mode tintMode) { 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; }
Example 17
Source File: TintCheckedTextView.java From MagicaSakura with Apache License 2.0 | 5 votes |
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); } else { setCheckMarkDrawable(drawable); setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } }
Example 18
Source File: ThemeUtil.java From talk-android with MIT License | 4 votes |
public static Drawable getDrawableWithColor(Resources res, @DrawableRes int drawableResId, @ColorRes int color) { Drawable drawable = DrawableCompat.wrap(res.getDrawable(drawableResId).mutate()); DrawableCompat.setTint(drawable, res.getColor(color)); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN); return drawable; }
Example 19
Source File: ShadowUtils.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
public void setTintMode(Mode tintMode) { DrawableCompat.setTintMode(this.mDrawable, tintMode); }
Example 20
Source File: DrawableWrapper.java From ticdesign with Apache License 2.0 | 4 votes |
@Override public void setTintMode(PorterDuff.Mode tintMode) { DrawableCompat.setTintMode(mDrawable, tintMode); }