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.