Created
January 20, 2015 07:42
-
-
Save longkai/607247b52aa29546effc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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