From 6179110b6bfe8ee0880a055a31c12a88f9bd9b20 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 8 Mar 2018 16:27:02 +0100 Subject: [android] - add expression conversion, add getters (#11352) --- .../mapboxsdk/style/layers/PropertyValue.java | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index a57c440df4..fa1779a6c7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -4,8 +4,9 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.google.gson.JsonArray; import com.mapbox.mapboxsdk.exceptions.ConversionException; -import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.utils.ColorUtils; import timber.log.Timber; @@ -40,34 +41,38 @@ public class PropertyValue { } /** - * Returns if this is a function. + * Returns if this is a expression. * - * @return true if is a function, false if not + * @return true if this is a expression, false if not */ - public boolean isFunction() { - return !isNull() && value instanceof Function; + public boolean isExpression() { + return !isNull() && value instanceof JsonArray; } /** - * Returns if this is a value. + * Get the expression of the property. * - * @return true if is a value, false if not + * @return the property expression */ - public boolean isValue() { - return !isNull() && !isFunction(); - } - @Nullable - public Function getFunction() { - if (isFunction()) { - // noinspection unchecked - return (Function) value; + public Expression getExpression() { + if (isExpression()) { + return Expression.Converter.convert((JsonArray) value); } else { - Timber.w("not a function, try value"); + Timber.w("not a expression, try value"); return null; } } + /** + * Returns if this is a value. + * + * @return true if is a value, false if not + */ + public boolean isValue() { + return !isNull() && !isExpression(); + } + /** * Get the value of the property. * @@ -77,7 +82,7 @@ public class PropertyValue { public T getValue() { if (isValue()) { // noinspection unchecked - return (T) value; + return value; } else { Timber.w("not a value, try function"); return null; @@ -114,4 +119,4 @@ public class PropertyValue { public String toString() { return String.format("%s: %s", name, value); } -} +} \ No newline at end of file -- cgit v1.2.1