-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mama1emon <andrew.khokhlove@gmail.com>
- Loading branch information
Showing
3 changed files
with
73 additions
and
40 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
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/tangem/tap/WindowObscurationObserver.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,68 @@ | ||
package com.tangem.tap | ||
|
||
import android.os.Build | ||
import android.view.MotionEvent | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import androidx.lifecycle.LifecycleOwner | ||
import com.tangem.core.analytics.api.AnalyticsEventHandler | ||
import com.tangem.core.analytics.models.event.TechAnalyticsEvent | ||
import com.tangem.core.analytics.models.event.TechAnalyticsEvent.WindowObscured.ObscuredState | ||
import timber.log.Timber | ||
|
||
internal object WindowObscurationObserver : DefaultLifecycleObserver { | ||
|
||
private var isWindowPartiallyObscuredAlreadySent: Boolean = false | ||
private var isWindowFullyObscuredAlreadySent: Boolean = false | ||
|
||
private var isReadyToProxy = false | ||
|
||
override fun onResume(owner: LifecycleOwner) { | ||
super.onResume(owner) | ||
isReadyToProxy = true | ||
} | ||
|
||
override fun onPause(owner: LifecycleOwner) { | ||
super.onPause(owner) | ||
isReadyToProxy = false | ||
} | ||
|
||
fun dispatchTouchEvent(event: MotionEvent, analyticsEventHandler: AnalyticsEventHandler): Boolean { | ||
if (!isReadyToProxy) return true | ||
|
||
val isPartiallyObscured = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
event.flags and MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED != 0 | ||
} else { | ||
false | ||
} | ||
|
||
if (isPartiallyObscured) { | ||
Timber.d("Window is partially obscured") | ||
|
||
if (!isWindowPartiallyObscuredAlreadySent) { | ||
analyticsEventHandler.send( | ||
event = TechAnalyticsEvent.WindowObscured(state = ObscuredState.PARTIALLY), | ||
) | ||
|
||
isWindowPartiallyObscuredAlreadySent = true | ||
} | ||
} | ||
|
||
val isFullyObscured = event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED != 0 | ||
|
||
if (isFullyObscured) { | ||
Timber.d("Window is partially or fully obscured") | ||
|
||
if (!isWindowFullyObscuredAlreadySent) { | ||
analyticsEventHandler.send( | ||
event = TechAnalyticsEvent.WindowObscured(state = ObscuredState.FULLY), | ||
) | ||
|
||
isWindowFullyObscuredAlreadySent = true | ||
} | ||
|
||
return false | ||
} | ||
|
||
return true | ||
} | ||
} |
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