Search in sources :

Example 6 with RoundRectShape

use of android.graphics.drawable.shapes.RoundRectShape in project wire-android by wireapp.

the class ViewUtils method getRoundedRect.

public static Drawable getRoundedRect(int cornerRadius, int backgroundColor) {
    RoundRectShape rect = new RoundRectShape(new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius }, null, null);
    ShapeDrawable background = new ShapeDrawable(rect);
    background.getPaint().setColor(backgroundColor);
    return background;
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 7 with RoundRectShape

use of android.graphics.drawable.shapes.RoundRectShape in project smartmodule by carozhu.

the class BadgeView method getDefaultBackground.

private ShapeDrawable getDefaultBackground() {
    int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP);
    float[] outerR = new float[] { r, r, r, r, r, r, r, r };
    RoundRectShape rr = new RoundRectShape(outerR, null, null);
    ShapeDrawable drawable = new ShapeDrawable(rr);
    drawable.getPaint().setColor(badgeColor);
    return drawable;
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Example 8 with RoundRectShape

use of android.graphics.drawable.shapes.RoundRectShape in project FlatUI by eluleci.

the class FlatToggleButton 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_FlatToggleButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatToggleButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        space = a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_space, space);
        padding = space / 10;
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    ShapeDrawable uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
    InsetDrawable uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, padding);
    ShapeDrawable uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedEnabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    uncheckedEnabledBack.setIntrinsicWidth(space / 2 * 5);
    uncheckedEnabledBack.setIntrinsicHeight(space);
    uncheckedEnabledBack.setPadding(0, 0, space / 2 * 5, 0);
    Drawable[] d1 = { uncheckedEnabledBack, uncheckedEnabledFront };
    LayerDrawable uncheckedEnabled = new LayerDrawable(d1);
    // creating checked-enabled state drawable
    ShapeDrawable checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
    InsetDrawable checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, padding);
    ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedEnabledBack.getPaint().setColor(attributes.getColor(3));
    checkedEnabledBack.setPadding(space / 2 * 5, 0, 0, 0);
    Drawable[] d2 = { checkedEnabledBack, checkedEnabledFront };
    LayerDrawable checkedEnabled = new LayerDrawable(d2);
    // creating unchecked-disabled state drawable
    ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedDisabledFrontCore.getPaint().setColor(Color.parseColor("#d2d2d2"));
    InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, padding);
    ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    uncheckedDisabledBack.setPadding(0, 0, space / 2 * 5, 0);
    Drawable[] d3 = { uncheckedDisabledBack, uncheckedDisabledFront };
    LayerDrawable uncheckedDisabled = new LayerDrawable(d3);
    // creating checked-disabled state drawable
    ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedDisabledFrontCore.getPaint().setColor(attributes.getColor(3));
    InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, padding);
    ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    checkedDisabledBack.setPadding(space / 2 * 5, 0, 0, 0);
    Drawable[] d4 = { checkedDisabledBack, checkedDisabledFront };
    LayerDrawable checkedDisabled = new LayerDrawable(d4);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(uncheckedEnabled, padding * 2));
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(checkedEnabled, padding * 2));
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(uncheckedDisabled, padding * 2));
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(checkedDisabled, padding * 2));
    setBackgroundDrawable(states);
    setText("");
    setTextOff("");
    setTextOn("");
    setTextSize(0);
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 9 with RoundRectShape

use of android.graphics.drawable.shapes.RoundRectShape in project FlatUI by eluleci.

the class FlatButton method init.

private void init(AttributeSet attrs) {
    // saving padding values for using them after setting background drawable
    final int paddingTop = getPaddingTop();
    final int paddingRight = getPaddingRight();
    final int paddingLeft = getPaddingLeft();
    final int paddingBottom = getPaddingBottom();
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setTouchEffect(a.getInt(R.styleable.fl_FlatButton_fl_touchEffect, Attributes.DEFAULT_TOUCH_EFFECT));
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatButton_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatButton_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatButton_fl_fontExtension));
        attributes.setTextAppearance(a.getInt(R.styleable.fl_FlatButton_fl_textAppearance, Attributes.DEFAULT_TEXT_APPEARANCE));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        // getting view specific attributes
        bottom = a.getDimensionPixelSize(R.styleable.fl_FlatButton_fl_blockButtonEffectHeight, bottom);
        a.recycle();
    }
    if (attributes.hasTouchEffect()) {
        boolean hasRippleEffect = attributes.getTouchEffect() == Attributes.RIPPLE_TOUCH_EFFECT;
        touchEffectAnimator = new TouchEffectAnimator(this);
        touchEffectAnimator.setHasRippleEffect(hasRippleEffect);
        touchEffectAnimator.setEffectColor(attributes.getColor(1));
        touchEffectAnimator.setClipRadius(attributes.getRadius());
    }
    /*mPaint = new Paint();
        mPaint.setColor(attributes.getColor(1));
        mPaint.setAlpha(mAlpha);*/
    // creating normal state drawable
    ShapeDrawable normalFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    normalFront.getPaint().setColor(attributes.getColor(2));
    ShapeDrawable normalBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    normalBack.getPaint().setColor(attributes.getColor(1));
    normalBack.setPadding(0, 0, 0, bottom);
    Drawable[] d = { normalBack, normalFront };
    LayerDrawable normal = new LayerDrawable(d);
    // creating pressed state drawable
    ShapeDrawable pressedFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    pressedFront.getPaint().setColor(attributes.getColor(1));
    ShapeDrawable pressedBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    pressedBack.getPaint().setColor(attributes.getColor(0));
    if (bottom != 0)
        pressedBack.setPadding(0, 0, 0, bottom / 2);
    Drawable[] d2 = { pressedBack, pressedFront };
    LayerDrawable pressed = new LayerDrawable(d2);
    // creating disabled state drawable
    ShapeDrawable disabledFront = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    disabledFront.getPaint().setColor(attributes.getColor(3));
    disabledFront.getPaint().setAlpha(0xA0);
    ShapeDrawable disabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    disabledBack.getPaint().setColor(attributes.getColor(2));
    Drawable[] d3 = { disabledBack, disabledFront };
    LayerDrawable disabled = new LayerDrawable(d3);
    StateListDrawable states = new StateListDrawable();
    if (!attributes.hasTouchEffect())
        states.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed);
    states.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, pressed);
    states.addState(new int[] { android.R.attr.state_enabled }, normal);
    states.addState(new int[] { -android.R.attr.state_enabled }, disabled);
    setBackgroundDrawable(states);
    setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    if (attributes.getTextAppearance() == 1)
        setTextColor(attributes.getColor(0));
    else if (attributes.getTextAppearance() == 2)
        setTextColor(attributes.getColor(3));
    else
        setTextColor(Color.WHITE);
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) TouchEffectAnimator(com.cengalabs.flatui.TouchEffectAnimator) Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 10 with RoundRectShape

use of android.graphics.drawable.shapes.RoundRectShape in project Euclid by Yalantis.

the class EuclidActivity method buildAvatarCircleOverlay.

/**
     * This method creates a view with empty/transparent circle in it's center. This view is used
     * to cover the profile avatar.
     *
     * @return - ShapeDrawable object.
     */
private ShapeDrawable buildAvatarCircleOverlay() {
    int radius = 666;
    ShapeDrawable overlay = new ShapeDrawable(new RoundRectShape(null, new RectF(sScreenWidth / 2 - dpToPx(getCircleRadiusDp() * 2), sProfileImageHeight / 2 - dpToPx(getCircleRadiusDp() * 2), sScreenWidth / 2 - dpToPx(getCircleRadiusDp() * 2), sProfileImageHeight / 2 - dpToPx(getCircleRadiusDp() * 2)), new float[] { radius, radius, radius, radius, radius, radius, radius, radius }));
    overlay.getPaint().setColor(getResources().getColor(R.color.gray));
    return overlay;
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) RectF(android.graphics.RectF) ShapeDrawable(android.graphics.drawable.ShapeDrawable)

Aggregations

RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)14 ShapeDrawable (android.graphics.drawable.ShapeDrawable)12 RectF (android.graphics.RectF)3 TypedArray (android.content.res.TypedArray)2 Drawable (android.graphics.drawable.Drawable)2 InsetDrawable (android.graphics.drawable.InsetDrawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2 OvalShape (android.graphics.drawable.shapes.OvalShape)2 Attributes (com.cengalabs.flatui.Attributes)2 SuppressLint (android.annotation.SuppressLint)1 Typeface (android.graphics.Typeface)1 TouchEffectAnimator (com.cengalabs.flatui.TouchEffectAnimator)1