2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android
.view
.animation
;
19 import android
.content
.Context
;
20 import android
.content
.res
.Resources
;
21 import android
.content
.res
.Resources
.Theme
;
22 import android
.content
.res
.TypedArray
;
23 import android
.util
.AttributeSet
;
25 import com
.android
.internal
.R
;
26 import com
.android
.internal
.view
.animation
.HasNativeInterpolator
;
27 import com
.android
.internal
.view
.animation
.NativeInterpolatorFactory
;
28 import com
.android
.internal
.view
.animation
.NativeInterpolatorFactoryHelper
;
31 * An interpolator where the change flings forward and overshoots the last value
34 @HasNativeInterpolator
35 public class OvershootInterpolator
extends BaseInterpolator
implements NativeInterpolatorFactory
{
36 private final float mTension
;
38 public OvershootInterpolator() {
43 * @param tension Amount of overshoot. When tension equals 0.0f, there is
44 * no overshoot and the interpolator becomes a simple
45 * deceleration interpolator.
47 public OvershootInterpolator(float tension
) {
51 public OvershootInterpolator(Context context
, AttributeSet attrs
) {
52 this(context
.getResources(), context
.getTheme(), attrs
);
56 public OvershootInterpolator(Resources res
, Theme theme
, AttributeSet attrs
) {
59 a
= theme
.obtainStyledAttributes(attrs
, R
.styleable
.OvershootInterpolator
, 0, 0);
61 a
= res
.obtainAttributes(attrs
, R
.styleable
.OvershootInterpolator
);
64 mTension
= a
.getFloat(R
.styleable
.OvershootInterpolator_tension
, 2.0f
);
65 setChangingConfiguration(a
.getChangingConfigurations());
69 public float getInterpolation(float t
) {
70 // _o(t) = t * t * ((tension + 1) * t + tension)
71 // o(t) = _o(t - 1) + 1
73 return t
* t
* ((mTension
+ 1) * t
+ mTension
) + 1.0f
;
78 public long createNativeInterpolator() {
79 return NativeInterpolatorFactoryHelper
.createOvershootInterpolator(mTension
);