use of android.graphics.drawable.StateListDrawable in project UltimateAndroid by cymcsg.
the class RelativeLayoutFeedback method setSelector.
private void setSelector(TypedArray a) {
touchFeedbackDrawable = new StateListDrawable();
touchFeedbackDrawable.addState(new int[] { android.R.attr.state_pressed }, getColor(a));
}
use of android.graphics.drawable.StateListDrawable 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 android.graphics.drawable.StateListDrawable in project MaterialLibrary by DeveloperPaul123.
the class MaterialFABMenuItem method getFillDrawable.
private Drawable getFillDrawable() {
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, getShapeDrawable(disabledColor));
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, getShapeDrawable(pressedColor));
stateListDrawable.addState(new int[] {}, getShapeDrawable(color));
return stateListDrawable;
}
use of android.graphics.drawable.StateListDrawable in project android_packages_apps_Launcher2 by CyanogenMod.
the class HolographicLinearLayout method drawableStateChanged.
@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
if (mImageView != null) {
Drawable d = mImageView.getDrawable();
if (d instanceof StateListDrawable) {
StateListDrawable sld = (StateListDrawable) d;
sld.setState(getDrawableState());
}
}
}
use of android.graphics.drawable.StateListDrawable in project android_packages_apps_Launcher2 by CyanogenMod.
the class HolographicViewHelper method generatePressedFocusedStates.
/**
* Generate the pressed/focused states if necessary.
*/
void generatePressedFocusedStates(ImageView v) {
if (!mStatesUpdated && v != null) {
mStatesUpdated = true;
Bitmap original = createOriginalImage(v, mTempCanvas);
Bitmap outline = createPressImage(v, mTempCanvas);
FastBitmapDrawable originalD = new FastBitmapDrawable(original);
FastBitmapDrawable outlineD = new FastBitmapDrawable(outline);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_pressed }, outlineD);
states.addState(new int[] { android.R.attr.state_focused }, outlineD);
states.addState(new int[] {}, originalD);
v.setImageDrawable(states);
}
}
Aggregations