Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sr-integration-test #2340

Merged
merged 14 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package com.datadog.android.sessionreplay.utils

//noinspection SuspiciousImport
import android.annotation.SuppressLint
import android.graphics.Paint
import android.graphics.PorterDuffColorFilter
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
Expand Down Expand Up @@ -118,15 +120,33 @@ open class LegacyDrawableToColorMapper : DrawableToColorMapper {
}

if (fillPaint == null) return null

val fillColor: Int = fillPaint.color
val filterColor = try {
fillPaint.colorFilter?.let {
mColorField?.get(it) as? Int
} ?: fillPaint.color
} catch (e: IllegalArgumentException) {
internalLogger.log(
InternalLogger.Level.WARN,
InternalLogger.Target.MAINTAINER,
{ "Unable to read ColorFilter.mColorField field through reflection" },
e
)
fillPaint.color
} catch (e: IllegalAccessException) {
internalLogger.log(
InternalLogger.Level.WARN,
InternalLogger.Target.MAINTAINER,
{ "Unable to read ColorFilter.mColorField field through reflection" },
e
)
fillPaint.color
}
val fillAlpha = (fillPaint.alpha * drawable.alpha) / MAX_ALPHA_VALUE

return if (fillAlpha == 0) {
null
} else {
// TODO RUM-3469 resolve other color filter types
mergeColorAndAlpha(fillColor, fillAlpha)
mergeColorAndAlpha(filterColor, fillAlpha)
}
}

Expand All @@ -137,7 +157,7 @@ open class LegacyDrawableToColorMapper : DrawableToColorMapper {
* @return the color to map to or null if not applicable
*/
protected open fun resolveInsetDrawable(drawable: InsetDrawable, internalLogger: InternalLogger): Int? {
return null
return drawable.drawable?.let { mapDrawableToColor(it, internalLogger) }
}

/**
Expand All @@ -151,6 +171,7 @@ open class LegacyDrawableToColorMapper : DrawableToColorMapper {
}

companion object {
@SuppressLint("DiscouragedPrivateApi")
@Suppress("PrivateAPI", "SwallowedException", "TooGenericExceptionCaught")
internal val fillPaintField = try {
GradientDrawable::class.java.getDeclaredField("mFillPaint").apply {
Expand All @@ -163,5 +184,18 @@ open class LegacyDrawableToColorMapper : DrawableToColorMapper {
} catch (e: NullPointerException) {
null
}

@Suppress("PrivateAPI", "SwallowedException", "TooGenericExceptionCaught")
internal val mColorField = try {
PorterDuffColorFilter::class.java.getDeclaredField("mColor").apply {
this.isAccessible = true
}
} catch (e: NoSuchFieldException) {
null
} catch (e: SecurityException) {
null
} catch (e: NullPointerException) {
null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[{
"type": 4,
"data": {
"width": 411,
"height": 914
"width": 320,
"height": 640
}
}, {
"type": 6,
Expand All @@ -14,17 +14,9 @@
"data": {
"wireframes": [
{
"width": 411,
"height": 914,
"shapeStyle": {
"backgroundColor": "#303030ff",
"opacity": 1.0
},
"type": "shape"
},
{
"width": 172,
"height": 19,
"type": "text",
"text": "Welcome to Session Replay",
"textStyle": {
Expand All @@ -46,23 +38,11 @@
}
},
{
"width": 88,
"height": 48,
"shapeStyle": {
"backgroundColor": "#5a595bff",
"opacity": 1.0
},
"type": "shape"
},
{
"width": 88,
"height": 48,
"border": {
"color": "#000000ff",
"width": 1
},
"type": "text",
"text": "Click Me",
"text": "CLICK ME",
"textStyle": {
"family": "roboto, sans-serif",
"size": 14,
Expand All @@ -72,20 +52,14 @@
"padding": {
"top": 14,
"bottom": 14,
"left": 11,
"right": 11
"left": 12,
"right": 12
},
"alignment": {
"horizontal": "center",
"vertical": "center"
}
}
},
{
"width": 411,
"height": 56,
"type": "placeholder",
"label": "Toolbar"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[{
"type": 4,
"data": {
"width": 411,
"height": 914
"width": 320,
"height": 640
}
}, {
"type": 6,
Expand All @@ -14,17 +14,9 @@
"data": {
"wireframes": [
{
"width": 411,
"height": 914,
"shapeStyle": {
"backgroundColor": "#303030ff",
"opacity": 1.0
},
"type": "shape"
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "Default CheckBox",
"textStyle": {
Expand All @@ -46,17 +38,10 @@
}
},
{
"width": 16,
"height": 16,
"border": {
"color": "#a538afff",
"width": 1
},
"type": "shape"
"type": "image",
"isEmpty": false
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "App Compat CheckBox",
"textStyle": {
Expand All @@ -78,17 +63,10 @@
}
},
{
"width": 16,
"height": 16,
"border": {
"color": "#cc0000ff",
"width": 1
},
"type": "shape"
"type": "image",
"isEmpty": false
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "Material CheckBox",
"textStyle": {
Expand All @@ -110,17 +88,10 @@
}
},
{
"width": 16,
"height": 16,
"border": {
"color": "#ffbb33ff",
"width": 1
},
"type": "shape"
"type": "image",
"isEmpty": false
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "Default Radio",
"textStyle": {
Expand All @@ -142,21 +113,10 @@
}
},
{
"width": 16,
"height": 16,
"shapeStyle": {
"opacity": 1.0,
"cornerRadius": 10
},
"border": {
"color": "#a538afff",
"width": 1
},
"type": "shape"
"type": "image",
"isEmpty": false
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "App Compat Radio",
"textStyle": {
Expand All @@ -178,21 +138,10 @@
}
},
{
"width": 16,
"height": 16,
"shapeStyle": {
"opacity": 1.0,
"cornerRadius": 10
},
"border": {
"color": "#cc0000ff",
"width": 1
},
"type": "shape"
"type": "image",
"isEmpty": false
},
{
"width": 395,
"height": 32,
"type": "text",
"text": "Material Radio",
"textStyle": {
Expand All @@ -214,23 +163,8 @@
}
},
{
"width": 16,
"height": 16,
"shapeStyle": {
"opacity": 1.0,
"cornerRadius": 10
},
"border": {
"color": "#ffbb33ff",
"width": 1
},
"type": "shape"
},
{
"width": 411,
"height": 56,
"type": "placeholder",
"label": "Toolbar"
"type": "image",
"isEmpty": false
}
]
}
Expand Down
Loading