Search in sources :

Example 1 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project Launcher3 by chislon.

the class HolographicLinearLayout method drawableStateChanged.

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (mImageView != null) {
        mHolographicHelper.generatePressedFocusedStates(mImageView);
        Drawable d = mImageView.getDrawable();
        if (d instanceof StateListDrawable) {
            StateListDrawable sld = (StateListDrawable) d;
            sld.setState(getDrawableState());
            sld.invalidateSelf();
        }
    }
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 2 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project UltimateRecyclerView by cymcsg.

the class JellyBeanFloatingActionButton method createFillDrawable.

/**
     * more advanced usage for fillable in alpha
     *
     * @param circleRect the defined rectangle
     * @return StateListDrawable item
     */
protected StateListDrawable createFillDrawable(RectF circleRect) {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createAlphaDrawble(circleRect, mColorPressed, mAlpha_press));
    drawable.addState(new int[] {}, createAlphaDrawble(circleRect, mColorNormal, mAlpha_normal));
    return drawable;
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 3 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project circular-progress-button by dmytrodanylyk.

the class CircularProgressButton method initErrorStateDrawable.

private void initErrorStateDrawable() {
    int colorPressed = getPressedColor(mErrorColorState);
    StrokeGradientDrawable drawablePressed = createDrawable(colorPressed);
    mErrorStateDrawable = new StateListDrawable();
    mErrorStateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawablePressed.getGradientDrawable());
    mErrorStateDrawable.addState(StateSet.WILD_CARD, background.getGradientDrawable());
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) SuppressLint(android.annotation.SuppressLint)

Example 4 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FlexibleAdapter by davideas.

the class FastScroller method setBubbleAndHandleColor.

private void setBubbleAndHandleColor(int accentColor) {
    //TODO: Programmatically generate the Drawables instead of using resources
    //BubbleDrawable accentColor
    GradientDrawable bubbleDrawable;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        bubbleDrawable = (GradientDrawable) getResources().getDrawable(R.drawable.fast_scroller_bubble, null);
    } else {
        //noinspection deprecation
        bubbleDrawable = (GradientDrawable) getResources().getDrawable(R.drawable.fast_scroller_bubble);
    }
    assert bubbleDrawable != null;
    bubbleDrawable.setColor(accentColor);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        bubble.setBackground(bubbleDrawable);
    } else {
        //noinspection deprecation
        bubble.setBackgroundDrawable(bubbleDrawable);
    }
    //HandleDrawable accentColor
    try {
        StateListDrawable stateListDrawable;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            stateListDrawable = (StateListDrawable) getResources().getDrawable(R.drawable.fast_scroller_handle, null);
        } else {
            //noinspection deprecation
            stateListDrawable = (StateListDrawable) getResources().getDrawable(R.drawable.fast_scroller_handle);
        }
        //Method is still hidden, invoke Java reflection
        Method getStateDrawable = StateListDrawable.class.getMethod("getStateDrawable", int.class);
        GradientDrawable handleDrawable = (GradientDrawable) getStateDrawable.invoke(stateListDrawable, 0);
        handleDrawable.setColor(accentColor);
        handle.setImageDrawable(stateListDrawable);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Method(java.lang.reflect.Method) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 5 with StateListDrawable

use of android.graphics.drawable.StateListDrawable in project FlatUI by eluleci.

the class FlatCheckBox method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatCheckBox);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatCheckBox_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatCheckBox_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatCheckBox_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatCheckBox_fl_fontExtension));
        attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_size, Attributes.DEFAULT_SIZE_PX));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        attributes.setBorderWidth(attributes.getSize() / 10);
        // getting view specific attributes
        dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_dotMargin, dotMargin);
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedEnabled = new GradientDrawable();
    uncheckedEnabled.setCornerRadius(attributes.getRadius());
    uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedEnabled.setColor(Color.TRANSPARENT);
    uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    // creating checked-enabled state drawable
    GradientDrawable checkedOutside = new GradientDrawable();
    checkedOutside.setCornerRadius(attributes.getRadius());
    checkedOutside.setSize(attributes.getSize(), attributes.getSize());
    checkedOutside.setColor(Color.TRANSPARENT);
    checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
    checkedCore.setCornerRadius(attributes.getRadius());
    checkedCore.setIntrinsicHeight(attributes.getSize());
    checkedCore.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
    LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedDisabled = new GradientDrawable();
    uncheckedDisabled.setCornerRadius(attributes.getRadius());
    uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedDisabled.setColor(Color.TRANSPARENT);
    uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    // creating checked-disabled state drawable
    GradientDrawable checkedOutsideDisabled = new GradientDrawable();
    checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
    checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
    checkedOutsideDisabled.setColor(Color.TRANSPARENT);
    checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
    checkedCoreDisabled.setCornerRadius(attributes.getRadius());
    checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
    checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
    LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
    setButtonDrawable(states);
    // setting padding for avoiding text to appear on icon
    setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
    setTextColor(attributes.getColor(2));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) PaintDrawable(android.graphics.drawable.PaintDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Aggregations

StateListDrawable (android.graphics.drawable.StateListDrawable)163 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)15 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 Paint (android.graphics.Paint)8 ColorStateList (android.content.res.ColorStateList)7 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