176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren/* 276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * Copyright (C) 2007 The Android Open Source Project 376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * 476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * Licensed under the Apache License, Version 2.0 (the "License"); 576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * you may not use this file except in compliance with the License. 676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * You may obtain a copy of the License at 776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * 876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * http://www.apache.org/licenses/LICENSE-2.0 976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * 1076086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * Unless required by applicable law or agreed to in writing, software 1176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * distributed under the License is distributed on an "AS IS" BASIS, 1276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * See the License for the specific language governing permissions and 1476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * limitations under the License. 1576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren */ 1676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 1776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wrenpackage com.android.dreams.phototable; 1876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 1976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wrenimport android.view.animation.DecelerateInterpolator; 2088d80f4471c900628e2cb6eef23029b99af48e09Chris Wrenimport android.view.animation.Interpolator; 2176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wrenimport android.view.animation.LinearInterpolator; 2276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 2376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren/** 2476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * An interpolator where the rate of change starts out quickly and 2576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * and then decelerates. 2676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren * 2776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren */ 2876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wrenpublic class SoftLandingInterpolator implements Interpolator { 2976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final LinearInterpolator fly; 3076086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final DecelerateInterpolator slide; 3176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final float mI; 3276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final float mO; 3376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final float upperRange; 3476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final float bottom; 3576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren private final float top; 3676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 3776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren public SoftLandingInterpolator(float i, float o) { 3876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren fly = new LinearInterpolator(); 3976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren slide = new DecelerateInterpolator(); 4076086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren mI = i; 4176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren mO = o; 4276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren final float epsilon = Math.min(mI / 2f, (1f - mI) / 2f); 4376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren bottom = mI - epsilon; 4476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren top = mI + epsilon; 4576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren upperRange = 1f - bottom; 4676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren } 4776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 4876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren public float getInterpolation(float input) { 4976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren final float f = fly.getInterpolation(input / upperRange) * mO; 5076086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren final float s = slide.getInterpolation((input - bottom) / upperRange) * (1f - mO) + mO; 5176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 5276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren float value; 5376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren if (input < bottom) { 5476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren value = f; 5576086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren } else if (input < top) { 5676086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren final float alpha = (input - bottom) / (top - bottom); 5776086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren value = (1f - alpha) * f + alpha * s; 5876086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren } else { 5976086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren value = s; 6076086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren } 6176086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren 6276086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren return value; 6376086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren } 6476086400f8e68b810bf1b3db0dc4f7133c8644aeChris Wren} 65