Skip to content

Instantly share code, notes, and snippets.

@longkai
Created January 20, 2015 07:42
Show Gist options
  • Save longkai/607247b52aa29546effc to your computer and use it in GitHub Desktop.
Save longkai/607247b52aa29546effc to your computer and use it in GitHub Desktop.
package com.imaygou.android.helper.drawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
/**
* Created by longkai on 20/1/15.
*/
public class DrawableBuilder {
private int radius;
private int solidColor;
private int strokeWidth;
private int strokeColor;
public DrawableBuilder setRadius(int radius) {
this.radius = radius;
return this;
}
public DrawableBuilder setSolidColor(int solidColor) {
this.solidColor = solidColor;
return this;
}
public DrawableBuilder setStrokeWidth(int strokeWidth) {
this.strokeWidth = strokeWidth;
return this;
}
public DrawableBuilder setStrokeColor(int strokeColor) {
this.strokeColor = strokeColor;
return this;
}
public Drawable build() {
GradientDrawable drawable = new GradientDrawable();
drawable.setCornerRadius(radius);
if (solidColor != 0) {
drawable.setColor(solidColor);
}
if (strokeWidth != 0 && strokeColor != 0) {
drawable.setStroke(strokeWidth, strokeColor);
}
return drawable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment