Added ShadowAnimationSet
diff --git a/src/main/java/com/xtremelabs/robolectric/Robolectric.java b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
index f0800ed..4a69fde 100644
--- a/src/main/java/com/xtremelabs/robolectric/Robolectric.java
+++ b/src/main/java/com/xtremelabs/robolectric/Robolectric.java
@@ -108,10 +108,7 @@
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
-import android.view.animation.AlphaAnimation;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.view.animation.TranslateAnimation;
+import android.view.animation.*;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
@@ -231,6 +228,7 @@
ShadowAndroidHttpClient.class,
ShadowAnimation.class,
ShadowAnimationDrawable.class,
+ ShadowAnimationSet.class,
ShadowAnimationUtils.class,
ShadowApplication.class,
ShadowAppWidgetManager.class,
@@ -515,6 +513,10 @@
return (ShadowAnimationDrawable) shadowOf_(instance);
}
+ public static ShadowAnimationSet shadowOf(AnimationSet instance) {
+ return (ShadowAnimationSet) shadowOf_(instance);
+ }
+
public static ShadowAnimationUtils shadowOf(AnimationUtils instance) {
return (ShadowAnimationUtils) shadowOf_(instance);
}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java
new file mode 100644
index 0000000..5160bf8
--- /dev/null
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowAnimationSet.java
@@ -0,0 +1,30 @@
+package com.xtremelabs.robolectric.shadows;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.view.animation.Animation;
+import android.view.animation.AnimationSet;
+
+import com.xtremelabs.robolectric.internal.Implementation;
+import com.xtremelabs.robolectric.internal.Implements;
+import com.xtremelabs.robolectric.internal.RealObject;
+
+@Implements(AnimationSet.class)
+public class ShadowAnimationSet extends ShadowAnimation {
+ private ArrayList<Animation> animationList = new ArrayList<Animation>();
+
+ @RealObject
+ private AnimationSet realAnimationSet;
+
+
+ @Implementation
+ public void addAnimation(Animation anim) {
+ animationList.add(anim);
+ }
+
+ @Implementation
+ public List<Animation> getAnimations() {
+ return animationList;
+ }
+}
diff --git a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
index 9a79387..f0beafe 100644
--- a/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
+++ b/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTranslateAnimation.java
@@ -16,6 +16,18 @@
private int toYType;
private float toYValue;
+ public void __constructor__(float fromXValue, float toXValue,
+ float fromYValue, float toYValue) {
+ this.fromXType = TranslateAnimation.ABSOLUTE;
+ this.fromXValue = fromXValue;
+ this.toXType = TranslateAnimation.ABSOLUTE;
+ this.toXValue = toXValue;
+ this.fromYType = TranslateAnimation.ABSOLUTE;
+ this.fromYValue = fromYValue;
+ this.toYType = TranslateAnimation.ABSOLUTE;
+ this.toYValue = toYValue;
+ }
+
public void __constructor__(int fromXType, float fromXValue, int toXType, float toXValue,
int fromYType, float fromYValue, int toYType, float toYValue) {
this.fromXType = fromXType;
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java
new file mode 100644
index 0000000..ef968a8
--- /dev/null
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/AnimationSetTest.java
@@ -0,0 +1,45 @@
+package com.xtremelabs.robolectric.shadows;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import android.view.animation.*;
+
+import com.xtremelabs.robolectric.WithTestDefaultsRunner;
+
+import static com.xtremelabs.robolectric.Robolectric.shadowOf;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+@RunWith(WithTestDefaultsRunner.class)
+public class AnimationSetTest {
+ private AnimationSet set;
+ private ShadowAnimationSet shadow;
+
+ @Before
+ public void setUp() {
+ set = new AnimationSet(true);
+ shadow = shadowOf(set);
+ }
+
+
+ @Test
+ public void testAnimationList() {
+ Animation alpha = new AlphaAnimation(1f, 2f);
+ Animation translate = new TranslateAnimation(1f, 2f, 3f, 4f);
+ Animation rotate = new RotateAnimation(1f, 2f);
+ set.addAnimation(alpha);
+ set.addAnimation(translate);
+ set.addAnimation(rotate);
+
+ List<Animation> list = shadow.getAnimations();
+ assertThat(list.size(), equalTo(3));
+ assertThat(list.get(0), sameInstance(alpha));
+ assertThat(list.get(1), sameInstance(translate));
+ assertThat(list.get(2), sameInstance(rotate));
+ }
+
+}
diff --git a/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java b/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
index c8b3429..716fe6d 100644
--- a/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
+++ b/src/test/java/com/xtremelabs/robolectric/shadows/TranslateAnimationTest.java
@@ -1,5 +1,6 @@
package com.xtremelabs.robolectric.shadows;
+import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;
import org.junit.Before;
@@ -33,4 +34,19 @@
assertThat(shadow.getToYType(), equalTo(7));
assertThat(shadow.getToYValue(), equalTo(8f));
}
+
+ @Test
+ public void animationParametersFromConstructor2() throws Exception {
+ TranslateAnimation animation2 = new TranslateAnimation(1, 2, 3, 4);
+ ShadowTranslateAnimation shadow2 = shadowOf(animation2);
+ int defType = Animation.ABSOLUTE;
+ assertThat(shadow2.getFromXType(), equalTo(defType));
+ assertThat(shadow2.getFromXValue(), equalTo(1f));
+ assertThat(shadow2.getToXType(), equalTo(defType));
+ assertThat(shadow2.getToXValue(), equalTo(2f));
+ assertThat(shadow2.getFromYType(), equalTo(defType));
+ assertThat(shadow2.getFromYValue(), equalTo(3f));
+ assertThat(shadow2.getToYType(), equalTo(defType));
+ assertThat(shadow2.getToYValue(), equalTo(4f));
+ }
}