Search in sources :

Example 46 with StateListDrawable

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));
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 47 with StateListDrawable

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;
}
Also used : FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) ArrayList(java.util.ArrayList) StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) StateListDrawable(android.graphics.drawable.StateListDrawable) FilterableStateListDrawable(com.bilibili.magicasakura.drawables.FilterableStateListDrawable)

Example 48 with StateListDrawable

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;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 49 with 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());
        }
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 50 with StateListDrawable

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) StateListDrawable(android.graphics.drawable.StateListDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)166 Drawable (android.graphics.drawable.Drawable)43 LayerDrawable (android.graphics.drawable.LayerDrawable)24 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 GradientDrawable (android.graphics.drawable.GradientDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)17 Bitmap (android.graphics.Bitmap)13 TextView (android.widget.TextView)12 ShapeDrawable (android.graphics.drawable.ShapeDrawable)11 View (android.view.View)11 AnimationDrawable (android.graphics.drawable.AnimationDrawable)9 ClipDrawable (android.graphics.drawable.ClipDrawable)9 SuppressLint (android.annotation.SuppressLint)8 ColorStateList (android.content.res.ColorStateList)8 Paint (android.graphics.Paint)8 RippleDrawable (android.graphics.drawable.RippleDrawable)7 TargetApi (android.annotation.TargetApi)6 TypedArray (android.content.res.TypedArray)6 TextPaint (android.text.TextPaint)5 Button (android.widget.Button)5