-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-6195: Implement caching logic for path based images
- Loading branch information
1 parent
c5216f9
commit 6bd6400
Showing
17 changed files
with
1,076 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...se/src/main/kotlin/com/datadog/android/sessionreplay/compose/internal/utils/ColorUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.sessionreplay.compose.internal.utils | ||
|
||
import android.graphics.Color | ||
import com.datadog.android.api.InternalLogger | ||
import java.util.Locale | ||
|
||
internal class ColorUtils( | ||
private val logger: InternalLogger = InternalLogger.UNBOUND | ||
) { | ||
internal fun parseColorSafe(color: String): Int? { | ||
return try { | ||
@Suppress("UnsafeThirdPartyFunctionCall") // handling IllegalArgumentException | ||
Color.parseColor(color) | ||
} catch (e: IllegalArgumentException) { | ||
logger.log( | ||
target = InternalLogger.Target.MAINTAINER, | ||
level = InternalLogger.Level.WARN, | ||
messageBuilder = { COLOR_PARSE_ERROR.format(Locale.US, color) }, | ||
throwable = e | ||
) | ||
null | ||
} | ||
} | ||
|
||
internal fun convertRgbaToArgb(rgbaString: String): String { | ||
if (rgbaString.length < 2) return rgbaString | ||
|
||
// for takeLast: n > 0 | ||
@Suppress("UnsafeThirdPartyFunctionCall") | ||
val alphaValue = rgbaString.takeLast(2) | ||
|
||
// for substring: length is necessarily > 1 at this point | ||
// for dropLast: n > 0 | ||
@Suppress("UnsafeThirdPartyFunctionCall") | ||
val rgbColor = rgbaString | ||
.substring(1) | ||
.dropLast(2) | ||
return "#$alphaValue$rgbColor" | ||
} | ||
|
||
internal companion object { | ||
internal const val COLOR_PARSE_ERROR = "Failed to parse color: %s" | ||
} | ||
} |
Oops, something went wrong.