Skip to content

Commit

Permalink
Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy Budiyev committed Nov 30, 2017
1 parent ee9b12f commit 6d857c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class CircularProgressBar extends View {
private static final int DEFAULT_FOREGROUND_STROKE_COLOR = Color.BLUE;
private static final int DEFAULT_BACKGROUND_STROKE_COLOR = Color.BLACK;
private static final int DEFAULT_PROGRESS_ANIMATION_DURATION = 500;
private static final int DEFAULT_INDETERMINATE_GROW_ANIMATION_DURATION = 2000;
private static final int DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION = 1000;
private static final int DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION = 2000;
private static final int DEFAULT_INDETERMINATE_ARC_ANIMATION_DURATION = 1000;
private static final boolean DEFAULT_ANIMATE_PROGRESS = true;
private static final boolean DEFAULT_DRAW_BACKGROUND_STROKE = true;
private static final boolean DEFAULT_INDETERMINATE = false;
Expand Down Expand Up @@ -161,8 +161,8 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
mBackgroundStrokePaint.setColor(DEFAULT_BACKGROUND_STROKE_COLOR);
mBackgroundStrokePaint
.setStrokeWidth(Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density));
mIndeterminateStartAnimator.setDuration(DEFAULT_INDETERMINATE_GROW_ANIMATION_DURATION);
mIndeterminateSweepAnimator.setDuration(DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION);
mIndeterminateStartAnimator.setDuration(DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION);
mIndeterminateSweepAnimator.setDuration(DEFAULT_INDETERMINATE_ARC_ANIMATION_DURATION);
} else {
TypedArray attributes = null;
try {
Expand All @@ -179,11 +179,11 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attribu
.getInteger(R.styleable.CircularProgressBar_progressAnimationDuration,
DEFAULT_PROGRESS_ANIMATION_DURATION));
mIndeterminateStartAnimator.setDuration(attributes
.getInteger(R.styleable.CircularProgressBar_indeterminateGrowAnimationDuration,
DEFAULT_INDETERMINATE_GROW_ANIMATION_DURATION));
.getInteger(R.styleable.CircularProgressBar_indeterminateRotationAnimationDuration,
DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION));
mIndeterminateSweepAnimator.setDuration(attributes
.getInteger(R.styleable.CircularProgressBar_indeterminateSweepAnimationDuration,
DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION));
.getInteger(R.styleable.CircularProgressBar_indeterminateArcAnimationDuration,
DEFAULT_INDETERMINATE_ARC_ANIMATION_DURATION));
mForegroundStrokePaint.setColor(attributes
.getColor(R.styleable.CircularProgressBar_foregroundStrokeColor,
DEFAULT_FOREGROUND_STROKE_COLOR));
Expand Down Expand Up @@ -380,8 +380,8 @@ protected void onDetachedFromWindow() {

public final class Configurator {
private long progressAnimationDuration;
private long indeterminateGrowAnimationDuration;
private long indeterminateSweepAnimationDuration;
private long indeterminateRotationAnimationDuration;
private long indeterminateArcAnimationDuration;
private float maximum;
private float progress;
private float startAngle;
Expand All @@ -396,8 +396,8 @@ public final class Configurator {

private Configurator() {
progressAnimationDuration = mProgressAnimator.getDuration();
indeterminateGrowAnimationDuration = mIndeterminateStartAnimator.getDuration();
indeterminateSweepAnimationDuration = mIndeterminateSweepAnimator.getDuration();
indeterminateRotationAnimationDuration = mIndeterminateStartAnimator.getDuration();
indeterminateArcAnimationDuration = mIndeterminateSweepAnimator.getDuration();
maximum = mMaximum;
progress = mProgress;
startAngle = mStartAngle;
Expand All @@ -424,8 +424,8 @@ public void apply() {
mMaximum = maximum;
mAnimateProgress = animateProgress;
mProgressAnimator.setDuration(progressAnimationDuration);
mIndeterminateStartAnimator.setDuration(indeterminateGrowAnimationDuration);
mIndeterminateSweepAnimator.setDuration(indeterminateSweepAnimationDuration);
mIndeterminateStartAnimator.setDuration(indeterminateRotationAnimationDuration);
mIndeterminateSweepAnimator.setDuration(indeterminateArcAnimationDuration);
mIndeterminateSweepAnimator.setFloatValues(360f - indeterminateMinimumAngle * 2f);
Paint foregroundStrokePaint = mForegroundStrokePaint;
Paint backgroundStrokePaint = mBackgroundStrokePaint;
Expand Down Expand Up @@ -491,15 +491,15 @@ public Configurator indeterminateMinimumAngle(float value) {
/**
* Grow animation duration in milliseconds for indeterminate mode
*/
public void indeterminateGrowAnimationDuration(long value) {
indeterminateGrowAnimationDuration = value;
public void indeterminateRotationAnimationDuration(long value) {
indeterminateRotationAnimationDuration = value;
}

/**
* Sweep animation duration in milliseconds for indeterminate mode
*/
public void indeterminateSweepAnimationDuration(long value) {
indeterminateSweepAnimationDuration = value;
public void indeterminateArcAnimationDuration(long value) {
indeterminateArcAnimationDuration = value;
}

/**
Expand Down Expand Up @@ -613,9 +613,7 @@ public void onAnimationEnd(Animator animation) {
mIndeterminateOffsetAngle = (mIndeterminateOffsetAngle + mIndeterminateMinimumAngle * 2f) % 360f;
}
if (!mCancelled) {
if (!animation.isRunning()) {
animation.start();
}
animation.start();
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CircularProgressBar">
<attr name="maximum" format="float"/>
<attr name="progress" format="float"/>
<attr name="startAngle" format="float"/>
<attr name="indeterminateMinimumAngle" format="float"/>
<attr name="progressAnimationDuration" format="integer"/>
<attr name="indeterminateGrowAnimationDuration" format="integer"/>
<attr name="indeterminateSweepAnimationDuration" format="integer"/>
<attr name="foregroundStrokeColor" format="color"/>
<attr name="backgroundStrokeColor" format="color"/>
<attr name="foregroundStrokeWidth" format="dimension"/>
<attr name="backgroundStrokeWidth" format="dimension"/>
<attr name="animateProgress" format="boolean"/>
<attr name="drawBackgroundStroke" format="boolean"/>
<attr name="indeterminate" format="boolean"/>
<attr format="float" name="maximum"/>
<attr format="float" name="progress"/>
<attr format="boolean" name="animateProgress"/>
<attr format="integer" name="progressAnimationDuration"/>
<attr format="color" name="foregroundStrokeColor"/>
<attr format="dimension" name="foregroundStrokeWidth"/>
<attr format="boolean" name="drawBackgroundStroke"/>
<attr format="color" name="backgroundStrokeColor"/>
<attr format="dimension" name="backgroundStrokeWidth"/>
<attr format="float" name="startAngle"/>
<attr format="boolean" name="indeterminate"/>
<attr format="float" name="indeterminateMinimumAngle"/>
<attr format="integer" name="indeterminateArcAnimationDuration"/>
<attr format="integer" name="indeterminateRotationAnimationDuration"/>
</declare-styleable>
</resources>

0 comments on commit 6d857c8

Please sign in to comment.