diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-11-13 18:29:25 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-12-04 17:22:38 +0100 |
commit | 794b851f02b98c5f1652edc141b1a6feb459d59b (patch) | |
tree | 66fda491ea0a100d3a45092ce2840d590fc7fefa /platform/android/MapboxGLAndroidSDK | |
parent | 1e7c7e048991a33167d5fb40f6c9ea2a44885104 (diff) | |
download | qtlocation-mapboxgl-794b851f02b98c5f1652edc141b1a6feb459d59b.tar.gz |
[android] expose Formatted text-field setter
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
5 files changed, 39 insertions, 15 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index e370a366f5..72591196d4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -2,10 +2,11 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.Keep; import android.support.annotation.NonNull; - import android.support.annotation.Nullable; + import com.google.gson.JsonElement; import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.types.Formatted; import com.mapbox.mapboxsdk.utils.ThreadUtils; /** @@ -137,9 +138,12 @@ public abstract class Layer { @Nullable private Object convertValue(@Nullable Object value) { - if (value != null && value instanceof Expression) { + if (value instanceof Expression) { return ((Expression) value).toArray(); + } else if (value instanceof Formatted) { + return ((Formatted) value).toArray(); + } else { + return value; } - return value; } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 51edca3002..3d8b921a79 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -5,6 +5,7 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.types.Formatted; import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString; /** @@ -2140,6 +2141,16 @@ public class PropertyFactory { * @param value a Formatted value * @return property wrapper around Formatted */ + public static PropertyValue<Formatted> textField(Formatted value) { + return new LayoutPropertyValue<>("text-field", value); + } + + /** + * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options. + * + * @param value a Formatted value + * @return property wrapper around Formatted + */ public static PropertyValue<Expression> textField(Expression value) { return new LayoutPropertyValue<>("text-field", value); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs index 7474e7ebb8..f4b171489a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs @@ -9,6 +9,7 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import com.mapbox.mapboxsdk.style.expressions.Expression; +import com.mapbox.mapboxsdk.style.types.Formatted; import static com.mapbox.mapboxsdk.utils.ColorUtils.colorToRgbaString; /** @@ -73,7 +74,8 @@ public class PropertyFactory { public static PropertyValue<String> <%- camelizeWithLeadingLowercase(property.name) %>(String value) { return new LayoutPropertyValue<>("<%- property.name %>", value); } -<% } else {-%> + +<% } -%> /** * <%- propertyFactoryMethodDoc(property) %> * @@ -83,7 +85,6 @@ public class PropertyFactory { public static PropertyValue<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) { return new LayoutPropertyValue<>("<%- property.name %>", value); } -<% } -%> /** * <%- propertyFactoryMethodDoc(property) %> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java index 9be08dcebd..fb2d361bfc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/Formatted.java @@ -17,18 +17,9 @@ public class Formatted { /** * Create a new formatted text. * - * @param formattedSection section with formatting options - */ - public Formatted(FormattedSection formattedSection) { - this(new FormattedSection[] {formattedSection}); - } - - /** - * Create a new formatted text. - * * @param formattedSections sections with formatting options */ - public Formatted(FormattedSection[] formattedSections) { + public Formatted(FormattedSection... formattedSections) { this.formattedSections = formattedSections; } @@ -41,6 +32,14 @@ public class Formatted { return formattedSections; } + public Object[] toArray() { + Object[] sections = new Object[formattedSections.length]; + for (int i = 0; i < formattedSections.length; i++) { + sections[i] = formattedSections[i].toArray(); + } + return sections; + } + @Override public boolean equals(@Nullable Object o) { if (this == o) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java index 7d0caec992..c96a104afd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java @@ -5,6 +5,8 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; /** * A component of the {@link Formatted}. @@ -117,4 +119,11 @@ public class FormattedSection { result = 31 * result + Arrays.hashCode(fontStack); return result; } + + Object[] toArray() { + Map<String, Object> params = new HashMap<>(); + params.put("font-scale", fontScale); + params.put("text-font", fontStack); + return new Object[] {text, params}; + } } |