Home | History | Annotate | Download | only in shadows
      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 ShadowFrameLayout {
     11 
     12   private int currentChild = 0;
     13 
     14   @Implementation
     15   public int getDisplayedChild() {
     16     return currentChild;
     17   }
     18 
     19   @Implementation
     20   public 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
     29   public View getCurrentView() {
     30     return ((ViewGroup) realView).getChildAt(getDisplayedChild());
     31   }
     32 
     33   @Implementation
     34   public void showNext() {
     35     setDisplayedChild((getDisplayedChild() + 1) % ((ViewGroup) realView).getChildCount());
     36   }
     37 
     38   @Implementation
     39   public void showPrevious() {
     40     setDisplayedChild(getDisplayedChild() == 0 ? ((ViewGroup) realView).getChildCount() - 1 : getDisplayedChild() - 1);
     41   }
     42 }
     43