• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
LogDecelerateInterpolator(int base, int drift)11     public LogDecelerateInterpolator(int base, int drift) {
12         mBase = base;
13         mDrift = drift;
14 
15         mLogScale = 1f / computeLog(1, mBase, mDrift);
16     }
17 
computeLog(float t, int base, int drift)18     static float computeLog(float t, int base, int drift) {
19         return (float) -Math.pow(base, -t) + 1 + (drift * t);
20     }
21 
22     @Override
getInterpolation(float t)23     public float getInterpolation(float t) {
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;
27     }
28 }
29