@@ -43,22 +43,16 @@ public class BadgeDrawable extends Drawable {
43
43
@ IntDef ({TYPE_NUMBER , TYPE_ONLY_ONE_TEXT , TYPE_WITH_TWO_TEXT , TYPE_WITH_TWO_TEXT_COMPLEMENTARY })
44
44
public @interface BadgeType {}
45
45
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
-
51
46
private static class Config {
52
47
private int badgeType = TYPE_NUMBER ;
53
- private float cornerRadius ;
54
48
private int number = 0 ;
55
49
private String text1 = "" ;
56
50
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 );
60
55
private Typeface typeface = Typeface .DEFAULT_BOLD ;
61
-
62
56
}
63
57
private Config _CONFIG ;
64
58
@@ -86,16 +80,6 @@ public Builder type(@BadgeType int type) {
86
80
return this ;
87
81
}
88
82
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
-
99
83
public Builder number (int number ) {
100
84
config .number = number ;
101
85
return this ;
@@ -111,6 +95,11 @@ public Builder text2(String text2) {
111
95
return this ;
112
96
}
113
97
98
+ public Builder textSize (float size ) {
99
+ config .textSize = size ;
100
+ return this ;
101
+ }
102
+
114
103
public Builder badgeColor (int color ) {
115
104
config .badgeColor = color ;
116
105
return this ;
@@ -121,8 +110,13 @@ public Builder textColor(int color) {
121
110
return this ;
122
111
}
123
112
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 ;
126
120
return this ;
127
121
}
128
122
@@ -160,17 +154,15 @@ public void setBadgeType(@BadgeType int type) {
160
154
}
161
155
162
156
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 ;
167
160
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 ;
170
163
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 ;
174
166
}
175
167
176
168
public void setBadgeColor (int color ) {
@@ -234,7 +226,7 @@ private void measureBadge() {
234
226
badgeHeight = (int ) (_CONFIG .textSize * 1.4f );
235
227
badgeWidth = (int ) (text1Width + _CONFIG .textSize * 0.4f );
236
228
237
- setCornerRadius (DEFAULT_CORNER_RADIUS );
229
+ setCornerRadius (_CONFIG . cornerRadius );
238
230
break ;
239
231
240
232
case TYPE_WITH_TWO_TEXT :
@@ -243,7 +235,7 @@ private void measureBadge() {
243
235
badgeHeight = (int ) (_CONFIG .textSize * 1.4f );
244
236
badgeWidth = (int ) (text1Width + text2Width + _CONFIG .textSize * 0.7f );
245
237
246
- setCornerRadius (DEFAULT_CORNER_RADIUS );
238
+ setCornerRadius (_CONFIG . cornerRadius );
247
239
break ;
248
240
249
241
case TYPE_WITH_TWO_TEXT_COMPLEMENTARY :
@@ -252,7 +244,7 @@ private void measureBadge() {
252
244
badgeHeight = (int ) (_CONFIG .textSize * 1.4f );
253
245
badgeWidth = (int ) (text1Width + text2Width + _CONFIG .textSize * 0.6f );
254
246
255
- setCornerRadius (DEFAULT_CORNER_RADIUS );
247
+ setCornerRadius (_CONFIG . cornerRadius );
256
248
break ;
257
249
258
250
default :
0 commit comments