Guest User

Untitled

a guest
Jan 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import android.view.animation.Interpolator;
  2.  
  3. import static java.lang.Math.*;
  4.  
  5. public class BetterBounceInterpolator implements Interpolator {
  6. private int mBounces;
  7. private double mEnergy;
  8.  
  9. /** Have more control over how to bounce your values.
  10. *
  11. */
  12. public BetterBounceInterpolator(){
  13. this(3);
  14. }
  15.  
  16. /** Have more control over how to bounce your values.
  17. *
  18. * @param bounces number of times to bounce before coming to a rest
  19. */
  20. public BetterBounceInterpolator(int bounces){
  21. this(bounces, 0.3f);
  22. }
  23.  
  24. /** Have more control over how to bounce your values.
  25. *
  26. * @param bounces number of times to bounce before coming to a rest
  27. * @param energyFactor control how the bounce loses momentum. 0 is lose energy linearly. 1 energy loss slows down over time, -1 energy loss speeds up over time. Values greater than 1 and less than -1 cause over/under bounce
  28. */
  29. public BetterBounceInterpolator(int bounces, double energyFactor){
  30. mBounces = bounces;
  31. mEnergy = energyFactor + 0.5;
  32. }
  33.  
  34. @Override public float getInterpolation(float x) {
  35. return (float) (1d + (-abs(cos(x * 10 * mBounces/PI)) * getCurveAdjustment(x)));
  36. }
  37.  
  38. private double getCurveAdjustment(double x){
  39. return -((1 - x) * (1 - x) * 0 + 2 * (1 - x) * x * mEnergy + x * x * 1) + 1;
  40. }
  41. }
Add Comment
Please, Sign In to add comment