• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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.dreams.phototable;
18 
19 import android.view.animation.Interpolator;
20 import android.view.animation.DecelerateInterpolator;
21 import android.view.animation.LinearInterpolator;
22 import android.util.Log;
23 
24 /**
25  * An interpolator where the rate of change starts out quickly and
26  * and then decelerates.
27  *
28  */
29 public class SoftLandingInterpolator implements Interpolator {
30     private final LinearInterpolator fly;
31     private final DecelerateInterpolator slide;
32     private final float mI;
33     private final float mO;
34     private final float lowerRange;
35     private final float upperRange;
36     private final float bottom;
37     private final float top;
38 
SoftLandingInterpolator(float i, float o)39     public SoftLandingInterpolator(float i, float o) {
40         fly = new LinearInterpolator();
41         slide = new  DecelerateInterpolator();
42         mI = i;
43         mO = o;
44         final float epsilon = Math.min(mI / 2f, (1f - mI) / 2f);
45         bottom = mI - epsilon;
46         top = mI + epsilon;
47         lowerRange = top;
48         upperRange = 1f - bottom;
49     }
50 
getInterpolation(float input)51     public float getInterpolation(float input) {
52         final float f = fly.getInterpolation(input / upperRange) * mO;
53         final float s = slide.getInterpolation((input - bottom) / upperRange) * (1f - mO) + mO;
54 
55         float value;
56         if (input < bottom) {
57             value = f;
58         } else if (input < top) {
59             final float alpha = (input - bottom) / (top - bottom);
60             value = (1f - alpha) * f + alpha * s;
61         } else {
62             value = s;
63         }
64 
65         return value;
66     }
67 }
68