Zokivasilic8
12/05/2023, 12:36 PMorg.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration
File being compiled: (68,5) in Kotlin file[0m
[10:27:02]: ▸ [35mThe root cause java.io.FileNotFoundException was thrown at: java.base/java.io.FileInputStream.open0(Native Method)
Thanks to all who can help out on this issue. 🙂Jose Ramon (JR)
12/05/2023, 1:22 PMZokivasilic8
12/05/2023, 1:49 PMpackage com.usemenu.sdk.brandresources.assets.svg
import android.content.res.Resources
import android.graphics.Canvas
import android.graphics.RectF
import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.toDrawable
import coil.ImageLoader
import coil.decode.*
import coil.fetch.SourceResult
import coil.request.Options
import coil.request.css
import com.caverock.androidsvg.RenderOptions
import com.caverock.androidsvg.SVG
import kotlinx.coroutines.runInterruptible
class CustomCoilSvgDecoder @JvmOverloads constructor(
private val source: ImageSource,
private val options: Options,
private val useViewBoundsAsIntrinsicSize: Boolean = true
) : Decoder {
override suspend fun decode(): DecodeResult =
runInterruptible {
val svg = source.source().use { SVG.getFromInputStream(it.inputStream()) }
val svgWidth: Float
val svgHeight: Float
val viewBox: RectF? = svg.documentViewBox
if (useViewBoundsAsIntrinsicSize && viewBox != null) {
svgWidth = viewBox.width()
svgHeight = viewBox.height()
} else {
svgWidth = svg.documentWidth
svgHeight = svg.documentHeight
}
val bitmapWidth: Int
val bitmapHeight: Int
val resScalingFactor = Resources.getSystem().displayMetrics.density
if (svgWidth > 0 && svgHeight > 0) {
bitmapWidth = (resScalingFactor * svgWidth).toInt()
bitmapHeight = (resScalingFactor * svgHeight).toInt()
} else {
bitmapWidth = DEFAULT_SIZE
bitmapHeight = DEFAULT_SIZE
}
// Set the SVG's view box to enable scaling if it is not set.
if (viewBox == null && svgWidth > 0 && svgHeight > 0) {
svg.setDocumentViewBox(0f, 0f, svgWidth, svgHeight)
}
svg.setDocumentWidth("100%")
svg.setDocumentHeight("100%")
val bitmap = createBitmap(bitmapWidth, bitmapHeight)
val renderOptions = options.parameters.css()?.let { RenderOptions().css(it) }
svg.renderToCanvas(Canvas(bitmap), renderOptions)
DecodeResult(
drawable = bitmap.toDrawable(options.context.resources),
isSampled = true // SVGs can always be re-decoded at a higher resolution.
)
}
class Factory @JvmOverloads constructor(
val useViewBoundsAsIntrinsicSize: Boolean = true
) : Decoder.Factory {
override fun create(
result: SourceResult,
options: Options,
imageLoader: ImageLoader
): Decoder? {
if (!isApplicable(result)) return null
return CustomCoilSvgDecoder(result.source, options, useViewBoundsAsIntrinsicSize)
}
private fun isApplicable(result: SourceResult): Boolean {
return result.mimeType == MIME_TYPE_SVG || DecodeUtils.isSvg(result.source.source())
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
return other is Factory &&
useViewBoundsAsIntrinsicSize == other.useViewBoundsAsIntrinsicSize
}
override fun hashCode() = useViewBoundsAsIntrinsicSize.hashCode()
}
companion object {
private const val MIME_TYPE_SVG = "image/svg+xml"
private const val DEFAULT_SIZE = 512
}
}
AndreyVanDenHaag
12/05/2023, 7:17 PMZokivasilic8
12/06/2023, 9:03 AMZokivasilic8
12/06/2023, 9:50 AMCaused by: java.io.FileNotFoundException: HmsLocationProvider.java (No such file or directory)