From aeddc24d87331acf4a093aa610119edc08988cdb Mon Sep 17 00:00:00 2001 From: Sarah Lensing Date: Tue, 3 Oct 2017 11:25:38 -0600 Subject: [PATCH] Update Stylesheets (#465) * migrate all styles to use themed repos * fix tests and temporarily comment out two * tmp deploy sdk for this branch * update style switcher example * deploy samples temporarily * disable location in sample on destroy * tangram 0.8.1 * refill default lod 10 * autoselect theme defaults when style switched * yaml generator cleanup * update zinc lod default * update test * https for submodules * fix MapInitializerTests * add test coverage for themes * rm tmp circle branch deployment * deprecate zinc style * rm log --- .gitmodules | 15 +- core/build.gradle | 4 +- core/src/main/assets/styles/bubble-wrap | 2 +- .../main/assets/styles/cinnabar-more-labels | 1 - core/src/main/assets/styles/cinnabar-style | 1 + core/src/main/assets/styles/refill-style | 2 +- core/src/main/assets/styles/walkabout-style | 1 + .../assets/styles/walkabout-style-more-labels | 1 - .../main/assets/styles/zinc-style-more-labels | 1 - .../android/graphics/ImportYamlGenerator.java | 63 +++++--- .../android/graphics/MapInitializer.java | 6 + .../android/graphics/MapStateManager.java | 6 +- .../mapzen/android/graphics/MapzenMap.java | 10 ++ .../graphics/model/BubbleWrapStyle.java | 42 ++++- .../android/graphics/model/CinnabarStyle.java | 49 +++++- .../android/graphics/model/RefillStyle.java | 4 +- .../android/graphics/model/ThemeColor.java | 5 +- .../graphics/model/ThemedMapStyle.java | 2 + .../graphics/model/WalkaboutStyle.java | 42 ++++- .../android/graphics/model/ZincStyle.java | 54 ++++++- .../graphics/ImportYamlGeneratorTest.java | 26 +++ .../android/graphics/MapInitializerTest.java | 57 +++++-- .../android/graphics/MapStateManagerTest.java | 9 +- .../android/graphics/MapzenMapTest.java | 27 +++- .../android/graphics/TestTangramMapView.java | 7 + .../graphics/model/BubbleWrapStyleTest.java | 51 ++++++ .../graphics/model/CinnabarStyleTest.java | 60 +++++++ .../graphics/model/RefillStyleTest.java | 4 +- .../graphics/model/WalkaboutStyleTest.java | 51 ++++++ .../android/graphics/model/ZincStyleTest.java | 59 +++++++ .../src/main/AndroidManifest.xml | 4 +- .../sdk/sample/SwitchStyleActivity.java | 152 ++++++++++++++---- .../main/res/layout/activity_switch_style.xml | 110 +++++++++++++ .../res/layout/gray_spinner_dropdown_item.xml | 9 ++ .../src/main/res/layout/gray_spinner_item.xml | 10 ++ .../src/main/res/values/dimens.xml | 2 + .../src/main/res/values/strings.xml | 1 - 37 files changed, 844 insertions(+), 106 deletions(-) delete mode 160000 core/src/main/assets/styles/cinnabar-more-labels create mode 160000 core/src/main/assets/styles/cinnabar-style create mode 160000 core/src/main/assets/styles/walkabout-style delete mode 160000 core/src/main/assets/styles/walkabout-style-more-labels delete mode 160000 core/src/main/assets/styles/zinc-style-more-labels create mode 100644 core/src/test/java/com/mapzen/android/graphics/model/BubbleWrapStyleTest.java create mode 100644 core/src/test/java/com/mapzen/android/graphics/model/CinnabarStyleTest.java create mode 100644 core/src/test/java/com/mapzen/android/graphics/model/WalkaboutStyleTest.java create mode 100644 core/src/test/java/com/mapzen/android/graphics/model/ZincStyleTest.java create mode 100644 samples/mapzen-android-sdk-sample/src/main/res/layout/activity_switch_style.xml create mode 100644 samples/mapzen-android-sdk-sample/src/main/res/layout/gray_spinner_dropdown_item.xml create mode 100644 samples/mapzen-android-sdk-sample/src/main/res/layout/gray_spinner_item.xml diff --git a/.gitmodules b/.gitmodules index 0c025f99..9e0c3b87 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,18 +1,15 @@ [submodule "core/src/main/assets/styles/bubble-wrap"] path = core/src/main/assets/styles/bubble-wrap url = https://github.com/tangrams/bubble-wrap.git -[submodule "core/src/main/assets/styles/cinnabar-more-labels"] - path = core/src/main/assets/styles/cinnabar-more-labels - url = https://github.com/tangrams/cinnabar-style-more-labels.git -[submodule "core/src/main/assets/styles/walkabout-style-more-labels"] - path = core/src/main/assets/styles/walkabout-style-more-labels - url = https://github.com/tangrams/walkabout-style-more-labels.git -[submodule "core/src/main/assets/styles/zinc-style-more-labels"] - path = core/src/main/assets/styles/zinc-style-more-labels - url = https://github.com/tangrams/zinc-style-more-labels.git [submodule "samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style"] path = samples/mapzen-android-sdk-sample/src/main/assets/styles/tron-style url = https://github.com/tangrams/tron-style.git [submodule "core/src/main/assets/styles/refill-style"] path = core/src/main/assets/styles/refill-style url = https://github.com/tangrams/refill-style +[submodule "core/src/main/assets/styles/cinnabar-style"] + path = core/src/main/assets/styles/cinnabar-style + url = https://github.com/tangrams/cinnabar-style.git +[submodule "core/src/main/assets/styles/walkabout-style"] + path = core/src/main/assets/styles/walkabout-style + url = https://github.com/tangrams/walkabout-style.git diff --git a/core/build.gradle b/core/build.gradle index 653f1c1c..f4bc5f5d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -19,7 +19,7 @@ group = GROUP version = VERSION_NAME project.archivesBaseName = POM_ARTIFACT_ID -ext.tangram_version = "0.8.0" +ext.tangram_version = "0.8.1" def SDK_VERSION = hasProperty('version') ? '"' + version + '"' : "null"; @@ -64,7 +64,7 @@ task checkstyle(type: Checkstyle) { apply from: rootProject.file('gradle/gradle-mvn-push.gradle') task submodules { - def folder = new File( 'core/src/main/assets/styles/walkabout-style-more-labels/walkabout-style-more-labels.yaml' ) + def folder = new File( 'core/src/main/assets/styles/walkabout-style/walkabout-style.yaml' ) if(!folder.exists()) { throw new GradleException("Submodules aren't present, please run:\n`git submodule init`, " + "\n`git submodule update`\nfrom your root directory") diff --git a/core/src/main/assets/styles/bubble-wrap b/core/src/main/assets/styles/bubble-wrap index a11850b9..3ed99f98 160000 --- a/core/src/main/assets/styles/bubble-wrap +++ b/core/src/main/assets/styles/bubble-wrap @@ -1 +1 @@ -Subproject commit a11850b95823385838cd439a76b0fb91017cec3e +Subproject commit 3ed99f98ee0dd4c6ae3f747e05e3e7cfdfeb33bc diff --git a/core/src/main/assets/styles/cinnabar-more-labels b/core/src/main/assets/styles/cinnabar-more-labels deleted file mode 160000 index 4b1ba0b8..00000000 --- a/core/src/main/assets/styles/cinnabar-more-labels +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4b1ba0b8011555581fd6a72c81ebba01149569f9 diff --git a/core/src/main/assets/styles/cinnabar-style b/core/src/main/assets/styles/cinnabar-style new file mode 160000 index 00000000..079418b2 --- /dev/null +++ b/core/src/main/assets/styles/cinnabar-style @@ -0,0 +1 @@ +Subproject commit 079418b29539a001470c5c1c9c7b5464ef060c7a diff --git a/core/src/main/assets/styles/refill-style b/core/src/main/assets/styles/refill-style index a85ba8c8..3801ad27 160000 --- a/core/src/main/assets/styles/refill-style +++ b/core/src/main/assets/styles/refill-style @@ -1 +1 @@ -Subproject commit a85ba8c8b9ed423197fbe0b7f27f017eed7712fd +Subproject commit 3801ad27e12158159ce71711efa52875a06fccbf diff --git a/core/src/main/assets/styles/walkabout-style b/core/src/main/assets/styles/walkabout-style new file mode 160000 index 00000000..291d90a8 --- /dev/null +++ b/core/src/main/assets/styles/walkabout-style @@ -0,0 +1 @@ +Subproject commit 291d90a85e55164f101cee039ecc70062c33b285 diff --git a/core/src/main/assets/styles/walkabout-style-more-labels b/core/src/main/assets/styles/walkabout-style-more-labels deleted file mode 160000 index 66bbe1d3..00000000 --- a/core/src/main/assets/styles/walkabout-style-more-labels +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 66bbe1d3bc6fc495c88e08f77e2f9cb473fc5419 diff --git a/core/src/main/assets/styles/zinc-style-more-labels b/core/src/main/assets/styles/zinc-style-more-labels deleted file mode 160000 index ab520391..00000000 --- a/core/src/main/assets/styles/zinc-style-more-labels +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab5203913e2ed0ad249d81a562945195a60855db diff --git a/core/src/main/java/com/mapzen/android/graphics/ImportYamlGenerator.java b/core/src/main/java/com/mapzen/android/graphics/ImportYamlGenerator.java index afe38009..aeaea26c 100644 --- a/core/src/main/java/com/mapzen/android/graphics/ImportYamlGenerator.java +++ b/core/src/main/java/com/mapzen/android/graphics/ImportYamlGenerator.java @@ -3,6 +3,8 @@ import com.mapzen.android.graphics.model.ThemeColor; import com.mapzen.android.graphics.model.ThemedMapStyle; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; + /** * Handles creating fully qualified import yaml for a given {@link ThemedMapStyle} so that * it can be applied by {@link MapzenMap}. @@ -17,26 +19,45 @@ class ImportYamlGenerator { */ String getImportYaml(ThemedMapStyle themedMapStyle, int labelLevel, int detailLevel, ThemeColor color) { - String labelFileName = new StringBuilder() - .append("label-") - .append(labelLevel) - .append(".yaml") - .toString(); - String detailFileName = new StringBuilder() - .append("detail-") - .append(detailLevel) - .append(".yaml") - .toString(); - String colorFileName = new StringBuilder() - .append("color-") - .append(color.toString()) - .append(".yaml") - .toString(); - return "{ import: [ " - + themedMapStyle.getBaseStyleFilename() + ", " - + themedMapStyle.getThemesPath() + labelFileName + ", " - + themedMapStyle.getThemesPath() + detailFileName + ", " - + themedMapStyle.getThemesPath() + colorFileName - + " ] }"; + StringBuilder importBuilder = new StringBuilder() + .append("{ import: [ ") + .append(themedMapStyle.getBaseStyleFilename()) + .append(", "); + + if (labelLevel != NONE) { + importBuilder.append(themedMapStyle.getThemesPath()); + importBuilder.append("label-"); + importBuilder.append(labelLevel); + importBuilder.append(".yaml"); + } + + if (labelLevel != NONE && (detailLevel != NONE || colorExists(color))) { + importBuilder.append(", "); + } + + if (detailLevel != NONE) { + importBuilder.append(themedMapStyle.getThemesPath()); + importBuilder.append("detail-"); + importBuilder.append(detailLevel); + importBuilder.append(".yaml"); + } + + if (detailLevel != NONE && colorExists(color)) { + importBuilder.append(", "); + } + + if (colorExists(color)) { + importBuilder.append(themedMapStyle.getThemesPath()); + importBuilder.append("color-"); + importBuilder.append(color.toString()); + importBuilder.append(".yaml"); + } + + importBuilder.append(" ] }"); + return importBuilder.toString(); + } + + private boolean colorExists(ThemeColor color) { + return color != null && color != ThemeColor.NONE; } } diff --git a/core/src/main/java/com/mapzen/android/graphics/MapInitializer.java b/core/src/main/java/com/mapzen/android/graphics/MapInitializer.java index 77790132..4bfc3a51 100644 --- a/core/src/main/java/com/mapzen/android/graphics/MapInitializer.java +++ b/core/src/main/java/com/mapzen/android/graphics/MapInitializer.java @@ -90,6 +90,12 @@ private void loadMap(final MapView mapView, MapStyle mapStyle, boolean styleExpl mapStyle = restoredMapStyle; } mapStateManager.setMapStyle(mapStyle); + if (mapStyle instanceof ThemedMapStyle) { + ThemedMapStyle themedStyle = (ThemedMapStyle) mapStyle; + mapStateManager.setLabelLevel(themedStyle.getDefaultLabelLevel()); + mapStateManager.setLod(themedStyle.getDefaultLod()); + mapStateManager.setThemeColor(themedStyle.getDefaultColor()); + } loadMap(mapView, mapStyle, callback); } diff --git a/core/src/main/java/com/mapzen/android/graphics/MapStateManager.java b/core/src/main/java/com/mapzen/android/graphics/MapStateManager.java index 7fd65cf6..22e45f69 100644 --- a/core/src/main/java/com/mapzen/android/graphics/MapStateManager.java +++ b/core/src/main/java/com/mapzen/android/graphics/MapStateManager.java @@ -6,6 +6,8 @@ import com.mapzen.android.graphics.model.ThemeColor; import com.mapzen.tangram.LngLat; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; + /** * Manages parameters around {@link MapzenMap}'s state so that it can be restore upon orientation * change. @@ -15,8 +17,8 @@ class MapStateManager { private boolean persistMapState = true; private LngLat position = new LngLat(0, 0); private MapStyle mapStyle = new BubbleWrapStyle(); - private int labelLevel = 0; - private int lod = 0; + private int labelLevel = NONE; + private int lod = NONE; private ThemeColor themeColor = null; private float zoom = 0; private float rotation = 0; 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 9c65cc6c..ef4e7279 100644 --- a/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java +++ b/core/src/main/java/com/mapzen/android/graphics/MapzenMap.java @@ -40,6 +40,7 @@ import static com.mapzen.android.graphics.internal.EaseTypeConverter.EASE_TYPE_TO_MAP_CONTROLLER_EASE_TYPE; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; /** * This is the main class of the Mapzen Android API and is the entry point for all methods related @@ -1203,6 +1204,9 @@ private ThemedMapStyle getThemedMapStyle() { * @return */ private boolean isValidLabelLevel(int labelLevel) { + if (labelLevel == NONE) { + return true; + } return labelLevel >= 0 && labelLevel < getThemedMapStyle().getLabelCount(); } @@ -1214,6 +1218,9 @@ private boolean isValidLabelLevel(int labelLevel) { * @return */ private boolean isValidLod(int lod) { + if (lod == NONE) { + return true; + } return lod >= 0 && lod < getThemedMapStyle().getLodCount(); } @@ -1225,6 +1232,9 @@ private boolean isValidLod(int lod) { * @return */ private boolean isValidColor(ThemeColor color) { + if (color == ThemeColor.NONE) { + return true; + } return getThemedMapStyle().getColors().contains(color); } diff --git a/core/src/main/java/com/mapzen/android/graphics/model/BubbleWrapStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/BubbleWrapStyle.java index c2fb1be1..39d4c9c6 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/BubbleWrapStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/BubbleWrapStyle.java @@ -1,14 +1,52 @@ package com.mapzen.android.graphics.model; +import java.util.Set; + /** * BubbleWrap default map style. */ -public class BubbleWrapStyle extends MapStyle { +public class BubbleWrapStyle extends ThemedMapStyle { /** * Creates a new instance. */ public BubbleWrapStyle() { - super("styles/bubble-wrap/bubble-wrap-style-more-labels.yaml"); + super("styles/bubble-wrap/bubble-wrap-style.yaml"); + } + + @Override public String getBaseStyleFilename() { + return "bubble-wrap-style.yaml"; + } + + @Override public String getStyleRootPath() { + return "styles/bubble-wrap/"; + } + + @Override public String getThemesPath() { + return "themes/"; + } + + @Override public int getDefaultLod() { + return NONE; + } + + @Override public int getLodCount() { + return NONE; + } + + @Override public int getDefaultLabelLevel() { + return 5; + } + + @Override public int getLabelCount() { + return 12; + } + + @Override public ThemeColor getDefaultColor() { + return ThemeColor.NONE; + } + + @Override public Set getColors() { + return null; } } diff --git a/core/src/main/java/com/mapzen/android/graphics/model/CinnabarStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/CinnabarStyle.java index bc5c45b8..16889dae 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/CinnabarStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/CinnabarStyle.java @@ -1,14 +1,59 @@ package com.mapzen.android.graphics.model; +import java.util.HashSet; +import java.util.Set; + +import static com.mapzen.android.graphics.model.ThemeColor.CINNABAR; + /** * Cinnabar default map style. */ -public class CinnabarStyle extends MapStyle { +public class CinnabarStyle extends ThemedMapStyle { + + private final Set supportedColors = new HashSet() { { + add(CINNABAR); + } }; /** * Creates a new instance. */ public CinnabarStyle() { - super("styles/cinnabar-more-labels/cinnabar-style-more-labels.yaml"); + super("styles/cinnabar-style/cinnabar-style.yaml"); + } + + @Override public String getBaseStyleFilename() { + return "cinnabar-style.yaml"; + } + + @Override public String getStyleRootPath() { + return "styles/cinnabar-style/"; + } + + @Override public String getThemesPath() { + return "themes/"; + } + + @Override public int getDefaultLod() { + return NONE; + } + + @Override public int getLodCount() { + return NONE; + } + + @Override public int getDefaultLabelLevel() { + return 5; + } + + @Override public int getLabelCount() { + return 12; + } + + @Override public ThemeColor getDefaultColor() { + return CINNABAR; + } + + @Override public Set getColors() { + return supportedColors; } } diff --git a/core/src/main/java/com/mapzen/android/graphics/model/RefillStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/RefillStyle.java index 064d0e4f..1ecea5c8 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/RefillStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/RefillStyle.java @@ -16,6 +16,7 @@ import static com.mapzen.android.graphics.model.ThemeColor.PINKYELLOW; import static com.mapzen.android.graphics.model.ThemeColor.PURPLEGREEN; import static com.mapzen.android.graphics.model.ThemeColor.SEPIA; +import static com.mapzen.android.graphics.model.ThemeColor.ZINC; /** * Refill default map style. @@ -36,6 +37,7 @@ public class RefillStyle extends ThemedMapStyle { add(PINKYELLOW); add(PURPLEGREEN); add(SEPIA); + add(ZINC); } }; /** @@ -58,7 +60,7 @@ public RefillStyle() { } @Override public int getDefaultLod() { - return 5; + return 10; } @Override public int getLodCount() { diff --git a/core/src/main/java/com/mapzen/android/graphics/model/ThemeColor.java b/core/src/main/java/com/mapzen/android/graphics/model/ThemeColor.java index 3bb01977..204c0b65 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/ThemeColor.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/ThemeColor.java @@ -4,6 +4,7 @@ * Available color themes for {@link RefillStyle}. */ public enum ThemeColor { + NONE(null), BLACK("black"), BLUE("blue"), BLUEGRAY("blue-gray"), @@ -16,7 +17,9 @@ public enum ThemeColor { PINK("pink"), PINKYELLOW("pink-yellow"), PURPLEGREEN("purple-green"), - SEPIA("sepia"); + SEPIA("sepia"), + CINNABAR("cinnabar"), + ZINC("zinc"); private final String color; diff --git a/core/src/main/java/com/mapzen/android/graphics/model/ThemedMapStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/ThemedMapStyle.java index 4aca6cbf..efc9ffba 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/ThemedMapStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/ThemedMapStyle.java @@ -7,6 +7,8 @@ */ public abstract class ThemedMapStyle extends MapStyle { + public static final int NONE = -1; + /** * Constructor. * @param baseSceneFile diff --git a/core/src/main/java/com/mapzen/android/graphics/model/WalkaboutStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/WalkaboutStyle.java index 94c0c435..208aa38f 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/WalkaboutStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/WalkaboutStyle.java @@ -1,14 +1,52 @@ package com.mapzen.android.graphics.model; +import java.util.Set; + /** * Walkabout outdoor map style. */ -public class WalkaboutStyle extends MapStyle { +public class WalkaboutStyle extends ThemedMapStyle { /** * Creates a new instance. */ public WalkaboutStyle() { - super("styles/walkabout-style-more-labels/walkabout-style-more-labels.yaml"); + super("styles/walkabout-style/walkabout-style.yaml"); + } + + @Override public String getBaseStyleFilename() { + return "walkabout-style.yaml"; + } + + @Override public String getStyleRootPath() { + return "styles/walkabout-style/"; + } + + @Override public String getThemesPath() { + return "themes/"; + } + + @Override public int getDefaultLod() { + return NONE; + } + + @Override public int getLodCount() { + return NONE; + } + + @Override public int getDefaultLabelLevel() { + return 5; + } + + @Override public int getLabelCount() { + return 12; + } + + @Override public ThemeColor getDefaultColor() { + return ThemeColor.NONE; + } + + @Override public Set getColors() { + return null; } } diff --git a/core/src/main/java/com/mapzen/android/graphics/model/ZincStyle.java b/core/src/main/java/com/mapzen/android/graphics/model/ZincStyle.java index 6eb91250..a0cb43a1 100644 --- a/core/src/main/java/com/mapzen/android/graphics/model/ZincStyle.java +++ b/core/src/main/java/com/mapzen/android/graphics/model/ZincStyle.java @@ -1,14 +1,64 @@ package com.mapzen.android.graphics.model; +import java.util.HashSet; +import java.util.Set; + +import static com.mapzen.android.graphics.model.ThemeColor.ZINC; + /** * Zinc more labels map style. + * + * Deprecated in favor of {@link RefillStyle} with {@link ThemeColor#ZINC}. */ -public class ZincStyle extends MapStyle { +@Deprecated +public class ZincStyle extends ThemedMapStyle { + + private final Set supportedColors = new HashSet() { + { + add(ZINC); + } + }; /** * Creates a new instance. */ public ZincStyle() { - super("styles/zinc-style-more-labels/zinc-style-more-labels.yaml"); + super("styles/refill-style/refill-style.yaml"); + } + + @Override public String getBaseStyleFilename() { + return "refill-style.yaml"; + } + + @Override public String getStyleRootPath() { + return "styles/refill-style/"; + } + + @Override public String getThemesPath() { + return "themes/"; + } + + @Override public int getDefaultLod() { + return 10; + } + + @Override public int getLodCount() { + return 12; + } + + @Override public int getDefaultLabelLevel() { + return 5; + } + + @Override public int getLabelCount() { + return 12; + } + + @Override public ThemeColor getDefaultColor() { + return ZINC; + } + + @Override public Set getColors() { + return supportedColors; } } diff --git a/core/src/test/java/com/mapzen/android/graphics/ImportYamlGeneratorTest.java b/core/src/test/java/com/mapzen/android/graphics/ImportYamlGeneratorTest.java index b0af36a4..33b3135d 100644 --- a/core/src/test/java/com/mapzen/android/graphics/ImportYamlGeneratorTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/ImportYamlGeneratorTest.java @@ -1,10 +1,12 @@ package com.mapzen.android.graphics; import com.mapzen.android.graphics.model.RefillStyle; +import com.mapzen.android.graphics.model.ThemeColor; import org.junit.Test; import static com.mapzen.android.graphics.model.ThemeColor.PINK; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; import static org.assertj.core.api.Assertions.assertThat; public class ImportYamlGeneratorTest { @@ -17,4 +19,28 @@ public class ImportYamlGeneratorTest { assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml, " + "themes/detail-5.yaml, themes/color-pink.yaml ] }"); } + + @Test public void getImportYaml_shouldReturnCorrectStringForNoLod() throws Exception { + String yaml = yamlGenerator.getImportYaml(refillStyle, 3, NONE, PINK); + assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml, " + + "themes/color-pink.yaml ] }"); + } + + @Test public void getImportYaml_shouldReturnCorrectStringForNoColor() throws Exception { + String yaml = yamlGenerator.getImportYaml(refillStyle, 3, 8, null); + assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml, " + + "themes/detail-8.yaml ] }"); + + yamlGenerator.getImportYaml(refillStyle, 3, 8, ThemeColor.NONE); + assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml, " + + "themes/detail-8.yaml ] }"); + } + + @Test public void getImportYaml_shouldReturnCorrectStringForNoLodNoColor() throws Exception { + String yaml = yamlGenerator.getImportYaml(refillStyle, 3, NONE, null); + assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml ] }"); + + yamlGenerator.getImportYaml(refillStyle, 3, NONE, ThemeColor.NONE); + assertThat(yaml).isEqualTo("{ import: [ refill-style.yaml, themes/label-3.yaml ] }"); + } } diff --git a/core/src/test/java/com/mapzen/android/graphics/MapInitializerTest.java b/core/src/test/java/com/mapzen/android/graphics/MapInitializerTest.java index b35b1358..1c58da4d 100644 --- a/core/src/test/java/com/mapzen/android/graphics/MapInitializerTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/MapInitializerTest.java @@ -2,10 +2,11 @@ import com.mapzen.android.core.CoreDI; import com.mapzen.android.core.MapzenManager; -import com.mapzen.android.graphics.model.BubbleWrapStyle; import com.mapzen.android.graphics.model.BitmapMarkerManager; +import com.mapzen.android.graphics.model.BubbleWrapStyle; import com.mapzen.android.graphics.model.RefillStyle; import com.mapzen.android.graphics.model.ThemeColor; +import com.mapzen.android.graphics.model.ThemedMapStyle; import com.mapzen.tangram.MapController; import com.mapzen.tangram.SceneUpdate; @@ -88,7 +89,7 @@ public class MapInitializerTest { expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); - verify(mapController).loadSceneFileAsync(anyString(), argThat( + verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); } @@ -116,7 +117,7 @@ public class MapInitializerTest { expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); - verify(mapController).loadSceneFileAsync(anyString(), argThat( + verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); } @@ -144,7 +145,7 @@ public class MapInitializerTest { expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); - verify(mapController).loadSceneFileAsync(anyString(), argThat( + verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); } @@ -160,9 +161,6 @@ public class MapInitializerTest { tangramMapView.callback = callback; when(mapView.getTangramMapView()).thenReturn(tangramMapView); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); - mapStateManager.setThemeColor(ThemeColor.BLACK); - mapStateManager.setLabelLevel(10); - mapStateManager.setLod(10); // Act RefillStyle refillStyle = new RefillStyle(); @@ -175,9 +173,48 @@ public class MapInitializerTest { expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); - String yaml = "{ import: [ refill-style.yaml, themes/label-10.yaml, " + String yaml = "{ import: [ refill-style.yaml, themes/label-5.yaml, " + "themes/detail-10.yaml, themes/color-black.yaml ] }"; - verify(mapController).loadSceneYamlAsync(eq(yaml), eq(refillStyle.getStyleRootPath()), argThat( - new SceneUpdatesMatcher(expected))); + verify(mapController).loadSceneYamlAsync(eq(yaml), eq(refillStyle.getStyleRootPath()), + argThat(new SceneUpdatesMatcher(expected))); + } + + @Test public void init_shouldSetDefaultLodForThemedStyle() throws Exception { + TestMapView mapView = mock(TestMapView.class); + TestTangramMapView tangramMapView = mock(TestTangramMapView.class); + MapController mapController = mock(MapController.class); + when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( + mapController); + when(mapView.getTangramMapView()).thenReturn(tangramMapView); + ThemedMapStyle style = new RefillStyle(); + mapStateManager.setLod(-1); + mapInitializer.init(mapView, style, new TestCallback()); + assertThat(mapStateManager.getLod()).isEqualTo(style.getDefaultLod()); + } + + @Test public void init_shouldSetDefaultLabelLevelForThemedStyle() throws Exception { + TestMapView mapView = mock(TestMapView.class); + TestTangramMapView tangramMapView = mock(TestTangramMapView.class); + MapController mapController = mock(MapController.class); + when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( + mapController); + when(mapView.getTangramMapView()).thenReturn(tangramMapView); + ThemedMapStyle style = new RefillStyle(); + mapStateManager.setLabelLevel(-1); + mapInitializer.init(mapView, style, new TestCallback()); + assertThat(mapStateManager.getLabelLevel()).isEqualTo(style.getDefaultLabelLevel()); + } + + @Test public void init_shouldSetDefaultColorForThemedStyle() throws Exception { + TestMapView mapView = mock(TestMapView.class); + TestTangramMapView tangramMapView = mock(TestTangramMapView.class); + MapController mapController = mock(MapController.class); + when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( + mapController); + when(mapView.getTangramMapView()).thenReturn(tangramMapView); + ThemedMapStyle style = new RefillStyle(); + mapStateManager.setThemeColor(ThemeColor.NONE); + mapInitializer.init(mapView, style, new TestCallback()); + assertThat(mapStateManager.getThemeColor()).isEqualTo(style.getDefaultColor()); } } diff --git a/core/src/test/java/com/mapzen/android/graphics/MapStateManagerTest.java b/core/src/test/java/com/mapzen/android/graphics/MapStateManagerTest.java index 47bff907..979c8ce5 100644 --- a/core/src/test/java/com/mapzen/android/graphics/MapStateManagerTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/MapStateManagerTest.java @@ -8,6 +8,7 @@ import org.junit.Test; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; import static org.assertj.core.api.Assertions.assertThat; public class MapStateManagerTest { @@ -106,8 +107,8 @@ public class MapStateManagerTest { assertThat(stateManager.isPathOverlayEnabled()).isEqualTo(true); } - @Test public void getLabelLevel_shouldDefaultToZero() { - assertThat(stateManager.getLabelLevel()).isEqualTo(0); + @Test public void getLabelLevel_shouldDefaultToNone() { + assertThat(stateManager.getLabelLevel()).isEqualTo(NONE); } @Test public void setLabelLevel_shouldUpdateLabelLevel() { @@ -115,8 +116,8 @@ public class MapStateManagerTest { assertThat(stateManager.getLabelLevel()).isEqualTo(4); } - @Test public void getLod_shouldDefaultToZero() { - assertThat(stateManager.getLod()).isEqualTo(0); + @Test public void getLod_shouldDefaultToNone() { + assertThat(stateManager.getLod()).isEqualTo(NONE); } @Test public void setDetailLevel_shouldUpdateDetailLevel() { 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 76c5c4cf..6da415bd 100644 --- a/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/MapzenMapTest.java @@ -41,6 +41,7 @@ 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 com.mapzen.android.graphics.model.ThemedMapStyle.NONE; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyFloat; @@ -660,7 +661,7 @@ 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).loadSceneYaml(anyString(), anyString(), any(List.class)); } @Test public void setStyle_shouldNotCallMapControllerAsyncMethod() throws Exception { @@ -670,12 +671,12 @@ public void applySceneUpdates_shouldClearQueuedUpdates() throws Exception { @Test public void setStyleAsync_shouldSetStyleAndGlobalVariables() throws Exception { map.setStyleAsync(new WalkaboutStyle(), null); - verify(mapController).loadSceneFileAsync(anyString(), any(List.class)); + verify(mapController).loadSceneYamlAsync(anyString(), anyString(), any(List.class)); } @Test public void setStyleAsync_shouldCallListenerOnSceneLoaded() throws Exception { int sceneId = 1; - when(mapController.loadSceneFileAsync(anyString(), anyList())).thenReturn(sceneId); + when(mapController.loadSceneYamlAsync(anyString(), anyString(), anyList())).thenReturn(sceneId); TestOnStyleLoadedListener listener = new TestOnStyleLoadedListener(); map.setStyleAsync(new WalkaboutStyle(), listener); map.internalSceneLoadListener.onSceneReady(sceneId, null); @@ -696,7 +697,7 @@ public void applySceneUpdates_shouldClearQueuedUpdates() throws Exception { 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).loadSceneFile(anyString(), argThat( + verify(mapController).loadSceneYaml(anyString(), anyString(), argThat( new SceneUpdatesMatcher(sceneUpdates))); } @@ -843,12 +844,12 @@ public void applySceneUpdates_shouldClearQueuedUpdates() throws Exception { @Test(expected = IllegalArgumentException.class) public void setStyleAndLabelLevel_shouldVerifyLowValue() throws Exception { - map.setStyleAndLabelLevel(new RefillStyle(), -1); + map.setStyleAndLabelLevel(new RefillStyle(), -10); } @Test(expected = IllegalArgumentException.class) public void setStyleAndLabelLevelAsync_shouldVerifyLowValue() throws Exception { - map.setStyleAndLabelLevelAsync(new RefillStyle(), -1, null); + map.setStyleAndLabelLevelAsync(new RefillStyle(), -10, null); } @Test(expected = IllegalArgumentException.class) @@ -861,6 +862,16 @@ public void setStyleAndLabelLevelAsync_shouldVerifyHighValue() throws Exception map.setStyleAndLabelLevelAsync(new RefillStyle(), 12, null); } + @Test public void setStyleLabelLevelLodThemeColorAsync_shouldVerifyNoValue() throws Exception { + map.setStyleLabelLevelLodThemeColorAsync(new RefillStyle(), NONE, NONE, ThemeColor.NONE, null); + verify(mapController).loadSceneYamlAsync(anyString(), anyString(), anyList()); + } + + @Test public void setStyleLabelLevelLodThemeColor_shouldVerifyNoValue() throws Exception { + map.setStyleLabelLevelLodThemeColor(new RefillStyle(), NONE, NONE, ThemeColor.NONE); + verify(mapController).loadSceneYaml(anyString(), anyString(), anyList()); + } + @Test public void setStyleAndLod_shouldCallLoadYamlWithCorrectValues() throws Exception { when(mapzenManager.getApiKey()).thenReturn("apiKey"); @@ -920,12 +931,12 @@ public void setStyleAndLabelLevelAsync_shouldVerifyHighValue() throws Exception @Test(expected = IllegalArgumentException.class) public void setStyleAndLod_shouldVerifyLowValue() throws Exception { - map.setStyleAndLod(new RefillStyle(), -1); + map.setStyleAndLod(new RefillStyle(), -10); } @Test(expected = IllegalArgumentException.class) public void setStyleAndLodAsync_shouldVerifyLowValue() throws Exception { - map.setStyleAndLodAsync(new RefillStyle(), -1, null); + map.setStyleAndLodAsync(new RefillStyle(), -10, null); } @Test(expected = IllegalArgumentException.class) diff --git a/core/src/test/java/com/mapzen/android/graphics/TestTangramMapView.java b/core/src/test/java/com/mapzen/android/graphics/TestTangramMapView.java index eac392fd..206c5f7b 100644 --- a/core/src/test/java/com/mapzen/android/graphics/TestTangramMapView.java +++ b/core/src/test/java/com/mapzen/android/graphics/TestTangramMapView.java @@ -39,6 +39,13 @@ public TestTangramMapView(Context context, AttributeSet attrs) { return null; } }); + when(controller.loadSceneYamlAsync(anyString(), anyString(), any(List.class))).thenAnswer( + new Answer() { + @Override public Void answer(InvocationOnMock invocation) throws Throwable { + mapView.getMapAsync(callback); + return null; + } + }); return controller; } } diff --git a/core/src/test/java/com/mapzen/android/graphics/model/BubbleWrapStyleTest.java b/core/src/test/java/com/mapzen/android/graphics/model/BubbleWrapStyleTest.java new file mode 100644 index 00000000..d5d9ada9 --- /dev/null +++ b/core/src/test/java/com/mapzen/android/graphics/model/BubbleWrapStyleTest.java @@ -0,0 +1,51 @@ +package com.mapzen.android.graphics.model; + +import org.junit.Test; + +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; +import static org.assertj.core.api.Assertions.assertThat; + +public class BubbleWrapStyleTest { + + private BubbleWrapStyle style = new BubbleWrapStyle(); + + @Test public void getSceneFile_shouldReturnCorrectValue() throws Exception { + assertThat(style.getSceneFile()).isEqualTo("styles/bubble-wrap/bubble-wrap-style.yaml"); + } + + @Test public void getBaseStyleFilename_shouldReturnCorrectValue() throws Exception { + assertThat(style.getBaseStyleFilename()).isEqualTo("bubble-wrap-style.yaml"); + } + + @Test public void getStyleRootPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getStyleRootPath()).isEqualTo("styles/bubble-wrap/"); + } + + @Test public void getThemesPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getThemesPath()).isEqualTo("themes/"); + } + + @Test public void getDefaultLod_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLod()).isEqualTo(NONE); + } + + @Test public void getLodCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLodCount()).isEqualTo(NONE); + } + + @Test public void getDefaultLabelLevel_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLabelLevel()).isEqualTo(5); + } + + @Test public void getLabelCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLabelCount()).isEqualTo(12); + } + + @Test public void getDefaultColor_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultColor()).isEqualTo(ThemeColor.NONE); + } + + @Test public void getColors_shouldReturnCorrectValue() throws Exception { + assertThat(style.getColors()).isNull(); + } +} diff --git a/core/src/test/java/com/mapzen/android/graphics/model/CinnabarStyleTest.java b/core/src/test/java/com/mapzen/android/graphics/model/CinnabarStyleTest.java new file mode 100644 index 00000000..4fb7a292 --- /dev/null +++ b/core/src/test/java/com/mapzen/android/graphics/model/CinnabarStyleTest.java @@ -0,0 +1,60 @@ +package com.mapzen.android.graphics.model; + +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static com.mapzen.android.graphics.model.ThemeColor.CINNABAR; +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; +import static org.assertj.core.api.Assertions.assertThat; + +public class CinnabarStyleTest { + + private CinnabarStyle style = new CinnabarStyle(); + + @Test public void getSceneFile_shouldReturnCorrectValue() throws Exception { + assertThat(style.getSceneFile()).isEqualTo("styles/cinnabar-style/cinnabar-style.yaml"); + } + + @Test public void getBaseStyleFilename_shouldReturnCorrectValue() throws Exception { + assertThat(style.getBaseStyleFilename()).isEqualTo("cinnabar-style.yaml"); + } + + @Test public void getStyleRootPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getStyleRootPath()).isEqualTo("styles/cinnabar-style/"); + } + + @Test public void getThemesPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getThemesPath()).isEqualTo("themes/"); + } + + @Test public void getDefaultLod_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLod()).isEqualTo(NONE); + } + + @Test public void getLodCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLodCount()).isEqualTo(NONE); + } + + @Test public void getDefaultLabelLevel_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLabelLevel()).isEqualTo(5); + } + + @Test public void getLabelCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLabelCount()).isEqualTo(12); + } + + @Test public void getDefaultColor_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultColor()).isEqualTo(ThemeColor.CINNABAR); + } + + @Test public void getColors_shouldReturnCorrectValue() throws Exception { + Set colors = new HashSet() { + { + add(CINNABAR); + } + }; + assertThat(style.getColors()).isEqualTo(colors); + } +} diff --git a/core/src/test/java/com/mapzen/android/graphics/model/RefillStyleTest.java b/core/src/test/java/com/mapzen/android/graphics/model/RefillStyleTest.java index fa8686a2..bd0a4eef 100644 --- a/core/src/test/java/com/mapzen/android/graphics/model/RefillStyleTest.java +++ b/core/src/test/java/com/mapzen/android/graphics/model/RefillStyleTest.java @@ -18,6 +18,7 @@ import static com.mapzen.android.graphics.model.ThemeColor.PINKYELLOW; import static com.mapzen.android.graphics.model.ThemeColor.PURPLEGREEN; import static com.mapzen.android.graphics.model.ThemeColor.SEPIA; +import static com.mapzen.android.graphics.model.ThemeColor.ZINC; import static org.assertj.core.api.Assertions.assertThat; public class RefillStyleTest { @@ -41,7 +42,7 @@ public class RefillStyleTest { } @Test public void getDefaultLod_shouldReturnCorrectValue() throws Exception { - assertThat(style.getDefaultLod()).isEqualTo(5); + assertThat(style.getDefaultLod()).isEqualTo(10); } @Test public void getLodCount_shouldReturnCorrectValue() throws Exception { @@ -75,6 +76,7 @@ public class RefillStyleTest { add(PINKYELLOW); add(PURPLEGREEN); add(SEPIA); + add(ZINC); } }; assertThat(style.getColors()).isEqualTo(colors); } diff --git a/core/src/test/java/com/mapzen/android/graphics/model/WalkaboutStyleTest.java b/core/src/test/java/com/mapzen/android/graphics/model/WalkaboutStyleTest.java new file mode 100644 index 00000000..2a2a7c18 --- /dev/null +++ b/core/src/test/java/com/mapzen/android/graphics/model/WalkaboutStyleTest.java @@ -0,0 +1,51 @@ +package com.mapzen.android.graphics.model; + +import org.junit.Test; + +import static com.mapzen.android.graphics.model.ThemedMapStyle.NONE; +import static org.assertj.core.api.Assertions.assertThat; + +public class WalkaboutStyleTest { + + private WalkaboutStyle style = new WalkaboutStyle(); + + @Test public void getSceneFile_shouldReturnCorrectValue() throws Exception { + assertThat(style.getSceneFile()).isEqualTo("styles/walkabout-style/walkabout-style.yaml"); + } + + @Test public void getBaseStyleFilename_shouldReturnCorrectValue() throws Exception { + assertThat(style.getBaseStyleFilename()).isEqualTo("walkabout-style.yaml"); + } + + @Test public void getStyleRootPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getStyleRootPath()).isEqualTo("styles/walkabout-style/"); + } + + @Test public void getThemesPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getThemesPath()).isEqualTo("themes/"); + } + + @Test public void getDefaultLod_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLod()).isEqualTo(NONE); + } + + @Test public void getLodCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLodCount()).isEqualTo(NONE); + } + + @Test public void getDefaultLabelLevel_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLabelLevel()).isEqualTo(5); + } + + @Test public void getLabelCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLabelCount()).isEqualTo(12); + } + + @Test public void getDefaultColor_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultColor()).isEqualTo(ThemeColor.NONE); + } + + @Test public void getColors_shouldReturnCorrectValue() throws Exception { + assertThat(style.getColors()).isNull(); + } +} diff --git a/core/src/test/java/com/mapzen/android/graphics/model/ZincStyleTest.java b/core/src/test/java/com/mapzen/android/graphics/model/ZincStyleTest.java new file mode 100644 index 00000000..3e1c1553 --- /dev/null +++ b/core/src/test/java/com/mapzen/android/graphics/model/ZincStyleTest.java @@ -0,0 +1,59 @@ +package com.mapzen.android.graphics.model; + +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static com.mapzen.android.graphics.model.ThemeColor.ZINC; +import static org.assertj.core.api.Assertions.assertThat; + +public class ZincStyleTest { + + private ZincStyle style = new ZincStyle(); + + @Test public void getSceneFile_shouldReturnCorrectValue() throws Exception { + assertThat(style.getSceneFile()).isEqualTo("styles/refill-style/refill-style.yaml"); + } + + @Test public void getBaseStyleFilename_shouldReturnCorrectValue() throws Exception { + assertThat(style.getBaseStyleFilename()).isEqualTo("refill-style.yaml"); + } + + @Test public void getStyleRootPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getStyleRootPath()).isEqualTo("styles/refill-style/"); + } + + @Test public void getThemesPath_shouldReturnCorrectValue() throws Exception { + assertThat(style.getThemesPath()).isEqualTo("themes/"); + } + + @Test public void getDefaultLod_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLod()).isEqualTo(10); + } + + @Test public void getLodCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLodCount()).isEqualTo(12); + } + + @Test public void getDefaultLabelLevel_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultLabelLevel()).isEqualTo(5); + } + + @Test public void getLabelCount_shouldReturnCorrectValue() throws Exception { + assertThat(style.getLabelCount()).isEqualTo(12); + } + + @Test public void getDefaultColor_shouldReturnCorrectValue() throws Exception { + assertThat(style.getDefaultColor()).isEqualTo(ZINC); + } + + @Test public void getColors_shouldReturnCorrectValue() throws Exception { + Set colors = new HashSet() { + { + add(ZINC); + } + }; + assertThat(style.getColors()).isEqualTo(colors); + } +} diff --git a/samples/mapzen-android-sdk-sample/src/main/AndroidManifest.xml b/samples/mapzen-android-sdk-sample/src/main/AndroidManifest.xml index 8977c732..0493f9c6 100644 --- a/samples/mapzen-android-sdk-sample/src/main/AndroidManifest.xml +++ b/samples/mapzen-android-sdk-sample/src/main/AndroidManifest.xml @@ -24,9 +24,7 @@ - + adapterView, View view, int i, long l) { + handleStyleSelected(i); + updateLODSpinner(); + updateLabelLevelSpinner(); + updateColorSpinner(); + } + + @Override public void onNothingSelected(AdapterView adapterView) { + + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutId()); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayShowTitleEnabled(false); - - Spinner spinner = (Spinner) findViewById(R.id.spinner); + styleSpinner = findViewById(R.id.styleSpinner); ArrayAdapter adapter = - ArrayAdapter.createFromResource(this, R.array.style_array, R.layout.simple_spinner_item); - adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(adapter); - spinner.setOnItemSelectedListener(this); + ArrayAdapter.createFromResource(this, R.array.style_array, R.layout.gray_spinner_item); + adapter.setDropDownViewResource(R.layout.gray_spinner_dropdown_item); + styleSpinner.setAdapter(adapter); + styleSpinner.setOnItemSelectedListener(styleSelectedListener); + styleSpinner.setSelection(0); + + lodSpinner = findViewById(R.id.lodSpinner); + + labelLevelSpinner = findViewById(R.id.labelLevelSpinner); + + colorSpinner = findViewById(R.id.colorSpinner); + + updateBtn = findViewById(R.id.updateMapBtn); + updateBtn.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View view) { + updateMap(); + } + }); - final Bundle state = savedInstanceState; mapFragment = (MapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment); mapFragment.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapzenMap mapzenMap) { @@ -51,8 +83,15 @@ public class SwitchStyleActivity extends BaseDemoActivity }); } + @Override protected void onDestroy() { + styleSpinner.setOnItemSelectedListener(null); + updateBtn.setOnClickListener(null); + mapzenMap.setMyLocationEnabled(false); + super.onDestroy(); + } + int getLayoutId() { - return R.layout.activity_spinner; + return R.layout.activity_switch_style; } /** @@ -60,41 +99,94 @@ int getLayoutId() { */ void configureMap() { mapzenMap.setPersistMapState(true); + mapzenMap.setMyLocationEnabled(true); } - private void changeMapStyle(MapStyle style) { + private void updateMap() { if (mapzenMap != null) { - mapzenMap.setStyle(style); + int labelLevel = labelLevelSpinner.getSelectedItem() != null ? + (int) labelLevelSpinner.getSelectedItem() : currentStyle.getDefaultLabelLevel(); + int lod = lodSpinner.getSelectedItem() != null ? + (int) lodSpinner.getSelectedItem() : currentStyle.getDefaultLod(); + ThemeColor color = colorSpinner.getSelectedItem() != null ? + (ThemeColor) colorSpinner.getSelectedItem() : currentStyle.getDefaultColor(); + updateBtn.setEnabled(false); + mapzenMap.setStyleLabelLevelLodThemeColorAsync(currentStyle, labelLevel, lod, color, + new OnStyleLoadedListener() { + @Override public void onStyleLoaded() { + updateBtn.setEnabled(true); + } + }); } } - @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { + private void handleStyleSelected(int position) { + ThemedMapStyle style; switch (position) { case 0: - // do nothing + style = new BubbleWrapStyle(); break; case 1: - changeMapStyle(new BubbleWrapStyle()); + style = new CinnabarStyle(); break; case 2: - changeMapStyle(new CinnabarStyle()); + style = new RefillStyle(); break; case 3: - changeMapStyle(new RefillStyle()); + style = new WalkaboutStyle(); break; case 4: - changeMapStyle(new WalkaboutStyle()); - break; - case 5: - changeMapStyle(new ZincStyle()); + style = new ZincStyle(); break; default: - changeMapStyle(new BubbleWrapStyle()); + style = new BubbleWrapStyle(); break; } + currentStyle = style; + } + + private void updateLODSpinner() { + ArrayAdapter adapter = + new ArrayAdapter(this, R.layout.gray_spinner_item); + adapter.setDropDownViewResource(R.layout.gray_spinner_dropdown_item); + if (currentStyle != null) { + for (int i = 0; i < currentStyle.getLodCount(); i++) { + adapter.add(i); + } + } + lodSpinner.setAdapter(adapter); + lodSpinner.setSelection(currentStyle.getDefaultLod()); } - @Override public void onNothingSelected(AdapterView parent) { - // Do nothing. + private void updateLabelLevelSpinner() { + ArrayAdapter adapter = + new ArrayAdapter(this, R.layout.gray_spinner_item); + adapter.setDropDownViewResource(R.layout.gray_spinner_dropdown_item); + if (currentStyle != null) { + for (int i = 0; i < currentStyle.getLabelCount(); i++) { + adapter.add(i); + } + } + labelLevelSpinner.setAdapter(adapter); + labelLevelSpinner.setSelection(currentStyle.getDefaultLabelLevel()); + } + + private void updateColorSpinner() { + ArrayAdapter adapter = + new ArrayAdapter(this, R.layout.gray_spinner_item); + adapter.setDropDownViewResource(R.layout.gray_spinner_dropdown_item); + int pos = 0; + if (currentStyle != null && currentStyle.getColors() != null) { + int i = 0; + for (ThemeColor color : currentStyle.getColors()) { + adapter.add(color); + if (color == currentStyle.getDefaultColor()) { + pos = i; + } + i++; + } + } + colorSpinner.setAdapter(adapter); + colorSpinner.setSelection(pos); } } diff --git a/samples/mapzen-android-sdk-sample/src/main/res/layout/activity_switch_style.xml b/samples/mapzen-android-sdk-sample/src/main/res/layout/activity_switch_style.xml new file mode 100644 index 00000000..855c2b0f --- /dev/null +++ b/samples/mapzen-android-sdk-sample/src/main/res/layout/activity_switch_style.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +