Created
February 26, 2017 01:06
-
-
Save westonal/03c81ea0718c8060b35a6d146d67da36 to your computer and use it in GitHub Desktop.
Auto reverse interpolator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.animation.TimeInterpolator; | |
| import android.view.animation.LinearInterpolator; | |
| /** | |
| * Maps time into another interpolator so that the animation plays, and then reverses. | |
| * i.e. time maps like so: | |
| * [0..0.5, 0.5..1] maps to [0..1, 1..0] | |
| */ | |
| public final class AutoReverseInterpolator implements TimeInterpolator { | |
| private final TimeInterpolator inner; | |
| /** | |
| * Decorator constructor, use if you don't want a linear interpolation. | |
| * @param inner | |
| */ | |
| public AutoReverseInterpolator(TimeInterpolator inner) { | |
| this.inner = inner; | |
| } | |
| /** | |
| * Linear interpolation constructor. | |
| */ | |
| public AutoReverseInterpolator() { | |
| this(new LinearInterpolator()); | |
| } | |
| @Override | |
| public float getInterpolation(float input) { | |
| input *= 2; | |
| if (input > 1) { | |
| input = 2 - input; | |
| } | |
| return inner.getInterpolation(input); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment