Example usage for android.graphics.drawable ShapeDrawable getPaint

List of usage examples for android.graphics.drawable ShapeDrawable getPaint

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable getPaint.

Prototype

public Paint getPaint() 

Source Link

Document

Returns the Paint used to draw the shape.

Usage

From source file:com.waz.zclient.utils.ViewUtils.java

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;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createImageViewShape(int color) {
    OvalShape ovalShape = new OvalShape();

    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources().getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources().getDimensionPixelSize(R.dimen.button_inset_vertical_material);

    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);

    return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV);
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight,
        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;// w  ww  .  j av  a 2s  .c  o  m
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void setBackgroundColor(View view, int backgroundColor) {
    Drawable background = view.getBackground();
    if (background instanceof ShapeDrawable) {
        ShapeDrawable shapeDrawable = (ShapeDrawable) background;
        shapeDrawable.getPaint().setColor(backgroundColor);
    } else if (background instanceof GradientDrawable) {
        GradientDrawable gradientDrawable = (GradientDrawable) background;
        gradientDrawable.setColor(backgroundColor);
    } else if (background instanceof ColorDrawable) {
        // alpha value may need to be set again after this call
        ColorDrawable colorDrawable = (ColorDrawable) background;
        colorDrawable.setColor(backgroundColor);
    } else {//from  w  w w.j  a  v a 2 s .c  o  m
        L.e("Unknown background type to set color on: " + view.getClass());
    }
}

From source file:org.opensilk.common.ui.widget.ColorCodedThumbnail.java

public void init(String title) {
    Integer color = null;// ww  w . jav  a  2s  .co m
    if (!TextUtils.isEmpty(title)) {
        if (title.equals("..")) {
            setText(title);
            color = R.color.red;
        } else {
            Character c = title.toUpperCase(Locale.US).charAt(0);
            setText(c.toString());
            if (c.compareTo('A') >= 0 && c.compareTo('Z') <= 0) {
                color = COLORS.get(c);
            } else if (c.compareTo('0') >= 0 && c.compareTo('9') <= 0) {
                color = COLORS.get(COLORS.keyAt(Integer.valueOf(c.toString())));
            }
        }
    }
    if (color == null) {
        color = R.color.gray;
    }
    ShapeDrawable bg = new ShapeDrawable(new OvalShape());
    bg.getPaint().setColor(getResources().getColor(color));
    setBackgroundDrawable(bg);
}

From source file:ezy.ui.view.ViewPagerIndicator.java

Drawable genDrawable(int color) {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(color);
    drawable.getPaint().setAntiAlias(true);
    return drawable;
}

From source file:org.mariotaku.twidere.view.HomeActionButton.java

@Override
public void setButtonColor(int color) {
    if (isInEditMode()) {
        final ShapeDrawable sd = new ShapeDrawable(new OvalShape());
        sd.getPaint().setColor(color);
        ViewSupport.setBackground(this, sd);
    } else {//from ww  w .j  ava2s . c  om
        ViewSupport.setBackground(this, new ColorDrawable(color));
    }
}

From source file:br.ufrgs.ufrgsmapas.views.BuildingClusterRenderer.java

private LayerDrawable makeClusterBackground() {
    this.mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    outline.getPaint().setColor(-2130706433);
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, this.mColoredCircleBackground });
    int strokeWidth = (int) (this.mDensity * 3.0F);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));

    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}