-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
774c798
commit 940f01c
Showing
26 changed files
with
483 additions
and
95 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
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
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
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
61 changes: 61 additions & 0 deletions
61
...-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/TouchPrivacyManager.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,61 @@ | ||
/* | ||
* 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.internal | ||
|
||
import android.graphics.Point | ||
import android.graphics.Rect | ||
import androidx.annotation.VisibleForTesting | ||
import com.datadog.android.sessionreplay.TouchPrivacy | ||
|
||
internal class TouchPrivacyManager( | ||
private val globalTouchPrivacy: TouchPrivacy | ||
) { | ||
// areas on screen where overrides are applied | ||
@VisibleForTesting internal val currentOverrideSnapshot = HashMap<Rect, TouchPrivacy>() | ||
|
||
// built during the view traversal and copied to currentOverrideSnapshot at the end | ||
@VisibleForTesting internal val nextOverrideSnapshot = HashMap<Rect, TouchPrivacy>() | ||
|
||
internal fun addTouchOverrideArea(bounds: Rect, touchPrivacy: TouchPrivacy) { | ||
nextOverrideSnapshot[bounds] = touchPrivacy | ||
} | ||
|
||
internal fun copyNextSnapshotToCurrentSnapshot() { | ||
currentOverrideSnapshot.clear() | ||
@Suppress("UnsafeThirdPartyFunctionCall") // NPE cannot happen here | ||
currentOverrideSnapshot.putAll(nextOverrideSnapshot) | ||
nextOverrideSnapshot.clear() | ||
} | ||
|
||
internal fun resolveTouchPrivacy(touchLocation: Point): TouchPrivacy { | ||
var showOverrideSet = false | ||
|
||
// avoid having the collection change while we iterate through it | ||
val overrideAreas = HashMap<Rect, TouchPrivacy>() | ||
@Suppress("UnsafeThirdPartyFunctionCall") // NPE cannot happen here | ||
overrideAreas.putAll(currentOverrideSnapshot) | ||
|
||
@Suppress("UnsafeThirdPartyFunctionCall") // ConcurrentModification cannot happen here | ||
overrideAreas.forEach { entry -> | ||
val area = entry.key | ||
val overrideValue = entry.value | ||
|
||
if (isWithinOverrideArea(touchLocation, area)) { | ||
when (overrideValue) { | ||
TouchPrivacy.HIDE -> return TouchPrivacy.HIDE | ||
TouchPrivacy.SHOW -> showOverrideSet = true | ||
} | ||
} | ||
} | ||
|
||
return if (showOverrideSet) TouchPrivacy.SHOW else globalTouchPrivacy | ||
} | ||
|
||
private fun isWithinOverrideArea(touchPoint: Point, overrideArea: Rect): Boolean = | ||
touchPoint.x in overrideArea.left..overrideArea.right && | ||
touchPoint.y in overrideArea.top..overrideArea.bottom | ||
} |
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
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
Oops, something went wrong.