Home | History | Annotate | Download | only in volume
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.systemui.volume;
     18 
     19 import android.animation.TimeInterpolator;
     20 
     21 public class SystemUIInterpolators {
     22     public static final class LogDecelerateInterpolator implements TimeInterpolator {
     23         private final float mBase;
     24         private final float mDrift;
     25         private final float mTimeScale;
     26         private final float mOutputScale;
     27 
     28         public LogDecelerateInterpolator() {
     29             this(400f, 1.4f, 0);
     30         }
     31 
     32         private LogDecelerateInterpolator(float base, float timeScale, float drift) {
     33             mBase = base;
     34             mDrift = drift;
     35             mTimeScale = 1f / timeScale;
     36 
     37             mOutputScale = 1f / computeLog(1f);
     38         }
     39 
     40         private float computeLog(float t) {
     41             return 1f - (float) Math.pow(mBase, -t * mTimeScale) + (mDrift * t);
     42         }
     43 
     44         @Override
     45         public float getInterpolation(float t) {
     46             return computeLog(t) * mOutputScale;
     47         }
     48     }
     49 
     50     public static final class LogAccelerateInterpolator implements TimeInterpolator {
     51         private final int mBase;
     52         private final int mDrift;
     53         private final float mLogScale;
     54 
     55         public LogAccelerateInterpolator() {
     56             this(100, 0);
     57         }
     58 
     59         private LogAccelerateInterpolator(int base, int drift) {
     60             mBase = base;
     61             mDrift = drift;
     62             mLogScale = 1f / computeLog(1, mBase, mDrift);
     63         }
     64 
     65         private static float computeLog(float t, int base, int drift) {
     66             return (float) -Math.pow(base, -t) + 1 + (drift * t);
     67         }
     68 
     69         @Override
     70         public float getInterpolation(float t) {
     71             return 1 - computeLog(1 - t, mBase, mDrift) * mLogScale;
     72         }
     73     }
     74 
     75     public interface Callback {
     76         void onAnimatingChanged(boolean animating);
     77     }
     78 }
     79