1package com.xtremelabs.robolectric.shadows; 2 3import android.graphics.drawable.Drawable; 4import com.google.android.maps.ItemizedOverlay; 5import com.google.android.maps.OverlayItem; 6import com.google.android.maps.ShadowItemizedOverlayBridge; 7import com.xtremelabs.robolectric.internal.Implementation; 8import com.xtremelabs.robolectric.internal.Implements; 9import com.xtremelabs.robolectric.internal.RealObject; 10 11import java.util.ArrayList; 12 13/** 14 * Shadow for {@code ItemizedOverlay} that keeps track of what has been called and enables the return value for 15 * {@link #hitTest(com.google.android.maps.OverlayItem, android.graphics.drawable.Drawable, int, int)} to be set up by 16 * tests. 17 */ 18@Implements(ItemizedOverlay.class) 19public class ShadowItemizedOverlay<Item extends OverlayItem> { 20 private boolean isPopulated; 21 private boolean shouldHit; 22 private boolean lastFocusedIndexWasReset; 23 private ArrayList<Item> items = new ArrayList<Item>(); 24 25 @RealObject 26 private ItemizedOverlay<Item> realObject; 27 28 @Implementation 29 public final void populate() { 30 isPopulated = true; 31 32 items.clear(); 33 for (int i = 0; i < realObject.size(); i++) { 34 items.add(getBridge().createItem(i)); 35 } 36 } 37 38 @Implementation 39 public final Item getItem(int position) { 40 return items.get(position); 41 } 42 43 @Implementation 44 public boolean hitTest(OverlayItem item, android.graphics.drawable.Drawable drawable, int i, int i1) { 45 return shouldHit; 46 } 47 48 @Implementation 49 public void setLastFocusedIndex(int i) { 50 lastFocusedIndexWasReset = (i == -1); 51 } 52 53 @Implementation 54 public static Drawable boundCenterBottom(Drawable drawable) { 55 return drawable; 56 } 57 58 /** 59 * Non-Android accessor that indicates whether {@link #setLastFocusedIndex(int)} has been called with a value other 60 * than -1. 61 * 62 * @return whether {@link #setLastFocusedIndex(int)} has been called with a value other 63 * than -1 64 */ 65 public boolean lastFocusedIndexWasReset() { 66 return lastFocusedIndexWasReset; 67 } 68 69 public void setIsPopulated(boolean isPopulated) { 70 this.isPopulated = isPopulated; 71 } 72 73 public boolean isPopulated() { 74 return isPopulated; 75 } 76 77 /** 78 * Sets up the return value for 79 * {@link #hitTest(com.google.android.maps.OverlayItem, android.graphics.drawable.Drawable, int, int)} 80 * 81 * @param shouldHit the value that 82 * {@link #hitTest(com.google.android.maps.OverlayItem, android.graphics.drawable.Drawable, int, int)} 83 * should return 84 */ 85 public void setShouldHit(boolean shouldHit) { 86 this.shouldHit = shouldHit; 87 } 88 89 private ShadowItemizedOverlayBridge<Item> getBridge() { 90 return new ShadowItemizedOverlayBridge<Item>(realObject); 91 } 92} 93