public MarkerDrawable(@NonNull ColorStateList tintList, int closedSize) { super(tintList); mInterpolator = new AccelerateDecelerateInterpolator(); mClosedStateSize = closedSize; mStartColor = tintList.getColorForState( new int[] {android.R.attr.state_pressed}, tintList.getDefaultColor()); mEndColor = tintList.getDefaultColor(); }
public ChartGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setWillNotDraw(false); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ChartGridView, defStyle, 0); mPrimary = a.getDrawable(R.styleable.ChartGridView_primaryDrawable); mSecondary = a.getDrawable(R.styleable.ChartGridView_secondaryDrawable); mBorder = a.getDrawable(R.styleable.ChartGridView_borderDrawable); final int taId = a.getResourceId(R.styleable.ChartGridView_android_textAppearance, -1); final TypedArray ta = context.obtainStyledAttributes(taId, com.android.internal.R.styleable.TextAppearance); mLabelSize = ta.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0); ta.recycle(); final ColorStateList labelColor = a.getColorStateList(R.styleable.ChartGridView_android_textColor); mLabelColor = labelColor.getDefaultColor(); a.recycle(); }
private void updateTint() { if (tint == null) tint = new TintPrimaryColorStateList(getContext()); int color = tint.getColorForState(getDrawableState(), tint.getDefaultColor()); if (leftGlow != null) leftGlow.setColor(color); if (rightGlow != null) rightGlow.setColor(color); postInvalidate(); }
/** * Sets the color of the seek thumb, as well as the color of the popup indicator. * * @param thumbColorStateList The ColorStateList the seek thumb will be changed to * @param indicatorColor The color the popup indicator will be changed to The indicator will * animate from thumbColorStateList(pressed state) to indicatorColor when opening */ public void setThumbColor(@NonNull ColorStateList thumbColorStateList, int indicatorColor) { mThumb.setColorStateList(thumbColorStateList); // we use the "pressed" color to morph the indicator from it to its own color int thumbColor = thumbColorStateList.getColorForState( new int[] {PRESSED_STATE}, thumbColorStateList.getDefaultColor()); mIndicator.setColors(indicatorColor, thumbColor); }
protected void resetHoverColor() { if (Utilities.ATLEAST_LOLLIPOP) { animateTextColor(mOriginalTextColor.getDefaultColor()); } else { mDrawable.setColorFilter(null); setTextColor(mOriginalTextColor); } }
private static ColorStateList createNavigationItemTintList( int baseColorAttrRes, int primaryColor, Context context) { ColorStateList baseColor = ViewUtils.getColorStateListFromAttrRes(baseColorAttrRes, context); int defaultColor = baseColor.getDefaultColor(); return new ColorStateList( new int[][] {DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET}, new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), primaryColor, defaultColor }); }
@Override protected boolean onStateChange(int[] stateSet) { final int newColor = mBackground.getColorForState(stateSet, mBackground.getDefaultColor()); final boolean colorChanged = newColor != mPaint.getColor(); if (colorChanged) { mPaint.setColor(newColor); } if (mTint != null && mTintMode != null) { mTintFilter = createTintFilter(mTint, mTintMode); return true; } return colorChanged; }
private boolean updateTint(int ai[]) { if (mTintList != null && mTintMode != null) { int i = mTintList.getColorForState(ai, mTintList.getDefaultColor()); ai = mTintMode; if (!mColorFilterSet || i != mCurrentColor || ai != mCurrentMode) { setColorFilter(i, ai); mCurrentColor = i; mCurrentMode = ai; mColorFilterSet = true; return true; } } return false; }
/** This method is idempotent so it only has effect the first time it's called */ private void init(Context context) { if (mInitialised) { return; } mInitialised = true; mDraweeHolder = DraweeHolder.create(null, context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ColorStateList imageTintList = getImageTintList(); if (imageTintList == null) { return; } setColorFilter(imageTintList.getDefaultColor()); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // Draw the switch int switchLeft = mSwitchLeft; int switchTop = mSwitchTop; int switchRight = mSwitchRight; int switchBottom = mSwitchBottom; mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom); mTrackDrawable.draw(canvas); canvas.save(); mTrackDrawable.getPadding(mTempRect); int switchInnerLeft = switchLeft + mTempRect.left; int switchInnerTop = switchTop + mTempRect.top; int switchInnerRight = switchRight - mTempRect.right; int switchInnerBottom = switchBottom - mTempRect.bottom; canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom); mThumbDrawable.getPadding(mTempRect); final int thumbPos = (int) (mThumbPosition + 0.5f); int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos; int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right; mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom); mThumbDrawable.draw(canvas); // mTextColors should not be null, but just in case if (mTextColors != null) { mTextPaint.setColor( mTextColors.getColorForState(getDrawableState(), mTextColors.getDefaultColor())); } mTextPaint.drawableState = getDrawableState(); Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { canvas.translate( (thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2, (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2); switchText.draw(canvas); } canvas.restore(); }
@Override protected void onDraw(Canvas canvas) { if ((getGravity() & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.CENTER_VERTICAL) { if ((getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.CENTER_HORIZONTAL) { super.onDraw(canvas); } else { final ColorStateList csl = getTextColors(); final int color = csl.getDefaultColor(); final int viewHeight = getHeight(); final float textSize = getTextSize(); final TextPaint paint = getPaint(); paint.setColor(color); // Logger.d("TEXT", String.format("Padding: %d", getPaddingTop())); canvas.drawText(getText().toString(), 0, (viewHeight / 2 + textSize / 2), paint); } } else { super.onDraw(canvas); } }
public void testColorStateList() throws NotFoundException, XmlPullParserException, IOException { final int[][] state = new int[][] {{0}, {0}}; final int[] colors = new int[] {Color.RED, Color.BLUE}; ColorStateList c = new ColorStateList(state, colors); assertTrue(c.isStateful()); assertEquals(Color.RED, c.getDefaultColor()); final int alpha = 36; final ColorStateList c1 = c.withAlpha(alpha); assertNotSame(Color.RED, c1.getDefaultColor()); // check alpha assertEquals(alpha, c1.getDefaultColor() >>> 24); assertEquals(Color.RED & 0x00FF0000, c1.getDefaultColor() & 0x00FF0000); final int xmlId = R.drawable.testcolor; final int colorInXml = 0xFFA6C839; // this color value is define in testcolor.xml file. final Resources res = getContext().getResources(); c = ColorStateList.createFromXml(res, res.getXml(xmlId)); assertEquals(colorInXml, c.getDefaultColor()); assertEquals(0, c.describeContents()); assertFalse(c.isStateful()); assertNotNull(c.toString()); assertEquals(colorInXml, c.getColorForState(new int[] {0}, 0)); c = ColorStateList.valueOf(Color.GRAY); assertEquals(Color.GRAY, c.getDefaultColor()); final Parcel parcel = Parcel.obtain(); c.writeToParcel(parcel, 0); parcel.setDataPosition(0); ColorStateList actual = ColorStateList.CREATOR.createFromParcel(parcel); // can only compare the state and the default color. because no API to // get every color of ColorStateList assertEquals(c.isStateful(), actual.isStateful()); assertEquals(c.getDefaultColor(), actual.getDefaultColor()); }
private ColorStateList createSwitchThumbColorStateList(Context paramContext) { int[][] arrayOfInt = new int[3][]; int[] arrayOfInt1 = new int[3]; ColorStateList localColorStateList = ThemeUtils.getThemeAttrColorStateList(paramContext, R.attr.colorSwitchThumbNormal); if ((localColorStateList != null) && (localColorStateList.isStateful())) { arrayOfInt[0] = ThemeUtils.DISABLED_STATE_SET; arrayOfInt1[0] = localColorStateList.getColorForState(arrayOfInt[0], 0); arrayOfInt[1] = ThemeUtils.CHECKED_STATE_SET; arrayOfInt1[1] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorControlActivated); arrayOfInt[2] = ThemeUtils.EMPTY_STATE_SET; arrayOfInt1[2] = localColorStateList.getDefaultColor(); } for (; ; ) { return new ColorStateList(arrayOfInt, arrayOfInt1); arrayOfInt[0] = ThemeUtils.DISABLED_STATE_SET; arrayOfInt1[0] = ThemeUtils.getDisabledThemeAttrColor(paramContext, R.attr.colorSwitchThumbNormal); arrayOfInt[1] = ThemeUtils.CHECKED_STATE_SET; arrayOfInt1[1] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorControlActivated); arrayOfInt[2] = ThemeUtils.EMPTY_STATE_SET; arrayOfInt1[2] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorSwitchThumbNormal); } }
public int getBorderColor() { return borderColor.getDefaultColor(); }
public static String GetColorFromCheckBox(CheckBox checkBox) { ColorStateList buttonTintList = checkBox.getButtonTintList(); return buttonTintList.getDefaultColor() + ""; }
public BatteryHistoryChart(Context context, AttributeSet attrs) { super(context, attrs); mBatteryBackgroundPaint.setARGB(255, 128, 128, 128); mBatteryBackgroundPaint.setStyle(Paint.Style.FILL); mBatteryGoodPaint.setARGB(128, 0, 255, 0); mBatteryGoodPaint.setStyle(Paint.Style.STROKE); mBatteryWarnPaint.setARGB(128, 255, 255, 0); mBatteryWarnPaint.setStyle(Paint.Style.STROKE); mBatteryCriticalPaint.setARGB(192, 255, 0, 0); mBatteryCriticalPaint.setStyle(Paint.Style.STROKE); mChargingPaint.setARGB(255, 0, 128, 0); mChargingPaint.setStyle(Paint.Style.STROKE); mScreenOnPaint.setStyle(Paint.Style.STROKE); mGpsOnPaint.setStyle(Paint.Style.STROKE); mWifiRunningPaint.setStyle(Paint.Style.STROKE); mWakeLockPaint.setStyle(Paint.Style.STROKE); mPhoneSignalChart.setColors( new int[] { 0x00000000, 0xffa00000, 0xffa0a000, 0xff808020, 0xff808040, 0xff808060, 0xff008000 }); mTextPaint.density = getResources().getDisplayMetrics().density; mTextPaint.setCompatibilityScaling(getResources().getCompatibilityInfo().applicationScale); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BatteryHistoryChart, 0, 0); ColorStateList textColor = null; int textSize = 15; int typefaceIndex = -1; int styleIndex = -1; TypedArray appearance = null; int ap = a.getResourceId(R.styleable.BatteryHistoryChart_android_textAppearance, -1); if (ap != -1) { appearance = context.obtainStyledAttributes(ap, com.android.internal.R.styleable.TextAppearance); } if (appearance != null) { int n = appearance.getIndexCount(); for (int i = 0; i < n; i++) { int attr = appearance.getIndex(i); switch (attr) { case com.android.internal.R.styleable.TextAppearance_textColor: textColor = appearance.getColorStateList(attr); break; case com.android.internal.R.styleable.TextAppearance_textSize: textSize = appearance.getDimensionPixelSize(attr, textSize); break; case com.android.internal.R.styleable.TextAppearance_typeface: typefaceIndex = appearance.getInt(attr, -1); break; case com.android.internal.R.styleable.TextAppearance_textStyle: styleIndex = appearance.getInt(attr, -1); break; } } appearance.recycle(); } int shadowcolor = 0; float dx = 0, dy = 0, r = 0; int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.BatteryHistoryChart_android_shadowColor: shadowcolor = a.getInt(attr, 0); break; case R.styleable.BatteryHistoryChart_android_shadowDx: dx = a.getFloat(attr, 0); break; case R.styleable.BatteryHistoryChart_android_shadowDy: dy = a.getFloat(attr, 0); break; case R.styleable.BatteryHistoryChart_android_shadowRadius: r = a.getFloat(attr, 0); break; case R.styleable.BatteryHistoryChart_android_textColor: textColor = a.getColorStateList(attr); break; case R.styleable.BatteryHistoryChart_android_textSize: textSize = a.getDimensionPixelSize(attr, textSize); break; case R.styleable.BatteryHistoryChart_android_typeface: typefaceIndex = a.getInt(attr, typefaceIndex); break; case R.styleable.BatteryHistoryChart_android_textStyle: styleIndex = a.getInt(attr, styleIndex); break; } } a.recycle(); mTextPaint.setColor(textColor.getDefaultColor()); mTextPaint.setTextSize(textSize); Typeface tf = null; switch (typefaceIndex) { case SANS: tf = Typeface.SANS_SERIF; break; case SERIF: tf = Typeface.SERIF; break; case MONOSPACE: tf = Typeface.MONOSPACE; break; } setTypeface(tf, styleIndex); if (shadowcolor != 0) { mTextPaint.setShadowLayer(r, dx, dy, shadowcolor); } }
@Override public void draw(Canvas canvas) { if (src instanceof StateListDrawable) { System.out.println("xx"); } Rect rect = new Rect(0, 0, srcWidth, srcHeight); src.setBounds(rect); Drawable drawable = src.getCurrent(); System.out.println("drawable" + drawable); src.draw(canvas); if (num > 0) { int numStr = num; if (num >= maxNum) { numStr = maxNum; } String text = String.valueOf(numStr); float length = textPaint.measureText(text); float beginX = srcWidth - length - textPadding * 2; float endX = srcWidth; float beginY = 0; FontMetrics fm = textPaint.getFontMetrics(); float endY = fm.descent - fm.ascent; float d = endY; float o_x = (beginX + endX) / 2; float o_y = (beginY + endY) / 2; if (textBg != null) { Rect padding = new Rect(); textBg.getPadding(padding); double maxWidth = Math.max(endX - beginX, textBg.getIntrinsicWidth() - padding.width()); maxWidth = endX - beginX; textBg.setBounds( 0, 0, (int) (maxWidth) + padding.width(), (int) (endY - beginY) + padding.height()); int x = (int) (srcWidth - textBg.getBounds().width()); canvas.save(); canvas.translate(x, 0); o_x = x + textBg.getBounds().width() / 2; textBg.draw(canvas); canvas.restore(); } else { paint.setStyle(Style.FILL); paint.setColor(textBackground); // canvas.drawCircle(o_x, o_y, (endY - beginY) / 2, paint); RectF oval = new RectF(); oval.top = beginY; oval.bottom = endY; oval.left = beginX; oval.right = endX; canvas.drawArc(oval, 0, 360, true, paint); } float baseLine = endY - fm.descent; if (textColorStateList != null) { int currentColor = textColorStateList.getColorForState(getState(), textColorStateList.getDefaultColor()); textPaint.setColor(currentColor); } canvas.drawText(String.valueOf(numStr), o_x - length / 2, baseLine, textPaint); // // FontMetrics fm = textPaint.getFontMetrics(); // // textPaint.setColor(Color.BLACK); // canvas.save(); // canvas.translate(0, 30); // canvas.drawText("xxYz��", 0, 0, textPaint); // canvas.drawLine(0, fm.ascent, bitmap.getWidth(), fm.ascent, // textPaint); // canvas.drawLine(0, fm.descent, bitmap.getWidth(), fm.descent, // textPaint); // // canvas.restore(); } }
private void setBackground(ColorStateList color) { mBackground = (color == null) ? ColorStateList.valueOf(Color.TRANSPARENT) : color; mPaint.setColor(mBackground.getColorForState(getState(), mBackground.getDefaultColor())); }
@Override public void setTextColor(ColorStateList colors) { mTextColor = colors.getDefaultColor(); super.setTextColor(colors); }
/** Utility for a common operation */ @ColorInt private int color(TypedArray array, @StyleableRes int res) { ColorStateList colorStateList = array.getColorStateList(res); return colorStateList == null ? 0 : colorStateList.getDefaultColor(); }
private void updateTint() { if (tint == null) return; int color = tint.getColorForState(getDrawableState(), tint.getDefaultColor()); if (leftGlow != null) leftGlow.setColor(color); if (rightGlow != null) rightGlow.setColor(color); }
public void setSeparatorColor(ColorStateList colorStateList) { if (colorStateList != null) { findById(this, R.id.separator).setBackgroundColor(colorStateList.getDefaultColor()); } }