30
30
import android .graphics .Rect ;
31
31
import android .graphics .drawable .Drawable ;
32
32
import android .text .TextUtils ;
33
+ import android .util .Log ;
33
34
import android .view .Gravity ;
34
35
import android .view .View ;
35
36
import android .view .ViewGroup ;
116
117
* </pre>
117
118
*
118
119
* <p>By default, {@code BadgeDrawable} is aligned to the top and end edges of its anchor view (with
119
- * some offsets). Call {@link #setBadgeGravity(int)} to change it to one of the other supported
120
- * modes . To adjust the badge's offsets w.r.t. the anchor's center, use {@link
120
+ * some offsets). Call {@link #setBadgeGravity(int)} to change it to {@link #TOP_START}, the other
121
+ * supported mode . To adjust the badge's offsets w.r.t. the anchor's center, use {@link
121
122
* BadgeDrawable#setHorizontalOffset(int)}, {@link BadgeDrawable#setVerticalOffset(int)}
122
123
*
123
124
* <p>Note: This is still under development and may not support the full range of customization
124
125
* Material Android components generally support (e.g. themed attributes).
125
126
*/
126
127
public class BadgeDrawable extends Drawable implements TextDrawableDelegate {
127
128
129
+ private static final String TAG = "Badge" ;
130
+
128
131
/** Position the badge can be set to. */
129
132
@ IntDef ({
130
133
TOP_END ,
@@ -141,11 +144,21 @@ public class BadgeDrawable extends Drawable implements TextDrawableDelegate {
141
144
/** The badge is positioned along the top and start edges of its anchor view */
142
145
public static final int TOP_START = Gravity .TOP | Gravity .START ;
143
146
144
- /** The badge is positioned along the bottom and end edges of its anchor view */
145
- public static final int BOTTOM_END = Gravity .BOTTOM | Gravity .END ;
147
+ /**
148
+ * The badge is positioned along the bottom and end edges of its anchor view
149
+ *
150
+ * @deprecated Bottom badge gravities are deprecated in favor of top gravities; use {@link
151
+ * #TOP_START} or {@link #TOP_END} instead.
152
+ */
153
+ @ Deprecated public static final int BOTTOM_END = Gravity .BOTTOM | Gravity .END ;
146
154
147
- /** The badge is positioned along the bottom and start edges of its anchor view */
148
- public static final int BOTTOM_START = Gravity .BOTTOM | Gravity .START ;
155
+ /**
156
+ * The badge is positioned along the bottom and start edges of its anchor view
157
+ *
158
+ * @deprecated Bottom badge gravities are deprecated in favor of top gravities; use {@link
159
+ * #TOP_START} or {@link #TOP_END} instead.
160
+ */
161
+ @ Deprecated public static final int BOTTOM_START = Gravity .BOTTOM | Gravity .START ;
149
162
150
163
@ StyleRes private static final int DEFAULT_STYLE = R .style .Widget_MaterialComponents_Badge ;
151
164
@ AttrRes private static final int DEFAULT_THEME_ATTR = R .attr .badgeStyle ;
@@ -664,9 +677,13 @@ public int getBadgeGravity() {
664
677
/**
665
678
* Sets this badge's gravity with respect to its anchor view.
666
679
*
667
- * @param gravity Constant representing one of 4 possible {@link BadgeGravity} values.
680
+ * @param gravity Constant representing one of the possible {@link BadgeGravity} values. There are
681
+ * two recommended gravities: {@link #TOP_START} and {@link #TOP_END}.
668
682
*/
669
683
public void setBadgeGravity (@ BadgeGravity int gravity ) {
684
+ if (gravity == BOTTOM_START || gravity == BOTTOM_END ) {
685
+ Log .w (TAG , "Bottom badge gravities are deprecated; please use a top gravity instead." );
686
+ }
670
687
if (state .getBadgeGravity () != gravity ) {
671
688
state .setBadgeGravity (gravity );
672
689
onBadgeGravityUpdated ();
0 commit comments