diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-11-07 17:17:26 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-11-20 12:22:16 +0100 |
commit | 9ac444a08d9701dc7b0da41859842a77d7be8e00 (patch) | |
tree | 08ab99d6caa7a24a9106382eedcc5812bf2c1811 /platform/android/MapboxGLAndroidSDK/src/main/java | |
parent | 1d73bda00d1e4c18ef32eac5053afa4cc9bc4b0a (diff) | |
download | qtlocation-mapboxgl-9ac444a08d9701dc7b0da41859842a77d7be8e00.tar.gz |
[android] removing plain text getter for "text-field"
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java')
6 files changed, 70 insertions, 98 deletions
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 bf5fd35fa5..ace5be3a82 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 @@ -2117,8 +2117,8 @@ public class PropertyFactory { /** * 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 String value - * @return property wrapper around String + * @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/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index 25c0a2bb32..ab45cb04f2 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 @@ -388,41 +388,11 @@ public class SymbolLayer extends Layer { /** * Get the TextField property * - * @return property wrapper value around String - */ - @NonNull - @SuppressWarnings("unchecked") - public PropertyValue<String> getTextField() { - checkThread(); - - PropertyValue propertyValue = new PropertyValue<>("text-field", nativeGetTextField()); - if (propertyValue.isExpression()) { - return (PropertyValue<String>) propertyValue; - } else { - String text = null; - - Formatted formatted = (Formatted) nativeGetTextField(); - if (formatted != null) { - StringBuilder builder = new StringBuilder(); - for (FormattedSection section : formatted.getFormattedSections()) { - builder.append(section.getText()); - } - text = builder.toString(); - } - - return (PropertyValue<String>) new PropertyValue("text-field", text); - } - } - - /** - * Get the TextField property as {@link Formatted} object - * - * @return property wrapper value around String - * @see Expression#format(Expression.FormatEntry...) + * @return property wrapper value around Formatted */ @NonNull @SuppressWarnings("unchecked") - public PropertyValue<Formatted> getFormattedTextField() { + public PropertyValue<Formatted> getTextField() { checkThread(); return (PropertyValue<Formatted>) new PropertyValue("text-field", nativeGetTextField()); } 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 60bbe941a6..e62c82e3b6 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 @@ -182,44 +182,8 @@ public class <%- camelize(type) %>Layer extends Layer { @SuppressWarnings("unchecked") public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() { checkThread(); -<% if (property.name === 'text-field' && property.type === 'formatted') { -%> - - PropertyValue propertyValue = new PropertyValue<>("text-field", nativeGetTextField()); - if (propertyValue.isExpression()) { - return (PropertyValue<String>) propertyValue; - } else { - String text = null; - - Formatted formatted = (Formatted) nativeGetTextField(); - if (formatted != null) { - StringBuilder builder = new StringBuilder(); - for (FormattedSection section : formatted.getFormattedSections()) { - builder.append(section.getText()); - } - text = builder.toString(); - } - - return (PropertyValue<String>) new PropertyValue("text-field", text); - } -<% } else { -%> return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); -<% } -%> } -<% if (property.name === 'text-field' && property.type === 'formatted') { -%> - - /** - * Get the <%- camelize(property.name) %> property as {@link Formatted} object - * - * @return property wrapper value around <%- propertyType(property) %> - * @see Expression#format(Expression.FormatEntry...) - */ - @NonNull - @SuppressWarnings("unchecked") - public PropertyValue<Formatted> getFormatted<%- camelize(property.name) %>() { - checkThread(); - return (PropertyValue<Formatted>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); - } -<% } -%> <% if (property.type == 'color') { -%> /** 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 697021b2d5..7474e7ebb8 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 @@ -63,6 +63,17 @@ public class PropertyFactory { <% } -%> <% for (const property of layoutProperties) { -%> +<% if (property.type === 'formatted') { -%> + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> <%- camelizeWithLeadingLowercase(property.name) %>(String value) { + return new LayoutPropertyValue<>("<%- property.name %>", value); + } +<% } else {-%> /** * <%- propertyFactoryMethodDoc(property) %> * @@ -72,6 +83,7 @@ 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 662ab2df7f..9be08dcebd 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 @@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.style.types; import android.support.annotation.Keep; import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; import java.util.Arrays; @@ -18,9 +17,17 @@ 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 */ - @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) public Formatted(FormattedSection[] formattedSections) { this.formattedSections = formattedSections; } 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 3a9802ebcd..7d0caec992 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 @@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.style.types; import android.support.annotation.Keep; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; import java.util.Arrays; @@ -12,20 +11,19 @@ import java.util.Arrays; */ @Keep public class FormattedSection { - private String text; - private double fontScale; - @Nullable - private String[] fontStack; + private final String text; + private final Number fontScale; + private final String[] fontStack; /** * Creates a formatted section. * * @param text displayed string - * @param fontScale scale of the font, 1.0 is default - * @param fontStack main and fallback fonts that are a part of the style + * @param fontScale scale of the font, setting to null will fall back to style's default settings + * @param fontStack main and fallback fonts that are a part of the style, + * setting null will fall back to style's default settings */ - @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) - public FormattedSection(@NonNull String text, double fontScale, @Nullable String[] fontStack) { + public FormattedSection(@NonNull String text, @Nullable Number fontScale, @Nullable String[] fontStack) { this.text = text; this.fontScale = fontScale; this.fontStack = fontStack; @@ -35,12 +33,30 @@ public class FormattedSection { * Creates a formatted section. * * @param text displayed string - * @param fontScale scale of the font, 1.0 is default + * @param fontScale scale of the font, setting to null will fall back to style's default settings */ - @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) - public FormattedSection(@NonNull String text, double fontScale) { - this.text = text; - this.fontScale = fontScale; + public FormattedSection(@NonNull String text, @Nullable Number fontScale) { + this(text, fontScale, null); + } + + /** + * Creates a formatted section. + * + * @param text displayed string + */ + public FormattedSection(@NonNull String text) { + this(text, null, null); + } + + /** + * Creates a formatted section. + * + * @param text displayed string + * @param fontStack main and fallback fonts that are a part of the style, + * setting null will fall back to style's default settings + */ + public FormattedSection(@NonNull String text, @Nullable String[] fontStack) { + this(text, null, fontStack); } /** @@ -56,9 +72,10 @@ public class FormattedSection { /** * Returns displayed text's font scale. * - * @return font scale, defaults to 1.0 + * @return font scale */ - public double getFontScale() { + @Nullable + public Number getFontScale() { return fontScale; } @@ -73,7 +90,7 @@ public class FormattedSection { } @Override - public boolean equals(@Nullable Object o) { + public boolean equals(Object o) { if (this == o) { return true; } @@ -81,20 +98,22 @@ public class FormattedSection { return false; } - FormattedSection section = (FormattedSection) o; + FormattedSection that = (FormattedSection) o; - return Double.compare(section.fontScale, fontScale) == 0 - && (text != null ? text.equals(section.text) : section.text == null) - && Arrays.equals(fontStack, section.fontStack); + if (text != null ? !text.equals(that.text) : that.text != null) { + return false; + } + if (fontScale != null ? !fontScale.equals(that.fontScale) : that.fontScale != null) { + return false; + } + // Probably incorrect - comparing Object[] arrays with Arrays.equals + return Arrays.equals(fontStack, that.fontStack); } @Override public int hashCode() { - int result; - long temp; - result = text != null ? text.hashCode() : 0; - temp = Double.doubleToLongBits(fontScale); - result = 31 * result + (int) (temp ^ (temp >>> 32)); + int result = text != null ? text.hashCode() : 0; + result = 31 * result + (fontScale != null ? fontScale.hashCode() : 0); result = 31 * result + Arrays.hashCode(fontStack); return result; } |