下面列出了android.graphics.drawable.PaintDrawable#setCornerRadius() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, com.cengalabs.flatui.R.styleable.fl_FlatSeekBar);
// getting common attributes
int customTheme = a.getResourceId(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setSize(a.getDimensionPixelSize(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_size, Attributes.DEFAULT_SIZE_PX));
a.recycle();
}
// setting thumb
PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
thumb.setCornerRadius(attributes.getSize() * 9 / 8);
thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
setThumb(thumb);
// progress
PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
progress.setCornerRadius(attributes.getSize());
progress.setIntrinsicHeight(attributes.getSize());
progress.setIntrinsicWidth(attributes.getSize());
progress.setDither(true);
ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT, ClipDrawable.HORIZONTAL);
// secondary progress
PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
secondary.setCornerRadius(attributes.getSize());
secondary.setIntrinsicHeight(attributes.getSize());
ClipDrawable secondaryProgressClip = new ClipDrawable(secondary, Gravity.LEFT, ClipDrawable.HORIZONTAL);
// background
PaintDrawable background = new PaintDrawable(attributes.getColor(3));
background.setCornerRadius(attributes.getSize());
background.setIntrinsicHeight(attributes.getSize());
// applying drawable
LayerDrawable ld = (LayerDrawable) getProgressDrawable();
ld.setDrawableByLayerId(R.id.background, background);
ld.setDrawableByLayerId(R.id.progress, progressClip);
ld.setDrawableByLayerId(R.id.secondaryProgress, secondaryProgressClip);
}
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatRadioButton);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatRadioButton_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setFontFamily(a.getString(R.styleable.fl_FlatRadioButton_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatRadioButton_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatRadioButton_fl_fontExtension));
attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_size, Attributes.DEFAULT_SIZE_PX));
attributes.setRadius(attributes.getSize() / 2);
attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
// getting view specific attributes
dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_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.getSize());
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.getSize());
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 be 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);
}
}
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);
}
}
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.fl_FlatSeekBar);
// getting common attributes
int customTheme = a.getResourceId(
R.styleable.fl_FlatSeekBar_fl_theme,
Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setSize(a.getDimensionPixelSize(
R.styleable.fl_FlatSeekBar_fl_size,
Attributes.DEFAULT_SIZE_PX));
a.recycle();
}
// setting thumb
PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
thumb.setCornerRadius(attributes.getSize() * 9 / 8);
thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
setThumb(thumb);
// progress
PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
progress.setCornerRadius(attributes.getSize());
progress.setIntrinsicHeight(attributes.getSize());
progress.setIntrinsicWidth(attributes.getSize());
progress.setDither(true);
ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT,
ClipDrawable.HORIZONTAL);
// secondary progress
PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
secondary.setCornerRadius(attributes.getSize());
secondary.setIntrinsicHeight(attributes.getSize());
ClipDrawable secondaryProgressClip = new ClipDrawable(secondary,
Gravity.LEFT, ClipDrawable.HORIZONTAL);
// background
PaintDrawable background = new PaintDrawable(attributes.getColor(3));
background.setCornerRadius(attributes.getSize());
background.setIntrinsicHeight(attributes.getSize());
// applying drawable
LayerDrawable ld = (LayerDrawable) getProgressDrawable();
ld.setDrawableByLayerId(android.R.id.background, background);
ld.setDrawableByLayerId(android.R.id.progress, progressClip);
ld.setDrawableByLayerId(android.R.id.secondaryProgress,
secondaryProgressClip);
}
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatRadioButton);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatRadioButton_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setFontFamily(a.getString(R.styleable.fl_FlatRadioButton_fl_fontFamily));
attributes.setFontWeight(a.getString(R.styleable.fl_FlatRadioButton_fl_fontWeight));
attributes.setFontExtension(a.getString(R.styleable.fl_FlatRadioButton_fl_fontExtension));
attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_size, Attributes.DEFAULT_SIZE_PX));
attributes.setRadius(attributes.getSize() / 2);
attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
// getting view specific attributes
dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_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.getSize());
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.getSize());
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 be 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);
}
}