Skip to content

Commit 06acaf7

Browse files
committed
Modify builder & fix issue
1 parent fc2ceb4 commit 06acaf7

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java

+26-34
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,16 @@ public class BadgeDrawable extends Drawable {
4343
@IntDef({TYPE_NUMBER, TYPE_ONLY_ONE_TEXT, TYPE_WITH_TWO_TEXT, TYPE_WITH_TWO_TEXT_COMPLEMENTARY})
4444
public @interface BadgeType {}
4545

46-
private static final float DEFAULT_CORNER_RADIUS = dipToPixels(2);
47-
private static final float DEFAULT_TEXT_SIZE = spToPixels(12);
48-
private static final int DEFAULT_BADGE_COLOR = 0xffCC3333;
49-
private static final int DEFAULT_TEXT_COLOR = 0xffFFFFFF;
50-
5146
private static class Config {
5247
private int badgeType = TYPE_NUMBER;
53-
private float cornerRadius;
5448
private int number = 0;
5549
private String text1 = "";
5650
private String text2 = "";
57-
private int badgeColor = DEFAULT_BADGE_COLOR;
58-
private int textColor = DEFAULT_TEXT_COLOR;
59-
private float textSize = DEFAULT_TEXT_SIZE;
51+
private float textSize = spToPixels(12);
52+
private int badgeColor = 0xffCC3333;
53+
private int textColor = 0xffFFFFFF;
54+
private float cornerRadius = dipToPixels(2);
6055
private Typeface typeface = Typeface.DEFAULT_BOLD;
61-
6256
}
6357
private Config _CONFIG;
6458

@@ -86,16 +80,6 @@ public Builder type(@BadgeType int type) {
8680
return this;
8781
}
8882

89-
public Builder cornerRadius(float radius) {
90-
config.cornerRadius = radius;
91-
return this;
92-
}
93-
94-
public Builder typeFace(Typeface typeface) {
95-
config.typeface = typeface;
96-
return this;
97-
}
98-
9983
public Builder number(int number) {
10084
config.number = number;
10185
return this;
@@ -111,6 +95,11 @@ public Builder text2(String text2) {
11195
return this;
11296
}
11397

98+
public Builder textSize(float size) {
99+
config.textSize = size;
100+
return this;
101+
}
102+
114103
public Builder badgeColor(int color) {
115104
config.badgeColor = color;
116105
return this;
@@ -121,8 +110,13 @@ public Builder textColor(int color) {
121110
return this;
122111
}
123112

124-
public Builder textSize(float size) {
125-
config.textSize = size;
113+
public Builder cornerRadius(float radius) {
114+
config.cornerRadius = radius;
115+
return this;
116+
}
117+
118+
public Builder typeFace(Typeface typeface) {
119+
config.typeface = typeface;
126120
return this;
127121
}
128122

@@ -160,17 +154,15 @@ public void setBadgeType(@BadgeType int type) {
160154
}
161155

162156
public void setCornerRadius(float radius) {
163-
if (_CONFIG.cornerRadius != radius) {
164-
_CONFIG.cornerRadius = radius;
165-
outerR[0] = outerR[1] = outerR[2] = outerR[3] =
166-
outerR[4] = outerR[5] = outerR[6] = outerR[7] = _CONFIG.cornerRadius;
157+
_CONFIG.cornerRadius = radius;
158+
outerR[0] = outerR[1] = outerR[2] = outerR[3] =
159+
outerR[4] = outerR[5] = outerR[6] = outerR[7] = radius;
167160

168-
outerROfText1[0] = outerROfText1[1] = outerROfText1[6] = outerROfText1[7] = _CONFIG.cornerRadius;
169-
outerROfText1[2] = outerROfText1[3] = outerROfText1[4] = outerROfText1[5] = 0f;
161+
outerROfText1[0] = outerROfText1[1] = outerROfText1[6] = outerROfText1[7] = radius;
162+
outerROfText1[2] = outerROfText1[3] = outerROfText1[4] = outerROfText1[5] = 0f;
170163

171-
outerROfText2[0] = outerROfText2[1] = outerROfText2[6] = outerROfText2[7] = 0f;
172-
outerROfText2[2] = outerROfText2[3] = outerROfText2[4] = outerROfText2[5] = _CONFIG.cornerRadius;
173-
}
164+
outerROfText2[0] = outerROfText2[1] = outerROfText2[6] = outerROfText2[7] = 0f;
165+
outerROfText2[2] = outerROfText2[3] = outerROfText2[4] = outerROfText2[5] = radius;
174166
}
175167

176168
public void setBadgeColor(int color) {
@@ -234,7 +226,7 @@ private void measureBadge() {
234226
badgeHeight = (int) (_CONFIG.textSize * 1.4f);
235227
badgeWidth = (int) (text1Width + _CONFIG.textSize * 0.4f);
236228

237-
setCornerRadius(DEFAULT_CORNER_RADIUS);
229+
setCornerRadius(_CONFIG.cornerRadius);
238230
break;
239231

240232
case TYPE_WITH_TWO_TEXT:
@@ -243,7 +235,7 @@ private void measureBadge() {
243235
badgeHeight = (int) (_CONFIG.textSize * 1.4f);
244236
badgeWidth = (int) (text1Width + text2Width + _CONFIG.textSize * 0.7f);
245237

246-
setCornerRadius(DEFAULT_CORNER_RADIUS);
238+
setCornerRadius(_CONFIG.cornerRadius);
247239
break;
248240

249241
case TYPE_WITH_TWO_TEXT_COMPLEMENTARY:
@@ -252,7 +244,7 @@ private void measureBadge() {
252244
badgeHeight = (int) (_CONFIG.textSize * 1.4f);
253245
badgeWidth = (int) (text1Width + text2Width + _CONFIG.textSize * 0.6f);
254246

255-
setCornerRadius(DEFAULT_CORNER_RADIUS);
247+
setCornerRadius(_CONFIG.cornerRadius);
256248
break;
257249

258250
default:

0 commit comments

Comments
 (0)