1 package org.robolectric.shadows; 2 3 import android.view.View; 4 import android.view.ViewGroup; 5 import android.widget.ViewAnimator; 6 import org.robolectric.annotation.Implementation; 7 import org.robolectric.annotation.Implements; 8 9 @Implements(ViewAnimator.class) 10 public class ShadowViewAnimator extends ShadowViewGroup { 11 12 private int currentChild = 0; 13 14 @Implementation getDisplayedChild()15 protected int getDisplayedChild() { 16 return currentChild; 17 } 18 19 @Implementation setDisplayedChild(int whichChild)20 protected void setDisplayedChild(int whichChild) { 21 currentChild = whichChild; 22 for (int i = ((ViewGroup) realView).getChildCount() - 1; i >= 0; i--) { 23 View child = ((ViewGroup) realView).getChildAt(i); 24 child.setVisibility(i == whichChild ? View.VISIBLE : View.GONE); 25 } 26 } 27 28 @Implementation getCurrentView()29 protected View getCurrentView() { 30 return ((ViewGroup) realView).getChildAt(getDisplayedChild()); 31 } 32 33 @Implementation showNext()34 protected void showNext() { 35 setDisplayedChild((getDisplayedChild() + 1) % ((ViewGroup) realView).getChildCount()); 36 } 37 38 @Implementation showPrevious()39 protected void showPrevious() { 40 setDisplayedChild(getDisplayedChild() == 0 ? ((ViewGroup) realView).getChildCount() - 1 : getDisplayedChild() - 1); 41 } 42 } 43