From 52cb6122f87a6769fad4c4d826b49cd95a37c83b Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Wed, 3 Aug 2016 16:03:03 -0400 Subject: [android] #5858 - added convenience methods for color properties --- .../mapboxsdk/exceptions/ConversionException.java | 22 +++ .../mapboxsdk/style/layers/BackgroundLayer.java | 31 +++- .../mapbox/mapboxsdk/style/layers/CircleLayer.java | 54 ++++++- .../mapbox/mapboxsdk/style/layers/FillLayer.java | 67 +++++++- .../mapbox/mapboxsdk/style/layers/LineLayer.java | 68 ++++++-- .../mapbox/mapboxsdk/style/layers/RasterLayer.java | 31 +++- .../mapbox/mapboxsdk/style/layers/SymbolLayer.java | 175 +++++++++++++++------ .../mapbox/mapboxsdk/style/layers/layer.java.ejs | 44 ++++++ .../mapboxsdk/style/sources/GeoJsonSource.java | 21 +++ .../mapboxsdk/style/sources/VectorSource.java | 23 +++ .../com/mapbox/mapboxsdk/utils/ColorUtils.java | 27 ++++ .../mapboxsdk/style/BackgroundLayerTest.java | 17 ++ .../mapbox/mapboxsdk/style/CircleLayerTest.java | 23 +++ .../com/mapbox/mapboxsdk/style/FillLayerTest.java | 45 ++++++ .../com/mapbox/mapboxsdk/style/LineLayerTest.java | 23 +++ .../mapbox/mapboxsdk/style/RasterLayerTest.java | 1 + .../mapbox/mapboxsdk/style/SymbolLayerTest.java | 89 +++++++++++ .../com/mapbox/mapboxsdk/style/layer.junit.ejs | 30 ++++ .../activity/style/RuntimeStyleActivity.java | 7 +- 19 files changed, 718 insertions(+), 80 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java new file mode 100644 index 0000000000..87656db2a9 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java @@ -0,0 +1,22 @@ +package com.mapbox.mapboxsdk.exceptions; + +/** + * Thrown on conversion errors + */ +public class ConversionException extends RuntimeException { + + public ConversionException() { + } + + public ConversionException(String detailMessage) { + super(detailMessage); + } + + public ConversionException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + } + + public ConversionException(Throwable throwable) { + super(throwable); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java index f7a71155ad..fae68c518e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Background Layer */ @@ -17,6 +24,11 @@ public class BackgroundLayer extends Layer { protected native void initialize(String layerId); + public BackgroundLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } + // Property getters @SuppressWarnings("unchecked") @@ -24,19 +36,34 @@ public class BackgroundLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetBackgroundColor()); } + /** + * The color with which the background will be drawn. + * @throws RuntimeException + */ + @ColorInt + public int getBackgroundColorAsInt() { + checkValidity(); + PropertyValue value = getBackgroundColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("background-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getBackgroundPattern() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetBackgroundPattern()); } - + @SuppressWarnings("unchecked") public PropertyValue getBackgroundOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetBackgroundOpacity()); } - + private native Object nativeGetBackgroundColor(); private native Object nativeGetBackgroundPattern(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index 6628fee47a..ce0e9fd5bd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Circle Layer */ @@ -21,6 +28,11 @@ public class CircleLayer extends Layer { nativeSetSourceLayer(sourceLayer); } + public CircleLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + public void setFilter(Filter.Statement filter) { checkValidity(); this.setFilter(filter.toArray()); @@ -31,6 +43,21 @@ public class CircleLayer extends Layer { nativeSetFilter(filter); } + public CircleLayer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + public CircleLayer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + + + public CircleLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } // Property getters @@ -39,43 +66,58 @@ public class CircleLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleRadius()); } - + @SuppressWarnings("unchecked") public PropertyValue getCircleColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleColor()); } + /** + * The color of the circle. + * @throws RuntimeException + */ + @ColorInt + public int getCircleColorAsInt() { + checkValidity(); + PropertyValue value = getCircleColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("circle-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getCircleBlur() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleBlur()); } - + @SuppressWarnings("unchecked") public PropertyValue getCircleOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getCircleTranslate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleTranslate()); } - + @SuppressWarnings("unchecked") public PropertyValue getCircleTranslateAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCircleTranslateAnchor()); } - + @SuppressWarnings("unchecked") public PropertyValue getCirclePitchScale() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetCirclePitchScale()); } - + private native Object nativeGetCircleRadius(); private native Object nativeGetCircleColor(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java index 7938af3c80..d188129e2a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Fill Layer */ @@ -21,6 +28,11 @@ public class FillLayer extends Layer { nativeSetSourceLayer(sourceLayer); } + public FillLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + public void setFilter(Filter.Statement filter) { checkValidity(); this.setFilter(filter.toArray()); @@ -31,6 +43,21 @@ public class FillLayer extends Layer { nativeSetFilter(filter); } + public FillLayer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + public FillLayer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + + + public FillLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } // Property getters @@ -39,43 +66,73 @@ public class FillLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillAntialias()); } - + @SuppressWarnings("unchecked") public PropertyValue getFillOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getFillColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillColor()); } + /** + * The color of the filled part of this layer. This color can be specified as rgba with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. + * @throws RuntimeException + */ + @ColorInt + public int getFillColorAsInt() { + checkValidity(); + PropertyValue value = getFillColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("fill-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getFillOutlineColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillOutlineColor()); } + /** + * The outline color of the fill. Matches the value of `fill-color` if unspecified. + * @throws RuntimeException + */ + @ColorInt + public int getFillOutlineColorAsInt() { + checkValidity(); + PropertyValue value = getFillOutlineColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("fill-outline-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getFillTranslate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillTranslate()); } - + @SuppressWarnings("unchecked") public PropertyValue getFillTranslateAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillTranslateAnchor()); } - + @SuppressWarnings("unchecked") public PropertyValue getFillPattern() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetFillPattern()); } - + private native Object nativeGetFillAntialias(); private native Object nativeGetFillOpacity(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java index 11cd709f49..ab5dd0815e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Line Layer */ @@ -21,6 +28,11 @@ public class LineLayer extends Layer { nativeSetSourceLayer(sourceLayer); } + public LineLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + public void setFilter(Filter.Statement filter) { checkValidity(); this.setFilter(filter.toArray()); @@ -31,6 +43,21 @@ public class LineLayer extends Layer { nativeSetFilter(filter); } + public LineLayer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + public LineLayer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + + + public LineLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } // Property getters @@ -39,85 +66,100 @@ public class LineLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineCap()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineJoin() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineJoin()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineMiterLimit() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineMiterLimit()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineRoundLimit() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineRoundLimit()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineColor()); } + /** + * The color with which the line will be drawn. + * @throws RuntimeException + */ + @ColorInt + public int getLineColorAsInt() { + checkValidity(); + PropertyValue value = getLineColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("line-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getLineTranslate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineTranslate()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineTranslateAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineTranslateAnchor()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineWidth() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineWidth()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineGapWidth() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineGapWidth()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineOffset() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineOffset()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineBlur() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineBlur()); } - + @SuppressWarnings("unchecked") public PropertyValue getLineDasharray() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLineDasharray()); } - + @SuppressWarnings("unchecked") public PropertyValue getLinePattern() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetLinePattern()); } - + private native Object nativeGetLineCap(); private native Object nativeGetLineJoin(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java index 1cbe5fb387..a6872cef0f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Raster Layer */ @@ -21,6 +28,16 @@ public class RasterLayer extends Layer { nativeSetSourceLayer(sourceLayer); } + public RasterLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + + + public RasterLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } // Property getters @@ -29,43 +46,43 @@ public class RasterLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterHueRotate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterHueRotate()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterBrightnessMin() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterBrightnessMin()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterBrightnessMax() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterBrightnessMax()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterSaturation() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterSaturation()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterContrast() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterContrast()); } - + @SuppressWarnings("unchecked") public PropertyValue getRasterFadeDuration() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetRasterFadeDuration()); } - + private native Object nativeGetRasterOpacity(); private native Object nativeGetRasterHueRotate(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index 281b4fc028..ccbfdb411f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -1,6 +1,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * Symbol Layer */ @@ -21,6 +28,11 @@ public class SymbolLayer extends Layer { nativeSetSourceLayer(sourceLayer); } + public SymbolLayer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } + public void setFilter(Filter.Statement filter) { checkValidity(); this.setFilter(filter.toArray()); @@ -31,6 +43,21 @@ public class SymbolLayer extends Layer { nativeSetFilter(filter); } + public SymbolLayer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + public SymbolLayer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + + + public SymbolLayer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } // Property getters @@ -39,289 +66,349 @@ public class SymbolLayer extends Layer { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetSymbolPlacement()); } - + @SuppressWarnings("unchecked") public PropertyValue getSymbolSpacing() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetSymbolSpacing()); } - + @SuppressWarnings("unchecked") public PropertyValue getSymbolAvoidEdges() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetSymbolAvoidEdges()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconAllowOverlap() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconAllowOverlap()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconIgnorePlacement() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconIgnorePlacement()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconOptional() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconOptional()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconRotationAlignment() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconRotationAlignment()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconSize() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconSize()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconTextFit() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconTextFit()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconTextFitPadding() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconTextFitPadding()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconImage() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconImage()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconRotate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconRotate()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconPadding() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconPadding()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconKeepUpright() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconKeepUpright()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconOffset() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconOffset()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextPitchAlignment() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextPitchAlignment()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextRotationAlignment() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextRotationAlignment()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextField() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextField()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextFont() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextFont()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextSize() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextSize()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextMaxWidth() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextMaxWidth()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextLineHeight() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextLineHeight()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextLetterSpacing() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextLetterSpacing()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextJustify() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextJustify()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextAnchor()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextMaxAngle() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextMaxAngle()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextRotate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextRotate()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextPadding() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextPadding()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextKeepUpright() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextKeepUpright()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextTransform() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextTransform()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextOffset() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextOffset()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextAllowOverlap() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextAllowOverlap()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextIgnorePlacement() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextIgnorePlacement()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextOptional() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextOptional()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconColor()); } + /** + * The color of the icon. This can only be used with sdf icons. + * @throws RuntimeException + */ + @ColorInt + public int getIconColorAsInt() { + checkValidity(); + PropertyValue value = getIconColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("icon-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getIconHaloColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconHaloColor()); } + /** + * The color of the icon's halo. Icon halos can only be used with sdf icons. + * @throws RuntimeException + */ + @ColorInt + public int getIconHaloColorAsInt() { + checkValidity(); + PropertyValue value = getIconHaloColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("icon-halo-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getIconHaloWidth() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconHaloWidth()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconHaloBlur() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconHaloBlur()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconTranslate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconTranslate()); } - + @SuppressWarnings("unchecked") public PropertyValue getIconTranslateAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetIconTranslateAnchor()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextOpacity() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextOpacity()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextColor()); } + /** + * The color with which the text will be drawn. + * @throws RuntimeException + */ + @ColorInt + public int getTextColorAsInt() { + checkValidity(); + PropertyValue value = getTextColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("text-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getTextHaloColor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextHaloColor()); } + /** + * The color of the text's halo, which helps it stand out from backgrounds. + * @throws RuntimeException + */ + @ColorInt + public int getTextHaloColorAsInt() { + checkValidity(); + PropertyValue value = getTextHaloColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("text-halo-color was set as a Function"); + } + } + @SuppressWarnings("unchecked") public PropertyValue getTextHaloWidth() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextHaloWidth()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextHaloBlur() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextHaloBlur()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextTranslate() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextTranslate()); } - + @SuppressWarnings("unchecked") public PropertyValue getTextTranslateAnchor() { checkValidity(); return (PropertyValue) new PropertyValue(nativeGetTextTranslateAnchor()); } - + private native Object nativeGetSymbolPlacement(); private native Object nativeGetSymbolSpacing(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 79bf98d389..00d9f09124 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -5,6 +5,13 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; + +import static com.mapbox.mapboxsdk.utils.ColorUtils.*; + /** * <%- camelize(type) %> Layer */ @@ -31,6 +38,11 @@ public class <%- camelize(type) %>Layer extends Layer { checkValidity(); nativeSetSourceLayer(sourceLayer); } + + public <%- camelize(type) %>Layer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } <% } -%> <% if (type !== 'background' && type !== 'raster') { -%> @@ -44,8 +56,23 @@ public class <%- camelize(type) %>Layer extends Layer { nativeSetFilter(filter); } + public <%- camelize(type) %>Layer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } + <% } -%> + public <%- camelize(type) %>Layer withProperties(@NonNull Property... properties) { + setProperties(properties); + return this; + } + // Property getters <% for (const property of properties) { -%> @@ -54,6 +81,23 @@ public class <%- camelize(type) %>Layer extends Layer { checkValidity(); return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue(nativeGet<%- camelize(property.name) %>()); } + <% if (property.type == 'color') { -%> + /** + * <%- property.doc %> + * @throws RuntimeException + */ + @ColorInt + public int get<%- camelize(property.name) %>AsInt() { + checkValidity(); + PropertyValue<<%- propertyType(property) %>> value = get<%- camelize(property.name) %>(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("<%- property.name %> was set as a Function"); + } + } + + <% } -%> <% } -%> <% for (const property of properties) { -%> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index f1399daf12..fc7928015e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -3,12 +3,27 @@ package com.mapbox.mapboxsdk.style.sources; import java.net.URL; import java.util.HashMap; +/** + * A GeoJson source. + * + * @see the style specification + */ public class GeoJsonSource extends Source { public static final String TYPE = "geojson"; private static final String DATA_KEY = "data"; + /** + * Create a GeoJsonSource from a raw json string + * + * @param id the source id + * @param geoJson raw Json body + */ public GeoJsonSource(String id, String geoJson) { super(id, TYPE); + if (geoJson == null || geoJson.startsWith("http")) { + throw new IllegalArgumentException("Expected a raw json body"); + } + //Wrap the String in a map as an Object is expected by the //style conversion template HashMap wrapper = new HashMap<>(); @@ -16,6 +31,12 @@ public class GeoJsonSource extends Source { this.put(DATA_KEY, wrapper); } + /** + * Create a GeoJsonSource from a remote geo json file + * + * @param id the source id + * @param url remote json file + */ public GeoJsonSource(String id, URL url) { super(id, TYPE); this.put(DATA_KEY, url.toExternalForm()); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index df3b73368c..381294083a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -2,19 +2,42 @@ package com.mapbox.mapboxsdk.style.sources; import java.net.URL; +/** + * A vector source. + * + * @see the style specification + */ public class VectorSource extends Source { public static final String TYPE = "vector"; private static final String URL_KEY = "url"; + /** + * Create a vector source from a remote url + * + * @param id the source id + * @param url the url + */ public VectorSource(String id, URL url) { this(id, url.toExternalForm()); } + /** + * Create a vector source from a remote url + * + * @param id the source id + * @param url the url + */ public VectorSource(String id, String url) { super(id, TYPE); this.put(URL_KEY, url); } + /** + * Create a vector source from a tilset + * + * @param id the source id + * @param tileSet the tileset + */ public VectorSource(String id, TileSet tileSet) { super(id, TYPE); this.putAll(tileSet.toValueObject()); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java index a0de07c5f1..ef404840e8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.utils; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; @@ -11,6 +12,10 @@ import android.util.TypedValue; import android.widget.ImageView; import com.mapbox.mapboxsdk.R; +import com.mapbox.mapboxsdk.exceptions.ConversionException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ColorUtils { @@ -87,4 +92,26 @@ public class ColorUtils { Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); DrawableCompat.setTintList(wrappedDrawable, getSelector(tintColor)); } + + static int normalizeColorComponent(String value) { + return (int) (Float.parseFloat(value) * 255); + } + + /** + * Convert an rgba string to a Color int + * + * @throws ConversionException on illegal input + */ + @ColorInt + public static int rgbaToColor(String value) { + Pattern c = Pattern.compile("rgba?\\s*\\(\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*,?\\s*(\\d+\\.?\\d*)?\\s*\\)"); + Matcher m = c.matcher(value); + if (m.matches() && m.groupCount() == 3) { + return Color.rgb(normalizeColorComponent(m.group(1)), normalizeColorComponent(m.group(2)), normalizeColorComponent(m.group(3))); + } else if (m.matches() && m.groupCount() == 4) { + return Color.argb(normalizeColorComponent(m.group(4)), normalizeColorComponent(m.group(1)), normalizeColorComponent(m.group(2)), normalizeColorComponent(m.group(3))); + } else { + throw new ConversionException("Not a valid rgb/rgba value"); + } + } } \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java index 1880d46ef3..009e07b00e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -85,6 +86,22 @@ public class BackgroundLayerTest extends BaseTest { assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testBackgroundColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + Log.i(TAG, "Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); + Log.i(TAG, "background-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(backgroundColor(Color.RED)); + assertEquals(layer.getBackgroundColorAsInt(), Color.RED); + } + @Test public void testBackgroundPattern() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java index 174c218a74..51d0cd94b1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -114,6 +115,28 @@ public class CircleLayerTest extends BaseTest { assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testCircleColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new CircleLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "circle-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(circleColor(Color.RED)); + assertEquals(layer.getCircleColorAsInt(), Color.RED); + } + @Test public void testCircleBlur() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java index 592eaa6c98..0773e28ae9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -146,6 +147,28 @@ public class FillLayerTest extends BaseTest { assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testFillColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new FillLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "fill-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(fillColor(Color.RED)); + assertEquals(layer.getFillColorAsInt(), Color.RED); + } + @Test public void testFillOutlineColor() { checkViewIsDisplayed(R.id.mapView); @@ -168,6 +191,28 @@ public class FillLayerTest extends BaseTest { assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testFillOutlineColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new FillLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "fill-outline-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(fillOutlineColor(Color.RED)); + assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); + } + @Test public void testFillTranslate() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java index f4e0a1d929..5fee78bc63 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -221,6 +222,28 @@ public class LineLayerTest extends BaseTest { assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testLineColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new LineLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "line-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(lineColor(Color.RED)); + assertEquals(layer.getLineColorAsInt(), Color.RED); + } + @Test public void testLineTranslate() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java index 48d6d355f5..a40127148b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java index ef067c6ad9..3b860866a5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java @@ -1,6 +1,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -922,6 +923,28 @@ public class SymbolLayerTest extends BaseTest { assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testIconColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new SymbolLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "icon-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(iconColor(Color.RED)); + assertEquals(layer.getIconColorAsInt(), Color.RED); + } + @Test public void testIconHaloColor() { checkViewIsDisplayed(R.id.mapView); @@ -944,6 +967,28 @@ public class SymbolLayerTest extends BaseTest { assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testIconHaloColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new SymbolLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "icon-halo-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(iconHaloColor(Color.RED)); + assertEquals(layer.getIconHaloColorAsInt(), Color.RED); + } + @Test public void testIconHaloWidth() { checkViewIsDisplayed(R.id.mapView); @@ -1076,6 +1121,28 @@ public class SymbolLayerTest extends BaseTest { assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testTextColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new SymbolLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "text-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(textColor(Color.RED)); + assertEquals(layer.getTextColorAsInt(), Color.RED); + } + @Test public void testTextHaloColor() { checkViewIsDisplayed(R.id.mapView); @@ -1098,6 +1165,28 @@ public class SymbolLayerTest extends BaseTest { assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); } + @Test + public void testTextHaloColorAsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new SymbolLayer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } + Log.i(TAG, "text-halo-color"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(textHaloColor(Color.RED)); + assertEquals(layer.getTextHaloColorAsInt(), Color.RED); + } + @Test public void testTextHaloWidth() { checkViewIsDisplayed(R.id.mapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs index 21106f3a33..115a27832b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs @@ -5,6 +5,7 @@ // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. package com.mapbox.mapboxsdk.style; +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; @@ -106,6 +107,35 @@ public class <%- camelize(type) %>LayerTest extends BaseTest { layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)); assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>); } +<% if (property.type == 'color') { -%> + + @Test + public void test<%- camelize(property.name) %>AsInt() { + checkViewIsDisplayed(R.id.mapView); + + mapboxMap = rule.getActivity().getMapboxMap(); + +<% if (type === 'background') { -%> + Log.i(TAG, "Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); +<% } else { -%> + if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { + Log.i(TAG, "Adding layer"); + layer = new <%- camelize(type) %>Layer("my-layer", "composite"); + layer.setSourceLayer("composite"); + mapboxMap.addLayer(layer); + //Layer reference is now stale, get new reference + layer = mapboxMap.getLayerAs("my-layer"); + } +<% } -%> + Log.i(TAG, "<%- property.name %>"); + assertNotNull(layer); + + //Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); + assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); + } +<% } -%> <% } -%> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java index b104f9ea03..4e0f5f8c41 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java @@ -345,9 +345,10 @@ public class RuntimeStyleActivity extends AppCompatActivity { mapboxMap.addSource(source); //Add a layer - FillLayer layer = new FillLayer("custom-tile-layers", "custom-tile-source"); - layer.setSourceLayer("water"); - mapboxMap.addLayer(layer); + mapboxMap.addLayer( + new FillLayer("custom-tile-layers", "custom-tile-source") + .withSourceLayer("water") + ); } private static class DefaultCallback implements MapboxMap.CancelableCallback { -- cgit v1.2.1