1/* 2 * Copyright (C) 2009 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 17package android.view.animation; 18 19import android.content.Context; 20import android.content.res.TypedArray; 21import android.util.AttributeSet; 22 23/** 24 * An interpolator where the change flings forward and overshoots the last value 25 * then comes back. 26 */ 27public class OvershootInterpolator implements Interpolator { 28 private final float mTension; 29 30 public OvershootInterpolator() { 31 mTension = 2.0f; 32 } 33 34 /** 35 * @param tension Amount of overshoot. When tension equals 0.0f, there is 36 * no overshoot and the interpolator becomes a simple 37 * deceleration interpolator. 38 */ 39 public OvershootInterpolator(float tension) { 40 mTension = tension; 41 } 42 43 public OvershootInterpolator(Context context, AttributeSet attrs) { 44 TypedArray a = context.obtainStyledAttributes(attrs, 45 com.android.internal.R.styleable.OvershootInterpolator); 46 47 mTension = 48 a.getFloat(com.android.internal.R.styleable.OvershootInterpolator_tension, 2.0f); 49 50 a.recycle(); 51 } 52 53 public float getInterpolation(float t) { 54 // _o(t) = t * t * ((tension + 1) * t + tension) 55 // o(t) = _o(t - 1) + 1 56 t -= 1.0f; 57 return t * t * ((mTension + 1) * t + mTension) + 1.0f; 58 } 59} 60