I am developing an Android library that registers all the touch inputs of an application. I have already managed to intercept all the touch inputs for actions (and fragments), but not pop-ups.
How to detect touch inputs for new windows that appear in activity?
The following code shows how I intercept all touch inputs for an activity window.
Inside, Application.onCreate()I call Application.registerActivityLifecycleCallbacks()and register the following callback:
override fun onActivityCreated(activity: Activity, savedState: Bundle?) {
val localCallback = activity.window.callback
activity.window.callback = object : ActivityWindowCallbackWrapper(activity, localCallback) {
override fun dispatchTouchEvent(motionEvent: MotionEvent): Boolean {
return super.dispatchTouchEvent(motionEvent)
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
}
}
}
This code captures all touch events for the activity window, and it recognizes when another window is focused (another window appears), but I don’t know how to register a callback for a newly focused window.
- , , .