From d6a058613e840922bdc520b61cd3715f4831fc2b Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Wed, 12 Apr 2023 10:50:32 +0200 Subject: [PATCH 1/3] Log snapshots --- .../src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt index 662817b61..38e3f1be7 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/GoogleMap.kt @@ -456,10 +456,13 @@ class GoogleMapImpl(context: Context, var options: GoogleMapOptions) : AbstractG val map = map if (map == null) { // Snapshot cannot be taken + Log.e(TAG, "snapshot could not be taken because map is null") runOnMainLooper { callback.onBitmapWrappedReady(ObjectWrapper.wrap(null)) } } else { + Log.d(TAG, "taking snapshot") map.snapshot { runOnMainLooper { + Log.d(TAG, "snapshot ready, providing to application") callback.onBitmapWrappedReady(ObjectWrapper.wrap(it)) } } -- GitLab From 0463e1a8e989e23acd40e869ce37594926e5c4a3 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Wed, 12 Apr 2023 10:50:42 +0200 Subject: [PATCH 2/3] Don't parse weight in custom styles In https://gitlab.e.foundation/e/backlog/-/issues/6834, an app is providing a Float instead of Int value incorrectly --- .../src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt index b1109160d..7a7f08b7e 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Styles.kt @@ -128,7 +128,7 @@ class Styler( @SerializedName("invert_lightness") val invertLightness: Boolean?, val visibility: String?, val color: String?, - val weight: Int? + //val weight: Int? ) /** -- GitLab From 0432b278bb51eae6e259c647ffe1d17350751c1f Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Wed, 12 Apr 2023 11:06:06 +0200 Subject: [PATCH 3/3] Handle nonsensical inputs in pattern generator Fixes crash in https://gitlab.e.foundation/e/backlog/-/issues/6834 --- .../org/microg/gms/maps/mapbox/Pattern.kt | 18 +++++++++++++++--- .../org/microg/gms/maps/mapbox/model/Circle.kt | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt index 0214f9ca5..5324b55c3 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/Pattern.kt @@ -7,6 +7,7 @@ import com.google.android.gms.maps.model.Dash import com.google.android.gms.maps.model.Dot import com.google.android.gms.maps.model.Gap import com.google.android.gms.maps.model.PatternItem +import kotlin.math.max fun PatternItem.getName(): String = when (this) { is Dash -> "dash${this.length}" @@ -18,9 +19,12 @@ fun PatternItem.getName(): String = when (this) { /** * Name of pattern, to identify it after it is added to map */ -fun List.getName(color: Int, strokeWidth: Float, skew: Float = 1f) = joinToString("-") { - it.getName() -} + "-${color}-width${strokeWidth}-skew${skew}" +fun List.getName(color: Int, strokeWidth: Float, skew: Float = 1f) = if (isEmpty()) { + "solid-${color}" +} else {joinToString("-") { + it.getName() + } + "-${color}-width${strokeWidth}-skew${skew}" +} /** * Gets width that a bitmap for this pattern item would have if the pattern's bitmap @@ -51,6 +55,14 @@ fun List.makeBitmap(paint: Paint, strokeWidth: Float, skew: Float): val width = getWidth(strokeWidth, skew).toInt() val height = (strokeWidth * skew).toInt() // avoids squished image bugs + // For empty list or nonsensical input (zero-width items) + if (width == 0 || height == 0) { + val nonZeroHeight = max(1f, strokeWidth) + return Bitmap.createBitmap(1, nonZeroHeight.toInt(), Bitmap.Config.ARGB_8888).also { + Canvas(it).drawRect(0f, 0f, nonZeroHeight, nonZeroHeight, paint) + } + } + val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) diff --git a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt index 93f3c1d32..5cc551212 100644 --- a/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt +++ b/play-services-maps-core-mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/Circle.kt @@ -285,7 +285,7 @@ class CircleImpl(private val map: GoogleMapImpl, private val id: String, options it.lineWidth = strokeWidth / map.dpiFactor - (strokePattern ?: listOf(Dash(1f))).let { pattern -> + (strokePattern ?: emptyList()).let { pattern -> val bitmapName = pattern.getName(strokeColor, strokeWidth) map.addBitmap(bitmapName, pattern.makeBitmap(strokeColor, strokeWidth)) line.annotation?.linePattern = bitmapName -- GitLab