1515import com .beardedhen .androidbootstrap .api .attributes .ViewGroupPosition ;
1616import com .beardedhen .androidbootstrap .api .defaults .ButtonMode ;
1717import com .beardedhen .androidbootstrap .api .defaults .DefaultBootstrapSize ;
18+ import com .beardedhen .androidbootstrap .api .view .BadgeContainerView ;
1819import com .beardedhen .androidbootstrap .api .view .BootstrapSizeView ;
1920import com .beardedhen .androidbootstrap .api .view .ButtonModeView ;
2021import com .beardedhen .androidbootstrap .api .view .OutlineableView ;
2930 * allowing the use of different selection modes e.g. Checkbox/Radio group.
3031 */
3132public class BootstrapButton extends AwesomeTextView implements BootstrapSizeView ,
32- OutlineableView , RoundableView , ButtonModeView {
33+ OutlineableView , RoundableView , ButtonModeView , BadgeContainerView {
3334
3435 private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapButton" ;
3536 private static final String KEY_MODE = "com.beardedhen.androidbootstrap.BootstrapButton.MODE" ;
@@ -50,6 +51,7 @@ public class BootstrapButton extends AwesomeTextView implements BootstrapSizeVie
5051 private float baselineHoriPadding ;
5152 private float baselineStrokeWidth ;
5253 private float baselineCornerRadius ;
54+ private BootstrapBadge bootstrapBadge ;
5355
5456 public BootstrapButton (Context context ) {
5557 super (context );
@@ -102,6 +104,7 @@ private void initialise(AttributeSet attrs) {
102104 bundle .putInt (KEY_INDEX , parentIndex );
103105 bundle .putFloat (BootstrapSizeView .KEY , bootstrapSize );
104106 bundle .putSerializable (KEY_MODE , buttonMode );
107+ if (bootstrapBadge != null ) bundle .putInt (BadgeContainerView .KEY , bootstrapBadge .getBadgeCount ());
105108 return bundle ;
106109 }
107110
@@ -113,6 +116,7 @@ private void initialise(AttributeSet attrs) {
113116 this .showOutline = bundle .getBoolean (OutlineableView .KEY );
114117 this .parentIndex = bundle .getInt (KEY_INDEX );
115118 this .bootstrapSize = bundle .getFloat (BootstrapSizeView .KEY );
119+ if (bootstrapBadge != null ) setBadgeCount (bundle .getInt (BadgeContainerView .KEY ));
116120
117121 Serializable m = bundle .getSerializable (KEY_MODE );
118122
@@ -237,6 +241,15 @@ void updateFromParent(BootstrapBrand bootstrapBrand,
237241 updateBootstrapState ();
238242 }
239243
244+ @ Override public void displayBadgeDrawable () {
245+ setCompoundDrawablesWithIntrinsicBounds (
246+ null ,
247+ null ,
248+ this .bootstrapBadge .getBadgeDrawable (),
249+ null );
250+ setCompoundDrawablePadding (DimenUtils .dpToPixels (4 ));
251+ }
252+
240253 /*
241254 * Getters/Setters
242255 */
@@ -275,10 +288,32 @@ public void setChecked(boolean checked) {
275288 this .buttonMode = buttonMode ;
276289 }
277290
291+ @ Override public void setBadge (BootstrapBadge badge ) {
292+ this .bootstrapBadge = badge ;
293+ this .bootstrapBadge .setBootstrapBrand (getBootstrapBrand (), true );
294+ this .bootstrapBadge .setBootstrapSize (getBootstrapSize ());
295+ displayBadgeDrawable ();
296+ }
297+
298+ @ Override public void setBadgeCount (int badgeCount ) {
299+ if (bootstrapBadge != null && badgeCount >= 0 ) {
300+ this .bootstrapBadge .setBadgeCount (badgeCount );
301+ displayBadgeDrawable ();
302+ }
303+ }
304+
305+ @ Override public int getBadgeCount () {
306+ if (bootstrapBadge != null ) return bootstrapBadge .getBadgeCount ();
307+ else return 0 ;
308+ }
278309 @ Override public float getBootstrapSize () {
279310 return bootstrapSize ;
280311 }
281312
313+ @ Override public BootstrapBadge getBootstrapBadge () {
314+ return bootstrapBadge ;
315+ }
316+
282317 @ Override public void setBootstrapSize (DefaultBootstrapSize bootstrapSize ) {
283318 setBootstrapSize (bootstrapSize .scaleFactor ());
284319 }
@@ -287,5 +322,4 @@ public void setChecked(boolean checked) {
287322 this .bootstrapSize = bootstrapSize ;
288323 updateBootstrapState ();
289324 }
290-
291325}
0 commit comments