Debian Codegraph @

core/java/android/view/animation/BounceInterpolator.java

raw symbols SCIP
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.graphics.animation.HasNativeInterpolator;
21 import android.graphics.animation.NativeInterpolator;
22 import android.graphics.animation.NativeInterpolatorFactory;
23 import android.util.AttributeSet;
24
25 /**
26 * An interpolator where the change bounces at the end.
27 */
28 @HasNativeInterpolator
29 public class BounceInterpolator extends BaseInterpolator implements NativeInterpolator {
30 public BounceInterpolator() {
31 }
32
33 @SuppressWarnings({"UnusedDeclaration"})
34 public BounceInterpolator(Context context, AttributeSet attrs) {
35 }
36
37 private static float bounce(float t) {
38 return t * t * 8.0f;
39 }
40
41 public float getInterpolation(float t) {
42 // _b(t) = t * t * 8
43 // bs(t) = _b(t) for t < 0.3535
44 // bs(t) = _b(t - 0.54719) + 0.7 for t < 0.7408
45 // bs(t) = _b(t - 0.8526) + 0.9 for t < 0.9644
46 // bs(t) = _b(t - 1.0435) + 0.95 for t <= 1.0
47 // b(t) = bs(t * 1.1226)
48 t *= 1.1226f;
49 if (t < 0.3535f) return bounce(t);
50 else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f;
51 else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f;
52 else return bounce(t - 1.0435f) + 0.95f;
53 }
54
55 /** @hide */
56 @Override
57 public long createNativeInterpolator() {
58 return NativeInterpolatorFactory.createBounceInterpolator();
59 }
60 }