mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
feat: 移除 null 事件
This commit is contained in:
parent
2749ac21a5
commit
24a0b3622d
|
@ -3,5 +3,5 @@ package li.songe.gkd.composition
|
|||
import android.view.accessibility.AccessibilityEvent
|
||||
|
||||
interface CanOnAccessibilityEvent {
|
||||
fun onAccessibilityEvent(f: (AccessibilityEvent?) -> Unit):Boolean
|
||||
fun onAccessibilityEvent(f: (AccessibilityEvent) -> Unit): Boolean
|
||||
}
|
|
@ -28,15 +28,15 @@ open class CompositionAbService(
|
|||
destroyHooks.forEach { f -> f() }
|
||||
}
|
||||
|
||||
private val onAccessibilityEventHooks by lazy { linkedSetOf<(AccessibilityEvent?) -> Unit>() }
|
||||
private val onAccessibilityEventHooks by lazy { linkedSetOf<(AccessibilityEvent) -> Unit>() }
|
||||
private val interestedEvents =
|
||||
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED or AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
|
||||
|
||||
override fun onAccessibilityEvent(f: (AccessibilityEvent?) -> Unit) =
|
||||
override fun onAccessibilityEvent(f: (AccessibilityEvent) -> Unit) =
|
||||
onAccessibilityEventHooks.add(f)
|
||||
|
||||
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|
||||
if (event?.eventType?.and(interestedEvents) != 0) {
|
||||
if (event != null && event.eventType.and(interestedEvents) != 0) {
|
||||
onAccessibilityEventHooks.forEach { f -> f(event) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,9 +155,6 @@ class GkdAbService : CompositionAbService({
|
|||
|
||||
val skipAppIds = listOf("com.android.systemui")
|
||||
onAccessibilityEvent { event ->
|
||||
if (event == null || event.packageName == null) return@onAccessibilityEvent
|
||||
if (!(event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)) return@onAccessibilityEvent
|
||||
|
||||
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED &&
|
||||
skipAppIds.contains(event.packageName.toString())
|
||||
) {
|
||||
|
@ -279,7 +276,7 @@ class GkdAbService : CompositionAbService({
|
|||
|
||||
var lastUpdateSubsTime = 0L
|
||||
onAccessibilityEvent {
|
||||
if (it?.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {// 筛选降低判断频率
|
||||
if (it.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {// 筛选降低判断频率
|
||||
// 借助 无障碍事件 触发自动检测更新
|
||||
val i = storeFlow.value.updateSubsInterval
|
||||
val t = System.currentTimeMillis()
|
||||
|
@ -394,7 +391,6 @@ class GkdAbService : CompositionAbService({
|
|||
|
||||
onAccessibilityEvent { e ->
|
||||
if (!storeFlow.value.captureScreenshot) return@onAccessibilityEvent
|
||||
e ?: return@onAccessibilityEvent
|
||||
val appId = e.packageName ?: return@onAccessibilityEvent
|
||||
val appCls = e.className ?: return@onAccessibilityEvent
|
||||
if (appId.contentEquals("com.miui.screenshot") &&
|
||||
|
|
Loading…
Reference in New Issue
Block a user