Loading play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt +22 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import org.microg.gms.maps.MapsConstants import org.microg.gms.maps.mapbox.utils.MapContext import java.lang.NumberFormatException import kotlin.math.pow import kotlin.math.roundToInt const val TAG = "GmsMapStyles" const val KEY_METADATA_FEATURE_TYPE = "microg:gms-type-feature" Loading Loading @@ -130,7 +131,7 @@ class Styler( /** * Returns true if string is likely to contain a color. */ fun String.isColor() = startsWith("hsl(") || startsWith("#") || startsWith("rgba(") fun String.isColor() = startsWith("hsl(") || startsWith("hsla(") || startsWith("#") || startsWith("rgba(") /** * Can parse colors in the format '#rrggbb', '#aarrggbb', 'hsl(h, s, l)', and 'rgba(r, g, b, a)' Loading Loading @@ -159,6 +160,26 @@ fun String.parseColor(): Int { Log.w(TAG, "Invalid color `$this`") 0 } } else if (startsWith("hsla(")) { val hslArray = replace("hsla(", "").replace(")", "").split(", ") if (hslArray.size != 4) { Log.w(TAG, "Invalid color `$this`") return 0 } return try { ColorUtils.setAlphaComponent( ColorUtils.HSLToColor( floatArrayOf( hslArray[0].toFloat(), hslArray[1].parseFloat(), hslArray[2].parseFloat() ) ), (hslArray[3].parseFloat() * 255).roundToInt() ) } catch (e: NumberFormatException) { Log.w(TAG, "Invalid color `$this`") 0 } } else if (startsWith("rgba(")) { return com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor(this) } Loading Loading
play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt +22 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ import org.microg.gms.maps.MapsConstants import org.microg.gms.maps.mapbox.utils.MapContext import java.lang.NumberFormatException import kotlin.math.pow import kotlin.math.roundToInt const val TAG = "GmsMapStyles" const val KEY_METADATA_FEATURE_TYPE = "microg:gms-type-feature" Loading Loading @@ -130,7 +131,7 @@ class Styler( /** * Returns true if string is likely to contain a color. */ fun String.isColor() = startsWith("hsl(") || startsWith("#") || startsWith("rgba(") fun String.isColor() = startsWith("hsl(") || startsWith("hsla(") || startsWith("#") || startsWith("rgba(") /** * Can parse colors in the format '#rrggbb', '#aarrggbb', 'hsl(h, s, l)', and 'rgba(r, g, b, a)' Loading Loading @@ -159,6 +160,26 @@ fun String.parseColor(): Int { Log.w(TAG, "Invalid color `$this`") 0 } } else if (startsWith("hsla(")) { val hslArray = replace("hsla(", "").replace(")", "").split(", ") if (hslArray.size != 4) { Log.w(TAG, "Invalid color `$this`") return 0 } return try { ColorUtils.setAlphaComponent( ColorUtils.HSLToColor( floatArrayOf( hslArray[0].toFloat(), hslArray[1].parseFloat(), hslArray[2].parseFloat() ) ), (hslArray[3].parseFloat() * 255).roundToInt() ) } catch (e: NumberFormatException) { Log.w(TAG, "Invalid color `$this`") 0 } } else if (startsWith("rgba(")) { return com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor(this) } Loading