private void applySupportProgressTint() { Log.e("themep", "apply progress tint"); if (mProgressTintInfo != null && (mProgressTintInfo.mHasTintList || mProgressTintInfo.mHasTintMode)) { Log.e("themep", "apply progress tint true"); final Drawable target = getTintTarget(android.R.id.progress, true); if (target != null) { TintManager.tintViewDrawable(mView, target, mProgressTintInfo); Log.e("themep", "apply progress tint true tint"); // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (target.isStateful()) { target.setState(mView.getDrawableState()); } } } }
public static void tintViewBackground(View view, TintInfo tint) { Drawable background; if (view == null || (background = view.getBackground()) == null) return; if (tint.mHasTintList || tint.mHasTintMode) { background.mutate(); if (background instanceof ColorDrawable) { ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { background.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation background.invalidateSelf(); } }
public static void tintViewDrawable(View view, Drawable drawable, TintInfo tint) { if (view == null || drawable == null) return; if (tint.mHasTintList || tint.mHasTintMode) { drawable.mutate(); if (drawable instanceof ColorDrawable) { ((ColorDrawable) drawable).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { drawable.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation drawable.invalidateSelf(); } }
public static float getBackgroundTintAlpha(View child) { if (!(child instanceof TintedView)) return 255; ColorStateList tint = ((TintedView) child).getBackgroundTint(); if (tint == null) return 255; int color = tint.getColorForState(child.getDrawableState(), tint.getDefaultColor()); return (color >> 24) & 0xff; }
/** * Sets the state on a drawable if it is clickable or should duplicate its parent's state. */ static void maybeSetDrawableState(View view, Drawable drawable, int flags, NodeInfo nodeInfo) { final boolean shouldSetState = (nodeInfo != null && nodeInfo.hasTouchEventHandlers()) || MountItem.isDuplicateParentState(flags); if (shouldSetState && drawable.isStateful()) { drawable.setState(view.getDrawableState()); } }
private void applySupportIndeterminateTint() { Drawable mIndeterminateDrawable = ((ProgressBar) mView).getIndeterminateDrawable(); if (mIndeterminateDrawable != null && mIndeterminateTintInfo != null) { final TintInfo tintInfo = mIndeterminateTintInfo; if (tintInfo.mHasTintList || tintInfo.mHasTintMode) { ((ProgressBar) mView).setIndeterminateDrawable(mIndeterminateDrawable = mIndeterminateDrawable.mutate()); TintManager.tintViewDrawable(mView, mIndeterminateDrawable, mIndeterminateTintInfo); // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (mIndeterminateDrawable.isStateful()) { mIndeterminateDrawable.setState(mView.getDrawableState()); } } } }
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; }
tintDrawable.setState(mView.getDrawableState()); tintDrawable.setState(mView.getDrawableState());
private boolean applySupportForegroundTint() { Drawable foregroundDrawable = getForeground(); if (foregroundDrawable != null && mForegroundTintInfo != null && mForegroundTintInfo.mHasTintList) { foregroundDrawable = DrawableCompat.wrap(foregroundDrawable); foregroundDrawable = foregroundDrawable.mutate(); if (mForegroundTintInfo.mHasTintList) { DrawableCompat.setTintList(foregroundDrawable, mForegroundTintInfo.mTintList); } if (mForegroundTintInfo.mHasTintMode) { DrawableCompat.setTintMode(foregroundDrawable, mForegroundTintInfo.mTintMode); } if (foregroundDrawable.isStateful()) { foregroundDrawable.setState(mView.getDrawableState()); } setForegroundDrawable(foregroundDrawable); return true; } return false; }
public boolean applySupportButtonDrawableTint() { Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) 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; }
public static ViewAttribute<ColorValue> createColorAttribute(@Nullable View view, @NonNull String name, @Nullable ColorStateList color) { int tintColorInt; if (color == null) { tintColorInt = 0x000; } else { int[] state = view == null ? new int[] { } : view.getDrawableState(); tintColorInt = color.getColorForState(state, color.getDefaultColor()); } return new ViewAttribute<>(name, new ColorValue(tintColorInt), new ColorDrawable(tintColorInt)); }
public void drawableStateChanged() { if (mForeground != null && mForeground.isStateful()) { mForeground.setState(mView.getDrawableState()); } }
public void drawVertical(Canvas canvas, RecyclerView parent) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); if (!hasDivider(parent, child)) { continue; } if (mDrawable.isStateful()) { mDrawable.setState(child.getDrawableState()); } RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin + Math.round(child.getTranslationY()); int bottom = top + mDrawable.getIntrinsicHeight(); drawDivider(canvas, left, top, right, bottom, child.getAlpha()); } }
public void drawHorizontal(Canvas canvas, RecyclerView parent) { int top = parent.getPaddingTop(); int bottom = parent.getHeight() - parent.getPaddingBottom(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); if (!hasDivider(parent, child)) { continue; } if (mDrawable.isStateful()) { mDrawable.setState(child.getDrawableState()); } RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int left = child.getRight() + params.rightMargin + Math.round(child.getTranslationX()); int right = left + mDrawable.getIntrinsicWidth(); drawDivider(canvas, left, top, right, bottom, child.getAlpha()); } }
drawable.setCallback(mView); if (drawable.isStateful()) { drawable.setState(mView.getDrawableState());
tintDrawable.setState(mWidget.getDrawableState());
data.put("DrawableState", getTranslator().drawableStates(v.getDrawableState())); data.put("DrawingCache", String.valueOf(v.getDrawingCache())); data.put("DrawingCacheBackgroundColor", getStringColor(v.getDrawingCacheBackgroundColor()));
tintDrawable.setState(mWidget.getDrawableState());
private void setRefineIcon(boolean invalidateIcon) { if (!invalidateIcon && mRefineIcon != null) return; mRefineIcon = TintedDrawable.constructTintedDrawable( getResources(), R.drawable.btn_suggestion_refine); mRefineIcon.setTint(ApiCompatibilityUtils.getColorStateList(getResources(), mUseDarkColors ? R.color.dark_mode_tint : R.color.light_mode_tint)); mRefineIcon.setBounds( 0, 0, mRefineIcon.getIntrinsicWidth(), mRefineIcon.getIntrinsicHeight()); mRefineIcon.setState(mRefineView.getDrawableState()); mRefineView.postInvalidateOnAnimation(); }