1 package com.xtremelabs.robolectric.shadows; 2 3 import com.google.android.maps.GeoPoint; 4 import com.google.android.maps.MapController; 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 8 /** 9 * A Shadow of {@code MapController} that tracks its own state and keeps the state of the {@code MapView} it controlls 10 * up to date. 11 */ 12 @SuppressWarnings({"UnusedDeclaration"}) 13 @Implements(MapController.class) 14 public class ShadowMapController { 15 private ShadowMapView shadowMapView; 16 private GeoPoint geoPointAnimatedTo; 17 18 @Implementation animateTo(com.google.android.maps.GeoPoint geoPoint)19 public void animateTo(com.google.android.maps.GeoPoint geoPoint) { 20 setCenter(geoPoint); 21 geoPointAnimatedTo = geoPoint; 22 } 23 24 @Implementation animateTo(com.google.android.maps.GeoPoint geoPoint, java.lang.Runnable runnable)25 public void animateTo(com.google.android.maps.GeoPoint geoPoint, java.lang.Runnable runnable) { 26 animateTo(geoPoint); 27 runnable.run(); 28 } 29 30 @Implementation setCenter(com.google.android.maps.GeoPoint geoPoint)31 public void setCenter(com.google.android.maps.GeoPoint geoPoint) { 32 shadowMapView.mapCenter = geoPoint; 33 } 34 35 @Implementation zoomToSpan(int latSpan, int lngSpan)36 public void zoomToSpan(int latSpan, int lngSpan) { 37 shadowMapView.latitudeSpan = latSpan; 38 shadowMapView.longitudeSpan = lngSpan; 39 } 40 41 @Implementation zoomIn()42 public boolean zoomIn() { 43 shadowMapView.zoomLevel++; 44 return true; 45 } 46 47 @Implementation zoomOut()48 public boolean zoomOut() { 49 shadowMapView.zoomLevel--; 50 return true; 51 } 52 53 @Implementation setZoom(int i)54 public int setZoom(int i) { 55 shadowMapView.zoomLevel = i; 56 return i; 57 } 58 59 /** 60 * Non-Android accessor that returns the {@code MapView} that is being controlled 61 * 62 * @return the {@code MapView} that is being controlled 63 */ getShadowMapView()64 public ShadowMapView getShadowMapView() { 65 return shadowMapView; 66 } 67 68 /** 69 * Non-Android accessor that returns the most recent value set by a call to either version of {@code animateTo()} 70 * 71 * @return the most recent value set by a call to either version of {@code animateTo()} 72 */ getGeoPointAnimatedTo()73 public GeoPoint getGeoPointAnimatedTo() { 74 return geoPointAnimatedTo; 75 } 76 77 /** 78 * Non-Android accessor that allows the {@code MapView} being controlled to be set explicitly. 79 * 80 * @param shadowMapView the {@link ShadowMapView} to be controlled (either created explicitly or obtained via a call 81 * to {@link com.xtremelabs.robolectric.RobolectricForMaps.shadowOf(com.google.android.maps.MapView)}) 82 */ setShadowMapView(ShadowMapView shadowMapView)83 void setShadowMapView(ShadowMapView shadowMapView) { 84 this.shadowMapView = shadowMapView; 85 } 86 } 87