diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-09-28 09:05:41 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-10-24 13:35:36 +0200 |
commit | 12b496945498358b7afb4af1efe4ae0c52b9c7d3 (patch) | |
tree | c4d4c31cbccfb39bcc8a4fd6a2a09f627173a56b /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java | |
parent | 78a1c30e80c70f36ffec8193753919277418a3ca (diff) | |
download | qtlocation-mapboxgl-12b496945498358b7afb4af1efe4ae0c52b9c7d3.tar.gz |
[android] "format" expression support
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.java | 100 |
1 files changed, 100 insertions, 0 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 new file mode 100644 index 0000000000..b3c36414cc --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java @@ -0,0 +1,100 @@ +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; + +/** + * A component of the {@link Formatted}. + */ +@Keep +public class FormattedSection { + private String text; + private double fontScale; + private 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 + */ + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + public FormattedSection(@NonNull String text, double fontScale, @Nullable String[] fontStack) { + this.text = text; + this.fontScale = fontScale; + this.fontStack = fontStack; + } + + /** + * Creates a formatted section. + * + * @param text displayed string + * @param fontScale scale of the font, 1.0 is default + */ + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + public FormattedSection(@NonNull String text, double fontScale) { + this.text = text; + this.fontScale = fontScale; + } + + /** + * Returns the displayed text. + * + * @return text + */ + @NonNull + public String getText() { + return text; + } + + /** + * Returns displayed text's font scale. + * + * @return font scale, defaults to 1.0 + */ + public double getFontScale() { + return fontScale; + } + + /** + * Returns the font stack with main and fallback fonts. + * + * @return font stack + */ + @Nullable + public String[] getFontStack() { + return fontStack; + } + + @Override + public boolean equals(@Nullable Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + FormattedSection section = (FormattedSection) o; + + return Double.compare(section.fontScale, fontScale) == 0 + && (text != null ? text.equals(section.text) : section.text == null) + && Arrays.equals(fontStack, section.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)); + result = 31 * result + Arrays.hashCode(fontStack); + return result; + } +} |