Jean-Baptiste Queru | 8b06628 | 2009-03-25 15:05:51 -0700 | [diff] [blame] | 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 | |
| 17 | package android.view.animation; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.TypedArray; |
| 21 | import android.util.AttributeSet; |
| 22 | |
| 23 | /** |
| 24 | * An interpolator where the change bounces at the end. |
| 25 | */ |
| 26 | public class BounceInterpolator implements Interpolator { |
| 27 | public BounceInterpolator() { |
| 28 | } |
| 29 | |
| 30 | @SuppressWarnings({"UnusedDeclaration"}) |
| 31 | public BounceInterpolator(Context context, AttributeSet attrs) { |
| 32 | } |
| 33 | |
| 34 | private static float bounce(float t) { |
| 35 | return t * t * 8.0f; |
| 36 | } |
| 37 | |
| 38 | public float getInterpolation(float t) { |
| 39 | // _b(t) = t * t * 8 |
| 40 | // bs(t) = _b(t) for t < 0.3535 |
| 41 | // bs(t) = _b(t - 0.54719) + 0.7 for t < 0.7408 |
| 42 | // bs(t) = _b(t - 0.8526) + 0.9 for t < 0.9644 |
| 43 | // bs(t) = _b(t - 1.0435) + 0.95 for t <= 1.0 |
| 44 | // b(t) = bs(t * 1.1226) |
| 45 | t *= 1.1226f; |
| 46 | if (t < 0.3535f) return bounce(t); |
| 47 | else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f; |
| 48 | else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f; |
| 49 | else return bounce(t - 1.0435f) + 0.95f; |
| 50 | } |
| 51 | } |