[android] removing plain text getter for "text-field"
This commit is contained in:
committed by
Łukasz Paczos
parent
1d73bda00d
commit
9ac444a08d
@@ -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);
|
||||
|
||||
@@ -388,41 +388,11 @@ public class SymbolLayer extends Layer {
|
||||
/**
|
||||
* Get the TextField property
|
||||
*
|
||||
* @return property wrapper value around String
|
||||
* @return property wrapper value around Formatted
|
||||
*/
|
||||
@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...)
|
||||
*/
|
||||
@NonNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public PropertyValue<Formatted> getFormattedTextField() {
|
||||
public PropertyValue<Formatted> getTextField() {
|
||||
checkThread();
|
||||
return (PropertyValue<Formatted>) new PropertyValue("text-field", nativeGetTextField());
|
||||
}
|
||||
|
||||
@@ -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') { -%>
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -15,12 +14,20 @@ import java.util.Arrays;
|
||||
public class Formatted {
|
||||
private final FormattedSection[] formattedSections;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user