You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
ColorStateList: load color with obtainStyledAttributes()
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.content.res;
|
package android.content.res;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.util.StateSet;
|
import android.util.StateSet;
|
||||||
@@ -186,25 +187,20 @@ public class ColorStateList {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int colorRes = 0;
|
|
||||||
int color = 0xffff0000;
|
int color = 0xffff0000;
|
||||||
boolean haveColor = false;
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
final int numAttrs = attrs.getAttributeCount();
|
final int numAttrs = attrs.getAttributeCount();
|
||||||
int[] stateSpec = new int[numAttrs];
|
int[] stateSpec = new int[numAttrs];
|
||||||
|
TypedArray a = Context.this_application.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ColorStateListItem);
|
||||||
|
color = a.getColor(com.android.internal.R.styleable.ColorStateListItem_color, color);
|
||||||
|
a.recycle();
|
||||||
for (i = 0; i < numAttrs; i++) {
|
for (i = 0; i < numAttrs; i++) {
|
||||||
final int stateResId = attrs.getAttributeNameResource(i);
|
final int stateResId = attrs.getAttributeNameResource(i);
|
||||||
if (stateResId == 0)
|
if (stateResId == 0)
|
||||||
break;
|
break;
|
||||||
if (stateResId == com.android.internal.R.attr.color) {
|
if (stateResId == com.android.internal.R.attr.color) {
|
||||||
colorRes = attrs.getAttributeResourceValue(i, 0);
|
|
||||||
|
|
||||||
if (colorRes == 0) {
|
|
||||||
color = attrs.getAttributeIntValue(i, color);
|
|
||||||
haveColor = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
stateSpec[j++] = attrs.getAttributeBooleanValue(i, false)
|
stateSpec[j++] = attrs.getAttributeBooleanValue(i, false)
|
||||||
? stateResId
|
? stateResId
|
||||||
@@ -213,13 +209,6 @@ public class ColorStateList {
|
|||||||
}
|
}
|
||||||
stateSpec = StateSet.trimStateSet(stateSpec, j);
|
stateSpec = StateSet.trimStateSet(stateSpec, j);
|
||||||
|
|
||||||
if (colorRes != 0) {
|
|
||||||
color = r.getColor(colorRes);
|
|
||||||
} else if (!haveColor) {
|
|
||||||
throw new XmlPullParserException(
|
|
||||||
parser.getPositionDescription() + ": <item> tag requires a 'android:color' attribute.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listSize == 0 || stateSpec.length == 0) {
|
if (listSize == 0 || stateSpec.length == 0) {
|
||||||
mDefaultColor = color;
|
mDefaultColor = color;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user