diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-03-26 12:49:33 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-05-22 16:32:04 +0200 |
commit | b21f9f3e35a60fc31fe20b23e7eb71155ab8027a (patch) | |
tree | ee1dbb8bc37d0dfe2880474f6eebd7816917c9e8 /platform/android/MapboxGLAndroidSDK/src/main/java/com | |
parent | 4224b89a9cf624f08bf96d36702c8b8d8de6554f (diff) | |
download | qtlocation-mapboxgl-b21f9f3e35a60fc31fe20b23e7eb71155ab8027a.tar.gz |
[android] return color string values in the [0-255] range
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
2 files changed, 10 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 859fcff378..f553b0433a 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 @@ -184,8 +184,7 @@ public class FormattedSection { 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))); + setTextColor((String) textColor); } @Override diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java index 0c5786fda4..ab3d68547e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java @@ -10,6 +10,7 @@ import android.support.annotation.NonNull; import android.support.v4.widget.ImageViewCompat; import android.util.TypedValue; import android.widget.ImageView; + import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.exceptions.ConversionException; @@ -111,12 +112,11 @@ public class ColorUtils { ImageViewCompat.setImageTintList(imageView, getSelector(tintColor)); } - private static int normalizeColorComponent(String value) { - return (int) (Float.parseFloat(value) * 255); - } - /** * Convert an rgba string to a Color int. + * <p> + * R, G, B color components have to be in the [0-255] range, while alpha has to be in the [0.0-1.0] range. + * For example: "rgba(255, 128, 0, 0.7)". * * @param value the String representation of rgba * @return the int representation of rgba @@ -124,15 +124,14 @@ public class ColorUtils { */ @ColorInt public static int rgbaToColor(@NonNull String value) { - Pattern c = Pattern.compile("rgba?\\s*\\(\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*," - + "?\\s*(\\d+\\.?\\d*)?\\s*\\)"); + Pattern c = Pattern.compile("rgba?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,?\\s*(\\d+\\.?\\d*)?\\s*\\)"); Matcher m = c.matcher(value); if (m.matches() && m.groupCount() == 3) { - return Color.rgb(normalizeColorComponent(m.group(1)), normalizeColorComponent(m.group(2)), - normalizeColorComponent(m.group(3))); + return Color.rgb(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)), + Integer.parseInt(m.group(3))); } else if (m.matches() && m.groupCount() == 4) { - return Color.argb(normalizeColorComponent(m.group(4)), normalizeColorComponent(m.group(1)), - normalizeColorComponent(m.group(2)), normalizeColorComponent(m.group(3))); + return Color.argb((int) (Float.parseFloat(m.group(4)) * 255), Integer.parseInt(m.group(1)), + Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3))); } else { throw new ConversionException("Not a valid rgb/rgba value"); } |