blob: 7d9528280f1ee22b9d9248b764d832fa93cfef99 [file] [log] [blame]
Adam Cohen6c5891a2014-07-09 23:53:15 -07001package com.android.launcher3;
2
3import android.animation.TimeInterpolator;
4
5public 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 Wickhambd42ba72016-05-03 16:03:46 -070024 // 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 Cohen6c5891a2014-07-09 23:53:15 -070027 }
28}