Android L (5.0) Source code gesture Recognition Ontouchlistener

Source: Internet
Author: User

In activity, the activity must implement the Ontouchlistener and Ongesturelistener two interfaces, and override the methods in order to listen for touch-screen touch events and gesture time. I summarize according to the source code of Android 5.0 under Ontouchlistener

First, the Android event-handling mechanism is based on the Listener (listener), which is more than what we call today's touchscreen-related events, through Ontouchlistener. Second, all view subclasses can add listeners to a class of events by means of Setontouchlistener (), Setonkeylistener (), and so on. Thirdly, listener is generally provided in the form of Interface (interface), which contains one or more abstract (abstract) methods, and we need to implement these methods to accomplish Ontouch (), OnKey (), and so on. Thus, when we set the event listener for a view and implement the abstract method in it, the program can give the appropriate response through the CALLBAKC function when a particular event is dispatch to the view.

Paste the View structure: The source code shows that the Class View provides a total of 12 internal interfaces, including:Onkeylistener,ontouchlistener, Onhoverlistener, Ongenericmotionlistener, Onlongclicklistener, Ondraglistener, Onfocuschangelistener,OnClickListener, Oncreatecontextmenulistener, Onsystemuivisibilitychangelistener, Onattachstatechangelistener, Onapplywindowinsetslistener,

Paste the source code:

1     /**2 * Interface definition for a callback to being invoked when a touch event is3 * Dispatched to this view. The callback'll be invoked before the touch4 * Event is given to the view.5      */6      Public InterfaceOntouchlistener {7         /**8 * Called when a touch event was dispatched to a view. This allows listeners to9 * Get a chance to respond before the target view.Ten          * One          * @paramv The View the touch event has a been dispatched to. A          * @paramEvent The Motionevent object containing full information about - * the event. -          * @returnTrue If the listener has consumed the event, false otherwise. the          */ -         BooleanOnTouch (View V, motionevent event); -}

Android L (5.0) Source code gesture Recognition Ontouchlistener

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.