Event delivery mechanism

 

 

Two, MotionEvent Profile

       Before talking about Android event distribution mechanism you a quick view of some MotionEvent, because it is this "event." The following description of the section taken in the source code:

 1 ......
 2  * <p>
 3  * Motion events describe movements in terms of an action code and a set of axis values.
 4  * The action code specifies the state change that occurred such as a pointer going
 5  * down or up.  The axis values describe the position and other movement properties.
 6  * </p>
 7 ......
 8 public final class MotionEvent extends InputEvent implements Parcelable {
 9     public static final int ACTION_DOWN  = 0;
10     public static final int ACTION_UP  = 1;
11     public static final int ACTION_MOVE  = 2;
12     ......
13 }

       MotionEvent, as the name suggests, action events mean. To describe an operation by an action code and a set of coordinate values. action code specifies the state when the pointer is pressed or lifted as change events such as the coordinate values ​​of the position and the other acts described event attribute values ​​in the screen. The following is MotionEvent toString method of printing out the results:

MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=173.0, y[0]=138.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x2, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=34268429, downTime=34268429, deviceId=8, source=0x1002 }

From here you can see, a lot of information action events, time, coordinates, etc. This article in being only concerned aciton this field, "action = ACTION_DOWN" expressed presses.

       Usually when you touch the screen, one of the most simple events include a "ACTION_DOWN" and "ACTION_UP", "ACTION_DOWN" in which a finger is pressed, and "" ACTION_UP "represents a finger up, and two action will constitute a complete event. If you have to move your finger on the screen, will also include "ACTION_MOVE", this time a complete event including "ACTION_DOWN", more "ACTION_MOVE", "ACTION_UP". of course, the actual work will be a lot of complex situations, There may be some other aciton, in order to facilitate the presentation of this paper, considering only "ACTION_DOWN" and "ACTION_UP" scene.

Guess you like

Origin www.cnblogs.com/andy-songwei/p/10987684.html