Native side events distributed to the Java side and the framework of the distribution of events to the UI, the process to see the source code, here is not redundant,
The working class diagram of the native side distribution event is as follows: The class diagram for the framework side distribution event is as follows: Starting with activity.dispatchtouchevent, the timing of the Action_down event is as follows: Analyze Android 5.0 source know, ViewGroup event Dispatch is a sequential traversal tree recursive process, in Action_ There are two things to do with the down event: 1. Recursively find the Touchtarget and mark the Mfirsttouchtarget in ViewGroup, and the whole process will generate a list of touchtarget, examples are as follows: if CustomView in Ontoucheve NT returns True, the resulting touchtarget linked list is decorview->content->...->relativelayout->customviewgroup-> CustomView Concrete implementation logic in Viewgroup.dispatchtouchevent and Addtouchtarget: After the Touchtarget list is generated, the following ACTION_UP events are processed, Simply follow the touchtarget to quickly find the target view, trigger its ontouch/ontouchevent/onclick, and the other Viewgroup/view ontouch/ontouchevent skip. 2. by activity.dispatchtouchevent->viewgroup.dispatchtouchevent->view.dispatchtouchevent-> View.ontouch/ontouchevent->viewgroup.ontouch/ontouchevent->activity.ontouchevent Dispatch Timing API, if the dispatch of intermediate events is consumed ( return true), then skip for subsequent event processing. Below analysis of the ACTION_UP event processing flow, viewgroup.dispatchtouchevent will check Mfirsttouchtarget, if Mfirsttouchtarget==null, Indicates that the child nodes of the ViewGroup do not perform their view.dispatchtouchevent on the target linked list generated by the Action_down event processing, if starting from DecorviewThe entire tree is not on the target list, The Activity.ontouch is executed by the last, and the corresponding code is as follows: ViewGroup.dispatchTouchEventViewGroup.dispatchTransformedTouchEvent if Mfirsttouchtarget is not nul L, the dispatchtouchevent is constantly called according to the target list, the final target view is found, and its ontouch/ontouchevent is executed with the following logic: in Ontouch and ontouchevent execution, The default processing returns False, that is, when you click on the child view of ViewGroup, when the Action_down event is dispatched, Viewgroup.ontouch and ontouchevent can still be executed, and registering the view's Onclicklistener will have an impact on the return value of the event consumption, as follows: 1.action_down event, if view/ ViewGroup the Onclicklistener is registered, Ontouchevent executes postdelay asynchronously when the True2.action_up event is returned. The execution time is therefore at the end of Activity.dispatchtouchevent. View.ontouchevent Action_down:: at Action_up
Android Touch Event distribution process source code analysis