[android] #5858 - added convenience methods for color properties

This commit is contained in:
Ivo van Dongen
2016-08-03 16:03:03 -04:00
parent f94c979886
commit 52cb6122f8
19 changed files with 718 additions and 80 deletions

View File

@@ -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);
}
}

View File

@@ -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<String>) new PropertyValue(nativeGetBackgroundColor());
}
/**
* The color with which the background will be drawn.
* @throws RuntimeException
*/
@ColorInt
public int getBackgroundColorAsInt() {
checkValidity();
PropertyValue<String> value = getBackgroundColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("background-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundPattern());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getBackgroundOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetBackgroundOpacity());
}
private native Object nativeGetBackgroundColor();
private native Object nativeGetBackgroundPattern();

View File

@@ -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<Float>) new PropertyValue(nativeGetCircleRadius());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleColor());
}
/**
* The color of the circle.
* @throws RuntimeException
*/
@ColorInt
public int getCircleColorAsInt() {
checkValidity();
PropertyValue<String> value = getCircleColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("circle-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleBlur());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getCircleTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetCircleTranslate());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleTranslateAnchor());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchScale() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCirclePitchScale());
}
private native Object nativeGetCircleRadius();
private native Object nativeGetCircleColor();

View File

@@ -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<Boolean>) new PropertyValue(nativeGetFillAntialias());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetFillOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillColor() {
checkValidity();
return (PropertyValue<String>) 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<String> value = getFillColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("fill-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillOutlineColor() {
checkValidity();
return (PropertyValue<String>) 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<String> 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<Float[]> getFillTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetFillTranslate());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillTranslateAnchor());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillPattern());
}
private native Object nativeGetFillAntialias();
private native Object nativeGetFillOpacity();

View File

@@ -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<String>) new PropertyValue(nativeGetLineCap());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineJoin() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineJoin());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineMiterLimit() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineMiterLimit());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineRoundLimit() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineRoundLimit());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineColor());
}
/**
* The color with which the line will be drawn.
* @throws RuntimeException
*/
@ColorInt
public int getLineColorAsInt() {
checkValidity();
PropertyValue<String> value = getLineColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("line-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetLineTranslate());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineTranslateAnchor());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineWidth());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineGapWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineGapWidth());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOffset() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineOffset());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineBlur());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineDasharray() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetLineDasharray());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getLinePattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLinePattern());
}
private native Object nativeGetLineCap();
private native Object nativeGetLineJoin();

View File

@@ -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<Float>) new PropertyValue(nativeGetRasterOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterHueRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterHueRotate());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMin() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterBrightnessMin());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMax() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterBrightnessMax());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterSaturation() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterSaturation());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterContrast() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterContrast());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterFadeDuration() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterFadeDuration());
}
private native Object nativeGetRasterOpacity();
private native Object nativeGetRasterHueRotate();

View File

@@ -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<String>) new PropertyValue(nativeGetSymbolPlacement());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getSymbolSpacing() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetSymbolSpacing());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getSymbolAvoidEdges() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetSymbolAvoidEdges());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconAllowOverlap() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconAllowOverlap());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconIgnorePlacement() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconIgnorePlacement());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconOptional() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconOptional());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconRotationAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconRotationAlignment());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconSize() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconSize());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTextFit() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconTextFit());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTextFitPadding() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconTextFitPadding());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconImage() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconImage());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconRotate());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconPadding() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconPadding());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconKeepUpright() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconKeepUpright());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconOffset() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconOffset());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextPitchAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextPitchAlignment());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextRotationAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextRotationAlignment());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextField() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextField());
}
@SuppressWarnings("unchecked")
public PropertyValue<String[]> getTextFont() {
checkValidity();
return (PropertyValue<String[]>) new PropertyValue(nativeGetTextFont());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextSize() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextSize());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextMaxWidth());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLineHeight() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextLineHeight());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLetterSpacing() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextLetterSpacing());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextJustify() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextJustify());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextAnchor());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxAngle() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextMaxAngle());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextRotate());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextPadding() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextPadding());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextKeepUpright() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextKeepUpright());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTransform() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextTransform());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextOffset() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetTextOffset());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextAllowOverlap() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextAllowOverlap());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextIgnorePlacement() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextIgnorePlacement());
}
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextOptional() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextOptional());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconColor());
}
/**
* The color of the icon. This can only be used with sdf icons.
* @throws RuntimeException
*/
@ColorInt
public int getIconColorAsInt() {
checkValidity();
PropertyValue<String> value = getIconColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("icon-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconHaloColor() {
checkValidity();
return (PropertyValue<String>) 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<String> 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<Float> getIconHaloWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconHaloWidth());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconHaloBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconHaloBlur());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconTranslate());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconTranslateAnchor());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextOpacity());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextColor());
}
/**
* The color with which the text will be drawn.
* @throws RuntimeException
*/
@ColorInt
public int getTextColorAsInt() {
checkValidity();
PropertyValue<String> value = getTextColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("text-color was set as a Function");
}
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextHaloColor() {
checkValidity();
return (PropertyValue<String>) 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<String> 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<Float> getTextHaloWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextHaloWidth());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextHaloBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextHaloBlur());
}
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetTextTranslate());
}
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextTranslateAnchor());
}
private native Object nativeGetSymbolPlacement();
private native Object nativeGetSymbolSpacing();

View File

@@ -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) { -%>

View File

@@ -3,12 +3,27 @@ package com.mapbox.mapboxsdk.style.sources;
import java.net.URL;
import java.util.HashMap;
/**
* A GeoJson source.
*
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">the style specification</a>
*/
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<String, String> 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());

View File

@@ -2,19 +2,42 @@ package com.mapbox.mapboxsdk.style.sources;
import java.net.URL;
/**
* A vector source.
*
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-vector">the style specification</a>
*/
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());

View File

@@ -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");
}
}
}