Search in sources :

Example 6 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class IconRoundCornerProgressBar method setProgressColor.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public void setProgressColor(int color) {
    progressColor = color;
    int radius = this.radius - (padding / 2);
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(progressColor);
    gradient.setCornerRadii(new float[] { 0, 0, radius, radius, radius, radius, 0, 0 });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackgroundDrawable(gradient);
    } else {
        layoutProgress.setBackground(gradient);
    }
    if (!isProgressBarCreated) {
        isProgressColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 7 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class IconRoundCornerProgressBar method setHeaderColor.

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void setHeaderColor(int color) {
    headerColor = color;
    int radius = this.radius - (padding / 2);
    GradientDrawable gradient = new GradientDrawable();
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setColor(headerColor);
    gradient.setCornerRadii(new float[] { radius, radius, 0, 0, 0, 0, radius, radius });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutHeader.setBackgroundDrawable(gradient);
    } else {
        layoutHeader.setBackground(gradient);
    }
    if (!isProgressBarCreated) {
        isHeaderColorSetBeforeDraw = true;
    }
}
Also used : SuppressLint(android.annotation.SuppressLint) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint)

Example 8 with GradientDrawable

use of android.graphics.drawable.GradientDrawable in project UltimateAndroid by cymcsg.

the class Configuration method getDrawableFromColor.

/**
	 * usd for get drawable from color
	 * 
	 * @param color
	 * @return
	 */
private Drawable getDrawableFromColor(int color) {
    GradientDrawable tempDrawable = new GradientDrawable();
    tempDrawable.setCornerRadius(this.getRadius());
    tempDrawable.setColor(color);
    return tempDrawable;
}
Also used : GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 9 with GradientDrawable

use of android.graphics.drawable.GradientDrawable 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 10 with GradientDrawable

use of android.graphics.drawable.GradientDrawable 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

GradientDrawable (android.graphics.drawable.GradientDrawable)163 Paint (android.graphics.Paint)19 Drawable (android.graphics.drawable.Drawable)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 SuppressLint (android.annotation.SuppressLint)18 View (android.view.View)18 TextView (android.widget.TextView)18 LayerDrawable (android.graphics.drawable.LayerDrawable)15 ImageView (android.widget.ImageView)14 LinearLayout (android.widget.LinearLayout)12 TypedArray (android.content.res.TypedArray)8 FrameLayout (android.widget.FrameLayout)6 TimeAnimator (android.animation.TimeAnimator)5 Typeface (android.graphics.Typeface)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Attributes (com.cengalabs.flatui.Attributes)5 Resources (android.content.res.Resources)4 TextPaint (android.text.TextPaint)4 Button (android.widget.Button)4