Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import android.animation.TimeInterpolator;
  2. import android.view.animation.LinearInterpolator;
  3.  
  4. /**
  5. * Maps time into another interpolator so that the animation plays, and then reverses.
  6. * i.e. time maps like so:
  7. * [0..0.5, 0.5..1] maps to [0..1, 1..0]
  8. */
  9. public final class AutoReverseInterpolator implements TimeInterpolator {
  10.  
  11. private final TimeInterpolator inner;
  12.  
  13. /**
  14. * Decorator constructor, use if you don't want a linear interpolation.
  15. * @param inner
  16. */
  17. public AutoReverseInterpolator(TimeInterpolator inner) {
  18. this.inner = inner;
  19. }
  20.  
  21. /**
  22. * Linear interpolation constructor.
  23. */
  24. public AutoReverseInterpolator() {
  25. this(new LinearInterpolator());
  26. }
  27.  
  28. @Override
  29. public float getInterpolation(float input) {
  30. input *= 2;
  31. if (input > 1) {
  32. input = 2 - input;
  33. }
  34. return inner.getInterpolation(input);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement