The job of the former is to add a touch effect (a view) to the Desktop (launcher launcher, which is actually an activity), and this special effect is available every time you touch it, no matter what you do on the desktop, it will show the effects! have been groping to do not know how to start, and then slowly after the experiment to know that there is an Android touch message delivery mechanism. It's really slow to find out for yourself, but it would be more effective if you knew the mechanism earlier.
Each touch of the user (onclick,onlongclick,onscroll,etc.) is composed of a action_down+n action_move+1 action_up, the user touch must first have a action_down response, The end of the user's touch will inevitably be a action_up. (Of course, if intercepted on the way, it may not have!) So how does view distribute messages and intercept messages?
The 1.View and its subclasses will have two methods:
public boolean dispatchtouchevent (motionevent ev) This method is used to distribute TouchEvent
public boolean ontouchevent (motionevent ev) This method is used to process touchevent
2. The special view subclass ViewGroup also has a method:
public boolean onintercepttouchevent (motionevent ev) This method is used to intercept touchevent
3. Distribution
Dispatchtouchevent receives a touch, it passes the message to the outermost view and then distributes it to the view of the child layer
4. Interception:
onintercepttouchevent Intercept returns true means to intercept the message and not to Child view is passed (the child view here is not an inheritance relationship, but an inclusive relationship). Returning false indicates that the message is not intercepted and can continue to the next level of view delivery message, the child view will be able to dispatchtouchevent received a touch message redistribution message
5. Message processing:
The ontouchevent handles the event, intercepts the message, or the last view that receives the message calls this method to handle the event, and if it returns true, it is correctly received and processed. Returning false means that it is not processed and will be passed to the parent view ( where the parent view is not an inheritance relationship, but an inclusive relationship )
6. Examples and manuscripts