Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

who calls Activity.dispatchTouchEvent( event )?

I am trying to add touch events from a file to the current application (build a new touch event according to the data found in the file ), and I am trying to understand the chain of calls when a "real" touch event is triggered.

From all the searches I conducted, I found that Activity.dispatchTouchEvent(ev) is the first method called when we have a touch event, then its forwarded to ViewGroup.dispatchTouchEvent and then to View.dispatchTouchEvent.

I want to find what is being called before Activity.dispatchTouchEvent(ev) and how the events is transfered from the HW to this method.

like image 363
Foad Rezek Avatar asked Dec 16 '13 18:12

Foad Rezek


People also ask

What is dispatchTouchEvent?

dispatchTouchEvent(MotionEvent) - This allows your Activity to intercept all touch events before they are dispatched to the window. • ViewGroup. onInterceptTouchEvent(MotionEvent) - This allows a ViewGroup to watch events as they are dispatched to child Views.

How to intercept touch event android?

Intercept touch events in a ViewGroup. The onInterceptTouchEvent() method is called whenever a touch event is detected on the surface of a ViewGroup , including on the surface of its children.

How are Android touch events delivered?

The touch event is passed in as a MotionEvent , which contains the x,y coordinates, time, type of event, and other information. The touch event is sent to the Window's superDispatchTouchEvent() .

How do I use onTouchEvent on Android?

After the Math. abs() calls, you're essentially testing if their finger is farther down the screen than it is across the screen. Store the initial down coordinates as member variables and set them during ACTION_DOWN . You declared two floats (touchX and touchY) inside the onTouchEvent method.


1 Answers

Maybe what you want is how android input framework works. The following blog about android input framework architecture may helps you.

Android Input Framework Architecture[Part 1] : Introduction to InputReader & InputDispatcher

The input process can simply be put as:

input hardware ------> kernel/driver(input protocol) -----> EventHub(framework/base/libs/ui) getevent------> InputReader ----> inputDispatcher ----> Window manager.

  1. First, InputReader convert the meta input event to android event (etc. MotionEvent/KeyEvent).
  2. Then, InputDispatcher dispatcher the event to WindowManager
  3. WindowManager calls Window.Callback.dispatchTouchEvent(***).
like image 71
chaman Avatar answered Oct 16 '22 02:10

chaman