diff options
author | Tobrun <tobrun@mapbox.com> | 2018-03-23 09:54:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 09:54:22 -0400 |
commit | c44fe25200a16294e42d73acff6168c8b778eda8 (patch) | |
tree | 4fff16944cdcfdc39d0762ee129050672cb60681 | |
parent | 9499a2bda7eed68f8a11cdecce0130b1be2054a4 (diff) | |
download | qtlocation-mapboxgl-c44fe25200a16294e42d73acff6168c8b778eda8.tar.gz |
[android] - correctly convert Android int colors with to-color expression (#11506)
3 files changed, 18 insertions, 38 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index dee8b043b8..531c1af420 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -135,7 +135,7 @@ public class Expression { * @return the color expression */ public static Expression color(@ColorInt int color) { - return new ExpressionLiteral(new Color(color)); + return toColor(literal(PropertyFactory.colorToRgbaString(color))); } /** @@ -1735,9 +1735,7 @@ public class Expression { */ private Object toValue(ExpressionLiteral expressionValue) { Object value = expressionValue.toValue(); - if (value instanceof Expression.Color) { - return ((Expression.Color) value).convertColor(); - } else if (value instanceof Expression.ExpressionLiteral) { + if (value instanceof Expression.ExpressionLiteral) { return toValue((ExpressionLiteral) value); } else if (value instanceof Expression) { return ((Expression) value).toArray(); @@ -1894,32 +1892,6 @@ public class Expression { } /** - * Expression color type. - */ - public static class Color { - - private int color; - - /** - * Creates a color color type from a color int. - * - * @param color the int color - */ - public Color(@ColorInt int color) { - this.color = color; - } - - /** - * Converts the int color to rgba(d, d, d, d) string representation - * - * @return the string representation of a color - */ - String convertColor() { - return PropertyFactory.colorToRgbaString(color); - } - } - - /** * Expression array type. */ public static class Array { diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java index 535efe5fdd..22c25fd0df 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java @@ -2,8 +2,6 @@ package com.mapbox.mapboxsdk.style.expressions; import android.graphics.Color; -import com.mapbox.mapboxsdk.style.layers.PropertyFactory; - import org.junit.Test; import java.util.Arrays; @@ -113,7 +111,7 @@ public class ExpressionTest { @Test public void testToRgba() throws Exception { - Object[] expected = new Object[] {"to-rgba", PropertyFactory.colorToRgbaString(Color.RED)}; + Object[] expected = new Object[] {"to-rgba", new Object[] {"to-color", "rgba(255, 0, 0, 255)"}}; Object[] actual = toRgba(color(Color.RED)).toArray(); assertTrue("expression should match", Arrays.deepEquals(expected, actual)); } @@ -1087,6 +1085,14 @@ public class ExpressionTest { float[] array = new float[] {0.2f, 0.5f}; Object[] expected = new Object[] {"literal", new Object[] {0.2f, 0.5f}}; Object[] actual = literal(array).toArray(); - assertEquals("primitive array should be convered", expected, actual); + assertEquals("primitive array should be converted", expected, actual); } + + @Test + public void testColorConversion() { + Expression greenColor = color(0xFF00FF00); + Object[] expected = new Object[] {"to-color", "rgba(0, 255, 0, 255)"}; + assertTrue("expression should match", Arrays.deepEquals(expected, greenColor.toArray())); + } + }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.java index eebe95a411..dae0714d42 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.style; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; @@ -33,6 +34,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba; import static com.mapbox.mapboxsdk.style.expressions.Expression.step; import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom; +import static com.mapbox.mapboxsdk.style.expressions.Expression.color; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOpacity; @@ -173,9 +175,9 @@ public class DataDrivenStyleActivity extends AppCompatActivity { fillColor( interpolate( exponential(0.5f), zoom(), - stop(1, rgb(255, 0, 0)), - stop(5, rgb(0, 0, 255)), - stop(10, rgb(0, 255, 0)) + stop(1, color(Color.RED)), + stop(5, color(Color.BLUE)), + stop(10, color(Color.GREEN)) ) ) ); @@ -460,7 +462,7 @@ public class DataDrivenStyleActivity extends AppCompatActivity { // Add a fill layer mapboxMap.addLayer(new FillLayer(AMSTERDAM_PARKS_LAYER, source.getId()) .withProperties( - fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)), + fillColor(color(Color.GREEN)), fillOutlineColor(rgb(0, 0, 255)), fillAntialias(true) ) |