diff --git a/README.md b/README.md index e2d5fdb..4af0e39 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,15 @@ circularProgress.setOnProgressChangeListener(new CircularProgressIndicator.OnPro --- +#### Setting interpolator +Default interpolator used for running animation is `AccelerateDecelerateInterpolator`, +but you can set any other one using setter: +```java +circularProgress.setInterpolator(new LinearInterpolator()); +``` + +--- + ### Download using Gradle Add this in your root `build.gradle` at the end of `repositories` in `allprojects` section: diff --git a/circularprogressindicator/src/main/java/antonkozyriatskyi/circularprogressindicator/CircularProgressIndicator.java b/circularprogressindicator/src/main/java/antonkozyriatskyi/circularprogressindicator/CircularProgressIndicator.java index 2c953f9..cd00909 100644 --- a/circularprogressindicator/src/main/java/antonkozyriatskyi/circularprogressindicator/CircularProgressIndicator.java +++ b/circularprogressindicator/src/main/java/antonkozyriatskyi/circularprogressindicator/CircularProgressIndicator.java @@ -25,6 +25,7 @@ import android.util.TypedValue; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.Interpolator; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -94,6 +95,9 @@ public class CircularProgressIndicator extends View { @Nullable private OnProgressChangeListener onProgressChangeListener; + @NonNull + private Interpolator animationInterpolator = new AccelerateDecelerateInterpolator(); + public CircularProgressIndicator(Context context) { super(context); init(context, null); @@ -384,7 +388,7 @@ public Double evaluate(float fraction, Double startValue, Double endValue) { }, oldCurrentProgress, progressValue); progressAnimator.setDuration(DEFAULT_ANIMATION_DURATION); progressAnimator.setValues(angleProperty); - progressAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); + progressAnimator.setInterpolator(animationInterpolator); progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { @@ -661,6 +665,15 @@ public boolean isFillBackgroundEnabled() { return isFillBackgroundEnabled; } + public void setInterpolator(@NonNull Interpolator interpolator) { + animationInterpolator = interpolator; + } + + @NonNull + public Interpolator getInterpolator() { + return animationInterpolator; + } + @Retention(RetentionPolicy.SOURCE) @IntDef({DIRECTION_CLOCKWISE, DIRECTION_COUNTERCLOCKWISE}) public @interface Direction {