summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java126
1 files changed, 114 insertions, 12 deletions
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 c96a104afd..a5b0dfbfe8 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
@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.style.types;
+import android.support.annotation.ColorInt;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import com.mapbox.mapboxsdk.utils.ColorUtils;
+
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -13,9 +16,19 @@ import java.util.Map;
*/
@Keep
public class FormattedSection {
- private final String text;
- private final Number fontScale;
- private final String[] fontStack;
+ private String text;
+ private Number fontScale;
+ private String[] fontStack;
+ private String textColor;
+
+ /**
+ * Creates a formatted section.
+ *
+ * @param text displayed string
+ */
+ public FormattedSection(@NonNull String text) {
+ this(text, null, null, null);
+ }
/**
* Creates a formatted section.
@@ -23,12 +36,23 @@ public class FormattedSection {
* @param text displayed string
* @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
+ * setting null will fall back to style's default settings.
+ * The requested font stack has to be a part of the used style.
+ * For more information see
+ * <a href="https://www.mapbox.com/help/define-font-stack/">the documentation</a>.
+ * @param textColor text color, setting to null will fall back to style's default settings.
+ * Value of red, green, blue components must range between 0 and 255,
+ * an alpha component must range between 0 and 1.
+ * <p>
+ * For more information see
+ * <a href="https://docs.mapbox.com/mapbox-gl-js/style-spec/#types-color">the documentation</a>.
*/
- public FormattedSection(@NonNull String text, @Nullable Number fontScale, @Nullable String[] fontStack) {
+ public FormattedSection(@NonNull String text, @Nullable Number fontScale, @Nullable String[] fontStack,
+ @Nullable String textColor) {
this.text = text;
this.fontScale = fontScale;
this.fontStack = fontStack;
+ this.textColor = textColor;
}
/**
@@ -36,18 +60,27 @@ public class FormattedSection {
*
* @param text displayed string
* @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
+ * @deprecated use {@link #FormattedSection(String)} and setters
+ * or {@link #FormattedSection(String, Number, String[], String)} instead
*/
- public FormattedSection(@NonNull String text, @Nullable Number fontScale) {
- this(text, fontScale, null);
+ @Deprecated
+ public FormattedSection(@NonNull String text, @Nullable Number fontScale, @Nullable String[] fontStack) {
+ this(text, fontScale, fontStack, null);
}
/**
* Creates a formatted section.
*
- * @param text displayed string
+ * @param text displayed string
+ * @param fontScale scale of the font, setting to null will fall back to style's default settings
+ * @deprecated use {@link #FormattedSection(String)} and setters
+ * or {@link #FormattedSection(String, Number, String[], String)} instead
*/
- public FormattedSection(@NonNull String text) {
- this(text, null, null);
+ @Deprecated
+ public FormattedSection(@NonNull String text, @Nullable Number fontScale) {
+ this(text, fontScale, null, null);
}
/**
@@ -56,9 +89,12 @@ public class FormattedSection {
* @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
+ * @deprecated use {@link #FormattedSection(String)} and setters
+ * or {@link #FormattedSection(String, Number, String[], String)} instead
*/
+ @Deprecated
public FormattedSection(@NonNull String text, @Nullable String[] fontStack) {
- this(text, null, fontStack);
+ this(text, null, fontStack, null);
}
/**
@@ -91,6 +127,67 @@ public class FormattedSection {
return fontStack;
}
+ /**
+ * Returns the text color.
+ *
+ * @return text color
+ */
+ public String getTextColor() {
+ return textColor;
+ }
+
+ /**
+ * Set font scale. Setting to null will fall back to style's default settings.
+ *
+ * @param fontScale fontScale
+ */
+ public void setFontScale(@Nullable Number fontScale) {
+ // called from JNI
+ this.fontScale = fontScale;
+ }
+
+ /**
+ * Set main and fallback fonts that are a part of the style. Setting null will fall back to style's default settings.
+ * <p>
+ * The requested font stack has to be a part of the used style.
+ * For more information see <a href="https://www.mapbox.com/help/define-font-stack/">the documentation</a>.
+ *
+ * @param fontStack fontStack
+ */
+ public void setFontStack(@Nullable String[] fontStack) {
+ // called from JNI
+ this.fontStack = fontStack;
+ }
+
+ /**
+ * Set text color. Setting to null will fall back to style's default settings.
+ * Value of red, green, blue components must range between 0 and 255,
+ * an alpha component must range between 0 and 1.
+ * <p>
+ * For more information see
+ * <a href="https://docs.mapbox.com/mapbox-gl-js/style-spec/#types-color">the documentation</a>.
+ *
+ * @param textColor text color
+ */
+ public void setTextColor(@Nullable String textColor) {
+ this.textColor = textColor;
+ }
+
+ /**
+ * Set the text color.
+ *
+ * @param textColor text color.
+ */
+ public void setTextColor(@ColorInt int textColor) {
+ this.textColor = ColorUtils.colorToRgbaString(textColor);
+ }
+
+ void setTextColor(@NonNull Object textColor) {
+ // called from JNI
+ // because core is returning R, G and B components in range of 0 to 1, we need to convert them to be in 0 to 255.
+ setTextColor(ColorUtils.colorToRgbaString(ColorUtils.rgbaToColor((String) textColor)));
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -109,7 +206,10 @@ public class FormattedSection {
return false;
}
// Probably incorrect - comparing Object[] arrays with Arrays.equals
- return Arrays.equals(fontStack, that.fontStack);
+ if (!Arrays.equals(fontStack, that.fontStack)) {
+ return false;
+ }
+ return textColor != null ? textColor.equals(that.textColor) : that.textColor == null;
}
@Override
@@ -117,6 +217,7 @@ public class FormattedSection {
int result = text != null ? text.hashCode() : 0;
result = 31 * result + (fontScale != null ? fontScale.hashCode() : 0);
result = 31 * result + Arrays.hashCode(fontStack);
+ result = 31 * result + (textColor != null ? textColor.hashCode() : 0);
return result;
}
@@ -124,6 +225,7 @@ public class FormattedSection {
Map<String, Object> params = new HashMap<>();
params.put("font-scale", fontScale);
params.put("text-font", fontStack);
+ params.put("text-color", textColor);
return new Object[] {text, params};
}
}