OverlayManager implements TouchInput.PanResponder, TouchInput.RotateResponder { public void setMyLocationEnabled(boolean enabled) { setMyLocationEnabled(enabled, true); } OverlayManager(MapView mapView, MapController mapController, MapDataManager mapDataManager,
      MapStateManager mapStateManager);   OverlayManager(MapView mapView, MapController mapController, MapDataManager mapDataManager,
      MapStateManager mapStateManager, LostApiClient lostApiClient); void setMyLocationEnabled(boolean enabled); void setMyLocationEnabled(boolean enabled, boolean persistMapData); boolean isMyLocationEnabled(); void setCompassOnClickListener(View.OnClickListener listener); void setFindMeOnClickListener(View.OnClickListener listener); void setZoomInOnClickListener(View.OnClickListener listener); void setZoomOutOnClickListener(View.OnClickListener listener); void setZoomButtonsEnabled(boolean enabled); boolean isZoomButtonsEnabled(); void setCompassButtonEnabled(boolean enabled); boolean isCompassEnabled(); MapData addPolyline(Polyline polyline); MapData addPolyline(Polyline polyline, boolean persistMapData); void removePolyline(); MapData addPolygon(Polygon polygon); MapData addPolygon(Polygon polygon, boolean persistMapData); void removePolygon(); MapData addMarker(Marker marker); MapData addMarker(Marker marker, boolean persistMapData); void removeMarker(); void drawRoutePins(LngLat start, LngLat end); void drawRoutePins(LngLat start, LngLat end, boolean persistMapData); void clearRoutePins(); void drawDroppedPin(LngLat point); void drawDroppedPin(LngLat point, boolean persistMapData); void clearDroppedPin(); void drawSearchResult(LngLat point, boolean active); void drawSearchResult(LngLat point, boolean active, int index); void drawSearchResult(LngLat point, boolean active, int index, boolean persistMapData); void clearSearchResult(); void drawRouteLocationMarker(LngLat point); void drawRouteLocationMarker(LngLat point, boolean persistMapData); void clearRouteLocationMarker(); void drawRouteLine(List<LngLat> points); void drawRouteLine(List<LngLat> points, boolean persistMapData); void clearRouteLine(); void drawTransitRouteLine(@NonNull List<LngLat> points, @Nullable List<LngLat> stations,
      @NonNull String colorHex); void drawTransitRouteLine(@NonNull List<LngLat> points, @Nullable List<LngLat> stations,
      @NonNull String colorHex, boolean persistMapData); void clearTransitRouteLine(); void setPersistMapData(boolean persistOnRecreation); void restoreMapData(); @Override boolean onPan(float startX, float startY, float endX, float endY); @Override boolean onFling(float posX, float posY, float velocityX, float velocityY); @Override boolean onRotate(float x, float y, float rotation); static final int ZOOM_BUTTON_ANIMATION_DURATION_MILLIS; static final float ZOOM_BUTTON_CHANGE; }
@Test public void setMyLocationEnabled_shouldCenterMapIfFindMeIsActive() throws Exception { doCallRealMethod().when(mapController).setPositionEased(any(LngLat.class), anyInt()); when(mapController.getPosition()).thenCallRealMethod(); overlayManager.setMyLocationEnabled(true); findMeButton.performClick(); Location location = mock(Location.class); when(location.getLatitude()).thenReturn(-70.0); when(location.getLongitude()).thenReturn(-40.0); overlayManager.locationListener.onLocationChanged(location); assertThat(mapController.getPosition().latitude).isEqualTo(-70.0); assertThat(mapController.getPosition().longitude).isEqualTo(-40.0); }
@Test public void setMyLocationEnabled_shouldNotCenterMapIfFindMeIsInactive() throws Exception { doCallRealMethod().when(mapController).setPositionEased(any(LngLat.class), anyInt()); when(mapController.getPosition()).thenCallRealMethod(); overlayManager.setMyLocationEnabled(true); Location location = mock(Location.class); when(location.getLatitude()).thenReturn(-70.0); when(location.getLongitude()).thenReturn(-40.0); overlayManager.locationListener.onLocationChanged(location); assertThat(mapController.getPosition().latitude).isEqualTo(0.0); assertThat(mapController.getPosition().longitude).isEqualTo(0.0); }
@Test public void setMyLocationEnabled_shouldNotChangeZoomLevel() throws Exception { doCallRealMethod().when(mapController).setPositionEased(any(LngLat.class), anyInt()); doCallRealMethod().when(mapController).setZoom(anyFloat()); when(mapController.getZoom()).thenCallRealMethod(); mapController.setZoom(17); overlayManager.setMyLocationEnabled(true); Location location = new Location("test"); Whitebox.invokeMethod(overlayManager.locationListener, "onLocationChanged", location); assertThat(mapController.getZoom()).isEqualTo(17); }
@Test public void setMyLocationEnabled_shouldNotChangeTilt() throws Exception { doCallRealMethod().when(mapController).setPositionEased(any(LngLat.class), anyInt()); doCallRealMethod().when(mapController).setTilt(anyFloat()); when(mapController.getTilt()).thenCallRealMethod(); mapController.setTilt(8); overlayManager.setMyLocationEnabled(true); Location location = new Location("test"); Whitebox.invokeMethod(overlayManager.locationListener, "onLocationChanged", location); assertThat(mapController.getTilt()).isEqualTo(8); }
@Test public void setMyLocationEnabled_shouldNotChangeRotation() throws Exception { doCallRealMethod().when(mapController).setPositionEased(any(LngLat.class), anyInt()); doCallRealMethod().when(mapController).setRotation(anyFloat()); when(mapController.getRotation()).thenCallRealMethod(); mapController.setRotation(8); overlayManager.setMyLocationEnabled(true); Location location = new Location("test"); Whitebox.invokeMethod(overlayManager.locationListener, "onLocationChanged", location); assertThat(mapController.getRotation()).isEqualTo(8); }
@Test public void setMyLocationEnabled_shouldUpdateMapStateManager() { overlayManager.setMyLocationEnabled(true); findMeButton.performClick(); verify(mapStateManager).setZoom(16f); Location loc = LocationServices.FusedLocationApi.getLastLocation(lostApiClient); LngLat lngLat = new LngLat(loc.getLongitude(), loc.getLatitude()); verify(mapStateManager).setPosition(lngLat); }
@Test public void setMyLocationEnabled_shouldAddMapDataIfEnabled() throws Exception { overlayManager.setMyLocationEnabled(true); assertThat(mapDataManager.getMapData()).isNotEmpty(); }
@Test public void setMyLocationEnabled_shouldRemoveMapDataIfDisabled() throws Exception { overlayManager.setMyLocationEnabled(true); overlayManager.setMyLocationEnabled(false); assertThat(mapDataManager.getMapData()).isEmpty(); }
@Test public void setMyLocationEnabled_shouldNotAddMoreThanOneMapData() throws Exception { overlayManager.setMyLocationEnabled(true); overlayManager.setMyLocationEnabled(true); assertThat(mapDataManager.getMapData()).hasSize(1); }
@Test public void onClickFindMe_shouldUpdateCurrentLocationMarker() throws Exception { overlayManager.setMyLocationEnabled(true); mapData.clear(); findMeButton.performClick(); assertThat(mapData.point).isNotNull(); }
@Test public void onClickFindMe_shouldUpdateMapPosition() throws Exception { overlayManager.setMyLocationEnabled(true); findMeButton.performClick(); verify(mapController, times(1)).setPositionEased(any(LngLat.class), anyInt()); verify(mapController, times(1)).requestRender(); }
@Test public void onClickFindMe_shouldZoomMap() throws Exception { overlayManager.setMyLocationEnabled(true); findMeButton.performClick(); verify(mapController, times(1)).setZoomEased(anyFloat(), anyInt()); verify(mapController, times(1)).requestRender(); }
@Test public void onClickFindMe_shouldToggleViewStateActivated() throws Exception { overlayManager.setMyLocationEnabled(true); findMeButton.performClick(); assertThat(findMeButton.isActivated()).isTrue(); findMeButton.performClick(); assertThat(findMeButton.isActivated()).isFalse(); }