I'm trying to create a View that will be used to Log all MotionEvent
.
This View is in a Service()
which is linked to the App from where I need the events to be logged.
My problem is that when this View comes on top of the App, as needed, all the events are consumed in this View.
Is there a way to prevent this View to consume the event, and let the View on the back to consume it ?
Here is the code of the Service()
class GestureTrackViewService : Service(), View.OnTouchListener {
var mWindowManager: WindowManager? = null
var mDummyView: LinearLayout? = null
override fun onBind(p0: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val params = WindowManager.LayoutParams(
1080, /* width */
1920, /* height */
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSPARENT)
params.gravity = Gravity.START or Gravity.TOP
mDummyView!!.isFocusable = false
mDummyView!!.isClickable = false
mWindowManager!!.addView(mDummyView, params)
return super.onStartCommand(intent, flags, startId)
}
override fun onCreate() {
mWindowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
mDummyView = LinearLayout(this)
val params = WindowManager.LayoutParams(1, WindowManager.LayoutParams.MATCH_PARENT)
mDummyView!!.layoutParams = params
mDummyView!!.setOnTouchListener(this)
super.onCreate()
}
override fun onTouch(p0: View, p1: MotionEvent): Boolean {
Log.e("SERVICE", "X: ${p1.rawX} || Y: ${p1.rawY}")
mDummyView!!.requestDisallowInterceptTouchEvent(false)
return false
}
}