diff --git a/features/dd-sdk-android-session-replay/api/apiSurface b/features/dd-sdk-android-session-replay/api/apiSurface index d55d961ac2..d851a6d6c2 100644 --- a/features/dd-sdk-android-session-replay/api/apiSurface +++ b/features/dd-sdk-android-session-replay/api/apiSurface @@ -74,6 +74,9 @@ class com.datadog.android.sessionreplay.recorder.mapper.EditTextMapper : TextVie constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper) override fun resolveCapturedText(android.widget.EditText, com.datadog.android.sessionreplay.TextAndInputPrivacy, Boolean): String companion object +open class com.datadog.android.sessionreplay.recorder.mapper.ImageViewMapper : BaseAsyncBackgroundWireframeMapper + constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper) + override fun map(android.widget.ImageView, com.datadog.android.sessionreplay.recorder.MappingContext, com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback, com.datadog.android.api.InternalLogger): List open class com.datadog.android.sessionreplay.recorder.mapper.TextViewMapper : BaseAsyncBackgroundWireframeMapper constructor(com.datadog.android.sessionreplay.utils.ViewIdentifierResolver, com.datadog.android.sessionreplay.utils.ColorStringFormatter, com.datadog.android.sessionreplay.utils.ViewBoundsResolver, com.datadog.android.sessionreplay.utils.DrawableToColorMapper) override fun map(T, com.datadog.android.sessionreplay.recorder.MappingContext, com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback, com.datadog.android.api.InternalLogger): List diff --git a/features/dd-sdk-android-session-replay/api/dd-sdk-android-session-replay.api b/features/dd-sdk-android-session-replay/api/dd-sdk-android-session-replay.api index 8aa55e21f4..067387c3db 100644 --- a/features/dd-sdk-android-session-replay/api/dd-sdk-android-session-replay.api +++ b/features/dd-sdk-android-session-replay/api/dd-sdk-android-session-replay.api @@ -1472,6 +1472,12 @@ public final class com/datadog/android/sessionreplay/recorder/mapper/EditTextMap public final class com/datadog/android/sessionreplay/recorder/mapper/EditTextMapper$Companion { } +public class com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper : com/datadog/android/sessionreplay/recorder/mapper/BaseAsyncBackgroundWireframeMapper { + public fun (Lcom/datadog/android/sessionreplay/utils/ViewIdentifierResolver;Lcom/datadog/android/sessionreplay/utils/ColorStringFormatter;Lcom/datadog/android/sessionreplay/utils/ViewBoundsResolver;Lcom/datadog/android/sessionreplay/utils/DrawableToColorMapper;)V + public synthetic fun map (Landroid/view/View;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/AsyncJobStatusCallback;Lcom/datadog/android/api/InternalLogger;)Ljava/util/List; + public fun map (Landroid/widget/ImageView;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/AsyncJobStatusCallback;Lcom/datadog/android/api/InternalLogger;)Ljava/util/List; +} + public class com/datadog/android/sessionreplay/recorder/mapper/TextViewMapper : com/datadog/android/sessionreplay/recorder/mapper/BaseAsyncBackgroundWireframeMapper { public fun (Lcom/datadog/android/sessionreplay/utils/ViewIdentifierResolver;Lcom/datadog/android/sessionreplay/utils/ColorStringFormatter;Lcom/datadog/android/sessionreplay/utils/ViewBoundsResolver;Lcom/datadog/android/sessionreplay/utils/DrawableToColorMapper;)V protected final fun createTextWireframe (Landroid/widget/TextView;Lcom/datadog/android/sessionreplay/recorder/MappingContext;Lcom/datadog/android/sessionreplay/utils/GlobalBounds;)Lcom/datadog/android/sessionreplay/model/MobileSegment$Wireframe$TextWireframe; diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/DefaultRecorderProvider.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/DefaultRecorderProvider.kt index 10dd2384e6..bbe80d462c 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/DefaultRecorderProvider.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/DefaultRecorderProvider.kt @@ -31,7 +31,6 @@ import com.datadog.android.sessionreplay.internal.recorder.mapper.ActionBarConta import com.datadog.android.sessionreplay.internal.recorder.mapper.ButtonMapper import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckBoxMapper import com.datadog.android.sessionreplay.internal.recorder.mapper.CheckedTextViewMapper -import com.datadog.android.sessionreplay.internal.recorder.mapper.ImageViewMapper import com.datadog.android.sessionreplay.internal.recorder.mapper.NumberPickerMapper import com.datadog.android.sessionreplay.internal.recorder.mapper.ProgressBarWireframeMapper import com.datadog.android.sessionreplay.internal.recorder.mapper.RadioButtonMapper @@ -45,6 +44,7 @@ import com.datadog.android.sessionreplay.internal.time.SessionReplayTimeProvider import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils import com.datadog.android.sessionreplay.recorder.OptionSelectorDetector import com.datadog.android.sessionreplay.recorder.mapper.EditTextMapper +import com.datadog.android.sessionreplay.recorder.mapper.ImageViewMapper import com.datadog.android.sessionreplay.recorder.mapper.TextViewMapper import com.datadog.android.sessionreplay.recorder.mapper.WireframeMapper import com.datadog.android.sessionreplay.utils.ColorStringFormatter @@ -97,11 +97,11 @@ internal class DefaultRecorderProvider( val viewBoundsResolver: ViewBoundsResolver = DefaultViewBoundsResolver val drawableToColorMapper: DrawableToColorMapper = DrawableToColorMapper.getDefault() val imageViewMapper = ImageViewMapper( - ImageViewUtils, - viewIdentifierResolver, - colorStringFormatter, - viewBoundsResolver, - drawableToColorMapper + viewIdentifierResolver = viewIdentifierResolver, + colorStringFormatter = colorStringFormatter, + viewBoundsResolver = viewBoundsResolver, + drawableToColorMapper = drawableToColorMapper, + imageViewUtils = ImageViewUtils ) val textViewMapper = TextViewMapper( viewIdentifierResolver, diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtils.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtils.kt index d95ab4886e..d5ca9d6b26 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtils.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtils.kt @@ -62,13 +62,13 @@ internal object ImageViewUtils { } internal fun resolveContentRectWithScaling( - view: ImageView, + imageView: ImageView, drawable: Drawable ): Rect { val drawableWidthPx = drawable.intrinsicWidth val drawableHeightPx = drawable.intrinsicHeight - val parentRect = resolveParentRectAbsPosition(view) + val parentRect = resolveParentRectAbsPosition(imageView) val childRect = Rect( 0, @@ -79,7 +79,7 @@ internal object ImageViewUtils { val resultRect: Rect - when (view.scaleType) { + when (imageView.scaleType) { ImageView.ScaleType.FIT_START -> { val contentRect = scaleRectToFitParent(parentRect, childRect) resultRect = positionRectAtStart(parentRect, contentRect) diff --git a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapper.kt b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper.kt similarity index 71% rename from features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapper.kt rename to features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper.kt index 5c00c371c8..2217dd4a08 100644 --- a/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapper.kt +++ b/features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapper.kt @@ -4,7 +4,7 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.sessionreplay.internal.recorder.mapper +package com.datadog.android.sessionreplay.recorder.mapper import android.widget.ImageView import androidx.annotation.UiThread @@ -13,7 +13,6 @@ import com.datadog.android.sessionreplay.internal.recorder.densityNormalized import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils import com.datadog.android.sessionreplay.model.MobileSegment import com.datadog.android.sessionreplay.recorder.MappingContext -import com.datadog.android.sessionreplay.recorder.mapper.BaseAsyncBackgroundWireframeMapper import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback import com.datadog.android.sessionreplay.utils.ColorStringFormatter import com.datadog.android.sessionreplay.utils.DrawableToColorMapper @@ -21,18 +20,41 @@ import com.datadog.android.sessionreplay.utils.ImageWireframeHelper import com.datadog.android.sessionreplay.utils.ViewBoundsResolver import com.datadog.android.sessionreplay.utils.ViewIdentifierResolver -internal class ImageViewMapper( - private val imageViewUtils: ImageViewUtils, - viewIdentifierResolver: ViewIdentifierResolver, - colorStringFormatter: ColorStringFormatter, - viewBoundsResolver: ViewBoundsResolver, - drawableToColorMapper: DrawableToColorMapper -) : BaseAsyncBackgroundWireframeMapper( - viewIdentifierResolver, - colorStringFormatter, - viewBoundsResolver, - drawableToColorMapper -) { +/** + * A [WireframeMapper] implementation to map an [ImageView] component. + */ +open class ImageViewMapper : BaseAsyncBackgroundWireframeMapper { + private val imageViewUtils: ImageViewUtils + + @Suppress("Unused") // used by external mappers + constructor( + viewIdentifierResolver: ViewIdentifierResolver, + colorStringFormatter: ColorStringFormatter, + viewBoundsResolver: ViewBoundsResolver, + drawableToColorMapper: DrawableToColorMapper + ) : this( + viewIdentifierResolver, + colorStringFormatter, + viewBoundsResolver, + drawableToColorMapper, + ImageViewUtils + ) + + internal constructor( + viewIdentifierResolver: ViewIdentifierResolver, + colorStringFormatter: ColorStringFormatter, + viewBoundsResolver: ViewBoundsResolver, + drawableToColorMapper: DrawableToColorMapper, + imageViewUtils: ImageViewUtils + ) : super( + viewIdentifierResolver, + colorStringFormatter, + viewBoundsResolver, + drawableToColorMapper + ) { + this.imageViewUtils = imageViewUtils + } + @UiThread override fun map( view: ImageView, @@ -58,6 +80,7 @@ internal class ImageViewMapper( } else { null } + val contentXPosInDp = contentRect.left.densityNormalized(density).toLong() val contentYPosInDp = contentRect.top.densityNormalized(density).toLong() val contentWidthPx = contentRect.width() diff --git a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtilsTest.kt b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtilsTest.kt index e21d45ef89..45bf0adcdd 100644 --- a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtilsTest.kt +++ b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/utils/ImageViewUtilsTest.kt @@ -278,7 +278,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -326,7 +326,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -374,7 +374,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -422,7 +422,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -477,7 +477,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -525,7 +525,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -577,7 +577,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -627,7 +627,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -673,7 +673,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) @@ -718,7 +718,7 @@ internal class ImageViewUtilsTest { // When val result = testedImageViewUtils.resolveContentRectWithScaling( - view = mockImageView, + imageView = mockImageView, drawable = mockDrawable ) diff --git a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapperTest.kt b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapperTest.kt similarity index 97% rename from features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapperTest.kt rename to features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapperTest.kt index afd7a758ff..668fb020cd 100644 --- a/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/recorder/mapper/ImageViewMapperTest.kt +++ b/features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/recorder/mapper/ImageViewMapperTest.kt @@ -4,7 +4,7 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.sessionreplay.internal.recorder.mapper +package com.datadog.android.sessionreplay.recorder.mapper import android.content.Context import android.content.res.Resources @@ -22,7 +22,6 @@ import com.datadog.android.sessionreplay.internal.utils.ImageViewUtils import com.datadog.android.sessionreplay.model.MobileSegment import com.datadog.android.sessionreplay.recorder.MappingContext import com.datadog.android.sessionreplay.recorder.SystemInformation -import com.datadog.android.sessionreplay.recorder.mapper.BaseAsyncBackgroundWireframeMapper import com.datadog.android.sessionreplay.utils.AsyncJobStatusCallback import com.datadog.android.sessionreplay.utils.ColorStringFormatter import com.datadog.android.sessionreplay.utils.DrawableToColorMapper @@ -194,11 +193,11 @@ internal class ImageViewMapperTest { ) testedMapper = ImageViewMapper( - stubImageViewUtils, - mockViewIdentifierResolver, - mockColorStringFormatter, - mockViewBoundsResolver, - mockDrawableToColorMapper + viewIdentifierResolver = mockViewIdentifierResolver, + colorStringFormatter = mockColorStringFormatter, + viewBoundsResolver = mockViewBoundsResolver, + drawableToColorMapper = mockDrawableToColorMapper, + imageViewUtils = stubImageViewUtils ) }