Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.graphics.drawable.Drawable;
      4 import android.graphics.drawable.LayerDrawable;
      5 import com.xtremelabs.robolectric.internal.Implementation;
      6 import com.xtremelabs.robolectric.internal.Implements;
      7 import com.xtremelabs.robolectric.internal.RealObject;
      8 
      9 import java.util.HashMap;
     10 import java.util.Map;
     11 
     12 @Implements(LayerDrawable.class)
     13 public class ShadowLayerDrawable extends ShadowDrawable {
     14     @RealObject
     15     protected LayerDrawable realLayerDrawable;
     16 
     17     protected Drawable[] drawables;
     18     private Map<Integer, Integer> indexForId = new HashMap<Integer, Integer>();
     19 
     20     public void __constructor__(Drawable[] drawables) {
     21         this.drawables = drawables;
     22     }
     23 
     24     @Implementation
     25     public int getNumberOfLayers() {
     26         return drawables.length;
     27     }
     28 
     29     @Implementation
     30     public Drawable getDrawable( int idx ) {
     31     	Drawable d = null;
     32     	if( idx < drawables.length && idx >= 0 ) {
     33     		d = drawables[ idx ];
     34     	}
     35     	return d;
     36     }
     37 
     38     @Implementation
     39     public boolean setDrawableByLayerId(int id, Drawable drawable) {
     40         if (!indexForId.containsKey(id)) {
     41             return false;
     42         }
     43         drawables[indexForId.get(id)] = drawable;
     44         return true;
     45     }
     46 
     47     @Implementation
     48     public void setId(int index, int id) {
     49         indexForId.put(id, index);
     50     }
     51 }
     52