Search code examples
androideventstouchdispatch

Dispatch Touch Events to Different Window (like PopUpWindow or Dialog Window)


I have one doubt related to Touch Event Dispatch.

Usually Activity is associated with one Window, so if i use code like somewhat below , events are dispatched properly to corresponding view at those cordinates.

getWindow().getDecoreView().dispatchTouchEvents().

But if some new Windows comes on to screen, (like Dialog or PopUpWindow) how to send events to those window?

  1. Is there any API available for the same?

  2. Any idea , how Android Framework dispatch events to focussed top most window?

  3. If we can expose API from framework for same, any pointer to particular Class or Function?


Solution

  • the event in android is dispatched level by level. The event starts from activity->ViewGroup->View, you can implement these methods to control the event dispatch:

    dispatchTouchEvent(MotionEvent)
    
    onTouchEvent(MotionEvent)
    
    onInterceptTouchEvent(MotionEvent)