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