List of usage examples for android.graphics.drawable AnimationDrawable setColorFilter
public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode)
From source file:com.tencent.tws.assistant.widget.CheckBox.java
private void setTintButtonDrawable(int colorControlNormal, int colorControlDisabled, int colorControlActivated, int colorControlActivateDisabled) { final PorterDuff.Mode DEFAULT_MODE = PorterDuff.Mode.SRC_IN; final boolean isSupportTintDrawable = ThemeUtils.isSupportTintDrawable(getContext()); TwsAnimatedStateListDrawable drawable = new TwsAnimatedStateListDrawable(); Drawable checkOffDisableDrawable = getResources().getDrawable(checkOffDisableResId); Drawable checkOnDisableDrawable = getResources().getDrawable(checkOnDisableResId); Drawable checkOffDrawable = getResources().getDrawable(checkOffResId); Drawable checkOnDrawable = getResources().getDrawable(checkOnResId); if (isSupportTintDrawable) { checkOffDisableDrawable.setColorFilter(colorControlDisabled, DEFAULT_MODE); checkOnDisableDrawable.setColorFilter(colorControlActivateDisabled, DEFAULT_MODE); checkOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE); checkOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE); }//from w w w . j a va 2s . c o m drawable.addState(checkOffDisableState, checkOffDisableDrawable, 0); drawable.addState(checkOnDisableState, checkOnDisableDrawable, 0); drawable.addState(checkOffState, checkOffDrawable, checkOffKeyframeId); drawable.addState(checkOnState, checkOnDrawable, checkOnkeyframeId); AnimationDrawable toOnDrawable = (AnimationDrawable) getResources().getDrawable(checkToOnResId); AnimationDrawable toOffDrawable = (AnimationDrawable) getResources().getDrawable(checkToOffResId); if (isSupportTintDrawable) { toOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE); toOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE); } drawable.addTransition(checkOffKeyframeId, checkOnkeyframeId, toOnDrawable, false); drawable.addTransition(checkOnkeyframeId, checkOffKeyframeId, toOffDrawable, false); setButtonDrawable(drawable); mIsSupportTintDrawable = isSupportTintDrawable; mColorControlActivated = colorControlActivated; mAnimationButtonDrawable = drawable; }
From source file:com.tencent.tws.assistant.widget.RadioButton.java
private void setAnimationButtonDrawable(boolean isAnimation) { mIsAnimationButton = isAnimation;//w ww . ja v a2 s .c o m if (isAnimation) { final boolean isSupportTintDrawable = ThemeUtils.isSupportTintDrawable(getContext()); int colorControlNormal = ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorControlNormal); int colorControlActivated = ThemeUtils.getThemeAttrColor(getContext(), R.attr.colorControlActivated); int colorControlDisabled = ThemeUtils.getDisabledThemeAttrColor(getContext(), R.attr.colorControlNormal); int colorControlActivateDisabled = ThemeUtils.getDisabledThemeAttrColor(getContext(), R.attr.colorControlActivated); final PorterDuff.Mode DEFAULT_MODE = PorterDuff.Mode.SRC_IN; if (colorControlNormal == 0) { colorControlNormal = getContext().getResources().getColor(R.color.control_normal_color); } if (colorControlActivated == 0) { colorControlActivated = getContext().getResources().getColor(R.color.control_activated_color); } if (colorControlDisabled == 0) { colorControlDisabled = getContext().getResources().getColor(R.color.control_disabled_color); } if (colorControlActivateDisabled == 0) { colorControlActivateDisabled = getContext().getResources() .getColor(R.color.control_activate_disabled_color); } TwsAnimatedStateListDrawable drawable = new TwsAnimatedStateListDrawable(); Drawable radioOffDisableDrawable = getResources().getDrawable(radioOffDisableResId); Drawable radioOnDisableDrawable = getResources().getDrawable(radioOnDisableResId); Drawable radioOffDrawable = getResources().getDrawable(radioOffResId); Drawable radioOnDrawable = getResources().getDrawable(radioOnResId); if (isSupportTintDrawable) { radioOffDisableDrawable.setColorFilter(colorControlDisabled, DEFAULT_MODE); radioOnDisableDrawable.setColorFilter(colorControlActivateDisabled, DEFAULT_MODE); radioOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE); radioOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE); } drawable.addState(radioOffDisableState, radioOffDisableDrawable, 0); drawable.addState(radioOnDisableState, radioOnDisableDrawable, 0); drawable.addState(radioOffState, radioOffDrawable, radioOffKeyframeId); drawable.addState(radioOnState, radioOnDrawable, radioOnkeyframeId); AnimationDrawable toOnDrawable = (AnimationDrawable) getResources().getDrawable(radioToOnResId); AnimationDrawable toOffDrawable = (AnimationDrawable) getResources().getDrawable(radioToOffResId); if (isSupportTintDrawable) { toOnDrawable.setColorFilter(colorControlActivated, DEFAULT_MODE); toOffDrawable.setColorFilter(colorControlNormal, DEFAULT_MODE); } drawable.addTransition(radioOffKeyframeId, radioOnkeyframeId, toOnDrawable, false); drawable.addTransition(radioOnkeyframeId, radioOffKeyframeId, toOffDrawable, false); setButtonDrawable(drawable); mIsSupportTintDrawable = isSupportTintDrawable; mColorControlActivated = colorControlActivated; mAnimationButtonDrawable = drawable; } }