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