[android] expose Formatted text-field setter
This commit is contained in:
committed by
Łukasz Paczos
parent
1e7c7e0489
commit
794b851f02
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -2134,6 +2135,16 @@ public class PropertyFactory {
|
||||
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<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.
|
||||
*
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -14,21 +14,12 @@ 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
|
||||
*/
|
||||
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) {
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user