@Override protected boolean onStateChange(int[] state) { int color = mColorStateList.getColorForState(state, mCurColor); if(mCurColor != color){ mCurColor = color; return true; } return false; }
int getColorForCurrentState(int defaultColor) { if (mColors != null) { return mColors.getColorForState(mState, defaultColor); } else { return defaultColor; } }
public TouchableUrlSpan(String url, ColorStateList textColor, int pressedBackgroundColor) { super(url); this.normalTextColor = textColor.getDefaultColor(); this.pressedTextColor = textColor.getColorForState(STATE_PRESSED, normalTextColor); this.pressedBackgroundColor = pressedBackgroundColor; }
private int getThumbColor(boolean checked){ mTempStates[0] = isEnabled() ? android.R.attr.state_enabled : -android.R.attr.state_enabled; mTempStates[1] = checked ? android.R.attr.state_checked : -android.R.attr.state_checked; return mThumbColors.getColorForState(mTempStates, 0); }
private int getTrackColor(boolean checked){ mTempStates[0] = isEnabled() ? android.R.attr.state_enabled : -android.R.attr.state_enabled; mTempStates[1] = checked ? android.R.attr.state_checked : -android.R.attr.state_checked; return mTrackColors.getColorForState(mTempStates, 0); }
@Override protected boolean onStateChange(int[] state) { int newColor = mBorderColor.getColorForState(state, 0); if (mBorderPaint.getColor() != newColor) { mBorderPaint.setColor(newColor); return true; } else { return super.onStateChange(state); } }
@Override public void setTextColor(ColorStateList colors) { this.textColor = colors.getColorForState(getDrawableState(), textColor); super.setTextColor(colors); }
public RoundedDrawable(Bitmap bitmap) { mBitmap = bitmap; mBitmapWidth = bitmap.getWidth(); mBitmapHeight = bitmap.getHeight(); mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight); mBitmapPaint = new Paint(); mBitmapPaint.setStyle(Paint.Style.FILL); mBitmapPaint.setAntiAlias(true); mBorderPaint = new Paint(); mBorderPaint.setStyle(Paint.Style.STROKE); mBorderPaint.setAntiAlias(true); mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); mBorderPaint.setStrokeWidth(mBorderWidth); }
public RoundedDrawable setBorderColor(ColorStateList colors) { mBorderColor = colors != null ? colors : ColorStateList.valueOf(0); mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); return this; }
private PorterDuffColorFilter updateTintFilter(ColorStateList tint, PorterDuff.Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(getState(), Color.TRANSPARENT); return new PorterDuffColorFilter(color, tintMode); }
public void setColorFilter(ColorStateList tint) { this.tint = tint; super.setColorFilter(tint.getColorForState(getDrawableState(), 0)); }
private void updateTintColor() { int color = tint.getColorForState(getDrawableState(), 0); setColorFilter(color); }
private void drawStroke(Canvas canvas) { strokePaint.setStrokeWidth(strokeWidth * 2); strokePaint.setColor(stroke.getColorForState(getDrawableState(), stroke.getDefaultColor())); cornersMask.setFillType(Path.FillType.WINDING); canvas.drawPath(cornersMask, strokePaint); }
public void updateTint() { if (colorFilter != null) { paint.setColorFilter(colorFilter); } else if (tint != null && tintMode != null) { paint.setColorFilter(new PorterDuffColorFilter(tint.getColorForState(getState(), tint.getDefaultColor()), tintMode)); } else { paint.setColorFilter(null); } }
private static PorterDuffColorFilter createTintFilter(Context context, ColorStateList tint, PorterDuff.Mode tintMode, final int[] state) { if (tint == null || tintMode == null) { return null; } final int color = ThemeUtils.replaceColor(context, tint.getColorForState(state, tint.getDefaultColor())); return getPorterDuffColorFilter(color, tintMode); }
@Override protected boolean onStateChange(int[] states) { if (mColorStateList != null && mLayout != null) { final int previousColor = mLayout.getPaint().getColor(); final int currentColor = mColorStateList.getColorForState(states, mUserColor); if (currentColor != previousColor) { mLayout.getPaint().setColor(currentColor); invalidateSelf(); } } return super.onStateChange(states); }
public static int getDisabledThemeAttrColor(Context context, @AttrRes int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else { // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }
@Override public void setOutlineSpotShadowColor(ColorStateList color) { spotShadowColor = color; if (Carbon.IS_PIE_OR_HIGHER) { super.setOutlineSpotShadowColor(color.getColorForState(getDrawableState(), color.getDefaultColor())); } else { spotShadowColorFilter = new PorterDuffColorFilter(color.getColorForState(getDrawableState(), color.getDefaultColor()), PorterDuff.Mode.MULTIPLY); setElevation(elevation); setTranslationZ(translationZ); } }
@Override public void setOutlineSpotShadowColor(ColorStateList color) { spotShadowColor = color; if (Carbon.IS_PIE_OR_HIGHER) { super.setOutlineSpotShadowColor(color.getColorForState(getDrawableState(), color.getDefaultColor())); } else { spotShadowColorFilter = new PorterDuffColorFilter(color.getColorForState(getDrawableState(), color.getDefaultColor()), PorterDuff.Mode.MULTIPLY); setElevation(elevation); setTranslationZ(translationZ); } }
private void updateBackgroundColor(int[] state){ int color = mBackgroundColors.getColorForState(state, mBackgroundColors.getDefaultColor()); if(mCurrentBackgroundColor != color){ mCurrentBackgroundColor = color; for(int i = 0; i < getChildCount(); i++){ CircleCheckedTextView child = (CircleCheckedTextView)getChildAt(i); child.setBackgroundColor(color); } invalidate(); } }