增加无障碍开启关闭回调接口
This commit is contained in:
@@ -16,17 +16,22 @@ import java.util.concurrent.Executors
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
|
|
||||||
|
interface AccessibilityServiceCallback {
|
||||||
|
fun onServiceConnected()
|
||||||
|
fun onServiceDisconnected()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/2.
|
* Created by Stardust on 2017/5/2.
|
||||||
*/
|
*/
|
||||||
open class AccessibilityService : android.accessibilityservice.AccessibilityService() {
|
open class AccessibilityService : android.accessibilityservice.AccessibilityService() {
|
||||||
|
|
||||||
val onKeyObserver = OnKeyListener.Observer()
|
val onKeyObserver = OnKeyListener.Observer()
|
||||||
val keyInterrupterObserver = KeyInterceptor.Observer()
|
val keyInterrupterObserver = KeyInterceptor.Observer()
|
||||||
var fastRootInActiveWindow: AccessibilityNodeInfo? = null
|
var fastRootInActiveWindow: AccessibilityNodeInfo? = null
|
||||||
|
|
||||||
var bridge: AccessibilityBridge? = null
|
var bridge: AccessibilityBridge? = null
|
||||||
|
|
||||||
|
private var callback: AccessibilityServiceCallback? = null
|
||||||
|
|
||||||
private val gestureEventDispatcher = EventDispatcher<GestureListener>()
|
private val gestureEventDispatcher = EventDispatcher<GestureListener>()
|
||||||
|
|
||||||
private val eventExecutor by lazy { Executors.newSingleThreadExecutor() }
|
private val eventExecutor by lazy { Executors.newSingleThreadExecutor() }
|
||||||
@@ -88,6 +93,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
|||||||
instance = null
|
instance = null
|
||||||
bridge = null
|
bridge = null
|
||||||
eventExecutor.shutdownNow()
|
eventExecutor.shutdownNow()
|
||||||
|
callback?.onServiceDisconnected()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +110,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
callback?.onServiceConnected()
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
|
|
||||||
LOCK.lock()
|
LOCK.lock()
|
||||||
@@ -114,6 +120,10 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
|||||||
// FIXME: 2017/2/12 有时在无障碍中开启服务后这里不会调用服务也不会运行,安卓的BUG???
|
// FIXME: 2017/2/12 有时在无障碍中开启服务后这里不会调用服务也不会运行,安卓的BUG???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setCallback(callback: AccessibilityServiceCallback) {
|
||||||
|
this.callback = callback
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val TAG = "AccessibilityService"
|
private const val TAG = "AccessibilityService"
|
||||||
@@ -182,11 +192,7 @@ open class AccessibilityService : android.accessibilityservice.AccessibilityServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface GestureListener {
|
interface GestureListener {
|
||||||
|
|
||||||
fun onGesture(gestureId: Int)
|
fun onGesture(gestureId: Int)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user