@Override protected void onDrawRing(@NonNull Canvas canvas, @NonNull Paint paint) { int level = getLevel(); if (level == 0) { return; } float ratio = (float) level / LEVEL_MAX; float startAngle = ratio * mStartAngleMax; float sweepAngle = ratio * SWEEP_ANGLE_MAX; drawRing(canvas, paint, startAngle, sweepAngle); if (mShowBackground) { // Draw twice to emulate the background for secondary progress. drawRing(canvas, paint, startAngle, sweepAngle); } } }
@Override public void setShowBackground(boolean show) { if (mShowBackground != show) { mShowBackground = show; invalidateSelf(); } }
/** * Create a new {@code CircularProgressDrawable}. * * @param context the {@code Context} for retrieving style information. */ public CircularProgressDrawable(int style, @NonNull Context context) { super(new Drawable[] { new CircularProgressBackgroundDrawable(), new SingleCircularProgressDrawable(style), new SingleCircularProgressDrawable(style), }, context); } }
@Override protected boolean onLevelChange(@IntRange(from = 0, to = LEVEL_MAX) int level) { invalidateSelf(); return true; }