• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
__constructor__(Drawable[] drawables)20     public void __constructor__(Drawable[] drawables) {
21         this.drawables = drawables;
22     }
23 
24     @Implementation
getNumberOfLayers()25     public int getNumberOfLayers() {
26         return drawables.length;
27     }
28 
29     @Implementation
getDrawable( int idx )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
setDrawableByLayerId(int id, Drawable drawable)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
setId(int index, int id)48     public void setId(int index, int id) {
49         indexForId.put(id, index);
50     }
51 }
52