@Test public void draw() { TestCanvas canvas = new TestCanvas(); badge.draw(canvas); shape.assertCanvas(canvas); shape.assertBadgeColor(badgeColor); canvas.assertTextColor(textColor); }
@Override @SuppressLint("NewApi") public void draw(@NonNull Canvas canvas) { if (text.length() == 0) { return; } if (paintPreparationNeeded) { paintPreparationNeeded = false; onPrepareBadgePaint(badgePaint); onPrepareTextPaint(textPaint); } Rect rect = shape.draw(canvas, getBounds(), badgePaint, getLayoutDirection()); textPaint.setTextSize(rect.height() * MAGIC_TEXT_SCALE_FACTOR); float x = rect.exactCenterX(); float y = rect.exactCenterY() - (textPaint.ascent() + textPaint.descent()) * 0.5f; canvas.drawText(text, x, y, textPaint); }
TextBadge extends BadgeDrawable { @Override @SuppressLint("NewApi") public void draw(@NonNull Canvas canvas) { if (text.length() == 0) { return; } if (paintPreparationNeeded) { paintPreparationNeeded = false; onPrepareBadgePaint(badgePaint); onPrepareTextPaint(textPaint); } Rect rect = shape.draw(canvas, getBounds(), badgePaint, getLayoutDirection()); textPaint.setTextSize(rect.height() * MAGIC_TEXT_SCALE_FACTOR); float x = rect.exactCenterX(); float y = rect.exactCenterY() - (textPaint.ascent() + textPaint.descent()) * 0.5f; canvas.drawText(text, x, y, textPaint); } }
TextBadge extends BadgeDrawable { @Override @SuppressLint("NewApi") public void draw(@NonNull Canvas canvas) { if (text.length() == 0) { return; } if (paintPreparationNeeded) { paintPreparationNeeded = false; onPrepareBadgePaint(badgePaint); onPrepareTextPaint(textPaint); } Rect rect = shape.draw(canvas, getBounds(), badgePaint, getLayoutDirection()); textPaint.setTextSize(rect.height() * MAGIC_TEXT_SCALE_FACTOR); float x = rect.exactCenterX(); float y = rect.exactCenterY() - (textPaint.ascent() + textPaint.descent()) * 0.5f; canvas.drawText(text, x, y, textPaint); } TextBadge(@NonNull Context context, @NonNull BadgeShape shape); protected  TextBadge(@NonNull BadgeShape shape, @ColorInt int badgeColor, @ColorInt int textColor); }
TextBadge extends BadgeDrawable { @Override @SuppressLint("NewApi") public void draw(@NonNull Canvas canvas) { if (text.length() == 0) { return; } if (paintPreparationNeeded) { paintPreparationNeeded = false; onPrepareBadgePaint(badgePaint); onPrepareTextPaint(textPaint); } Rect rect = shape.draw(canvas, getBounds(), badgePaint, getLayoutDirection()); textPaint.setTextSize(rect.height() * MAGIC_TEXT_SCALE_FACTOR); float x = rect.exactCenterX(); float y = rect.exactCenterY() - (textPaint.ascent() + textPaint.descent()) * 0.5f; canvas.drawText(text, x, y, textPaint); } TextBadge(@NonNull Context context, @NonNull BadgeShape shape); protected  TextBadge(@NonNull BadgeShape shape, @ColorInt int badgeColor, @ColorInt int textColor); @Override @SuppressLint("NewApi") void draw(@NonNull Canvas canvas); @Override int getLayoutDirection(); @Override boolean onLayoutDirectionChanged(int layoutDirection); @Override @SuppressLint("NewApi") void setAlpha(int alpha); @Override @SuppressLint("NewApi") void setColorFilter(@Nullable ColorFilter colorFilter); final void setText(@Nullable CharSequence text); final String getText(); }
TextBadge extends BadgeDrawable { @Override @SuppressLint("NewApi") public void draw(@NonNull Canvas canvas) { if (text.length() == 0) { return; } if (paintPreparationNeeded) { paintPreparationNeeded = false; onPrepareBadgePaint(badgePaint); onPrepareTextPaint(textPaint); } Rect rect = shape.draw(canvas, getBounds(), badgePaint, getLayoutDirection()); textPaint.setTextSize(rect.height() * MAGIC_TEXT_SCALE_FACTOR); float x = rect.exactCenterX(); float y = rect.exactCenterY() - (textPaint.ascent() + textPaint.descent()) * 0.5f; canvas.drawText(text, x, y, textPaint); } TextBadge(@NonNull Context context, @NonNull BadgeShape shape); protected  TextBadge(@NonNull BadgeShape shape, @ColorInt int badgeColor, @ColorInt int textColor); @Override @SuppressLint("NewApi") void draw(@NonNull Canvas canvas); @Override int getLayoutDirection(); @Override boolean onLayoutDirectionChanged(int layoutDirection); @Override @SuppressLint("NewApi") void setAlpha(int alpha); @Override @SuppressLint("NewApi") void setColorFilter(@Nullable ColorFilter colorFilter); final void setText(@Nullable CharSequence text); final String getText();  }