Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ee194a

Browse files
committed
Update PdfiumAndroid to 1.3.1
Add method PDFView#getDocumentMeta() Add method PDFView#getTableOfContents() Add method Configurator#password(String) Add horizontal mode to ScrollBar Block interaction with PDFView when document is not loaded Fix PDFView exceptions in layout preview Update README and CHANGELOG Update version
1 parent ace748b commit 4ee194a

File tree

13 files changed

+306
-82
lines changed

13 files changed

+306
-82
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## 1.2.0 (2016-07-11)
2+
* update PdfiumAndroid to 1.3.1 with support for bookmarks, Table Of Contents and documents with password:
3+
* added method `PDFView#getDocumentMeta()`, which returns document metadata
4+
* added method `PDFView#getTableOfContents()`, which returns whole tree of bookmarks in PDF document
5+
* added method `Configurator#password(String)`
6+
* added horizontal mode to **ScrollBar** - use `ScrollBar#setHorizontal(true)` or `app:sb_horizontal="true"` in XML
7+
* block interaction with `PDFView` when document is not loaded - prevent some exceptions
8+
* fix `PDFView` exceptions in layout preview (edit mode)
9+
10+
## 1.1.2 (2016-06-27)
11+
* update PdfiumAndroid to 1.1.0, which fixes displaying multiple `PDFView`s at the same time and few errors with loading PDF documents.
12+
13+
## 1.1.1 (2016-06-17)
14+
* fixes bug with strange behavior when indices passed to `.pages()` don't start with `0`.
15+
16+
## 1.1.0 (2016-06-16)
17+
* added method `pdfView.fromUri(Uri)` for opening files from content providers
18+
* updated PdfiumAndroid to 1.0.3, which should fix bug with exception
19+
* updated sample with demonstration of `fromUri()` method
20+
* some minor fixes
21+
22+
## 1.0.0 (2016-06-06)
23+
* Initial release

README.md

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ Library for displaying PDF documents on Android, with `animations`, `gestures`,
66
It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 and higher.
77
Licensed under Apache License 2.0.
88

9-
## What's new in 1.1.0?
10-
* added method `pdfView.fromUri(Uri)` for opening files from content providers
11-
* updated PdfiumAndroid to 1.0.3, which should fix bug with exception
12-
* updated sample with demonstration of `fromUri()` method
13-
* some minor fixes
14-
15-
Version 1.1.1 fixes bug with strange behavior when indices passed to `.pages()` don't start with `0`.
16-
17-
Version 1.1.2 updates PdfiumAndroid to 1.1.0, which fixes displaying multiple `PDFView`s at the same time and few errors with loading PDF documents.
9+
## What's new in 1.2.0?
10+
* update PdfiumAndroid to 1.3.1 with support for bookmarks, Table Of Contents and documents with password:
11+
* added method `PDFView#getDocumentMeta()`, which returns document metadata
12+
* added method `PDFView#getTableOfContents()`, which returns whole tree of bookmarks in PDF document
13+
* added method `Configurator#password(String)`
14+
* added horizontal mode to **ScrollBar** - use `ScrollBar#setHorizontal(true)` or `app:sb_horizontal="true"` in XML
15+
* block interaction with `PDFView` when document is not loaded - prevent some exceptions
16+
* fix `PDFView` exceptions in layout preview (edit mode)
1817

1918
Next release is coming soon, it will introduce continuous scroll through whole document
2019
and some incompatibilities with current API (only few small).
@@ -23,7 +22,7 @@ and some incompatibilities with current API (only few small).
2322

2423
Add to _build.gradle_:
2524

26-
`compile 'com.github.barteksc:android-pdf-viewer:1.1.2'`
25+
`compile 'com.github.barteksc:android-pdf-viewer:1.2.0'`
2726

2827
Library is available in jcenter repository, probably it'll be in Maven Central soon.
2928

@@ -40,8 +39,12 @@ Library is available in jcenter repository, probably it'll be in Maven Central s
4039

4140
All available options with default values:
4241
``` java
43-
pdfView.fromAsset(pdfName)
44-
.pages(0, 2, 1, 3, 3, 3) //all pages are displayed by default
42+
pdfView.fromUri(Uri)
43+
or
44+
pdfView.fromFile(File)
45+
or
46+
pdfView.fromAsset(String)
47+
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
4548
.enableSwipe(true)
4649
.enableDoubletap(true)
4750
.swipeVertical(false)
@@ -51,6 +54,7 @@ pdfView.fromAsset(pdfName)
5154
.onLoad(onLoadCompleteListener)
5255
.onPageChange(onPageChangeListener)
5356
.onError(onErrorListener)
57+
.password(null)
5458
.load();
5559
```
5660

@@ -62,8 +66,9 @@ pdfView.fromAsset(pdfName)
6266

6367
Use **ScrollBar** class to place scrollbar view near **PDFView**
6468

65-
1. in layout XML (it's important that the parent view is **RelativeLayout**)
69+
1. in layout XML (it's important that the parent view is **RelativeLayout**):
6670

71+
Vertically:
6772
``` xml
6873
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
6974
android:layout_width="match_parent"
@@ -84,6 +89,27 @@ Use **ScrollBar** class to place scrollbar view near **PDFView**
8489

8590
</RelativeLayout>
8691
```
92+
Horizontally:
93+
``` xml
94+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
95+
android:layout_width="match_parent"
96+
android:layout_height="match_parent"
97+
xmlns:app="http://schemas.android.com/apk/res-auto">
98+
99+
<com.github.barteksc.pdfviewer.PDFView
100+
android:id="@+id/pdfView"
101+
android:layout_width="match_parent"
102+
android:layout_height="match_parent"/>
103+
104+
<com.github.barteksc.pdfviewer.ScrollBar
105+
android:id="@+id/scrollBar"
106+
android:layout_width="match_parent"
107+
android:layout_height="wrap_content"
108+
app:sb_horizontal="true"
109+
android:layout_alignParentBottom="true" />
110+
111+
</RelativeLayout>
112+
```
87113
2. in activity or fragment
88114
``` java
89115

@@ -97,9 +123,11 @@ Use **ScrollBar** class to place scrollbar view near **PDFView**
97123
ScrollBar scrollBar = (ScrollBar) findViewById(R.id.scrollBar);
98124
pdfView.setScrollBar(scrollBar);
99125
}
100-
101126
```
102127

128+
`scrollBar.setHorizontal(true);` or `app:sb_horizontal="true"` may be used to set **ScrollBar** in horizontal mode.
129+
130+
103131
Scrollbar styling:
104132
``` xml
105133
<com.github.barteksc.pdfviewpager.view.ScrollBar
@@ -108,12 +136,13 @@ Scrollbar styling:
108136
app:sb_handlerColor="..." <!-- scrollbar handler color -->
109137
app:sb_indicatorColor="..." <!-- background color of current page indicator -->
110138
app:sb_indicatorTextColor="..." <!-- text color of current page indicator -->
139+
app:sb_horizontal="true|false|reference" <!-- whether to set horizontal mode -->
111140
android:background="..." <!-- scrollbar background -->
112141
/>
113142
```
114143

115144
**ScrollBarPageIndicator** is added to scrollbar automatically and is shown while dragging scrollbar handler,
116-
displaying number of page on current position.
145+
displaying number of page on current position. Its position is automatically calculated based on **ScrollBar**'s position.
117146

118147
## Additional options
119148

android-pdf-viewer/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ext {
1313
siteUrl = 'https://github.com/barteksc/AndroidPdfViewer'
1414
gitUrl = 'https://github.com/barteksc/AndroidPdfViewer.git'
1515

16-
libraryVersion = '1.1.2'
16+
libraryVersion = '1.2.0'
1717

1818
developerId = 'barteksc'
1919
developerName = 'Bartosz Schiller'
@@ -32,13 +32,13 @@ android {
3232
minSdkVersion 11
3333
targetSdkVersion 23
3434
versionCode 1
35-
versionName "1.1.2"
35+
versionName "1.2.0"
3636
}
3737

3838
}
3939

4040
dependencies {
41-
compile 'com.github.barteksc:pdfium-android:1.1.0'
41+
compile 'com.github.barteksc:pdfium-android:1.3.1'
4242
}
4343

4444
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/DecodingAsyncTask.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ class DecodingAsyncTask extends AsyncTask<Void, Void, Throwable> {
4040
private Context context;
4141
private PdfiumCore pdfiumCore;
4242
private PdfDocument pdfDocument;
43+
private String password;
4344

44-
public DecodingAsyncTask(String path, boolean isAsset, PDFView pdfView, PdfiumCore pdfiumCore) {
45+
public DecodingAsyncTask(String path, boolean isAsset, String password, PDFView pdfView, PdfiumCore pdfiumCore) {
4546
this.cancelled = false;
4647
this.pdfView = pdfView;
4748
this.isAsset = isAsset;
49+
this.password = password;
4850
this.pdfiumCore = pdfiumCore;
4951
this.path = path;
5052
context = pdfView.getContext();
@@ -56,7 +58,7 @@ protected Throwable doInBackground(Void... params) {
5658
if (isAsset) {
5759
path = FileUtils.fileFromAsset(context, path).getAbsolutePath();
5860
}
59-
pdfDocument = pdfiumCore.newDocument(getSeekableFileDescriptor(path));
61+
pdfDocument = pdfiumCore.newDocument(getSeekableFileDescriptor(path), password);
6062
return null;
6163
} catch (Throwable t) {
6264
return t;

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* - DocumentPage = A page of the PDF document.
6666
* - UserPage = A page as defined by the user.
6767
* By default, they're the same. But the user can change the pages order
68-
* using {@link #load(String, boolean, OnLoadCompleteListener, OnErrorListener, int[])}. In this
68+
* using {@link #load(String, boolean, String, OnLoadCompleteListener, OnErrorListener, int[])}. In this
6969
* particular case, a userPage of 5 can refer to a documentPage of 17.
7070
*/
7171
public class PDFView extends SurfaceView {
@@ -275,6 +275,11 @@ public class PDFView extends SurfaceView {
275275
*/
276276
public PDFView(Context context, AttributeSet set) {
277277
super(context, set);
278+
279+
if(isInEditMode()) {
280+
return;
281+
}
282+
278283
miniMapRequired = false;
279284
cacheManager = new CacheManager();
280285
animationManager = new AnimationManager(this);
@@ -299,11 +304,11 @@ public PDFView(Context context, AttributeSet set) {
299304
pdfiumCore = new PdfiumCore(context);
300305
}
301306

302-
private void load(String path, boolean isAsset, OnLoadCompleteListener listener, OnErrorListener onErrorListener) {
303-
load(path, isAsset, listener, onErrorListener, null);
307+
private void load(String path, boolean isAsset, String password, OnLoadCompleteListener listener, OnErrorListener onErrorListener) {
308+
load(path, isAsset, password, listener, onErrorListener, null);
304309
}
305310

306-
private void load(String path, boolean isAsset, OnLoadCompleteListener onLoadCompleteListener, OnErrorListener onErrorListener, int[] userPages) {
311+
private void load(String path, boolean isAsset, String password, OnLoadCompleteListener onLoadCompleteListener, OnErrorListener onErrorListener, int[] userPages) {
307312

308313
if (!recycled) {
309314
throw new IllegalStateException("Don't call load on a PDF View without recycling it first.");
@@ -319,11 +324,11 @@ private void load(String path, boolean isAsset, OnLoadCompleteListener onLoadCom
319324
this.onLoadCompleteListener = onLoadCompleteListener;
320325
this.onErrorListener = onErrorListener;
321326

327+
recycled = false;
322328
// Start decoding document
323-
decodingAsyncTask = new DecodingAsyncTask(path, isAsset, this, pdfiumCore);
329+
decodingAsyncTask = new DecodingAsyncTask(path, isAsset, password, this, pdfiumCore);
324330
decodingAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
325331

326-
327332
}
328333

329334
/**
@@ -336,6 +341,9 @@ public void jumpTo(int page) {
336341
}
337342

338343
void showPage(int pageNb) {
344+
if(recycled) {
345+
return;
346+
}
339347
state = State.SHOWN;
340348

341349
// Check the page number and makes the
@@ -421,6 +429,10 @@ public void recycle() {
421429
state = State.DEFAULT;
422430
}
423431

432+
public boolean isRecycled() {
433+
return recycled;
434+
}
435+
424436
@Override
425437
protected void onDetachedFromWindow() {
426438
recycle();
@@ -429,6 +441,9 @@ protected void onDetachedFromWindow() {
429441

430442
@Override
431443
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
444+
if(isInEditMode()) {
445+
return;
446+
}
432447
animationManager.stopAll();
433448
calculateOptimalWidthAndHeight();
434449
loadPages();
@@ -475,6 +490,10 @@ protected void onDraw(Canvas canvas) {
475490
// Draws background
476491
canvas.drawColor(Color.WHITE);
477492

493+
if(recycled) {
494+
return;
495+
}
496+
478497
if (state != State.SHOWN) {
479498
return;
480499
}
@@ -795,6 +814,8 @@ public void loadComplete(PdfDocument pdfDocument) {
795814
}
796815

797816
public void loadError(Throwable t) {
817+
recycle();
818+
invalidate();
798819
if (this.onErrorListener != null) {
799820
this.onErrorListener.onError(t);
800821
} else {
@@ -1153,6 +1174,20 @@ public void useBestQuality(boolean bestQuality) {
11531174
this.bestQuality = bestQuality;
11541175
}
11551176

1177+
public PdfDocument.Meta getDocumentMeta() {
1178+
if(pdfDocument == null) {
1179+
return null;
1180+
}
1181+
return pdfiumCore.getDocumentMeta(pdfDocument);
1182+
}
1183+
1184+
public List<PdfDocument.Bookmark> getTableOfContents() {
1185+
if(pdfDocument == null) {
1186+
return new ArrayList<>();
1187+
}
1188+
return pdfiumCore.getTableOfContents(pdfDocument);
1189+
}
1190+
11561191
/**
11571192
* Use an asset file as the pdf source
11581193
*/
@@ -1223,6 +1258,8 @@ public class Configurator {
12231258

12241259
private int maskAlpha = Constants.MASK_ALPHA;
12251260

1261+
private String password = null;
1262+
12261263
private Configurator(String path, boolean isAsset) {
12271264
this.path = path;
12281265
this.isAsset = isAsset;
@@ -1273,6 +1310,11 @@ public Configurator swipeVertical(boolean swipeVertical) {
12731310
return this;
12741311
}
12751312

1313+
public Configurator password(String password) {
1314+
this.password = password;
1315+
return this;
1316+
}
1317+
12761318
/**
12771319
* @param maskColor - mask color (default Color.BLACK)
12781320
* @param maskAlpha - alpha value in [0,255] (default 20)
@@ -1298,9 +1340,9 @@ public void load() {
12981340
PDFView.this.maskPaint.setColor(maskColor);
12991341
PDFView.this.maskPaint.setAlpha(maskAlpha);
13001342
if (pageNumbers != null) {
1301-
PDFView.this.load(path, isAsset, onLoadCompleteListener, onErrorListener, pageNumbers);
1343+
PDFView.this.load(path, isAsset, password, onLoadCompleteListener, onErrorListener, pageNumbers);
13021344
} else {
1303-
PDFView.this.load(path, isAsset, onLoadCompleteListener, onErrorListener);
1345+
PDFView.this.load(path, isAsset, password, onLoadCompleteListener, onErrorListener);
13041346
}
13051347
}
13061348

0 commit comments

Comments
 (0)