Skip to content

Commit

Permalink
Add setProgressInterpolator
Browse files Browse the repository at this point in the history
  • Loading branch information
gansgar committed Dec 15, 2018
1 parent 178e800 commit e74e8a9
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.budiyev.android.circularprogressbar;

import android.animation.Animator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
Expand Down Expand Up @@ -67,6 +68,8 @@ public final class CircularProgressBar extends View {
private static final boolean DEFAULT_ANIMATE_PROGRESS = true;
private static final boolean DEFAULT_DRAW_BACKGROUND_STROKE = false;
private static final boolean DEFAULT_INDETERMINATE = false;
private static final TimeInterpolator DEFAULT_PROGRESS_ANIMATOR = new DecelerateInterpolator();

private final Runnable mSweepRestartAction = new SweepRestartAction();
private final RectF mDrawRect = new RectF();
private final ValueAnimator mProgressAnimator = new ValueAnimator();
Expand Down Expand Up @@ -154,6 +157,18 @@ public void setProgress(final float progress) {
}
}

/**
* Set the current animation interpolator
*/
public void setProgressInterpolator(final TimeInterpolator interpolator) {
if (mVisible) {
if (mProgressAnimator.isRunning()) {
mProgressAnimator.end();
}
}
mProgressAnimator.setInterpolator(interpolator == null ? DEFAULT_PROGRESS_ANIMATOR : interpolator);
}

/**
* Maximum progress for non-indeterminate mode
*/
Expand Down Expand Up @@ -600,7 +615,7 @@ private void initialize(@NonNull final Context context, @Nullable final Attribut
}
}
}
mProgressAnimator.setInterpolator(new DecelerateInterpolator());
mProgressAnimator.setInterpolator(DEFAULT_PROGRESS_ANIMATOR);
mProgressAnimator.addUpdateListener(new ProgressUpdateListener());
mIndeterminateStartAnimator.setFloatValues(360f);
mIndeterminateStartAnimator.setRepeatMode(ValueAnimator.RESTART);
Expand Down

0 comments on commit e74e8a9

Please sign in to comment.