Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Dec 17, 2017
1 parent 7a12bbf commit 7c39634
Showing 1 changed file with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void setMaximum(float maximum) {
}

/**
* Start angle for non-indeterminate mode (in degrees)
* Start angle for non-indeterminate mode (in degrees),between -360 and 360 degrees
*/
public void setStartAngle(@FloatRange(from = -360f, to = 360f) float angle) {
checkStartAngle(angle);
Expand All @@ -180,7 +180,20 @@ public void setAnimateProgress(boolean animate) {
}

/**
* Minimum angle for indeterminate mode (in degrees)
* Progress animation duration for non- indeterminate mode
*/
public void setProgressAnimationDuration(@IntRange(from = 0) long duration) {
checkAnimationDuration(duration);
if (mVisible) {
if (mProgressAnimator.isRunning()) {
mProgressAnimator.end();
}
}
mProgressAnimator.setDuration(duration);
}

/**
* Minimum angle for indeterminate mode, between 0 and 120 degrees
*/
public void setIndeterminateMinimumAngle(@FloatRange(from = 0f, to = 120f) float angle) {
checkIndeterminateMinimumAngle(angle);
Expand All @@ -197,6 +210,7 @@ public void setIndeterminateMinimumAngle(@FloatRange(from = 0f, to = 120f) float
* Rotation animation duration for indeterminate mode
*/
public void setIndeterminateRotationAnimationDuration(@IntRange(from = 0) long duration) {
checkAnimationDuration(duration);
stopIndeterminateAnimations();
mIndeterminateStartAnimator.setDuration(duration);
invalidate();
Expand All @@ -209,6 +223,7 @@ public void setIndeterminateRotationAnimationDuration(@IntRange(from = 0) long d
* Sweep animation duration for indeterminate mode
*/
public void setIndeterminateSweepAnimationDuration(@IntRange(from = 0) long duration) {
checkAnimationDuration(duration);
stopIndeterminateAnimations();
mIndeterminateSweepAnimator.setDuration(duration);
invalidate();
Expand Down Expand Up @@ -365,19 +380,27 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
defStyleRes);
mMaximum = attributes.getFloat(R.styleable.CircularProgressBar_maximum, DEFAULT_MAXIMUM);
mProgress = attributes.getFloat(R.styleable.CircularProgressBar_progress, DEFAULT_PROGRESS);
mStartAngle = attributes.getFloat(R.styleable.CircularProgressBar_startAngle, DEFAULT_START_ANGLE);
mIndeterminateMinimumAngle = attributes
.getFloat(R.styleable.CircularProgressBar_indeterminateMinimumAngle,
DEFAULT_INDETERMINATE_MINIMUM_ANGLE);
mProgressAnimator.setDuration(attributes
.getInteger(R.styleable.CircularProgressBar_progressAnimationDuration,
DEFAULT_PROGRESS_ANIMATION_DURATION));
mIndeterminateStartAnimator.setDuration(attributes
float startAngle = attributes.getFloat(R.styleable.CircularProgressBar_startAngle, DEFAULT_START_ANGLE);
checkStartAngle(startAngle);
mStartAngle = startAngle;
float minimumAngle = attributes.getFloat(R.styleable.CircularProgressBar_indeterminateMinimumAngle,
DEFAULT_INDETERMINATE_MINIMUM_ANGLE);
checkIndeterminateMinimumAngle(minimumAngle);
mIndeterminateMinimumAngle = minimumAngle;
long progressDuration = attributes.getInteger(R.styleable.CircularProgressBar_progressAnimationDuration,
DEFAULT_PROGRESS_ANIMATION_DURATION);
checkAnimationDuration(progressDuration);
mProgressAnimator.setDuration(progressDuration);
long rotationDuration = attributes
.getInteger(R.styleable.CircularProgressBar_indeterminateRotationAnimationDuration,
DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION));
mIndeterminateSweepAnimator.setDuration(attributes
DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION);
checkAnimationDuration(rotationDuration);
mIndeterminateStartAnimator.setDuration(rotationDuration);
long sweepDuration = attributes
.getInteger(R.styleable.CircularProgressBar_indeterminateSweepAnimationDuration,
DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION));
DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION);
checkAnimationDuration(sweepDuration);
mIndeterminateSweepAnimator.setDuration(sweepDuration);
mForegroundStrokePaint.setColor(attributes
.getColor(R.styleable.CircularProgressBar_foregroundStrokeColor,
DEFAULT_FOREGROUND_STROKE_COLOR));
Expand All @@ -402,8 +425,6 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
}
}
}
checkStartAngle(mStartAngle);
checkIndeterminateMinimumAngle(mIndeterminateMinimumAngle);
mProgressAnimator.setInterpolator(new DecelerateInterpolator());
mProgressAnimator.addUpdateListener(new ProgressUpdateListener());
mIndeterminateStartAnimator.setFloatValues(360f);
Expand Down Expand Up @@ -493,6 +514,12 @@ private void checkIndeterminateMinimumAngle(float angle) {
}
}

private void checkAnimationDuration(long duration) {
if (duration < 0) {
throw new IllegalArgumentException("Animation duration can't be negative");
}
}

private final class ProgressUpdateListener implements ValueAnimator.AnimatorUpdateListener {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand Down

0 comments on commit 7c39634

Please sign in to comment.