summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/tests/coretests/AndroidManifest.xml7
-rw-r--r--core/tests/coretests/res/layout/animator_set_squares.xml32
-rw-r--r--core/tests/coretests/src/android/animation/AnimatorSetActivity.java14
-rw-r--r--core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java155
4 files changed, 208 insertions, 0 deletions
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index 3afc3dfa3b11..3c1036846595 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -1267,6 +1267,13 @@
</intent-filter>
</activity>
+ <activity android:name="android.animation.AnimatorSetActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+ </intent-filter>
+ </activity>
+
<activity android:name="android.content.res.ResourceCacheActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/core/tests/coretests/res/layout/animator_set_squares.xml b/core/tests/coretests/res/layout/animator_set_squares.xml
new file mode 100644
index 000000000000..23e6eea06a2b
--- /dev/null
+++ b/core/tests/coretests/res/layout/animator_set_squares.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@android:color/white"
+ android:orientation="horizontal">
+ <View
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:padding="10dp"
+ android:background="#F00"
+ android:id="@+id/square1"/>
+ <View
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:padding="10dp"
+ android:background="#0F0"
+ android:id="@+id/square2"/>
+ <View
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:padding="10dp"
+ android:background="#00F"
+ android:id="@+id/square3"/>
+ <View
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:padding="10dp"
+ android:background="@android:color/black"
+ android:id="@+id/square4"/>
+</LinearLayout> \ No newline at end of file
diff --git a/core/tests/coretests/src/android/animation/AnimatorSetActivity.java b/core/tests/coretests/src/android/animation/AnimatorSetActivity.java
new file mode 100644
index 000000000000..501ea485b8b2
--- /dev/null
+++ b/core/tests/coretests/src/android/animation/AnimatorSetActivity.java
@@ -0,0 +1,14 @@
+package android.animation;
+
+import com.android.frameworks.coretests.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class AnimatorSetActivity extends Activity {
+ @Override
+ public void onCreate(Bundle savedBundleInstance) {
+ super.onCreate(savedBundleInstance);
+ setContentView(R.layout.animator_set_squares);
+ }
+}
diff --git a/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java b/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java
new file mode 100644
index 000000000000..af0c9cd164b0
--- /dev/null
+++ b/core/tests/coretests/src/android/animation/AnimatorSetActivityTest.java
@@ -0,0 +1,155 @@
+package android.animation;
+
+import com.android.frameworks.coretests.R;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.View;
+
+import java.util.ArrayList;
+
+public class AnimatorSetActivityTest extends ActivityInstrumentationTestCase2<AnimatorSetActivity> {
+
+ private AnimatorSetActivity mActivity;
+ private ObjectAnimator a1,a2,a3;
+ private ValueAnimator a4,a5;
+
+ public AnimatorSetActivityTest() {
+ super(AnimatorSetActivity.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+
+ View square1 = mActivity.findViewById(R.id.square1);
+ View square2 = mActivity.findViewById(R.id.square2);
+ View square3 = mActivity.findViewById(R.id.square3);
+ a1 = ObjectAnimator.ofFloat(square1, View.TRANSLATION_X, 0f, 500f, 0f).setDuration(250);
+ a2 = ObjectAnimator.ofFloat(square2, View.ALPHA, 1f, 0f).setDuration(350);
+ a3 = ObjectAnimator.ofFloat(square3, View.ROTATION, 0, 90).setDuration(450);
+ a4 = ValueAnimator.ofInt(100, 200).setDuration(450);
+ a5 = ValueAnimator.ofFloat(10f, 5f).setDuration(850);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ mActivity = null;
+ a1 = null;
+ a2 = null;
+ a3 = null;
+ a4 = null;
+ a5 = null;
+ super.tearDown();
+ }
+
+ @SmallTest
+ public void testGetChildAnimations() {
+ AnimatorSet s1 = new AnimatorSet();
+ s1.playTogether(a1, a2, a3);
+ ArrayList<Animator> children = s1.getChildAnimations();
+ assertEquals(3, children.size());
+ assertTrue(children.contains(a1));
+ assertTrue(children.contains(a2));
+ assertTrue(children.contains(a3));
+
+ AnimatorSet s2 = new AnimatorSet();
+ s2.playSequentially(a1, a2, a3);
+ children = s2.getChildAnimations();
+ assertEquals(3, children.size());
+ assertTrue(children.contains(a1));
+ assertTrue(children.contains(a2));
+ assertTrue(children.contains(a3));
+
+ AnimatorSet s3 = new AnimatorSet();
+ s3.play(a1).before(a2).after(s1).with(s2).after(a3);
+ ArrayList<Animator> s3Children = s3.getChildAnimations();
+ assertNotNull(s3Children);
+ assertEquals(5, s3Children.size());
+ assertTrue(s3Children.contains(a1));
+ assertTrue(s3Children.contains(a2));
+ assertTrue(s3Children.contains(a3));
+ assertTrue(s3Children.contains(s1));
+ assertTrue(s3Children.contains(s2));
+
+ AnimatorSet s4 = new AnimatorSet();
+ s4.playSequentially(s3Children);
+ ArrayList<Animator> s4Children = s4.getChildAnimations();
+ assertNotNull(s4Children);
+ assertEquals(s3Children.size(), s4Children.size());
+ for (int i = 0; i < s3Children.size(); i++) {
+ Animator child = s3Children.get(i);
+ assertTrue(s4Children.contains(child));
+ }
+ }
+
+ @SmallTest
+ public void testTotalDuration() {
+ ArrayList<Animator> list = new ArrayList<>(5);
+ list.add(a1);
+ list.add(a2);
+ list.add(a3);
+ list.add(a4);
+ list.add(a5);
+
+ // Run animations sequentially and test the total duration against sum of durations.
+ AnimatorSet s1 = new AnimatorSet();
+ s1.playSequentially(list);
+ long totalDuration = 0;
+ for (int i = 0; i < list.size(); i++) {
+ Animator anim = list.get(i);
+ anim.setStartDelay(0);
+ totalDuration += list.get(i).getDuration();
+ }
+ assertEquals(totalDuration, s1.getTotalDuration());
+
+ // Add delay to set, and test total duration
+ s1.setStartDelay(200);
+ assertEquals(totalDuration + 200, s1.getTotalDuration());
+
+ a1.setStartDelay(100);
+ assertEquals(totalDuration + 200 + 100, s1.getTotalDuration());
+
+ // Run animations simultaneously, test the total duration against the longest duration
+ AnimatorSet s2 = new AnimatorSet();
+ s2.playTogether(list);
+ long maxDuration = 0;
+ for (int i = 0; i < list.size(); i++) {
+ long duration = list.get(i).getDuration();
+ list.get(i).setStartDelay(100);
+ maxDuration = maxDuration > (duration + 100) ? maxDuration : (duration + 100);
+ }
+ assertEquals(maxDuration, s2.getTotalDuration());
+
+ // Form a cycle in the AnimatorSet and test the total duration
+ AnimatorSet s3 = new AnimatorSet();
+ s3.play(a1).before(a2).after(a3);
+ s3.play(a1).after(a2).with(a4);
+ assertEquals(AnimatorSet.DURATION_INFINITE, s3.getTotalDuration());
+
+ // Put all the animators in a cycle
+ AnimatorSet s4 = new AnimatorSet();
+ s4.play(a1).after(a2);
+ s4.play(a2).after(a1);
+ assertEquals(AnimatorSet.DURATION_INFINITE, s4.getTotalDuration());
+
+ // No cycle in the set, run a2, a1, a3 in sequence, and a2, a4, a5 together
+ AnimatorSet s5 = new AnimatorSet();
+ s5.play(a1).after(a2).before(a3);
+ s5.play(a2).with(a4).with(a5);
+ long duration = a1.getDuration() + a1.getStartDelay() + a2.getDuration() + a2
+ .getStartDelay() + a3.getDuration() + a3.getStartDelay();
+ long a4Duration = a4.getDuration() + a4.getStartDelay();
+ long a5Duration = a5.getDuration() + a5.getStartDelay();
+ duration = Math.max(duration, a4Duration);
+ duration = Math.max(duration, a5Duration);
+ assertEquals(duration, s5.getTotalDuration());
+
+ // Change one animator to repeat infinitely and test the total time
+ a3.setRepeatCount(ValueAnimator.INFINITE);
+ assertEquals(AnimatorSet.DURATION_INFINITE, s5.getTotalDuration());
+
+ }
+
+}