Skip to content

Commit 7a4ecb0

Browse files
wcshigsajith
authored andcommitted
Update TextDrawableHelper's constructor to take a delegate.
Update ChipDrawable and BadgeDrwable to pass a delegate when they instantiate TextDrawbleHelper. PiperOrigin-RevId: 245469285
1 parent 1df3a6a commit 7a4ecb0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/java/com/google/android/material/badge/BadgeDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private BadgeDrawable(Context context) {
276276
badgeWidePadding = res.getDimensionPixelSize(R.dimen.mtrl_badge_long_text_horizontal_padding);
277277
badgeWithTextRadius = res.getDimensionPixelSize(R.dimen.mtrl_badge_with_text_radius);
278278

279-
textDrawableHelper = new TextDrawableHelper();
279+
textDrawableHelper = new TextDrawableHelper(/* delegate= */ this);
280280
textDrawableHelper.getTextPaint().setTextAlign(Paint.Align.CENTER);
281281
this.savedState = new SavedState(context);
282282
setTextAppearanceResource(R.style.TextAppearance_MaterialComponents_Badge);

lib/java/com/google/android/material/chip/ChipDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private ChipDrawable(
330330
initializeElevationOverlay(context);
331331

332332
this.context = context;
333-
textDrawableHelper = new TextDrawableHelper();
333+
textDrawableHelper = new TextDrawableHelper(/* delegate= */ this);
334334

335335
text = "";
336336

lib/java/com/google/android/material/internal/TextDrawableHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public void onFontRetrievalFailed(int reason) {
7070
private WeakReference<TextDrawableDelegate> delegate = new WeakReference<>(null);
7171
@Nullable private TextAppearance textAppearance;
7272

73+
/**
74+
* Please provide a delegate if your text font may load asynchronously.
75+
*/
76+
public TextDrawableHelper(@Nullable TextDrawableDelegate delegate) {
77+
setDelegate(delegate);
78+
}
79+
7380
/** Sets the delegate that owns this TextDrawableHelper. */
7481
public void setDelegate(@Nullable TextDrawableDelegate delegate) {
7582
this.delegate = new WeakReference<>(delegate);

0 commit comments

Comments
 (0)