Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Budiyev committed Nov 15, 2017
1 parent 88de31e commit 3b9c074
Showing 1 changed file with 24 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public class CircularProgressBar extends View {
private float mMaximum;
private float mProgress;
private float mStartAngle;
private float mIndeterminateGrowAngle;
private float mIndeterminateStartAngle;
private float mIndeterminateSweepAngle;
private float mIndeterminateOffsetAngle;
private float mIndeterminateMinimumAngle;
private float mIndeterminateGrowAngleOffset;
private boolean mIndeterminate;
private boolean mAnimateProgress;
private boolean mDrawBackgroundStroke;
Expand Down Expand Up @@ -190,31 +190,27 @@ protected void onDraw(Canvas canvas) {
if (mDrawBackgroundStroke) {
canvas.drawOval(mDrawRect, mBackgroundStrokePaint);
}
Paint foregroundPaint = mForegroundStrokePaint;
float start;
float sweep;
if (mIndeterminate) {
float startAngle;
float sweepAngle;
float startAngle = mIndeterminateStartAngle;
float sweepAngle = mIndeterminateSweepAngle;
float offsetAngle = mIndeterminateOffsetAngle;
float minimumAngle = mIndeterminateMinimumAngle;
if (mIndeterminateGrowMode) {
startAngle = mIndeterminateGrowAngle - mIndeterminateGrowAngleOffset;
sweepAngle = mIndeterminateSweepAngle + mIndeterminateMinimumAngle;
start = startAngle - offsetAngle;
sweep = sweepAngle + minimumAngle;
} else {
startAngle = mIndeterminateGrowAngle + mIndeterminateSweepAngle -
mIndeterminateGrowAngleOffset;
sweepAngle = 360f - mIndeterminateSweepAngle - mIndeterminateMinimumAngle;
start = startAngle + sweepAngle - offsetAngle;
sweep = 360f - sweepAngle - minimumAngle;
}
canvas.drawArc(mDrawRect, startAngle, sweepAngle, false, foregroundPaint);
} else {
float progress;
if (mProgress > mMaximum) {
progress = mMaximum;
} else if (mProgress < -mMaximum) {
progress = -mMaximum;
} else {
progress = mProgress;
}
float sweepAngle = 360f * progress / mMaximum;
canvas.drawArc(mDrawRect, mStartAngle, sweepAngle, false, foregroundPaint);
float maximum = mMaximum;
float progress = mProgress;
start = mStartAngle;
sweep = 360f * Math.abs(progress) > Math.abs(maximum) ? maximum : progress / maximum;
}
canvas.drawArc(mDrawRect, start, sweep, false, mForegroundStrokePaint);
}

private void initialize(@NonNull Context context, @Nullable AttributeSet attributeSet,
Expand All @@ -232,7 +228,7 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
mMaximum = DEFAULT_MAXIMUM;
mProgress = DEFAULT_PROGRESS;
mStartAngle = DEFAULT_START_ANGLE;
mIndeterminateGrowAngle = 0F;
mIndeterminateStartAngle = 0F;
mIndeterminateSweepAngle = 0F;
mIndeterminateMinimumAngle = DEFAULT_INDETERMINATE_MINIMUM_ANGLE;
mProgressAnimator.setDuration(DEFAULT_PROGRESS_ANIMATION_DURATION);
Expand Down Expand Up @@ -399,8 +395,6 @@ public final class Configurator {
private float maximum;
private float progress;
private float startAngle;
private float indeterminateGrowAngle;
private float indeterminateSweepAngle;
private float indeterminateMinimumAngle;
private float foregroundStrokeWidth;
private float backgroundStrokeWidth;
Expand All @@ -417,8 +411,6 @@ private Configurator() {
maximum = mMaximum;
progress = mProgress;
startAngle = mStartAngle;
indeterminateGrowAngle = mIndeterminateGrowAngle;
indeterminateSweepAngle = mIndeterminateSweepAngle;
indeterminateMinimumAngle = mIndeterminateMinimumAngle;
indeterminate = mIndeterminate;
animateProgress = mAnimateProgress;
Expand Down Expand Up @@ -452,8 +444,6 @@ public void apply() {
foregroundStrokePaint.setStrokeWidth(foregroundStrokeWidth);
backgroundStrokePaint.setStrokeWidth(backgroundStrokeWidth);
mStartAngle = startAngle;
mIndeterminateGrowAngle = indeterminateGrowAngle;
mIndeterminateSweepAngle = indeterminateSweepAngle;
mIndeterminateMinimumAngle = indeterminateMinimumAngle;
mDrawBackgroundStroke = drawBackgroundStroke;
invalidateDrawRect();
Expand Down Expand Up @@ -499,24 +489,6 @@ public Configurator startAngle(float value) {
return this;
}

/**
* Grow angle for indeterminate mode
*/
@NonNull
public Configurator indeterminateGrowAngle(float value) {
indeterminateGrowAngle = value;
return this;
}

/**
* Sweep angle for indeterminate mode
*/
@NonNull
public Configurator indeterminateSweepAngle(float value) {
indeterminateSweepAngle = value;
return this;
}

/**
* Minimum angle for indeterminate mode
*/
Expand Down Expand Up @@ -623,7 +595,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
private final class GrowUpdateListener implements ValueAnimator.AnimatorUpdateListener {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mIndeterminateGrowAngle = (float) animation.getAnimatedValue();
mIndeterminateStartAngle = (float) animation.getAnimatedValue();
invalidate();
}
}
Expand Down Expand Up @@ -653,10 +625,11 @@ public void onAnimationCancel(Animator animation) {

@Override
public void onAnimationRepeat(Animator animation) {
mIndeterminateGrowMode = !mIndeterminateGrowMode;
if (mIndeterminateGrowMode) {
mIndeterminateGrowAngleOffset =
(mIndeterminateGrowAngleOffset + mIndeterminateMinimumAngle * 2f) % 360f;
boolean growMode = !mIndeterminateGrowMode;
mIndeterminateGrowMode = growMode;
if (growMode) {
mIndeterminateOffsetAngle =
(mIndeterminateOffsetAngle + mIndeterminateMinimumAngle * 2f) % 360f;
}
}
}
Expand Down

0 comments on commit 3b9c074

Please sign in to comment.