Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Budiyev committed Jan 12, 2018
1 parent 6ed8bea commit c1f2773
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class CircularProgressBar extends View {
private float mIndeterminateSweepAngle;
private float mIndeterminateOffsetAngle;
private float mIndeterminateMinimumAngle;
private float mForegroundStrokeCapAngle;
private boolean mIndeterminate;
private boolean mAnimateProgress;
private boolean mDrawBackgroundStroke;
Expand Down Expand Up @@ -330,6 +331,16 @@ protected void onDraw(Canvas canvas) {
sweep = 360f;
}
}
float capAngle = mForegroundStrokeCapAngle;
if (capAngle != 0f && Math.abs(sweep) != 360f) {
if (sweep > 0) {
start += capAngle;
sweep -= capAngle * 2f;
} else if (sweep < 0) {
start -= capAngle;
sweep += capAngle * 2f;
}
}
canvas.drawArc(mDrawRect, start, sweep, false, mForegroundStrokePaint);
}

Expand Down Expand Up @@ -521,6 +532,32 @@ private void invalidateDrawRect(int width, int height) {
mDrawRect.set(thickness / 2f + 1f, thickness / 2f + 1f, width - thickness / 2f - 1f,
height - thickness / 2f - 1f);
}
invalidateForegroundStrokeCapAngle();
}

private void invalidateForegroundStrokeCapAngle() {
Paint.Cap strokeCap = mForegroundStrokePaint.getStrokeCap();
if (strokeCap == null) {
mForegroundStrokeCapAngle = 0f;
return;
}
switch (strokeCap) {
case SQUARE:
case ROUND: {
float r = mDrawRect.centerX();
if (r != 0) {
mForegroundStrokeCapAngle = 90f * mForegroundStrokePaint.getStrokeWidth() / (float) Math.PI / r;
} else {
mForegroundStrokeCapAngle = 0f;
}
break;
}
case BUTT:
default: {
mForegroundStrokeCapAngle = 0f;
break;
}
}
}

private void setProgressInternal(float progress) {
Expand Down

0 comments on commit c1f2773

Please sign in to comment.