├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── android-pdf-viewer
├── build.gradle
├── publish-mavencentral.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── github
│ │ └── barteksc
│ │ └── pdfviewer
│ │ ├── AnimationManager.java
│ │ ├── CacheManager.java
│ │ ├── DecodingAsyncTask.java
│ │ ├── DragPinchManager.java
│ │ ├── PDFView.java
│ │ ├── PagesLoader.java
│ │ ├── PdfFile.java
│ │ ├── RenderingHandler.java
│ │ ├── exception
│ │ ├── FileNotFoundException.java
│ │ └── PageRenderingException.java
│ │ ├── link
│ │ ├── DefaultLinkHandler.java
│ │ └── LinkHandler.java
│ │ ├── listener
│ │ ├── Callbacks.java
│ │ ├── OnDrawListener.java
│ │ ├── OnErrorListener.java
│ │ ├── OnLoadCompleteListener.java
│ │ ├── OnLongPressListener.java
│ │ ├── OnPageChangeListener.java
│ │ ├── OnPageErrorListener.java
│ │ ├── OnPageScrollListener.java
│ │ ├── OnRenderListener.java
│ │ └── OnTapListener.java
│ │ ├── model
│ │ ├── LinkTapEvent.java
│ │ └── PagePart.java
│ │ ├── scroll
│ │ ├── DefaultScrollHandle.java
│ │ └── ScrollHandle.java
│ │ ├── source
│ │ ├── AssetSource.java
│ │ ├── ByteArraySource.java
│ │ ├── DocumentSource.java
│ │ ├── FileSource.java
│ │ ├── InputStreamSource.java
│ │ └── UriSource.java
│ │ └── util
│ │ ├── ArrayUtils.java
│ │ ├── Constants.java
│ │ ├── FileUtils.java
│ │ ├── FitPolicy.java
│ │ ├── MathUtils.java
│ │ ├── PageSizeCalculator.java
│ │ ├── SnapEdge.java
│ │ └── Util.java
│ └── res
│ ├── drawable
│ ├── default_scroll_handle_bottom.xml
│ ├── default_scroll_handle_left.xml
│ ├── default_scroll_handle_right.xml
│ └── default_scroll_handle_top.xml
│ └── values
│ └── attrs.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── sample.pdf
│ ├── java
│ └── com
│ │ └── github
│ │ └── barteksc
│ │ └── sample
│ │ └── PDFViewActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_open_in_browser_grey_700_48dp.png
│ ├── drawable-mdpi
│ └── ic_open_in_browser_grey_700_48dp.png
│ ├── drawable-xhdpi
│ └── ic_open_in_browser_grey_700_48dp.png
│ ├── drawable-xxhdpi
│ └── ic_open_in_browser_grey_700_48dp.png
│ ├── drawable-xxxhdpi
│ └── ic_open_in_browser_grey_700_48dp.png
│ ├── drawable
│ └── ic_launcher.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── options.xml
│ └── values
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | build/
3 | lint.xml
4 | bin/
5 | gen/
6 | .settings
7 | .project
8 | .classpath
9 | out
10 | gen-external-apklibs/
11 | classes/
12 |
13 | # Local configuration file (sdk path, etc)
14 | local.properties
15 |
16 | # Android Studio
17 | .idea/
18 | */out
19 | !*/build/apk/
20 | */production/
21 | *.iws
22 | *.ipr
23 | *.iml
24 | *~
25 | *.swp
26 |
27 | # gradle
28 | .gradle
29 |
30 | .DS_Store
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 3.2.0-beta.3 (2022-05-22)
2 | * Change minimum SDK version to 19
3 | * Drop MIPS support
4 | * Update to Androidx
5 | * Switch pdfium-android to a [fork](https://github.com/mhiew/PdfiumAndroid) so we can disable jetifier
6 |
7 | ## 3.2.0-beta.2 (2021-12-27)
8 | * Fix a potential NPE due to out of sync render thread management [Pull Request](https://github.com/barteksc/AndroidPdfViewer/pull/824)
9 | * Update the sample app configuration so that it can compile [Pull Request](https://github.com/mhiew/AndroidPdfViewer/pull/2)
10 |
11 | ## 3.2.0-beta.1 (2019-08-18)
12 | * Merge PR #714 with optimized page load
13 | * Merge PR #776 with fix for max & min zoom level
14 | * Merge PR #722 with fix for showing right position when view size changed
15 | * Merge PR #703 with fix for too many threads
16 | * Merge PR #702 with fix for memory leak
17 | * Merge PR #689 with possibility to disable long click
18 | * Merge PR #628 with fix for hiding scroll handle
19 | * Merge PR #627 with `fitEachPage` option
20 | * Merge PR #638 and #406 with fixed NPE
21 | * Merge PR #780 with README fix
22 | * Update compile SDK and support library to 28
23 | * Update Gradle and Gradle Plugin
24 |
25 | ## 3.1.0-beta.1 (2018-06-29)
26 | * Merge pull request #557 for snapping pages (scrolling page by page)
27 | * merge pull request #618 for night mode
28 | * Merge pull request #566 for `OnLongTapListener`
29 | * Update PdfiumAndroid to 1.9.0, which uses `c++_shared` instead of `gnustl_static`
30 | * Update Gradle Plugin
31 | * Update compile SDK and support library to 26
32 | * Change minimum SDK to 14
33 |
34 | ## 3.0.0-beta.5 (2018-01-06)
35 | * Fix issue with `Configurator#pages()` from #486
36 | * Fix `IllegalStateException` from #464
37 | * Fix not detecting links reported in #447
38 |
39 | ## 3.0.0-beta.4 (2017-12-15)
40 | * Fix not loaded pages when using animated `PDFView#jumpTo()`
41 | * Fix NPE in `canScrollVertically()` and `canScrollHorizontally()`
42 |
43 | ## 3.0.0-beta.3 (2017-11-18)
44 | * Fix bug preventing `OnErrorListener` from being called
45 |
46 | ## 3.0.0-beta.2 (2017-11-15)
47 | * Fix rendering with maximum zoom
48 | * Improve fit policies
49 | * Update PdfiumAndroid to 1.8.1
50 |
51 | ## 3.0.0-beta.1 (2017-11-12)
52 | * Add support for documents with different page sizes
53 | * Add support for links
54 | * Add support for defining page fit policy (fit width, height or both)
55 | * Update sample.pdf to contain different page sizes
56 |
57 | ## 2.8.1 (2017-11-11)
58 | * Fix bug with rendering `PDFView` in Android Studio Layout Editor
59 |
60 | ## 2.8.0 (2017-10-31)
61 | * Add handling of invalid pages, inspired by pull request #433. Exception on page opening crashed application until now,
62 | currently `OnPageErrorListener` set with `.onPageError()` is called. Invalid page color can be set using `.invalidPageColor()`
63 | * Implement `canScrollVertically()` and `canScrollHorizontally()` methods to work e.g. with `SwipeRefreshLayout`
64 | * Fix bug when `Configurator#load()` method was called before view has been measured, which resulted in empty canvas
65 |
66 | ## 2.7.0 (2017-08-30)
67 | * Merge pull request by [owurman](https://github.com/owurman) with added OnTapListener
68 | * Merge bugfix by [lzwandnju](https://github.com/lzwandnju) to prevent `ArithmeticException: divide by zero`
69 |
70 | ## 2.7.0-beta.1 (2017-07-05)
71 | * Updates PdfiumAndroid to 1.7.0 which reduces memory usage about twice and improves performance by using RGB 565 format (when not using `pdfView.useBestQuality(true)`)
72 |
73 | ## 2.7.0-beta (2017-06-16)
74 | * Update PdfiumAndroid to 1.6.1, which fixed font rendering (issue #253)
75 | * Add `.spacing(int)` method to add spacing (in dp) between document pages
76 | * Fix drawing with `.onDraw(onDrawListener)`
77 | * Add `.onDrawAll(onDrawListener)` method to draw on all pages
78 | * Add small rendering improvements
79 | * Fix rendering when duplicated pages are passed to `.pages(..)`
80 |
81 | ## 2.6.1 (2017-06-08)
82 | * Fix disappearing scroll handle
83 |
84 | ## 2.6.0 (2017-06-04)
85 | * Fix fling on single-page documents
86 | * Greatly improve overall fling experience
87 |
88 | ## 2.5.1 (2017-04-08)
89 | * Temporarily downgrade PdfiumAndroid until #253 will be fixed
90 |
91 | ## 2.5.0 (2017-03-23)
92 | * Update PdfiumAndroid to 1.6.0, which is based on newest Pdfium from Android 7.1.1. It should fix many rendering and fonts problems
93 | * Add method `pdfView.fitToWidth()`, which called in `OnRenderListener.onInitiallyRendered()` will fit document to width of the screen (inspired by [1stmetro](https://github.com/1stmetro))
94 | * Add change from pull request by [isanwenyu](https://github.com/isanwenyu) to get rid of rare IllegalArgumentException while rendering
95 | * Add `OnRenderListener`, that will be called once, right before document is drawn on the screen
96 | * Add `Configurator.enableAntialiasing()` to improve rendering on low-res screen a little bit (as suggested by [majkimester](majkimester))
97 | * Modify engine to not block UI when big documents are loaded
98 | * Change `Constants` interface and inner interfaces to static public classes, to allow modifying core config values
99 |
100 | ## 2.4.0 (2016-12-30)
101 | * Merge pull request by [hansinator85](https://github.com/hansinator85) which allows to enable/disable rendering during scale
102 | * Make rendering during scale disabled by default (looks better)
103 | * Merge pull request by [cesquivias](https://github.com/cesquivias) which replaces RenderingAsyncTask with Handler to simply code and work with testing frameworks
104 |
105 | ## 2.3.0 (2016-11-19)
106 | * Add mechanism for providing documents from different sources - more info in README
107 | * Update PdfiumAndroid to 1.5.0
108 | * Thanks to document sources and PdfiumAndroid update, in-memory documents are supported
109 | * Fix not working OnClickListener on PDFView
110 | * **com.github.barteksc.exception.FileNotFoundException** is deprecated and all usages was removed.
111 | All exceptions are delivered to old Configurator#onError() listener.
112 |
113 | ## 2.2.0 (2016-11-15)
114 | * Merge pull request by [skarempudi](https://github.com/skarempudi) which fixes SDK 23 permission problems in sample app
115 | * Merge pull request by skarempudi for showing info on phones without file manager
116 | * Add feature from 1.x - canvas is set to drawable from View#getBackground()
117 |
118 | ## 2.1.0 (2016-09-16)
119 | * fixed loading document from subfolder in assets directory
120 | * fixed scroll handle NPE after document loading error (improvement of 2.0.3 fix)
121 | * fixed incorrect scroll handle position with additional views in RelativeLayout
122 | * improved cache usage and fixed bug with rendering when zooming
123 | * if you are using custom scroll handle: scroll handle implementation changed a little bit, check DefaultScrollHandle source for details
124 |
125 | ## 2.0.3 (2016-08-30)
126 | * Fix scroll handle NPE after document loading error
127 |
128 | ## 2.0.2 (2016-08-27)
129 | * Fix exceptions caused by improperly finishing rendering task
130 |
131 | ## 2.0.1 (2016-08-16)
132 | * Fix NPE when onDetachFromWindow is called
133 |
134 | ## 2.0.0 (2016-08-14)
135 | * few API changes
136 | * improved rendering speed and accuracy
137 | * added continuous scroll - now it behaves like Adobe Reader and others
138 | * added `fling` scroll gesture for velocity based scrolling
139 | * added scroll handle as a replacement for scrollbar
140 |
141 | ### Changes in 2.0 API
142 | * `Configurator#defaultPage(int)` and `PDFView#jumpTo(int)` now require page index (i.e. starting from 0)
143 | * `OnPageChangeListener#onPageChanged(int, int)` is called with page index (i.e. starting from 0)
144 | * removed scrollbar
145 | * added scroll handle as a replacement for scrollbar, use with `Configurator#scrollHandle()`
146 | * added `OnPageScrollListener` listener due to continuous scroll, register with `Configurator#onPageScroll()`
147 | * default scroll direction is vertical, so `Configurator#swipeVertical()` was changed to `Configurator#swipeHorizontal()`
148 | * removed minimap and mask configuration
149 |
150 | ## 1.4.0 (2016-07-25)
151 | * Fix NPE and IndexOutOfBound bugs when rendering parts
152 | * Merge pull request by [paulo-sato-daitan](https://github.com/paulo-sato-daitan) for disabling page change animation
153 | * Merge pull request by [Miha-x64](https://github.com/Miha-x64) for drawing background if set on `PDFView`
154 |
155 | ## 1.3.0 (2016-07-13)
156 | * update PdfiumAndroid to 1.4.0 with support for rendering annotations
157 | * merge pull request by [usef](https://github.com/usef) for rendering annotations
158 |
159 | ## 1.2.0 (2016-07-11)
160 | * update PdfiumAndroid to 1.3.1 with support for bookmarks, Table Of Contents and documents with password:
161 | * added method `PDFView#getDocumentMeta()`, which returns document metadata
162 | * added method `PDFView#getTableOfContents()`, which returns whole tree of bookmarks in PDF document
163 | * added method `Configurator#password(String)`
164 | * added horizontal mode to **ScrollBar** - use `ScrollBar#setHorizontal(true)` or `app:sb_horizontal="true"` in XML
165 | * block interaction with `PDFView` when document is not loaded - prevent some exceptions
166 | * fix `PDFView` exceptions in layout preview (edit mode)
167 |
168 | ## 1.1.2 (2016-06-27)
169 | * update PdfiumAndroid to 1.1.0, which fixes displaying multiple `PDFView`s at the same time and few errors with loading PDF documents.
170 |
171 | ## 1.1.1 (2016-06-17)
172 | * fixes bug with strange behavior when indices passed to `.pages()` don't start with `0`.
173 |
174 | ## 1.1.0 (2016-06-16)
175 | * added method `pdfView.fromUri(Uri)` for opening files from content providers
176 | * updated PdfiumAndroid to 1.0.3, which should fix bug with exception
177 | * updated sample with demonstration of `fromUri()` method
178 | * some minor fixes
179 |
180 | ## 1.0.0 (2016-06-06)
181 | * Initial release
182 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | #### This is a fork of the [AndroidPdfViewer](https://github.com/barteksc/AndroidPdfViewer)
3 | switch back to the mainline repo when it gets migrated off JCenter
4 |
5 |
6 | # Android PdfViewer
7 |
8 | __AndroidPdfViewer 1.x is available on [AndroidPdfViewerV1](https://github.com/barteksc/AndroidPdfViewerV1)
9 | repo, where can be developed independently. Version 1.x uses different engine for drawing document on canvas,
10 | so if you don't like 2.x version, try 1.x.__
11 |
12 | Library for displaying PDF documents on Android, with `animations`, `gestures`, `zoom` and `double tap` support.
13 | It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 (Android 3.0) and higher.
14 | Licensed under Apache License 2.0.
15 |
16 | ## 3.2.0-beta.3
17 | * Change minimum SDK version to 19
18 | * Drop MIPS support
19 | * Update to Androidx
20 | * Switch pdfium-android to a [fork](https://github.com/mhiew/PdfiumAndroid) so we can disable jetifier
21 |
22 | ## 3.2.0-beta.2
23 | * Fix a potential NPE due to out of sync render thread management [Pull Request](https://github.com/barteksc/AndroidPdfViewer/pull/824)
24 | * Update the sample app configuration so that it can compile [Pull Request](https://github.com/mhiew/AndroidPdfViewer/pull/2)
25 |
26 | ## What's new in 3.2.0-beta.1?
27 | * Merge PR #714 with optimized page load
28 | * Merge PR #776 with fix for max & min zoom level
29 | * Merge PR #722 with fix for showing right position when view size changed
30 | * Merge PR #703 with fix for too many threads
31 | * Merge PR #702 with fix for memory leak
32 | * Merge PR #689 with possibility to disable long click
33 | * Merge PR #628 with fix for hiding scroll handle
34 | * Merge PR #627 with `fitEachPage` option
35 | * Merge PR #638 and #406 with fixed NPE
36 | * Merge PR #780 with README fix
37 | * Update compile SDK and support library to 28
38 | * Update Gradle and Gradle Plugin
39 |
40 | ## Changes in 3.0 API
41 | * Replaced `Contants.PRELOAD_COUNT` with `PRELOAD_OFFSET`
42 | * Removed `PDFView#fitToWidth()` (variant without arguments)
43 | * Removed `Configurator#invalidPageColor(int)` method as invalid pages are not rendered
44 | * Removed page size parameters from `OnRenderListener#onInitiallyRendered(int)` method, as document may have different page sizes
45 | * Removed `PDFView#setSwipeVertical()` method
46 |
47 | ## Installation
48 |
49 | Add to _build.gradle_:
50 |
51 | ```groovy
52 | allprojects {
53 | repositories {
54 | ...
55 | mavenCentral()
56 | ...
57 | }
58 | }
59 | ```
60 |
61 | `implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.3'`
62 |
63 | ## ProGuard
64 | If you are using ProGuard, add following rule to proguard config file:
65 |
66 | ```proguard
67 | -keep class com.shockwave.**
68 | ```
69 |
70 | ## Include PDFView in your layout
71 |
72 | ``` xml
73 |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.exception; 17 | 18 | @Deprecated 19 | public class FileNotFoundException extends RuntimeException { 20 | 21 | public FileNotFoundException(String detailMessage) { 22 | super(detailMessage); 23 | } 24 | 25 | public FileNotFoundException(String detailMessage, Throwable throwable) { 26 | super(detailMessage, throwable); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/exception/PageRenderingException.java: -------------------------------------------------------------------------------- 1 | package com.github.barteksc.pdfviewer.exception; 2 | 3 | public class PageRenderingException extends Exception { 4 | private final int page; 5 | 6 | public PageRenderingException(int page, Throwable cause) { 7 | super(cause); 8 | this.page = page; 9 | } 10 | 11 | public int getPage() { 12 | return page; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/link/DefaultLinkHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.link; 17 | 18 | import android.content.Context; 19 | import android.content.Intent; 20 | import android.net.Uri; 21 | import android.util.Log; 22 | 23 | import com.github.barteksc.pdfviewer.PDFView; 24 | import com.github.barteksc.pdfviewer.model.LinkTapEvent; 25 | 26 | public class DefaultLinkHandler implements LinkHandler { 27 | 28 | private static final String TAG = DefaultLinkHandler.class.getSimpleName(); 29 | 30 | private PDFView pdfView; 31 | 32 | public DefaultLinkHandler(PDFView pdfView) { 33 | this.pdfView = pdfView; 34 | } 35 | 36 | @Override 37 | public void handleLinkEvent(LinkTapEvent event) { 38 | String uri = event.getLink().getUri(); 39 | Integer page = event.getLink().getDestPageIdx(); 40 | if (uri != null && !uri.isEmpty()) { 41 | handleUri(uri); 42 | } else if (page != null) { 43 | handlePage(page); 44 | } 45 | } 46 | 47 | private void handleUri(String uri) { 48 | Uri parsedUri = Uri.parse(uri); 49 | Intent intent = new Intent(Intent.ACTION_VIEW, parsedUri); 50 | Context context = pdfView.getContext(); 51 | if (intent.resolveActivity(context.getPackageManager()) != null) { 52 | context.startActivity(intent); 53 | } else { 54 | Log.w(TAG, "No activity found for URI: " + uri); 55 | } 56 | } 57 | 58 | private void handlePage(int page) { 59 | pdfView.jumpTo(page); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/link/LinkHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.link; 17 | 18 | import com.github.barteksc.pdfviewer.model.LinkTapEvent; 19 | 20 | public interface LinkHandler { 21 | 22 | /** 23 | * Called when link was tapped by user 24 | * 25 | * @param event current event 26 | */ 27 | void handleLinkEvent(LinkTapEvent event); 28 | } 29 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/Callbacks.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | import android.view.MotionEvent; 19 | 20 | import com.github.barteksc.pdfviewer.link.LinkHandler; 21 | import com.github.barteksc.pdfviewer.model.LinkTapEvent; 22 | 23 | public class Callbacks { 24 | 25 | /** 26 | * Call back object to call when the PDF is loaded 27 | */ 28 | private OnLoadCompleteListener onLoadCompleteListener; 29 | 30 | /** 31 | * Call back object to call when document loading error occurs 32 | */ 33 | private OnErrorListener onErrorListener; 34 | 35 | /** 36 | * Call back object to call when the page load error occurs 37 | */ 38 | private OnPageErrorListener onPageErrorListener; 39 | 40 | /** 41 | * Call back object to call when the document is initially rendered 42 | */ 43 | private OnRenderListener onRenderListener; 44 | 45 | /** 46 | * Call back object to call when the page has changed 47 | */ 48 | private OnPageChangeListener onPageChangeListener; 49 | 50 | /** 51 | * Call back object to call when the page is scrolled 52 | */ 53 | private OnPageScrollListener onPageScrollListener; 54 | 55 | /** 56 | * Call back object to call when the above layer is to drawn 57 | */ 58 | private OnDrawListener onDrawListener; 59 | 60 | private OnDrawListener onDrawAllListener; 61 | 62 | /** 63 | * Call back object to call when the user does a tap gesture 64 | */ 65 | private OnTapListener onTapListener; 66 | 67 | /** 68 | * Call back object to call when the user does a long tap gesture 69 | */ 70 | private OnLongPressListener onLongPressListener; 71 | 72 | /** 73 | * Call back object to call when clicking link 74 | */ 75 | private LinkHandler linkHandler; 76 | 77 | public void setOnLoadComplete(OnLoadCompleteListener onLoadCompleteListener) { 78 | this.onLoadCompleteListener = onLoadCompleteListener; 79 | } 80 | 81 | public void callOnLoadComplete(int pagesCount) { 82 | if (onLoadCompleteListener != null) { 83 | onLoadCompleteListener.loadComplete(pagesCount); 84 | } 85 | } 86 | 87 | public void setOnError(OnErrorListener onErrorListener) { 88 | this.onErrorListener = onErrorListener; 89 | } 90 | 91 | public OnErrorListener getOnError() { 92 | return onErrorListener; 93 | } 94 | 95 | public void setOnPageError(OnPageErrorListener onPageErrorListener) { 96 | this.onPageErrorListener = onPageErrorListener; 97 | } 98 | 99 | public boolean callOnPageError(int page, Throwable error) { 100 | if (onPageErrorListener != null) { 101 | onPageErrorListener.onPageError(page, error); 102 | return true; 103 | } 104 | return false; 105 | } 106 | 107 | public void setOnRender(OnRenderListener onRenderListener) { 108 | this.onRenderListener = onRenderListener; 109 | } 110 | 111 | public void callOnRender(int pagesCount) { 112 | if (onRenderListener != null) { 113 | onRenderListener.onInitiallyRendered(pagesCount); 114 | } 115 | } 116 | 117 | public void setOnPageChange(OnPageChangeListener onPageChangeListener) { 118 | this.onPageChangeListener = onPageChangeListener; 119 | } 120 | 121 | public void callOnPageChange(int page, int pagesCount) { 122 | if (onPageChangeListener != null) { 123 | onPageChangeListener.onPageChanged(page, pagesCount); 124 | } 125 | } 126 | 127 | public void setOnPageScroll(OnPageScrollListener onPageScrollListener) { 128 | this.onPageScrollListener = onPageScrollListener; 129 | } 130 | 131 | public void callOnPageScroll(int currentPage, float offset) { 132 | if (onPageScrollListener != null) { 133 | onPageScrollListener.onPageScrolled(currentPage, offset); 134 | } 135 | } 136 | 137 | public void setOnDraw(OnDrawListener onDrawListener) { 138 | this.onDrawListener = onDrawListener; 139 | } 140 | 141 | public OnDrawListener getOnDraw() { 142 | return onDrawListener; 143 | } 144 | 145 | public void setOnDrawAll(OnDrawListener onDrawAllListener) { 146 | this.onDrawAllListener = onDrawAllListener; 147 | } 148 | 149 | public OnDrawListener getOnDrawAll() { 150 | return onDrawAllListener; 151 | } 152 | 153 | public void setOnTap(OnTapListener onTapListener) { 154 | this.onTapListener = onTapListener; 155 | } 156 | 157 | public boolean callOnTap(MotionEvent event) { 158 | return onTapListener != null && onTapListener.onTap(event); 159 | } 160 | 161 | public void setOnLongPress(OnLongPressListener onLongPressListener) { 162 | this.onLongPressListener = onLongPressListener; 163 | } 164 | 165 | public void callOnLongPress(MotionEvent event) { 166 | if (onLongPressListener != null) { 167 | onLongPressListener.onLongPress(event); 168 | } 169 | } 170 | 171 | public void setLinkHandler(LinkHandler linkHandler) { 172 | this.linkHandler = linkHandler; 173 | } 174 | 175 | public void callLinkHandler(LinkTapEvent event) { 176 | if (linkHandler != null) { 177 | linkHandler.handleLinkEvent(event); 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnDrawListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | import android.graphics.Canvas; 19 | 20 | /** 21 | * This interface allows an extern class to draw 22 | * something on the PDFView canvas, above all images. 23 | */ 24 | public interface OnDrawListener { 25 | 26 | /** 27 | * This method is called when the PDFView is 28 | * drawing its view. 29 | *
30 | * The page is starting at (0,0) 31 | * 32 | * @param canvas The canvas on which to draw things. 33 | * @param pageWidth The width of the current page. 34 | * @param pageHeight The height of the current page. 35 | * @param displayedPage The current page index 36 | */ 37 | void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage); 38 | } 39 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | public interface OnErrorListener { 19 | 20 | /** 21 | * Called if error occurred while opening PDF 22 | * @param t Throwable with error 23 | */ 24 | void onError(Throwable t); 25 | } 26 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnLoadCompleteListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | /** 19 | * Implement this interface to receive events from PDFView 20 | * when loading is complete. 21 | */ 22 | public interface OnLoadCompleteListener { 23 | 24 | /** 25 | * Called when the PDF is loaded 26 | * @param nbPages the number of pages in this PDF file 27 | */ 28 | void loadComplete(int nbPages); 29 | } 30 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnLongPressListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | import android.view.MotionEvent; 19 | 20 | /** 21 | * Implement this interface to receive events from PDFView 22 | * when view has been long pressed 23 | */ 24 | public interface OnLongPressListener { 25 | 26 | /** 27 | * Called when the user has a long tap gesture, before processing scroll handle toggling 28 | * 29 | * @param e MotionEvent that registered as a confirmed long press 30 | */ 31 | void onLongPress(MotionEvent e); 32 | } 33 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnPageChangeListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | /** 19 | * Implements this interface to receive events from PDFView 20 | * when a page has changed through swipe 21 | */ 22 | public interface OnPageChangeListener { 23 | 24 | /** 25 | * Called when the user use swipe to change page 26 | * 27 | * @param page the new page displayed, starting from 0 28 | * @param pageCount the total page count 29 | */ 30 | void onPageChanged(int page, int pageCount); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnPageErrorListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | public interface OnPageErrorListener { 19 | 20 | /** 21 | * Called if error occurred while loading PDF page 22 | * @param t Throwable with error 23 | */ 24 | void onPageError(int page, Throwable t); 25 | } 26 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnPageScrollListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | /** 19 | * Implements this interface to receive events from PDFView 20 | * when a page has been scrolled 21 | */ 22 | public interface OnPageScrollListener { 23 | 24 | /** 25 | * Called on every move while scrolling 26 | * 27 | * @param page current page index 28 | * @param positionOffset see {@link com.github.barteksc.pdfviewer.PDFView#getPositionOffset()} 29 | */ 30 | void onPageScrolled(int page, float positionOffset); 31 | } 32 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnRenderListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | public interface OnRenderListener { 19 | 20 | /** 21 | * Called only once, when document is rendered 22 | * @param nbPages number of pages 23 | */ 24 | void onInitiallyRendered(int nbPages); 25 | } 26 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/listener/OnTapListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.listener; 17 | 18 | import android.view.MotionEvent; 19 | 20 | /** 21 | * Implement this interface to receive events from PDFView 22 | * when view has been touched 23 | */ 24 | public interface OnTapListener { 25 | 26 | /** 27 | * Called when the user has a tap gesture, before processing scroll handle toggling 28 | * 29 | * @param e MotionEvent that registered as a confirmed single tap 30 | * @return true if the single tap was handled, false to toggle scroll handle 31 | */ 32 | boolean onTap(MotionEvent e); 33 | } 34 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/model/LinkTapEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.model; 17 | 18 | import android.graphics.RectF; 19 | 20 | import com.shockwave.pdfium.PdfDocument; 21 | 22 | public class LinkTapEvent { 23 | private float originalX; 24 | private float originalY; 25 | private float documentX; 26 | private float documentY; 27 | private RectF mappedLinkRect; 28 | private PdfDocument.Link link; 29 | 30 | public LinkTapEvent(float originalX, float originalY, float documentX, float documentY, RectF mappedLinkRect, PdfDocument.Link link) { 31 | this.originalX = originalX; 32 | this.originalY = originalY; 33 | this.documentX = documentX; 34 | this.documentY = documentY; 35 | this.mappedLinkRect = mappedLinkRect; 36 | this.link = link; 37 | } 38 | 39 | public float getOriginalX() { 40 | return originalX; 41 | } 42 | 43 | public float getOriginalY() { 44 | return originalY; 45 | } 46 | 47 | public float getDocumentX() { 48 | return documentX; 49 | } 50 | 51 | public float getDocumentY() { 52 | return documentY; 53 | } 54 | 55 | public RectF getMappedLinkRect() { 56 | return mappedLinkRect; 57 | } 58 | 59 | public PdfDocument.Link getLink() { 60 | return link; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/model/PagePart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.model; 17 | 18 | import android.graphics.Bitmap; 19 | import android.graphics.RectF; 20 | 21 | public class PagePart { 22 | 23 | private int page; 24 | 25 | private Bitmap renderedBitmap; 26 | 27 | private RectF pageRelativeBounds; 28 | 29 | private boolean thumbnail; 30 | 31 | private int cacheOrder; 32 | 33 | public PagePart(int page, Bitmap renderedBitmap, RectF pageRelativeBounds, boolean thumbnail, int cacheOrder) { 34 | super(); 35 | this.page = page; 36 | this.renderedBitmap = renderedBitmap; 37 | this.pageRelativeBounds = pageRelativeBounds; 38 | this.thumbnail = thumbnail; 39 | this.cacheOrder = cacheOrder; 40 | } 41 | 42 | public int getCacheOrder() { 43 | return cacheOrder; 44 | } 45 | 46 | public int getPage() { 47 | return page; 48 | } 49 | 50 | public Bitmap getRenderedBitmap() { 51 | return renderedBitmap; 52 | } 53 | 54 | public RectF getPageRelativeBounds() { 55 | return pageRelativeBounds; 56 | } 57 | 58 | public boolean isThumbnail() { 59 | return thumbnail; 60 | } 61 | 62 | public void setCacheOrder(int cacheOrder) { 63 | this.cacheOrder = cacheOrder; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (!(obj instanceof PagePart)) { 69 | return false; 70 | } 71 | 72 | PagePart part = (PagePart) obj; 73 | return part.getPage() == page 74 | && part.getPageRelativeBounds().left == pageRelativeBounds.left 75 | && part.getPageRelativeBounds().right == pageRelativeBounds.right 76 | && part.getPageRelativeBounds().top == pageRelativeBounds.top 77 | && part.getPageRelativeBounds().bottom == pageRelativeBounds.bottom; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/scroll/DefaultScrollHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.barteksc.pdfviewer.scroll; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.Drawable; 6 | import android.os.Handler; 7 | import androidx.core.content.ContextCompat; 8 | import android.util.TypedValue; 9 | import android.view.MotionEvent; 10 | import android.view.ViewGroup; 11 | import android.widget.RelativeLayout; 12 | import android.widget.TextView; 13 | 14 | import com.github.barteksc.pdfviewer.PDFView; 15 | import com.github.barteksc.pdfviewer.R; 16 | import com.github.barteksc.pdfviewer.util.Util; 17 | 18 | public class DefaultScrollHandle extends RelativeLayout implements ScrollHandle { 19 | 20 | private final static int HANDLE_LONG = 65; 21 | private final static int HANDLE_SHORT = 40; 22 | private final static int DEFAULT_TEXT_SIZE = 16; 23 | 24 | private float relativeHandlerMiddle = 0f; 25 | 26 | protected TextView textView; 27 | protected Context context; 28 | private boolean inverted; 29 | private PDFView pdfView; 30 | private float currentPos; 31 | 32 | private Handler handler = new Handler(); 33 | private Runnable hidePageScrollerRunnable = new Runnable() { 34 | @Override 35 | public void run() { 36 | hide(); 37 | } 38 | }; 39 | 40 | public DefaultScrollHandle(Context context) { 41 | this(context, false); 42 | } 43 | 44 | public DefaultScrollHandle(Context context, boolean inverted) { 45 | super(context); 46 | this.context = context; 47 | this.inverted = inverted; 48 | textView = new TextView(context); 49 | setVisibility(INVISIBLE); 50 | setTextColor(Color.BLACK); 51 | setTextSize(DEFAULT_TEXT_SIZE); 52 | } 53 | 54 | @Override 55 | public void setupLayout(PDFView pdfView) { 56 | int align, width, height; 57 | Drawable background; 58 | // determine handler position, default is right (when scrolling vertically) or bottom (when scrolling horizontally) 59 | if (pdfView.isSwipeVertical()) { 60 | width = HANDLE_LONG; 61 | height = HANDLE_SHORT; 62 | if (inverted) { // left 63 | align = ALIGN_PARENT_LEFT; 64 | background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_left); 65 | } else { // right 66 | align = ALIGN_PARENT_RIGHT; 67 | background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_right); 68 | } 69 | } else { 70 | width = HANDLE_SHORT; 71 | height = HANDLE_LONG; 72 | if (inverted) { // top 73 | align = ALIGN_PARENT_TOP; 74 | background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_top); 75 | } else { // bottom 76 | align = ALIGN_PARENT_BOTTOM; 77 | background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_bottom); 78 | } 79 | } 80 | 81 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { 82 | setBackgroundDrawable(background); 83 | } else { 84 | setBackground(background); 85 | } 86 | 87 | LayoutParams lp = new LayoutParams(Util.getDP(context, width), Util.getDP(context, height)); 88 | lp.setMargins(0, 0, 0, 0); 89 | 90 | LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 91 | tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); 92 | 93 | addView(textView, tvlp); 94 | 95 | lp.addRule(align); 96 | pdfView.addView(this, lp); 97 | 98 | this.pdfView = pdfView; 99 | } 100 | 101 | @Override 102 | public void destroyLayout() { 103 | pdfView.removeView(this); 104 | } 105 | 106 | @Override 107 | public void setScroll(float position) { 108 | if (!shown()) { 109 | show(); 110 | } else { 111 | handler.removeCallbacks(hidePageScrollerRunnable); 112 | } 113 | if (pdfView != null) { 114 | setPosition((pdfView.isSwipeVertical() ? pdfView.getHeight() : pdfView.getWidth()) * position); 115 | } 116 | } 117 | 118 | private void setPosition(float pos) { 119 | if (Float.isInfinite(pos) || Float.isNaN(pos)) { 120 | return; 121 | } 122 | float pdfViewSize; 123 | if (pdfView.isSwipeVertical()) { 124 | pdfViewSize = pdfView.getHeight(); 125 | } else { 126 | pdfViewSize = pdfView.getWidth(); 127 | } 128 | pos -= relativeHandlerMiddle; 129 | 130 | if (pos < 0) { 131 | pos = 0; 132 | } else if (pos > pdfViewSize - Util.getDP(context, HANDLE_SHORT)) { 133 | pos = pdfViewSize - Util.getDP(context, HANDLE_SHORT); 134 | } 135 | 136 | if (pdfView.isSwipeVertical()) { 137 | setY(pos); 138 | } else { 139 | setX(pos); 140 | } 141 | 142 | calculateMiddle(); 143 | invalidate(); 144 | } 145 | 146 | private void calculateMiddle() { 147 | float pos, viewSize, pdfViewSize; 148 | if (pdfView.isSwipeVertical()) { 149 | pos = getY(); 150 | viewSize = getHeight(); 151 | pdfViewSize = pdfView.getHeight(); 152 | } else { 153 | pos = getX(); 154 | viewSize = getWidth(); 155 | pdfViewSize = pdfView.getWidth(); 156 | } 157 | relativeHandlerMiddle = ((pos + relativeHandlerMiddle) / pdfViewSize) * viewSize; 158 | } 159 | 160 | @Override 161 | public void hideDelayed() { 162 | handler.postDelayed(hidePageScrollerRunnable, 1000); 163 | } 164 | 165 | @Override 166 | public void setPageNum(int pageNum) { 167 | String text = String.valueOf(pageNum); 168 | if (!textView.getText().equals(text)) { 169 | textView.setText(text); 170 | } 171 | } 172 | 173 | @Override 174 | public boolean shown() { 175 | return getVisibility() == VISIBLE; 176 | } 177 | 178 | @Override 179 | public void show() { 180 | setVisibility(VISIBLE); 181 | } 182 | 183 | @Override 184 | public void hide() { 185 | setVisibility(INVISIBLE); 186 | } 187 | 188 | public void setTextColor(int color) { 189 | textView.setTextColor(color); 190 | } 191 | 192 | /** 193 | * @param size text size in dp 194 | */ 195 | public void setTextSize(int size) { 196 | textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size); 197 | } 198 | 199 | private boolean isPDFViewReady() { 200 | return pdfView != null && pdfView.getPageCount() > 0 && !pdfView.documentFitsView(); 201 | } 202 | 203 | @Override 204 | public boolean onTouchEvent(MotionEvent event) { 205 | 206 | if (!isPDFViewReady()) { 207 | return super.onTouchEvent(event); 208 | } 209 | 210 | switch (event.getAction()) { 211 | case MotionEvent.ACTION_DOWN: 212 | case MotionEvent.ACTION_POINTER_DOWN: 213 | pdfView.stopFling(); 214 | handler.removeCallbacks(hidePageScrollerRunnable); 215 | if (pdfView.isSwipeVertical()) { 216 | currentPos = event.getRawY() - getY(); 217 | } else { 218 | currentPos = event.getRawX() - getX(); 219 | } 220 | case MotionEvent.ACTION_MOVE: 221 | if (pdfView.isSwipeVertical()) { 222 | setPosition(event.getRawY() - currentPos + relativeHandlerMiddle); 223 | pdfView.setPositionOffset(relativeHandlerMiddle / (float) getHeight(), false); 224 | } else { 225 | setPosition(event.getRawX() - currentPos + relativeHandlerMiddle); 226 | pdfView.setPositionOffset(relativeHandlerMiddle / (float) getWidth(), false); 227 | } 228 | return true; 229 | case MotionEvent.ACTION_CANCEL: 230 | case MotionEvent.ACTION_UP: 231 | case MotionEvent.ACTION_POINTER_UP: 232 | hideDelayed(); 233 | pdfView.performPageSnap(); 234 | return true; 235 | } 236 | 237 | return super.onTouchEvent(event); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/scroll/ScrollHandle.java: -------------------------------------------------------------------------------- 1 | package com.github.barteksc.pdfviewer.scroll; 2 | 3 | import com.github.barteksc.pdfviewer.PDFView; 4 | 5 | public interface ScrollHandle { 6 | 7 | /** 8 | * Used to move the handle, called internally by PDFView 9 | * 10 | * @param position current scroll ratio between 0 and 1 11 | */ 12 | void setScroll(float position); 13 | 14 | /** 15 | * Method called by PDFView after setting scroll handle. 16 | * Do not call this method manually. 17 | * For usage sample see {@link DefaultScrollHandle} 18 | * 19 | * @param pdfView PDFView instance 20 | */ 21 | void setupLayout(PDFView pdfView); 22 | 23 | /** 24 | * Method called by PDFView when handle should be removed from layout 25 | * Do not call this method manually. 26 | */ 27 | void destroyLayout(); 28 | 29 | /** 30 | * Set page number displayed on handle 31 | * 32 | * @param pageNum page number 33 | */ 34 | void setPageNum(int pageNum); 35 | 36 | /** 37 | * Get handle visibility 38 | * 39 | * @return true if handle is visible, false otherwise 40 | */ 41 | boolean shown(); 42 | 43 | /** 44 | * Show handle 45 | */ 46 | void show(); 47 | 48 | /** 49 | * Hide handle immediately 50 | */ 51 | void hide(); 52 | 53 | /** 54 | * Hide handle after some time (defined by implementation) 55 | */ 56 | void hideDelayed(); 57 | } 58 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/AssetSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | 19 | import android.content.Context; 20 | import android.os.ParcelFileDescriptor; 21 | 22 | import com.github.barteksc.pdfviewer.util.FileUtils; 23 | import com.shockwave.pdfium.PdfDocument; 24 | import com.shockwave.pdfium.PdfiumCore; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | 29 | public class AssetSource implements DocumentSource { 30 | 31 | private final String assetName; 32 | 33 | public AssetSource(String assetName) { 34 | this.assetName = assetName; 35 | } 36 | 37 | @Override 38 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { 39 | File f = FileUtils.fileFromAsset(context, assetName); 40 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY); 41 | return core.newDocument(pfd, password); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/ByteArraySource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | import android.content.Context; 19 | 20 | import com.shockwave.pdfium.PdfDocument; 21 | import com.shockwave.pdfium.PdfiumCore; 22 | 23 | import java.io.IOException; 24 | 25 | public class ByteArraySource implements DocumentSource { 26 | 27 | private byte[] data; 28 | 29 | public ByteArraySource(byte[] data) { 30 | this.data = data; 31 | } 32 | 33 | @Override 34 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { 35 | return core.newDocument(data, password); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/DocumentSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | import android.content.Context; 19 | 20 | import com.shockwave.pdfium.PdfDocument; 21 | import com.shockwave.pdfium.PdfiumCore; 22 | 23 | import java.io.IOException; 24 | 25 | public interface DocumentSource { 26 | PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException; 27 | } 28 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/FileSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | import android.content.Context; 19 | import android.os.ParcelFileDescriptor; 20 | 21 | import com.shockwave.pdfium.PdfDocument; 22 | import com.shockwave.pdfium.PdfiumCore; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | public class FileSource implements DocumentSource { 28 | 29 | private File file; 30 | 31 | public FileSource(File file) { 32 | this.file = file; 33 | } 34 | 35 | @Override 36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { 37 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); 38 | return core.newDocument(pfd, password); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/InputStreamSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | import android.content.Context; 19 | 20 | import com.github.barteksc.pdfviewer.util.Util; 21 | import com.shockwave.pdfium.PdfDocument; 22 | import com.shockwave.pdfium.PdfiumCore; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | public class InputStreamSource implements DocumentSource { 28 | 29 | private InputStream inputStream; 30 | 31 | public InputStreamSource(InputStream inputStream) { 32 | this.inputStream = inputStream; 33 | } 34 | 35 | @Override 36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { 37 | return core.newDocument(Util.toByteArray(inputStream), password); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/source/UriSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Bartosz Schiller. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.barteksc.pdfviewer.source; 17 | 18 | import android.content.Context; 19 | import android.net.Uri; 20 | import android.os.ParcelFileDescriptor; 21 | 22 | import com.shockwave.pdfium.PdfDocument; 23 | import com.shockwave.pdfium.PdfiumCore; 24 | 25 | import java.io.IOException; 26 | 27 | public class UriSource implements DocumentSource { 28 | 29 | private Uri uri; 30 | 31 | public UriSource(Uri uri) { 32 | this.uri = uri; 33 | } 34 | 35 | @Override 36 | public PdfDocument createDocument(Context context, PdfiumCore core, String password) throws IOException { 37 | ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r"); 38 | return core.newDocument(pfd, password); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/util/ArrayUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Bartosz Schiller 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.github.barteksc.pdfviewer.util;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | public class ArrayUtils {
22 |
23 | private ArrayUtils() {
24 | // Prevents instantiation
25 | }
26 |
27 | /** Transforms (0,1,2,2,3) to (0,1,2,3) */
28 | public static int[] deleteDuplicatedPages(int[] pages) {
29 | List