Android project source code parsing 03 -- vudroid reader source code parsing 02: screen scrolling

Source: Internet
Author: User

When vudroid is used to display the content of a book, if you slide the screen, the following information is displayed:

In this figure, the blue area in the upper left corner shows the current page number, and the red circle in the upper right corner shows that the current page is being loaded.

Here we can think of two implementation schemes:

1) process user page flip operations in basevieweractivity, such as sliding and clicking the upper and lower keys. In this case, you can calculate the pages to be displayed based on specific user operations, notify documentview to display these pages, and update the Blue Circle and red circle areas in the figure.

2) process user page flip operations in documentview, such as sliding and clicking the top, bottom, and right keys. In this case, the page is displayed based on the specific user operation, and basevieweractivity is notified to update the Blue Circle and red circle areas in the graph.

If I design it, I will select solution 1. However, in the vudroid project, the author chooses solution 2 and implements it skillfully. We will only introduce the implementation mechanism of the content in the circle in the figure. The implementation of the content in the Red Circle is similar.

Let's first take a look at the classes involved here (I used EA to draw, because I am not very familiar with EA and UML, so it is inevitable that there are errors ):

The specific function calls are performed in the following order:

1. Initialization:

Basevieweractivity. oncreate ()
Currentpagemodel = new currentpagemodel ();
Currentpagemodel. addeventlistener (this) (actually called eventdispatcher. addeventlistener (Object listener ))

2. Execute (the function call sequence is from top to bottom ):

Documentview. scrollto () → documentview. onscrollchanged () → documentview. currentpagemodel. setcurrentpageindex () → eventdispatcher. Dispatch (New
Currentpagelistener. currentpagechangedevent (currentpageindex) → currentpagelistener. currentpagechangedevent. dispatchon (listener) → currentpagelistener. currentpagechangedevent. dispatchsafely (currentpagelistener
Listener) → basevieweractivity. currentpagechanged (INT pageindex) (actually called currentpagelistener. currentpagechanged (INT pageindex ))

As long as you understand the class relationships involved in this process and grasp the call sequence of the functions above, you can clarify the entire framework.

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.