Debian Codegraph @

core/java/android/view/animation/CycleInterpolator.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 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.Resources;
21 import android.content.res.Resources.Theme;
22 import android.content.res.TypedArray;
23 import android.graphics.animation.HasNativeInterpolator;
24 import android.graphics.animation.NativeInterpolator;
25 import android.graphics.animation.NativeInterpolatorFactory;
26 import android.util.AttributeSet;
27
28 import com.android.internal.R;
29
30 /**
31 * Repeats the animation for a specified number of cycles. The
32 * rate of change follows a sinusoidal pattern.
33 *
34 */
35 @HasNativeInterpolator
36 public class CycleInterpolator extends BaseInterpolator implements NativeInterpolator {
37 public CycleInterpolator(float cycles) {
38 mCycles = cycles;
39 }
40
41 public CycleInterpolator(Context context, AttributeSet attrs) {
42 this(context.getResources(), context.getTheme(), attrs);
43 }
44
45 /** @hide */
46 public CycleInterpolator(Resources resources, Theme theme, AttributeSet attrs) {
47 TypedArray a;
48 if (theme != null) {
49 a = theme.obtainStyledAttributes(attrs, R.styleable.CycleInterpolator, 0, 0);
50 } else {
51 a = resources.obtainAttributes(attrs, R.styleable.CycleInterpolator);
52 }
53
54 mCycles = a.getFloat(R.styleable.CycleInterpolator_cycles, 1.0f);
55 setChangingConfiguration(a.getChangingConfigurations());
56 a.recycle();
57 }
58
59 public float getInterpolation(float input) {
60 return (float)(Math.sin(2 * mCycles * Math.PI * input));
61 }
62
63 private float mCycles;
64
65 /** @hide */
66 @Override
67 public long createNativeInterpolator() {
68 return NativeInterpolatorFactory.createCycleInterpolator(mCycles);
69 }
70 }