TouchImageView source code analysis, touchimageview source code

Source: Internet
Author: User

TouchImageView source code analysis, touchimageview source code

TouchImageView source code analysis-Please call my code detective


Github has a nice project, https://github.com/Dreddik/AndroidTouchGallery


It mainly involves source code analysis in TouchImageView to analyze the transfer process of touch events.


When you click TouchImageView in this GalleryViewPager, the output is


Down = 0, move = 2, up = 1, cancle = 3;

From the print analysis, we can see that the onInerceptTouch of GalleryViewPager intercepts the down event, but the onInterceptTouch method that runs super returns the default value false, and then directly passes it to TouchImageView to execute the down event, viewPager differs from other ViewGroup touch events because the child View is actually a ViewGroup, that is, after the touch event intercepted by ViewPager is passed to the onTouchEvent event of the Viewgroup sub-view, even if the on touch event returned by the sub-view is false, the touch event is not transmitted to the ontouchevent of GalleryViewPager for processing. This is not the same as the transfer of touch events in general view groups. I don't understand why. It is like the OnTouchEvent event returned by the direct sub-View of ViewPager is true. As follows:



When the AdapterView set in ViewPager is a single View that is not a ViewGroup, the touch event is passed. After the event is down, it is directly returned to the TouchEvent processing of ViewPager. By default, the Child view returns false;



However, if the onTouch event returned by the sub-View is true, the next touch event will not be directly passed to the onTouchEvent event of ViewPager. Instead, the move event is consumed.



The onTouchEvent execution time in ViewPager is executed only when the child view of the Child ViewGroup or the touch event of the direct child view (the ontouchevent event of the Child view returns true) is Action_cancle.


If a separate ontouchevent event returns a non-ViewGroup sub-view that is false, the onTouchEvent method in ViewPager is directly executed after the sub-view is executed down.


For more information, see the android system source code.

PS: there may be a lot of problems to be analyzed here. I hope you can correct them if you see any errors.


How can I analyze the source code of android?

If you have a high level, you can start from which module, but if you are still at a general level and not very familiar with the code, I personally suggest you buy a related book so that it is better to take the book with you for analysis!

Linux source code analysis

Detailed analysis of linux TCP/IP stack code

1. Data Structure (msghdr, sk_buff, socket, sock, proto_ops, proto)

On the bsd socket layer, the operation object is socket, and data is stored in a data structure such as msghdr:

To create a socket, you must pass the family, type, and protocol parameters. To create a socket, you must create a socket instance, create a file descriptor structure, and establish some associations with each other, that is to say, establish a connection pointer and initialize these write and read operations on the file to map to the read and write Functions of the socket.

At the same time, initialize the socket operation function (proto_ops structure). If the input type parameter is of the STREAM type, it is initialized to SOCKET-> ops as inet_stream_ops. If it is of the DGRAM type, the SOCKET-ops is inet_dgram_ops. Inet_stream_ops is actually a struct that contains some entry functions for stream-type socket operations. In these functions, we mainly perform operations on the socket, at the same time, the socket-to-sock layer is passed by calling the related operations in sock mentioned below. For example, there is an inet_release operation in inet_stream_ops. In addition to the socket-Type Space release operation, this operation also calls the sock close operation of the socket connection. For the stream type, tcp_close to close sock

Release sock.

Create a socket and sock data space and initialize sock. the initialization process mainly involves initializing three queues, receive_queue (received data packet sk_buff linked list Queue ), send_queue (the sk_buff linked list queue for which data packets need to be sent), backlog_queue (mainly used for the packets whose three handshakes are successful and guessed by myself), and sock operations are initialized according to the family and type parameters, for example, if family is inet and type is stream, sock-> proto is initialized as tcp_prot. it includes the entry functions corresponding to the sock operation of the stream protocol.

When one end writes the socket, it first sorts the string buffer to be written into a msghdr data structure (see source code analysis of Linux kernel version 2.4 ), then, sock_sendmsg is called to transmit msghdr data to the inet layer. For each data packet in the data area of the msghdr structure, the sk_buff structure is created, the data is filled, and the data is mounted to the sending queue. Layer-by-layer protocol transfer. The Protocol at each layer does not copy data. Instead, perform operations on the sk_buff structure.
Reference: networking.ctocio.com.cn/tips/91/9385591.shtml

Related Article

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.