use of android.content.res.ColorStateList in project Carbon by ZieIony.
the class EditText method drawableStateChanged.
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
if (rippleDrawable != null && rippleDrawable.getStyle() != RippleDrawable.Style.Background)
rippleDrawable.setState(getDrawableState());
if (stateAnimator != null)
stateAnimator.setState(getDrawableState());
ColorStateList textColors = getTextColors();
if (textColors instanceof AnimatedColorStateList)
((AnimatedColorStateList) textColors).setState(getDrawableState());
if (tint != null && tint instanceof AnimatedColorStateList)
((AnimatedColorStateList) tint).setState(getDrawableState());
if (backgroundTint != null && backgroundTint instanceof AnimatedColorStateList)
((AnimatedColorStateList) backgroundTint).setState(getDrawableState());
}
use of android.content.res.ColorStateList in project remusic by aa112901.
the class ColorStateListUtils method createColorStateList.
static ColorStateList createColorStateList(Context context, int resId) {
if (resId <= 0)
return null;
TypedValue value = new TypedValue();
context.getResources().getValue(resId, value, true);
ColorStateList cl = null;
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
//Assume that "color/theme_color_primary" and "color/theme_color_profile" have the same color value;
//However, "color/theme_color_primary" need to replace by themeId, "color/theme_color_profile" not.
//If use value.data may cause "color/theme_color_profile" still been replaced by themeId
cl = ColorStateList.valueOf(ThemeUtils.replaceColorById(context, value.resourceId));
} else {
final String file = value.string.toString();
try {
if (file.endsWith("xml")) {
final XmlResourceParser rp = context.getResources().getAssets().openXmlResourceParser(value.assetCookie, file);
final AttributeSet attrs = Xml.asAttributeSet(rp);
int type;
while ((type = rp.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Seek parser to start tag.
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
cl = createFromXmlInner(context, rp, attrs);
rp.close();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
return cl;
}
use of android.content.res.ColorStateList in project remusic by aa112901.
the class ColorStateListUtils method inflateColorStateList.
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int depth;
int type;
LinkedList<int[]> stateList = new LinkedList<>();
LinkedList<Integer> colorList = new LinkedList<>();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color });
final int value = a1.getResourceId(0, Color.MAGENTA);
final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value);
a1.recycle();
TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha });
final float alphaMod = a2.getFloat(0, 1.0f);
a2.recycle();
colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor);
stateList.add(extractStateSet(attrs));
}
if (stateList.size() > 0 && stateList.size() == colorList.size()) {
int[] colors = new int[colorList.size()];
for (int i = 0; i < colorList.size(); i++) {
colors[i] = colorList.get(i);
}
return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors);
}
return null;
}
use of android.content.res.ColorStateList in project remusic by aa112901.
the class LayerDrawableUtils method inflateDrawable.
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
int layerAttrUseCount = 0;
int drawableUseCount = 0;
int space = STEP << 1;
//L,T,R,B,S,E,id
int[][] childLayersAttrs = new int[space][ATTRS.length];
Drawable[] drawables = new Drawable[space];
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
if (layerAttrUseCount >= childLayersAttrs.length) {
int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
childLayersAttrs = dstInt;
}
updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
layerAttrUseCount++;
Drawable drawable = getAttrDrawable(context, attrs, android.R.attr.drawable);
// element.
if (drawable == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
drawable = createFromXmlInner(context, parser, attrs);
} else {
final ColorStateList cls = getTintColorList(context, attrs, R.attr.drawableTint);
if (cls != null) {
drawable = ThemeUtils.tintDrawable(drawable, cls, getTintMode(context, attrs, R.attr.drawableTintMode));
}
}
if (drawable != null) {
if (drawableUseCount >= drawables.length) {
Drawable[] dst = new Drawable[drawables.length + STEP];
System.arraycopy(drawables, 0, dst, 0, drawables.length);
drawables = dst;
}
drawables[drawableUseCount] = drawable;
drawableUseCount++;
}
}
if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
return null;
} else {
LayerDrawable layerDrawable = new LayerDrawable(drawables);
for (int i = 0; i < drawables.length; i++) {
int[] childLayersAttr = childLayersAttrs[i];
if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
}
if (childLayersAttr[4] != 0) {
layerDrawable.setId(i, childLayersAttr[4]);
}
}
return layerDrawable;
}
}
use of android.content.res.ColorStateList in project remusic by aa112901.
the class ThemeUtils method getDisabledThemeAttrColor.
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);
}
}
Aggregations