use of com.bilibili.magicasakura.drawables.FilterableStateListDrawable in project MagicaSakura by Bilibili.
the class StateListDrawableInflateImpl method inflateDrawable.
@Override
public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
StateListDrawable sd = null;
ArrayList<int[]> states = new ArrayList<>();
ArrayList<Drawable> drawables = new ArrayList<>();
SparseArray<ColorFilter> mColorFilterMap = null;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
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;
}
Drawable dr = DrawableUtils.getAttrDrawable(context, attrs, android.R.attr.drawable);
states.add(DrawableUtils.extractStateSet(attrs));
// attributes and extracting states.
if (dr == 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");
}
dr = DrawableUtils.createFromXmlInner(context, parser, attrs);
} else {
ColorFilter colorFilter = DrawableUtils.getAttrColorFilter(context, attrs, R.attr.drawableTint, R.attr.drawableTintMode);
if (colorFilter != null) {
if (mColorFilterMap == null) {
mColorFilterMap = new SparseArray<>();
}
mColorFilterMap.put(drawables.size(), colorFilter);
}
}
drawables.add(dr);
}
if (states.size() >= 1) {
if (mColorFilterMap != null) {
sd = new FilterableStateListDrawable();
for (int i = 0; i < states.size(); i++) {
((FilterableStateListDrawable) sd).addState(states.get(i), drawables.get(i), mColorFilterMap.get(i));
}
} else {
sd = new StateListDrawable();
for (int i = 0; i < states.size(); i++) {
sd.addState(states.get(i), drawables.get(i));
}
}
}
return sd;
}
use of com.bilibili.magicasakura.drawables.FilterableStateListDrawable in project remusic by aa112901.
the class StateListDrawableUtils method inflateDrawable.
@Override
protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
StateListDrawable sd = null;
ArrayList<int[]> states = new ArrayList<>();
ArrayList<Drawable> drawables = new ArrayList<>();
SparseArray<ColorFilter> mColorFilterMap = null;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
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;
}
Drawable dr = getAttrDrawable(context, attrs, android.R.attr.drawable);
states.add(extractStateSet(attrs));
// attributes and extracting states.
if (dr == 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");
}
dr = createFromXmlInner(context, parser, attrs);
} else {
ColorFilter colorFilter = getAttrColorFilter(context, attrs, R.attr.drawableTint, R.attr.drawableTintMode);
if (colorFilter != null) {
if (mColorFilterMap == null) {
mColorFilterMap = new SparseArray<>();
}
mColorFilterMap.put(drawables.size(), colorFilter);
}
}
drawables.add(dr);
}
if (states.size() >= 1) {
if (mColorFilterMap != null) {
sd = new FilterableStateListDrawable();
for (int i = 0; i < states.size(); i++) {
((FilterableStateListDrawable) sd).addState(states.get(i), drawables.get(i), mColorFilterMap.get(i));
}
} else {
sd = new StateListDrawable();
for (int i = 0; i < states.size(); i++) {
sd.addState(states.get(i), drawables.get(i));
}
}
}
return sd;
}
Aggregations