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

Skip to content

Commit 126507a

Browse files
committed
Add fromUri method
Update PdfiumAndroid to 1.0.3 Update README Update version
1 parent 208682f commit 126507a

File tree

15 files changed

+433
-332
lines changed

15 files changed

+433
-332
lines changed

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ 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+
Next release is coming soon, it will introduce continuous scroll through whole document
16+
and some incompatibilities with current API (only few small).
17+
918
## Installation
1019

1120
Add to _build.gradle_:
1221

13-
`compile 'com.github.barteksc:android-pdf-viewer:1.0.0'`
22+
`compile 'com.github.barteksc:android-pdf-viewer:1.1.0'`
1423

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

@@ -25,21 +34,25 @@ Library is available in jcenter repository, probably it'll be in Maven Central s
2534

2635
## Load a PDF file
2736

37+
All available options with default values:
2838
``` java
2939
pdfView.fromAsset(pdfName)
30-
.pages(0, 2, 1, 3, 3, 3)
40+
.pages(0, 2, 1, 3, 3, 3) //all pages are displayed by default
41+
.enableSwipe(true)
42+
.enableDoubletap(true)
43+
.swipeVertical(false)
3144
.defaultPage(1)
3245
.showMinimap(false)
33-
.enableSwipe(true)
3446
.onDraw(onDrawListener)
3547
.onLoad(onLoadCompleteListener)
3648
.onPageChange(onPageChangeListener)
3749
.onError(onErrorListener)
3850
.load();
3951
```
4052

41-
* ```pages``` is optional, it allows you to filter and order the pages of the PDF as you need
42-
* ```onDraw``` is also optional, and allows you to draw something on a provided canvas, above the current page
53+
* `enableSwipe` is optional, it allows you to block changing pages using swipe
54+
* `pages` is optional, it allows you to filter and order the pages of the PDF as you need
55+
* `onDraw` is also optional, and allows you to draw something on a provided canvas, above the current page
4356

4457
## Show scrollbar
4558

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.0.0'
16+
libraryVersion = '1.1.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.0.0"
35+
versionName "1.1.0"
3636
}
3737

3838
}
3939

4040
dependencies {
41-
compile 'com.github.barteksc:pdfium-android:1.0.2'
41+
compile 'com.github.barteksc:pdfium-android:1.0.3'
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: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Bartosz Schiller
3-
* <p>
3+
* <p/>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
* <p>
7+
* <p/>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p>
9+
* <p/>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,6 @@
2727
import java.io.File;
2828
import java.io.FileDescriptor;
2929
import java.io.IOException;
30-
import java.net.URI;
3130

3231
class DecodingAsyncTask extends AsyncTask<Void, Void, Throwable> {
3332

@@ -55,7 +54,7 @@ public DecodingAsyncTask(String path, boolean isAsset, PDFView pdfView, PdfiumCo
5554
@Override
5655
protected Throwable doInBackground(Void... params) {
5756
try {
58-
if(isAsset) {
57+
if (isAsset) {
5958
path = FileUtils.fileFromAsset(context, path).getAbsolutePath();
6059
}
6160
pdfDocument = pdfiumCore.newDocument(getSeekableFileDescriptor(path));
@@ -74,8 +73,12 @@ protected FileDescriptor getSeekableFileDescriptor(String path) throws IOExcepti
7473
return pfd.getFileDescriptor();
7574
}
7675

77-
URI uri = URI.create(String.format("file://%s", path));
78-
pfd = context.getContentResolver().openFileDescriptor(Uri.parse(uri.toString()), "rw");
76+
if (!path.contains("://")) {
77+
path = String.format("file://%s", path);
78+
}
79+
80+
Uri uri = Uri.parse(path);
81+
pfd = context.getContentResolver().openFileDescriptor(uri, "r");
7982

8083
if (pfd == null) {
8184
throw new IOException("Cannot get FileDescriptor for " + path);

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2016 Bartosz Schiller
3-
* <p/>
3+
* <p>
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
* <p/>
7+
* <p>
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p/>
9+
* <p>
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,7 @@
2424
import android.graphics.PointF;
2525
import android.graphics.Rect;
2626
import android.graphics.RectF;
27+
import android.net.Uri;
2728
import android.os.AsyncTask;
2829
import android.util.AttributeSet;
2930
import android.util.Log;
@@ -279,7 +280,6 @@ public PDFView(Context context, AttributeSet set) {
279280
animationManager = new AnimationManager(this);
280281
dragPinchManager = new DragPinchManager(this);
281282

282-
283283
paint = new Paint();
284284
debugPaint = new Paint();
285285
debugPaint.setStyle(Style.STROKE);
@@ -352,10 +352,11 @@ void showPage(int pageNb) {
352352

353353
// Reset the zoom and center the page on the screen
354354
resetZoom();
355-
if (swipeVertical)
355+
if (swipeVertical) {
356356
animationManager.startYAnimation(currentYOffset, calculateCenterOffsetForPage(pageNb));
357-
else
357+
} else {
358358
animationManager.startXAnimation(currentXOffset, calculateCenterOffsetForPage(pageNb));
359+
}
359360
loadPages();
360361

361362
if (scrollBar != null) {
@@ -410,8 +411,9 @@ public void recycle() {
410411
if (pdfiumCore != null && pdfDocument != null) {
411412
pdfiumCore.closeDocument(pdfDocument);
412413
}
413-
openedPages.clear();
414414

415+
openedPages.clear();
416+
pdfDocument = null;
415417
recycled = true;
416418
state = State.DEFAULT;
417419
}
@@ -611,7 +613,7 @@ public void loadPages() {
611613

612614
/**
613615
* Render a page, creating 1 to <i>nbOfPartsLoadable</i> page parts. <br><br>
614-
* <p>
616+
* <p/>
615617
* This is one of the trickiest method of this library. It finds
616618
* the DocumentPage associated with the given UserPage, loads its
617619
* thumbnail, cut this page into 256x256 blocs considering the
@@ -959,7 +961,6 @@ public void moveTo(float offsetX, float offsetY) {
959961
}
960962

961963
} else {
962-
963964
float maxY = calculateCenterOffsetForPage(currentFilteredPage + 1);
964965
float minY = calculateCenterOffsetForPage(currentFilteredPage - 1);
965966
if (offsetY < maxY) {
@@ -995,7 +996,6 @@ public void moveTo(float offsetX, float offsetY) {
995996
}
996997

997998
} else {
998-
999999
float maxX = calculateCenterOffsetForPage(currentFilteredPage + 1);
10001000
float minX = calculateCenterOffsetForPage(currentFilteredPage - 1);
10011001
if (offsetX < maxX) {
@@ -1088,6 +1088,10 @@ public float getOptimalPageWidth() {
10881088
return optimalPageWidth;
10891089
}
10901090

1091+
public float getOptimalPageHeight() {
1092+
return optimalPageHeight;
1093+
}
1094+
10911095
private void setUserWantsMinimap(boolean userWantsMinimap) {
10921096
this.userWantsMinimap = userWantsMinimap;
10931097
}
@@ -1166,11 +1170,19 @@ public Configurator fromAsset(String assetName) {
11661170
* Use a file as the pdf source
11671171
*/
11681172
public Configurator fromFile(File file) {
1169-
if (!file.exists())
1170-
throw new FileNotFoundException(file.getAbsolutePath() + "does not exist.");
1173+
if (!file.exists()) {
1174+
throw new FileNotFoundException(file.getAbsolutePath() + " does not exist.");
1175+
}
11711176
return new Configurator(file.getAbsolutePath(), false);
11721177
}
11731178

1179+
/**
1180+
* Use URI as the pdf source, for use with content providers
1181+
*/
1182+
public Configurator fromUri(Uri uri) {
1183+
return new Configurator(uri.toString(), false);
1184+
}
1185+
11741186
private enum State {DEFAULT, LOADED, SHOWN}
11751187

11761188
public class Configurator {

0 commit comments

Comments
 (0)