From c1f2773e7da54ddcec6b6e4033210470f6972ac2 Mon Sep 17 00:00:00 2001 From: Yuriy Budiyev Date: Fri, 12 Jan 2018 14:52:37 +0300 Subject: [PATCH] Dev --- .../CircularProgressBar.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java index ed6c259..0fcef19 100644 --- a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java +++ b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java @@ -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; @@ -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); } @@ -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) {