Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Add opportunity to set custom interpolator (close #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonKozyriatskyi committed Feb 2, 2019
1 parent d7a1a68 commit 6d00669
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6d00669

Please sign in to comment.