19
19
import com .google .android .material .R ;
20
20
21
21
import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
22
+ import static com .google .android .material .badge .BadgeDrawable .BADGE_RADIUS_NOT_SPECIFIED ;
22
23
import static com .google .android .material .badge .BadgeDrawable .OFFSET_ALIGNMENT_MODE_LEGACY ;
23
24
import static com .google .android .material .badge .BadgeDrawable .TOP_END ;
24
25
@@ -71,6 +72,10 @@ public final class BadgeState {
71
72
72
73
final float badgeRadius ;
73
74
final float badgeWithTextRadius ;
75
+ final float badgeWidth ;
76
+ final float badgeHeight ;
77
+ final float badgeWithTextWidth ;
78
+ final float badgeWithTextHeight ;
74
79
final float badgeWidePadding ;
75
80
final int horizontalInset ;
76
81
final int horizontalInsetWithText ;
@@ -95,8 +100,7 @@ public final class BadgeState {
95
100
96
101
Resources res = context .getResources ();
97
102
badgeRadius =
98
- a .getDimensionPixelSize (
99
- R .styleable .Badge_badgeRadius , res .getDimensionPixelSize (R .dimen .mtrl_badge_radius ));
103
+ a .getDimensionPixelSize (R .styleable .Badge_badgeRadius , BADGE_RADIUS_NOT_SPECIFIED );
100
104
badgeWidePadding =
101
105
a .getDimensionPixelSize (
102
106
R .styleable .Badge_badgeWidePadding ,
@@ -112,9 +116,20 @@ public final class BadgeState {
112
116
.getDimensionPixelSize (R .dimen .mtrl_badge_text_horizontal_edge_offset );
113
117
114
118
badgeWithTextRadius =
115
- a .getDimensionPixelSize (
116
- R .styleable .Badge_badgeWithTextRadius ,
117
- res .getDimensionPixelSize (R .dimen .mtrl_badge_with_text_radius ));
119
+ a .getDimensionPixelSize (R .styleable .Badge_badgeWithTextRadius , BADGE_RADIUS_NOT_SPECIFIED );
120
+ badgeWidth =
121
+ a .getDimension (R .styleable .Badge_badgeWidth , res .getDimension (R .dimen .m3_badge_size ));
122
+ badgeWithTextWidth =
123
+ a .getDimension (
124
+ R .styleable .Badge_badgeWithTextWidth ,
125
+ res .getDimension (R .dimen .m3_badge_with_text_size ));
126
+ badgeHeight =
127
+ a .getDimension (R .styleable .Badge_badgeHeight , res .getDimension (R .dimen .m3_badge_size ));
128
+ badgeWithTextHeight =
129
+ a .getDimension (
130
+ R .styleable .Badge_badgeWithTextHeight ,
131
+ res .getDimension (R .dimen .m3_badge_with_text_size ));
132
+
118
133
offsetAlignmentMode =
119
134
a .getInt (R .styleable .Badge_offsetAlignmentMode , OFFSET_ALIGNMENT_MODE_LEGACY );
120
135
@@ -153,6 +168,30 @@ public final class BadgeState {
153
168
currentState .number = State .BADGE_NUMBER_NONE ;
154
169
}
155
170
171
+ currentState .badgeShapeAppearanceResId =
172
+ storedState .badgeShapeAppearanceResId == null
173
+ ? a .getResourceId (
174
+ R .styleable .Badge_badgeShapeAppearance ,
175
+ R .style .ShapeAppearance_M3_Sys_Shape_Corner_Full )
176
+ : storedState .badgeShapeAppearanceResId ;
177
+
178
+ currentState .badgeShapeAppearanceOverlayResId =
179
+ storedState .badgeShapeAppearanceOverlayResId == null
180
+ ? a .getResourceId (R .styleable .Badge_badgeShapeAppearanceOverlay , 0 )
181
+ : storedState .badgeShapeAppearanceOverlayResId ;
182
+
183
+ currentState .badgeWithTextShapeAppearanceResId =
184
+ storedState .badgeWithTextShapeAppearanceResId == null
185
+ ? a .getResourceId (
186
+ R .styleable .Badge_badgeWithTextShapeAppearance ,
187
+ R .style .ShapeAppearance_M3_Sys_Shape_Corner_Full )
188
+ : storedState .badgeWithTextShapeAppearanceResId ;
189
+
190
+ currentState .badgeWithTextShapeAppearanceOverlayResId =
191
+ storedState .badgeWithTextShapeAppearanceOverlayResId == null
192
+ ? a .getResourceId (R .styleable .Badge_badgeWithTextShapeAppearanceOverlay , 0 )
193
+ : storedState .badgeWithTextShapeAppearanceOverlayResId ;
194
+
156
195
currentState .backgroundColor =
157
196
storedState .backgroundColor == null
158
197
? readColorFromAttributes (context , a , R .styleable .Badge_backgroundColor )
@@ -326,6 +365,42 @@ void setTextAppearanceResId(@StyleRes int textAppearanceResId) {
326
365
currentState .badgeTextAppearanceResId = textAppearanceResId ;
327
366
}
328
367
368
+ int getBadgeShapeAppearanceResId () {
369
+ return currentState .badgeShapeAppearanceResId ;
370
+ }
371
+
372
+ void setBadgeShapeAppearanceResId (int shapeAppearanceResId ) {
373
+ overridingState .badgeShapeAppearanceResId = shapeAppearanceResId ;
374
+ currentState .badgeShapeAppearanceResId = shapeAppearanceResId ;
375
+ }
376
+
377
+ int getBadgeShapeAppearanceOverlayResId () {
378
+ return currentState .badgeShapeAppearanceOverlayResId ;
379
+ }
380
+
381
+ void setBadgeShapeAppearanceOverlayResId (int shapeAppearanceOverlayResId ) {
382
+ overridingState .badgeShapeAppearanceOverlayResId = shapeAppearanceOverlayResId ;
383
+ currentState .badgeShapeAppearanceOverlayResId = shapeAppearanceOverlayResId ;
384
+ }
385
+
386
+ int getBadgeWithTextShapeAppearanceResId () {
387
+ return currentState .badgeWithTextShapeAppearanceResId ;
388
+ }
389
+
390
+ void setBadgeWithTextShapeAppearanceResId (int shapeAppearanceResId ) {
391
+ overridingState .badgeWithTextShapeAppearanceResId = shapeAppearanceResId ;
392
+ currentState .badgeWithTextShapeAppearanceResId = shapeAppearanceResId ;
393
+ }
394
+
395
+ int getBadgeWithTextShapeAppearanceOverlayResId () {
396
+ return currentState .badgeWithTextShapeAppearanceOverlayResId ;
397
+ }
398
+
399
+ void setBadgeWithTextShapeAppearanceOverlayResId (int shapeAppearanceOverlayResId ) {
400
+ overridingState .badgeWithTextShapeAppearanceOverlayResId = shapeAppearanceOverlayResId ;
401
+ currentState .badgeWithTextShapeAppearanceOverlayResId = shapeAppearanceOverlayResId ;
402
+ }
403
+
329
404
@ BadgeGravity
330
405
int getBadgeGravity () {
331
406
return currentState .badgeGravity ;
@@ -456,6 +531,11 @@ public static final class State implements Parcelable {
456
531
@ ColorInt private Integer badgeTextColor ;
457
532
@ StyleRes private Integer badgeTextAppearanceResId ;
458
533
534
+ @ StyleRes private Integer badgeShapeAppearanceResId ;
535
+ @ StyleRes private Integer badgeShapeAppearanceOverlayResId ;
536
+ @ StyleRes private Integer badgeWithTextShapeAppearanceResId ;
537
+ @ StyleRes private Integer badgeWithTextShapeAppearanceOverlayResId ;
538
+
459
539
private int alpha = 255 ;
460
540
private int number = NOT_SET ;
461
541
private int maxCharacterCount = NOT_SET ;
@@ -493,6 +573,10 @@ public State() {}
493
573
backgroundColor = (Integer ) in .readSerializable ();
494
574
badgeTextColor = (Integer ) in .readSerializable ();
495
575
badgeTextAppearanceResId = (Integer ) in .readSerializable ();
576
+ badgeShapeAppearanceResId = (Integer ) in .readSerializable ();
577
+ badgeShapeAppearanceOverlayResId = (Integer ) in .readSerializable ();
578
+ badgeWithTextShapeAppearanceResId = (Integer ) in .readSerializable ();
579
+ badgeWithTextShapeAppearanceOverlayResId = (Integer ) in .readSerializable ();
496
580
alpha = in .readInt ();
497
581
number = in .readInt ();
498
582
maxCharacterCount = in .readInt ();
@@ -535,6 +619,10 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
535
619
dest .writeSerializable (backgroundColor );
536
620
dest .writeSerializable (badgeTextColor );
537
621
dest .writeSerializable (badgeTextAppearanceResId );
622
+ dest .writeSerializable (badgeShapeAppearanceResId );
623
+ dest .writeSerializable (badgeShapeAppearanceOverlayResId );
624
+ dest .writeSerializable (badgeWithTextShapeAppearanceResId );
625
+ dest .writeSerializable (badgeWithTextShapeAppearanceOverlayResId );
538
626
dest .writeInt (alpha );
539
627
dest .writeInt (number );
540
628
dest .writeInt (maxCharacterCount );
0 commit comments