summaryrefslogtreecommitdiff
path: root/core/java/android/animation/KeyframeSet.java
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2010-10-12 16:29:28 -0700
committerChet Haase <chet@google.com>2010-10-14 13:13:34 -0700
commit2794eb3b02e2404d453d3ad22a8a85a138130a07 (patch)
tree91fa1c08761921ce2976696234011c8d7f609161 /core/java/android/animation/KeyframeSet.java
parentbf5b247fa120b3f8ee0331d00be25b1cf74dd3f3 (diff)
Remove generics from Animator APIs
Change the manner of constructing Animator-related objects from constructors via generics to factory methods with type-specific method names. Should improve the proliferation of warnings due to generics issues and make the code more readable (less irrelevant angle brackets Floating around). Change-Id: Ib59a7dd72a95d438022e409ddeac48853082b943
Diffstat (limited to 'core/java/android/animation/KeyframeSet.java')
-rw-r--r--core/java/android/animation/KeyframeSet.java80
1 files changed, 77 insertions, 3 deletions
diff --git a/core/java/android/animation/KeyframeSet.java b/core/java/android/animation/KeyframeSet.java
index a24b1fbcdfd7..1741e60a62be 100644
--- a/core/java/android/animation/KeyframeSet.java
+++ b/core/java/android/animation/KeyframeSet.java
@@ -17,6 +17,7 @@
package android.animation;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* This class holds a collection of Keyframe objects and is called by ValueAnimator to calculate
@@ -31,12 +32,85 @@ class KeyframeSet {
public KeyframeSet(Keyframe... keyframes) {
mKeyframes = new ArrayList<Keyframe>();
- for (Keyframe keyframe : keyframes) {
- mKeyframes.add(keyframe);
- }
+ mKeyframes.addAll(Arrays.asList(keyframes));
mNumKeyframes = mKeyframes.size();
}
+ public static KeyframeSet ofInt(int... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ if (numKeyframes == 1) {
+ keyframes[0] = new Keyframe(0f, (Object) null);
+ keyframes[1] = new Keyframe(1f, values[0]);
+ } else {
+ keyframes[0] = new Keyframe(0f, values[0]);
+ for (int i = 1; i < numKeyframes; ++i) {
+ keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]);
+ }
+ }
+ return new KeyframeSet(keyframes);
+ }
+
+ public static KeyframeSet ofFloat(float... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ if (numKeyframes == 1) {
+ keyframes[0] = new Keyframe(0f, (Object) null);
+ keyframes[1] = new Keyframe(1f, values[0]);
+ } else {
+ keyframes[0] = new Keyframe(0f, values[0]);
+ for (int i = 1; i < numKeyframes; ++i) {
+ keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]);
+ }
+ }
+ return new KeyframeSet(keyframes);
+ }
+
+ public static KeyframeSet ofDouble(double... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ if (numKeyframes == 1) {
+ keyframes[0] = new Keyframe(0f, (Object) null);
+ keyframes[1] = new Keyframe(1f, values[0]);
+ } else {
+ keyframes[0] = new Keyframe(0f, values[0]);
+ for (int i = 1; i < numKeyframes; ++i) {
+ keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]);
+ }
+ }
+ return new KeyframeSet(keyframes);
+ }
+
+ public static KeyframeSet ofLong(long... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ if (numKeyframes == 1) {
+ keyframes[0] = new Keyframe(0f, (Object) null);
+ keyframes[1] = new Keyframe(1f, values[0]);
+ } else {
+ keyframes[0] = new Keyframe(0f, values[0]);
+ for (int i = 1; i < numKeyframes; ++i) {
+ keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]);
+ }
+ }
+ return new KeyframeSet(keyframes);
+ }
+
+ public static KeyframeSet ofObject(Object... values) {
+ int numKeyframes = values.length;
+ Keyframe keyframes[] = new Keyframe[Math.max(numKeyframes,2)];
+ if (numKeyframes == 1) {
+ keyframes[0] = new Keyframe(0f, (Object) null);
+ keyframes[1] = new Keyframe(1f, values[0]);
+ } else {
+ keyframes[0] = new Keyframe(0f, values[0]);
+ for (int i = 1; i < numKeyframes; ++i) {
+ keyframes[i] = new Keyframe((float) i / (numKeyframes - 1), values[i]);
+ }
+ }
+ return new KeyframeSet(keyframes);
+ }
+
/**
* Gets the animated value, given the elapsed fraction of the animation (interpolated by the
* animation's interpolator) and the evaluator used to calculate in-between values. This