diff --git a/README.md b/README.md index 6fdf1f3..78c97f8 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,21 @@ Path animations ( Inspiration from http://blog.csdn.net/tianjian4592/article/det ``` +Animations with custom evalutors - such as those available in [AnimationEasingFunctions](https://github.com/daimajia/AnimationEasingFunctions) for more advanced [easing interpolators](https://easings.net/) +```java +ViewAnimator.animate(view) + .translationY(0f, translateY) // up + .startDelay(1000) + .duration(150) + .interpolator(DecelerateInterpolator()) + .thenAnimate(view) + .translationY(translateY, 0f) // down with a 'boing' effect + .evaluator(ElasticEaseOut(500)) + .duration(500) + .onStop { startAnimation() } // restart the animation, by creating it again + .start() +``` + # Download Buy Me a Coffee at ko-fi.com diff --git a/viewanimator/src/main/java/com/github/florent37/viewanimator/AnimationBuilder.java b/viewanimator/src/main/java/com/github/florent37/viewanimator/AnimationBuilder.java index 8a1e435..1b268c4 100644 --- a/viewanimator/src/main/java/com/github/florent37/viewanimator/AnimationBuilder.java +++ b/viewanimator/src/main/java/com/github/florent37/viewanimator/AnimationBuilder.java @@ -3,6 +3,7 @@ import android.animation.Animator; import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; +import android.animation.TypeEvaluator; import android.animation.ValueAnimator; import android.graphics.Path; import android.graphics.PathMeasure; @@ -247,6 +248,11 @@ public AnimationBuilder interpolator(Interpolator interpolator) { return this; } + public AnimationBuilder evaluator(TypeEvaluator evaluator) { + viewAnimator.evaluator(evaluator); + return this; + } + public AnimationBuilder singleInterpolator(Interpolator interpolator) { singleInterpolator = interpolator; return this; diff --git a/viewanimator/src/main/java/com/github/florent37/viewanimator/ViewAnimator.java b/viewanimator/src/main/java/com/github/florent37/viewanimator/ViewAnimator.java index 54644d0..46985bc 100644 --- a/viewanimator/src/main/java/com/github/florent37/viewanimator/ViewAnimator.java +++ b/viewanimator/src/main/java/com/github/florent37/viewanimator/ViewAnimator.java @@ -2,6 +2,7 @@ import android.animation.Animator; import android.animation.AnimatorSet; +import android.animation.TypeEvaluator; import android.animation.ValueAnimator; import android.view.View; import android.view.ViewTreeObserver; @@ -30,6 +31,7 @@ public class ViewAnimator { private long duration = DEFAULT_DURATION; private long startDelay = 0; private Interpolator interpolator = null; + private TypeEvaluator evaluator = null; private int repeatCount = 0; private int repeatMode = RESTART; @@ -67,6 +69,7 @@ protected AnimatorSet createAnimatorSet() { ValueAnimator valueAnimator = (ValueAnimator) animator; valueAnimator.setRepeatCount(repeatCount); valueAnimator.setRepeatMode(repeatMode); + valueAnimator.setEvaluator(evaluator); } } @@ -203,4 +206,9 @@ public ViewAnimator interpolator(Interpolator interpolator) { return this; } + public ViewAnimator evaluator(TypeEvaluator evaluator) { + this.evaluator = evaluator; + return this; + } + }