From 4ee9736c0e716e58823cd1a07d890b4f5e6b4fac Mon Sep 17 00:00:00 2001 From: Sarah Lensing Date: Thu, 14 Sep 2017 10:29:05 -0600 Subject: [PATCH] Async setStyle (#450) * Add OnStyleLoadedListener * Add setStyleAsync * Add themed map style async methods --- .../mapzen/android/graphics/MapzenMap.java | 133 ++++++++++-- .../graphics/OnStyleLoadedListener.java | 12 ++ .../android/graphics/MapzenMapTest.java | 203 +++++++++++++++++- 3 files changed, 322 insertions(+), 26 deletions(-) create mode 100644 core/src/main/java/com/mapzen/android/graphics/OnStyleLoadedListener.java diff --git a/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java b/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java index defd0aed..9c65cc6c 100644 --- a/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java +++ b/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java @@ -149,6 +149,13 @@ public boolean onRotate(float x, float y, float rotation) { = new MapController.SceneLoadListener() { @Override public void onSceneReady(int sceneId, SceneError sceneError) { bitmapMarkerManager.restoreMarkers(); + if (sceneId == currSceneId) { + if (styleLoadedListener != null) { + styleLoadedListener.onStyleLoaded(); + styleLoadedListener = null; + } + currSceneId = Integer.MIN_VALUE; + } } }; @@ -161,6 +168,9 @@ public boolean onRotate(float x, float y, float rotation) { } }); + OnStyleLoadedListener styleLoadedListener = null; + int currSceneId = Integer.MIN_VALUE; + /** * Creates a new map based on the given {@link MapView} and {@link MapController}. */ @@ -201,19 +211,32 @@ public OverlayManager getOverlayManager() { return overlayManager; } + /** + * Sets the map's underlying stylesheet asynchronously. + */ + public void setStyleAsync(MapStyle mapStyle, OnStyleLoadedListener listener) { + styleLoadedListener = listener; + currSceneId = internalSetStyle(mapStyle, true); + } + /** * Sets the map's underlying stylesheet. */ public void setStyle(MapStyle mapStyle) { - mapStateManager.setMapStyle(mapStyle); - if (currentMapStyleIsThemed()) { - mapStateManager.setLabelLevel(getThemedMapStyle().getDefaultLabelLevel()); - mapStateManager.setLod(getThemedMapStyle().getDefaultLod()); - mapStateManager.setThemeColor(getThemedMapStyle().getDefaultColor()); - loadSceneYaml(); - } else { - loadSceneFile(); - } + internalSetStyle(mapStyle, false); + } + + /** + * Sets the map style with given label level and default detail and theme color values. If the + * label level is not supported by this theme then this method throws an + * {@link IllegalArgumentException}. + * @param themedMapStyle + * @param labelLevel + */ + public void setStyleAndLabelLevelAsync(ThemedMapStyle themedMapStyle, int labelLevel, + OnStyleLoadedListener listener) { + setStyleLabelLevelLodThemeColorAsync(themedMapStyle, labelLevel, + themedMapStyle.getDefaultLod(), themedMapStyle.getDefaultColor(), listener); } /** @@ -228,6 +251,19 @@ public void setStyleAndLabelLevel(ThemedMapStyle themedMapStyle, int labelLevel) themedMapStyle.getDefaultLod(), themedMapStyle.getDefaultColor()); } + /** + * Sets the map style with given detail level and default label and theme color values. If the + * detail level is not supported by this theme then this method throws an + * {@link IllegalArgumentException}. + * @param themedMapStyle + * @param detailLevel + */ + public void setStyleAndLodAsync(ThemedMapStyle themedMapStyle, int detailLevel, + OnStyleLoadedListener listener) { + setStyleLabelLevelLodThemeColorAsync(themedMapStyle, themedMapStyle.getDefaultLabelLevel(), + detailLevel, themedMapStyle.getDefaultColor(), listener); + } + /** * Sets the map style with given detail level and default label and theme color values. If the * detail level is not supported by this theme then this method throws an @@ -240,6 +276,17 @@ public void setStyleAndLod(ThemedMapStyle themedMapStyle, int detailLevel) { detailLevel, themedMapStyle.getDefaultColor()); } + /** + * Sets the map style with given theme color and default label and detail levels. + * @param themedMapStyle + * @param color + */ + public void setStyleAndThemeColorAsync(ThemedMapStyle themedMapStyle, ThemeColor color, + OnStyleLoadedListener listener) { + setStyleLabelLevelLodThemeColorAsync(themedMapStyle, themedMapStyle.getDefaultLabelLevel(), + themedMapStyle.getDefaultLod(), color, listener); + } + /** * Sets the map style with given theme color and default label and detail levels. * @param themedMapStyle @@ -250,6 +297,21 @@ public void setStyleAndThemeColor(ThemedMapStyle themedMapStyle, ThemeColor colo themedMapStyle.getDefaultLod(), color); } + /** + * Sets the map style with given label level, detail level, and theme color. If either the label + * or detail level are not supported, this method will throw an {@link IllegalArgumentException}. + * @param themedMapStyle + * @param labelLevel + * @param detailLevel + * @param color + */ + public void setStyleLabelLevelLodThemeColorAsync(ThemedMapStyle themedMapStyle, int labelLevel, + int detailLevel, ThemeColor color, OnStyleLoadedListener listener) { + styleLoadedListener = listener; + mapStateManager.setMapStyle(themedMapStyle); + currSceneId = setLabelLevelLodThemeColor(labelLevel, detailLevel, color, true); + } + /** * Sets the map style with given label level, detail level, and theme color. If either the label * or detail level are not supported, this method will throw an {@link IllegalArgumentException}. @@ -261,7 +323,7 @@ public void setStyleAndThemeColor(ThemedMapStyle themedMapStyle, ThemeColor colo public void setStyleLabelLevelLodThemeColor(ThemedMapStyle themedMapStyle, int labelLevel, int detailLevel, ThemeColor color) { mapStateManager.setMapStyle(themedMapStyle); - setLabelLevelLodThemeColor(labelLevel, detailLevel, color); + setLabelLevelLodThemeColor(labelLevel, detailLevel, color, false); } /** @@ -1064,26 +1126,55 @@ private List getGlobalSceneUpdates() { mapStateManager.isPathOverlayEnabled()); } + /** + * Sets the {@link MapStyle} and relevant theme configuration for {@link ThemedMapStyle}s. Loads + * the scene file either synchronously or asynchronously and returns the sceneId. + * @param mapStyle + * @param async + * @return + */ + private int internalSetStyle(MapStyle mapStyle, boolean async) { + mapStateManager.setMapStyle(mapStyle); + if (currentMapStyleIsThemed()) { + mapStateManager.setLabelLevel(getThemedMapStyle().getDefaultLabelLevel()); + mapStateManager.setLod(getThemedMapStyle().getDefaultLod()); + mapStateManager.setThemeColor(getThemedMapStyle().getDefaultColor()); + return loadSceneYaml(async); + } else { + return loadSceneFile(async); + } + } + /** * Internal convenience method for loading scene file when the current style is a * {@link MapStyle}. - * Applies all global scene updates. + * Applies all global scene updates. Loads asynchronously or + * synchronously. Returns the sceneId for the {@link MapController} scene update. */ - private void loadSceneFile() { - mapController.loadSceneFile(mapStateManager.getMapStyle().getSceneFile(), - getGlobalSceneUpdates()); + private int loadSceneFile(boolean async) { + if (async) { + return mapController.loadSceneFileAsync(mapStateManager.getMapStyle().getSceneFile(), + getGlobalSceneUpdates()); + } else { + return mapController.loadSceneFile(mapStateManager.getMapStyle().getSceneFile(), + getGlobalSceneUpdates()); + } } /** * Internal convenience method for loading scene yaml when the current style is a - * {@link ThemedMapStyle}. Applies all global scene updates. - * applied. + * {@link ThemedMapStyle}. Applies all global scene updates. Loads asynchronously or + * synchronously. Returns the sceneId for the {@link MapController} scene update. */ - private void loadSceneYaml() { + private int loadSceneYaml(boolean async) { String yaml = yamlGenerator.getImportYaml(getThemedMapStyle(), mapStateManager.getLabelLevel(), mapStateManager.getLod(), mapStateManager.getThemeColor()); String resourceRoot = getThemedMapStyle().getStyleRootPath(); - mapController.loadSceneYaml(yaml, resourceRoot, getGlobalSceneUpdates()); + if (async) { + return mapController.loadSceneYamlAsync(yaml, resourceRoot, getGlobalSceneUpdates()); + } else { + return mapController.loadSceneYaml(yaml, resourceRoot, getGlobalSceneUpdates()); + } } /** @@ -1147,8 +1238,8 @@ private boolean isValidColor(ThemeColor color) { * @param detailLevel * @param color */ - private void setLabelLevelLodThemeColor(int labelLevel, int detailLevel, - ThemeColor color) { + private int setLabelLevelLodThemeColor(int labelLevel, int detailLevel, + ThemeColor color, boolean async) { if (!isValidLabelLevel(labelLevel)) { throw new IllegalArgumentException("Invalid label level for " + getThemedMapStyle().getClass().getSimpleName()); @@ -1164,6 +1255,6 @@ private void setLabelLevelLodThemeColor(int labelLevel, int detailLevel, mapStateManager.setLabelLevel(labelLevel); mapStateManager.setLod(detailLevel); mapStateManager.setThemeColor(color); - loadSceneYaml(); + return loadSceneYaml(async); } } diff --git a/core/src/main/java/com/mapzen/android/graphics/OnStyleLoadedListener.java b/core/src/main/java/com/mapzen/android/graphics/OnStyleLoadedListener.java new file mode 100644 index 00000000..de61047e --- /dev/null +++ b/core/src/main/java/com/mapzen/android/graphics/OnStyleLoadedListener.java @@ -0,0 +1,12 @@ +package com.mapzen.android.graphics; + +/** + * Callback used when loading a new {@link com.mapzen.android.graphics.model.MapStyle} + * asynchronously. + */ +public interface OnStyleLoadedListener { + /** + * Called when the style has finished loaded. + */ + void onStyleLoaded(); +} diff --git a/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java b/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java index 49fab009..76c5c4cf 100644 --- a/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java @@ -40,9 +40,11 @@ import static com.mapzen.android.graphics.SceneUpdateManager.STYLE_GLOBAL_VAR_LANGUAGE; import static com.mapzen.android.graphics.SceneUpdateManager.STYLE_GLOBAL_VAR_PATH_OVERLAY; import static com.mapzen.android.graphics.SceneUpdateManager.STYLE_GLOBAL_VAR_TRANSIT_OVERLAY; +import static com.mapzen.android.graphics.model.ThemeColor.BLUE; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyFloat; +import static org.mockito.Matchers.anyList; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; @@ -658,8 +660,31 @@ public void applySceneUpdates_shouldClearQueuedUpdates() throws Exception { @Test public void setStyle_shouldSetStyleAndGlobalVariables() throws Exception { map.setStyle(new WalkaboutStyle()); - verify(mapController).loadSceneFile( - anyString(), any(List.class)); + verify(mapController).loadSceneFile(anyString(), any(List.class)); + } + + @Test public void setStyle_shouldNotCallMapControllerAsyncMethod() throws Exception { + map.setStyle(new WalkaboutStyle()); + verify(mapController, never()).loadSceneFileAsync(anyString(), any(List.class)); + } + + @Test public void setStyleAsync_shouldSetStyleAndGlobalVariables() throws Exception { + map.setStyleAsync(new WalkaboutStyle(), null); + verify(mapController).loadSceneFileAsync(anyString(), any(List.class)); + } + + @Test public void setStyleAsync_shouldCallListenerOnSceneLoaded() throws Exception { + int sceneId = 1; + when(mapController.loadSceneFileAsync(anyString(), anyList())).thenReturn(sceneId); + TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); + map.setStyleAsync(new WalkaboutStyle(), listener); + map.internalSceneLoadListener.onSceneReady(sceneId, null); + assertThat(listener.loaded).isTrue(); + } + + @Test public void setStyleAsync_shouldNotCallMapControllerSyncMethod() throws Exception { + map.setStyleAsync(new WalkaboutStyle(), null); + verify(mapController, never()).loadSceneFile(anyString(), any(List.class)); } @Test public void overlays_shouldBeDisabledByDefaultExceptPath() throws Exception { @@ -781,16 +806,61 @@ public void applySceneUpdates_shouldClearQueuedUpdates() throws Exception { new SceneUpdatesMatcher(sceneUpdates))); } + @Test public void setStyleAndLabelLevelAsync_shouldCallLoadYamlWithCorrectValues() + throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndLabelLevelAsync(refillStyle, 8, null); + + assertThat(mapStateManager.getThemeColor()).isEqualTo(refillStyle.getDefaultColor()); + assertThat(mapStateManager.getLabelLevel()).isEqualTo(8); + assertThat(mapStateManager.getLod()).isEqualTo(refillStyle.getDefaultLod()); + + String yaml = yamlGenerator.getImportYaml(refillStyle, 8, + mapStateManager.getLod(), mapStateManager.getThemeColor()); + String resourceRoot = refillStyle.getStyleRootPath(); + List sceneUpdates = new ArrayList<>(); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "apiKey")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, "en_us")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); + verify(mapController).loadSceneYamlAsync(eq(yaml), eq(resourceRoot), argThat( + new SceneUpdatesMatcher(sceneUpdates))); + } + + @Test public void setStyleAndLabelLevelAsync_shouldCallListenerOnSceneLoaded() throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + int sceneId = 8; + when(mapController.loadSceneYamlAsync(anyString(), anyString(), anyList())).thenReturn(sceneId); + TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndLabelLevelAsync(refillStyle, 8, listener); + map.internalSceneLoadListener.onSceneReady(sceneId, null); + assertThat(listener.loaded).isTrue(); + } + @Test(expected = IllegalArgumentException.class) public void setStyleAndLabelLevel_shouldVerifyLowValue() throws Exception { map.setStyleAndLabelLevel(new RefillStyle(), -1); } + @Test(expected = IllegalArgumentException.class) + public void setStyleAndLabelLevelAsync_shouldVerifyLowValue() throws Exception { + map.setStyleAndLabelLevelAsync(new RefillStyle(), -1, null); + } + @Test(expected = IllegalArgumentException.class) public void setStyleAndLabelLevel_shouldVerifyHighValue() throws Exception { map.setStyleAndLabelLevel(new RefillStyle(), 12); } + @Test(expected = IllegalArgumentException.class) + public void setStyleAndLabelLevelAsync_shouldVerifyHighValue() throws Exception { + map.setStyleAndLabelLevelAsync(new RefillStyle(), 12, null); + } + @Test public void setStyleAndLod_shouldCallLoadYamlWithCorrectValues() throws Exception { when(mapzenManager.getApiKey()).thenReturn("apiKey"); @@ -814,16 +884,60 @@ public void setStyleAndLabelLevel_shouldVerifyHighValue() throws Exception { new SceneUpdatesMatcher(sceneUpdates))); } + @Test public void setStyleAndLodAsync_shouldCallLoadYamlWithCorrectValues() throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndLodAsync(refillStyle, 8, null); + + assertThat(mapStateManager.getThemeColor()).isEqualTo(refillStyle.getDefaultColor()); + assertThat(mapStateManager.getLabelLevel()).isEqualTo(refillStyle.getDefaultLabelLevel()); + assertThat(mapStateManager.getLod()).isEqualTo(8); + + String yaml = yamlGenerator.getImportYaml(refillStyle, mapStateManager.getLabelLevel(), + 8, mapStateManager.getThemeColor()); + String resourceRoot = refillStyle.getStyleRootPath(); + List sceneUpdates = new ArrayList<>(); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "apiKey")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, "en_us")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); + verify(mapController).loadSceneYamlAsync(eq(yaml), eq(resourceRoot), argThat( + new SceneUpdatesMatcher(sceneUpdates))); + } + + @Test public void setStyleAndLodAsync_shouldCallListenerOnSceneLoaded() throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + int sceneId = 8; + when(mapController.loadSceneYamlAsync(anyString(), anyString(), anyList())).thenReturn(sceneId); + TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndLodAsync(refillStyle, 8, listener); + map.internalSceneLoadListener.onSceneReady(sceneId, null); + assertThat(listener.loaded).isTrue(); + } + @Test(expected = IllegalArgumentException.class) public void setStyleAndLod_shouldVerifyLowValue() throws Exception { map.setStyleAndLod(new RefillStyle(), -1); } + @Test(expected = IllegalArgumentException.class) + public void setStyleAndLodAsync_shouldVerifyLowValue() throws Exception { + map.setStyleAndLodAsync(new RefillStyle(), -1, null); + } + @Test(expected = IllegalArgumentException.class) public void setStyleAndLod_shouldVerifyHighValue() throws Exception { map.setStyleAndLod(new RefillStyle(), 12); } + @Test(expected = IllegalArgumentException.class) + public void setStyleAndLodAsync_shouldVerifyHighValue() throws Exception { + map.setStyleAndLodAsync(new RefillStyle(), 12, null); + } + @Test public void setStyleAndThemeColor_shouldCallLoadYamlWithCorrectValues() throws Exception { when(mapzenManager.getApiKey()).thenReturn("apiKey"); @@ -847,18 +961,53 @@ public void setStyleAndLod_shouldVerifyHighValue() throws Exception { new SceneUpdatesMatcher(sceneUpdates))); } + @Test public void setStyleAndThemeColorAsync_shouldCallLoadYamlWithCorrectValues() + throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndThemeColorAsync(refillStyle, ThemeColor.PINK, null); + + assertThat(mapStateManager.getThemeColor()).isEqualTo(ThemeColor.PINK); + assertThat(mapStateManager.getLabelLevel()).isEqualTo(refillStyle.getDefaultLabelLevel()); + assertThat(mapStateManager.getLod()).isEqualTo(refillStyle.getDefaultLod()); + + String yaml = yamlGenerator.getImportYaml(refillStyle, mapStateManager.getLabelLevel(), + mapStateManager.getLod(), ThemeColor.PINK); + String resourceRoot = refillStyle.getStyleRootPath(); + List sceneUpdates = new ArrayList<>(); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "apiKey")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, "en_us")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); + verify(mapController).loadSceneYamlAsync(eq(yaml), eq(resourceRoot), argThat( + new SceneUpdatesMatcher(sceneUpdates))); + } + + @Test public void setStyleAndThemeColorAsync_shouldCallListenerOnSceneLoaded() throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + int sceneId = 8; + when(mapController.loadSceneYamlAsync(anyString(), anyString(), anyList())).thenReturn(sceneId); + TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); + RefillStyle refillStyle = new RefillStyle(); + map.setStyleAndThemeColorAsync(refillStyle, BLUE, listener); + map.internalSceneLoadListener.onSceneReady(sceneId, null); + assertThat(listener.loaded).isTrue(); + } + @Test public void setStyleLabelDetailLevelThemeColor_shouldCallLoadYamlWithCorrectValues() throws Exception { when(mapzenManager.getApiKey()).thenReturn("apiKey"); RefillStyle refillStyle = new RefillStyle(); - map.setStyleLabelLevelLodThemeColor(refillStyle, 3, 4, ThemeColor.BLUE); + map.setStyleLabelLevelLodThemeColor(refillStyle, 3, 4, BLUE); - assertThat(mapStateManager.getThemeColor()).isEqualTo(ThemeColor.BLUE); + assertThat(mapStateManager.getThemeColor()).isEqualTo(BLUE); assertThat(mapStateManager.getLabelLevel()).isEqualTo(3); assertThat(mapStateManager.getLod()).isEqualTo(4); - String yaml = yamlGenerator.getImportYaml(refillStyle, 3, 4, ThemeColor.BLUE); + String yaml = yamlGenerator.getImportYaml(refillStyle, 3, 4, BLUE); String resourceRoot = refillStyle.getStyleRootPath(); List sceneUpdates = new ArrayList<>(); sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "apiKey")); @@ -870,6 +1019,41 @@ public void setStyleAndLod_shouldVerifyHighValue() throws Exception { new SceneUpdatesMatcher(sceneUpdates))); } + @Test public void setStyleLabelDetailLevelThemeColorAsync_shouldCallLoadYamlWithCorrectValues() + throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + + RefillStyle refillStyle = new RefillStyle(); + map.setStyleLabelLevelLodThemeColorAsync(refillStyle, 3, 4, BLUE, null); + + assertThat(mapStateManager.getThemeColor()).isEqualTo(BLUE); + assertThat(mapStateManager.getLabelLevel()).isEqualTo(3); + assertThat(mapStateManager.getLod()).isEqualTo(4); + + String yaml = yamlGenerator.getImportYaml(refillStyle, 3, 4, BLUE); + String resourceRoot = refillStyle.getStyleRootPath(); + List sceneUpdates = new ArrayList<>(); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "apiKey")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, "en_us")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); + sceneUpdates.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); + verify(mapController).loadSceneYamlAsync(eq(yaml), eq(resourceRoot), argThat( + new SceneUpdatesMatcher(sceneUpdates))); + } + + @Test public void setStyleLabelDetailLevelThemeColorAsync_shouldCallListenerOnSceneLoaded() + throws Exception { + when(mapzenManager.getApiKey()).thenReturn("apiKey"); + int sceneId = 8; + when(mapController.loadSceneYamlAsync(anyString(), anyString(), anyList())).thenReturn(sceneId); + TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); + RefillStyle refillStyle = new RefillStyle(); + map.setStyleLabelLevelLodThemeColorAsync(refillStyle, 1, 2, BLUE, listener); + map.internalSceneLoadListener.onSceneReady(sceneId, null); + assertThat(listener.loaded).isTrue(); + } + public class TestRotateResponder implements TouchInput.RotateResponder { boolean rotated = false; @@ -918,4 +1102,13 @@ private class TestViewCompleteListener implements ViewCompleteListener { viewComplete = true; } } + + private class TestOnStyleLoadedListener implements OnStyleLoadedListener { + + boolean loaded = false; + + @Override public void onStyleLoaded() { + loaded = true; + } + } }