-- Supports HTML, txt, Epub, fb2, and CSS
Fbreaderj process (code level ):
I. zlandroidwidget is loaded by the fbreader class of the program entry. zlandroidwidget inherits from view and instantiated the zlandroidactivity class when the ondraw () method of view is overloaded.
1. zlandroidactivity is a management abstract class inherited from activity. It reserves the filefromintent () and createapplication () abstract methods for implementation by the subclass fbreaderapp.
2. the oncreate () method of zlandroidactivity encapsulates the file opening action (the specific implementation logic is generated by the fbreader subclass to reload the createapplication () method to generate the fbreaderapp class (reload the initwindow () of the parent class zlapplication () method ).
3. fbreaderapp is a subclass of zlapplication. Zlapplication is also a Management Abstract class.
It provides the openfile () abstract method for subclass implementation. Because the view is drawn after the data is obtained, a port is left.
4. When the fbreaderapp performs the initwindow () operation, it first obtains the zlfile object through the path. The book object is generated through the zlfile object. Then call bookmodel in the openbookinternal () method. the createmodel () method transmits the generated book object to the bookreader class in C ++ to generate a bookmodel object and then return it to the Java layer through nativeformatplugin. Then, the bookmodel object is passed to the fbview, which completes most of the view rendering work.
5. The fbview parent class zltextview mainly performs the following operations when reloading the paint () method:
(1) obtain the wallpaper. If not, obtain the background color;
(2) obtain the current page mycurrentpage;
(3) Calculate the page information and obtain the page row information;
(4) Calculate the specific value of each row;
Draw each line (including the selection arrow on both sides of the text after drawing a long and pressed line ).
6. The buildinfos () method in zltextview constructs information in the entire zltextpage.
7. zltextpage (text page class) contains the lineinfos variable arraylist <zltextlineinfo> to accommodate all rows of information. The zltextlineinfo class contains the characters or image information of each row, include all the information on each page.
8. The style package adopts the decoration mode to organize a series of text style classes. The style definition defined in assets/default/styles. XML is read through the zltextstylecollection class. The classes in this package are used in the applycontrol () method of the zltextview class.
9. The bitmapmanager class (the management class of the display page) maintains up to two bitmaps in the memory using the mybitmaps variable.
Synchronize mybitmaps and myindexes to complete the logic of "front page", "Current page", and "back page.
Note: When nativeformatplugin is used to generate a bookmodel object, the acceptsfile (), readmetainfo (), readmodel (), and readcover () Methods call the implementation in C ++. Readannotation () calls the Java implementation in the plugincollection class.
2. zlandroidwidget introduces the zlviewwidget interface to implement the reset (), repaint (), startmanualscrolling (), and scrollmanuallyto () Methods of zlviewwidget.
III. zlandroidwidget introduces view. the onlongclicklistener interface is used to process long-pressed events in a view. In the ontouchevent () method, the longclickrunnable is delayed when the finger is pressed. If the longclickrunnable object is not canceled before the finger is lifted, if the mylongclickreceivmed variable is true. the action_up branch triggers the onfingerreleaseafterlongpress () method of the fbview class. The onfingerreleaseafterlongpress () method mainly processes the long-pressed response to the image.