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