Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
| 3 | import android.animation.TimeInterpolator; |
| 4 | |
| 5 | public class LogDecelerateInterpolator implements TimeInterpolator { |
| 6 | |
| 7 | int mBase; |
| 8 | int mDrift; |
| 9 | final float mLogScale; |
| 10 | |
| 11 | public LogDecelerateInterpolator(int base, int drift) { |
| 12 | mBase = base; |
| 13 | mDrift = drift; |
| 14 | |
| 15 | mLogScale = 1f / computeLog(1, mBase, mDrift); |
| 16 | } |
| 17 | |
| 18 | static float computeLog(float t, int base, int drift) { |
| 19 | return (float) -Math.pow(base, -t) + 1 + (drift * t); |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public float getInterpolation(float t) { |
Tony Wickham | bd42ba7 | 2016-05-03 16:03:46 -0700 | [diff] [blame] | 24 | // Due to rounding issues, the interpolation doesn't quite reach 1 even though it should. |
| 25 | // To account for this, we short-circuit to return 1 if the input is 1. |
| 26 | return Float.compare(t, 1f) == 0 ? 1f : computeLog(t, mBase, mDrift) * mLogScale; |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 27 | } |
| 28 | } |