Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08963287 authored by Fynn Godau's avatar Fynn Godau
Browse files

Merge branch '907-map-fixes' into 'master'

Fixes for Swiggy

See merge request !72
parents 71452df4 0432b278
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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))
                }
            }
+15 −3
Original line number Diff line number Diff line
@@ -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<PatternItem>.getName(color: Int, strokeWidth: Float, skew: Float = 1f) = joinToString("-") {
fun List<PatternItem>.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<PatternItem>.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)

+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ class Styler(
    @SerializedName("invert_lightness") val invertLightness: Boolean?,
    val visibility: String?,
    val color: String?,
    val weight: Int?
    //val weight: Int?
)

/**
+1 −1
Original line number Diff line number Diff line
@@ -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