Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7638 views
1
MuPDFActivity
2
~~~~~~~~~~~~~
3
4
MuPDFActivity is the main activity used when displaying and interacting with a
5
document. This class is responsible for creating the view hierarchy and the
6
menus.
7
8
9
Main view classes
10
~~~~~~~~~~~~~~~~~
11
12
ReaderView
13
~~~~~~~~~~
14
MuPDF uses Android's standard Adapter/AdapterView paradigm, where a subclass of
15
BaseAdapter supplies multiple views that have their motion on screen
16
choreographed by a subclass of AdapterView. There are several standard
17
AdapterView subclasses, but none support zooming into a specific subview and
18
then panning within it, so MuPDF has its own AdapterView subclass, namely
19
ReaderView. The class is intended to be general purpose and usable within any
20
document-viewing application. During page viewing, ReaderView handles all touch
21
events, recognises gestures and positions the displayed document pages
22
accordingly. ReaderView needs to handle positioning slightly differently
23
depending on whether MuPDF is reflowing text or not, and so it has two slightly
24
different modes of operation.
25
26
MuPDFReaderView
27
~~~~~~~~~~~~~~~
28
MuPDFReaderView subclasses ReaderView, so as to provide some of the
29
page-positioning behaviour that is specific to MuPDF. It overrides some of the
30
gesture recognition methods of ReaderView, so that it can perform special
31
handling of (e.g.) tapping on the side of the screen for page progression, and
32
tapping on links or form fields. It also handles the disabling of scrolling
33
during text-selection and annotation-drawing, and it performs the setup
34
operations needed by the individual page views as each newly appears.
35
36
MuPDFView
37
~~~~~~~~~
38
Document viewing uses different View subclasses to display the individual pages
39
depending on whether reflowing text or displaying pages unaltered. MuPDFView is
40
the common interface to the two view subclasses.
41
42
PageView
43
~~~~~~~~
44
PageView is the main View class used for non-reflow display of a page. Like
45
ReaderView, it is intended to be, as much as is possible, independent of the
46
specifics of MuPDF and usable in general document display apps. It is a
47
subclass of ViewGroup because page displays are built from several layers. The
48
lowest layer is a rendering of the page at a resolution that matches the screen
49
exactly when maximally zoomed out so that the page fits the screen. As the user
50
zooms in, this layer maintains a visible appearance of the page, but one that
51
becomes more blurred as zooming in progresses. A second layer provides a higher
52
resolution rendering of just the area of the page that is visible on screen,
53
and at a resolution that matches the screen. As the user pans, this layer is
54
updated on a background thread, so parts of the blurred layer will temporarily
55
become visible, but only momentarily later to be replaced by the high-quality
56
rendering. There is one further layer that is used to draw transparent shapes
57
for highlighting and the like.
58
59
MuPDFPageView
60
~~~~~~~~~~~~~
61
MuPDFPageView is a subclass of PageView, which handles some of the specifics of
62
MuPDF's behaviour, such as taps on links and form fields, text selection, and
63
annotation drawing. It also handles its parent class's bitmap rendering calls.
64
This is the class used to display pages in non-reflow mode. It implements the
65
MuPDFView interface.
66
67
MuPDFReflowView
68
~~~~~~~~~~~~~~~
69
This is the class used to display pages in reflow mode. Like MuPDFPageView it
70
implements the MuPDFView interface. It is a subclass of WebView, and achieves
71
reflowing by loading an HTML version of the page, which the MuPDF core
72
constructs.
73
74
MuPDFPageAdapter and MuPDFReflowAdapter
75
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76
As with any AdapterView subclass, ReaderView needs an Adapter subclass to
77
supply, on demand, the subviews for the pages currently displayed. These are
78
the two Adapter subclasses, supplying the subviews as MuPDFPageView and
79
MuPDFReflowView objects respectively. The former is a little more complex than
80
the latter, since it caches the sizes of the pages corresponding to the views
81
it supplies. It does so, so that page views, on their second and subsequent
82
appearances, can take on their correct size immediately. (The determining of
83
page size is not a completely trivial operation and is performed on a
84
background thread, as is all interaction with the core MuPDF library).
85
86
87
C library wrapper
88
~~~~~~~~~~~~~~~~~
89
90
MuPDFCore
91
~~~~~~~~~
92
This class is the interface to the MuPDF C library. It is used to render bitmap
93
versions of the page for display in the view classes mentioned above. It also
94
provides for interaction with objects within the page, such as the individual
95
text objects and annotations. Many of the methods take too long an execution
96
time to be run on the UI thread, hence they need to be run in the background,
97
and because even the fast methods have to be synchronised with the slower
98
methods, (almost) all methods should be called in the background. There are a
99
few non synchronised ones that have special purposes.
100
101
102
Link handling
103
~~~~~~~~~~~~~
104
There are three types of PDF links, each entailing different information and
105
requiring different handling. There are five classes involved in their
106
representation.
107
108
LinkInfo is the base class representing any one of the three
109
110
LinkInfoExternal, LinkInfoInternal and LinkInfoRemote are the three subclasses
111
representing the specific cases.
112
113
LinkInfoVisitor is a class implementing a common Java paradigm which allows
114
case analysis on the three different types of link, executing different methods
115
for each.
116
117
BitmapHolder
118
~~~~~~~~~~~~
119
BitmapHolder is the solution to a problem in allocating the Bitmaps to which
120
rendering is performed by background tasks. Renderings for the purpose of
121
update have to be passed a Bitmap with the current page state. During frenetic
122
page flicking a large number of rendering tasks can be queued, each holding
123
reference to a Bitmap. Rather than pass the Bitmap directly, we pass a
124
BitmapHolder containing a reference to the Bitmap. When a page view transitions
125
off screen, the BitmapHolder's reference to the Bitmap can be nulled to release
126
it.
127
128
SearchTask and SearchTaskResult
129
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
SearchTask encapsulates the process of searching for a text string within a
131
document. The class uses an AsyncTask internally to perform the search in the
132
background and reports the result by calling onTextFound. A SearchTaskResult
133
object is used to return the result of the search.
134
135
SafeAnimatorInflator
136
~~~~~~~~~~~~~~~~~~~~
137
This class is a simple wrapper around AnimatorInflator. AnimatorInflator
138
doesn't exist in some of the Android API levels MuPDF supports, and the wrapper
139
allows for a test of API-level before the point at which the class would be
140
loaded.
141
142
MuPDFAlert and MuPDFAlertInternal
143
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
This class represents the information issued by a javascript app.alert call.
145
MuPDFAlertInternal represents the same information, but with Java enums
146
replaced by ints, which are easier to return from JNI code.
147
148
TextChar and TextWord
149
~~~~~~~~~~~~~~~~~~~~~
150
TextChar is used when processing the individual characters of the page. Each
151
TextChar object contains the character and the rectangular area of the page at
152
which it appears. TextWord is used to gather TextChars into words.
153
154
Annotation
155
~~~~~~~~~~
156
This class represents the type and position on page of a PDF annotation.
157
158
Other activities
159
~~~~~~~~~~~~~~~~
160
The app has three activities other than document-viewing.
161
162
ChoosePDFActivity
163
~~~~~~~~~~~~~~~~~
164
ChoosePDFActivity allows the user to navigate local disc directories and view a
165
list of loadable files, from which one can be chosen. It derives off
166
ListActivity, and so displays the files in a standard ListView. ChoosePDFItem
167
represents the various types of list entry: up-one, directory or file.
168
ChoosePDFAdapter populates the list view.
169
170
OutlineActivity
171
~~~~~~~~~~~~~~~
172
OutlineActivity displays a PDF document's outline as a list of selectable
173
section titles. OutlineActivityData represents the current state of the
174
activity. OutlineItem represents the individual items, and OutlineAdapter
175
populates the list view.
176
177
PrintDialogActivity
178
~~~~~~~~~~~~~~~~~~~
179
This activity allows the user to print documents via Google Cloud Print.
180
181
182
Copied system classes
183
~~~~~~~~~~~~~~~~~~~~~
184
AsyncTask has had improvements made to it since issuing at the lowest android
185
API level we support, and so we include the improved version as part of the
186
MuPDF app. We also include Deque and ArrayDeque, which are used my AsyncTask.
187
188
189