Skip to content

Commit 187fbf5

Browse files
committed
Fix loading document from subfolder in assets directory
Fix scroll handle NPE after document loading error (improvement of 2.0.3 fix) Fix incorrect scroll handle position with additional views in RelativeLayout Improve cache usage and fix bug with rendering when zooming Update gradle version Update gradle plugin and maven gradle plugin Update README and CHANGELOG Update version
1 parent 87bcd47 commit 187fbf5

File tree

10 files changed

+65
-38
lines changed

10 files changed

+65
-38
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.1.0 (2016-09-16)
2+
* fixed loading document from subfolder in assets directory
3+
* fixed scroll handle NPE after document loading error (improvement of 2.0.3 fix)
4+
* fixed incorrect scroll handle position with additional views in RelativeLayout
5+
* improved cache usage and fixed bug with rendering when zooming
6+
* if you are using custom scroll handle: scroll handle implementation changed a little bit, check DefaultScrollHandle source for details
7+
18
## 2.0.3 (2016-08-30)
29
* Fix scroll handle NPE after document loading error
310

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ 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 2.0.0?
10-
* few API changes
11-
* improved rendering speed and accuracy
12-
* added continuous scroll - now it behaves like Adobe Reader and others
13-
* added `fling` scroll gesture for velocity based scrolling
14-
* added scroll handle as a replacement for scrollbar
15-
16-
2.0.1 fixes NPE when onDetachFromWindow is called.
17-
18-
2.0.2 fixes exceptions caused by improperly finishing rendering task.
19-
20-
2.0.3 fixes scroll handle NPE after document loading error
9+
## What's new in 2.1.0?
10+
* fixed loading document from subfolder in assets directory
11+
* fixed scroll handle NPE after document loading error (improvement of 2.0.3 fix)
12+
* fixed incorrect scroll handle position with additional views in RelativeLayout
13+
* improved cache usage and fixed bug with rendering when zooming
14+
* if you are using custom scroll handle: scroll handle implementation changed a little bit, check DefaultScrollHandle source for details
2115

2216
## Changes in 2.0 API
2317
* `Configurator#defaultPage(int)` and `PDFView#jumpTo(int)` now require page index (i.e. starting from 0)
@@ -32,7 +26,7 @@ Licensed under Apache License 2.0.
3226

3327
Add to _build.gradle_:
3428

35-
`compile 'com.github.barteksc:android-pdf-viewer:2.0.3'`
29+
`compile 'com.github.barteksc:android-pdf-viewer:2.1.0'`
3630

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

@@ -78,7 +72,7 @@ pdfView.fromAsset(String)
7872

7973
Scroll handle is replacement for **ScrollBar** from 1.x branch.
8074

81-
If you want to use **ScrollHandle**, it's important that the parent view is **RelativeLayout**.
75+
From version 2.1.0 putting **PDFView** in **RelativeLayout** to use **ScrollHandle** is not required, you can use any layout.
8276

8377
To use scroll handle just register it using method `Configurator#scrollHandle()`.
8478
This method accepts implementations of **ScrollHandle** interface.

android-pdf-viewer/build.gradle

Lines changed: 2 additions & 2 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 = '2.0.3'
16+
libraryVersion = '2.1.0'
1717

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

3838
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.util.AttributeSet;
3030
import android.util.Log;
3131
import android.view.View;
32+
import android.widget.RelativeLayout;
3233

3334
import com.github.barteksc.pdfviewer.exception.FileNotFoundException;
3435
import com.github.barteksc.pdfviewer.listener.OnDrawListener;
@@ -68,7 +69,7 @@
6869
* using {@link #load(String, boolean, String, OnLoadCompleteListener, OnErrorListener, int[])}. In this
6970
* particular case, a userPage of 5 can refer to a documentPage of 17.
7071
*/
71-
public class PDFView extends View {
72+
public class PDFView extends RelativeLayout {
7273

7374
private static final String TAG = PDFView.class.getSimpleName();
7475

@@ -238,6 +239,8 @@ enum ScrollDir {
238239

239240
private ScrollHandle scrollHandle;
240241

242+
private boolean isScrollHandleInit = false;
243+
241244
ScrollHandle getScrollHandle() {
242245
return scrollHandle;
243246
}
@@ -273,6 +276,7 @@ public PDFView(Context context, AttributeSet set) {
273276
debugPaint.setStyle(Style.STROKE);
274277

275278
pdfiumCore = new PdfiumCore(context);
279+
setWillNotDraw(false);
276280
}
277281

278282
private void load(String path, boolean isAsset, String password, OnLoadCompleteListener listener, OnErrorListener onErrorListener) {
@@ -446,7 +450,7 @@ public void recycle() {
446450
// Clear caches
447451
cacheManager.recycle();
448452

449-
if (scrollHandle != null && state != State.ERROR) {
453+
if (scrollHandle != null && isScrollHandleInit) {
450454
scrollHandle.destroyLayout();
451455
}
452456

@@ -459,6 +463,7 @@ public void recycle() {
459463
filteredUserPageIndexes = null;
460464
pdfDocument = null;
461465
scrollHandle = null;
466+
isScrollHandleInit = false;
462467
currentXOffset = currentYOffset = 0;
463468
zoom = 1f;
464469
recycled = true;
@@ -666,6 +671,7 @@ public void loadComplete(PdfDocument pdfDocument) {
666671

667672
if (scrollHandle != null) {
668673
scrollHandle.setupLayout(this);
674+
isScrollHandleInit = true;
669675
}
670676

671677
// Notify the listener

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ private int loadRelative(int number, int nbOfPartsLoadable, boolean outsideView)
116116
loadThumbnail(holder.page, documentPage);
117117

118118
if (pdfView.isSwipeVertical()) {
119-
for (int col = 0; col < colsRows.first; col++) {
119+
int firstCol = MathUtils.floor(xOffset / colWidth);
120+
firstCol = MathUtils.min(firstCol - 1, 0);
121+
int lastCol = MathUtils.ceil((xOffset + pdfView.getWidth()) / colWidth);
122+
lastCol = MathUtils.max(lastCol + 1, colsRows.first);
123+
for (int col = firstCol; col <= lastCol; col++) {
120124
if (loadCell(holder.page, documentPage, holder.row, col, pageRelativePartWidth, pageRelativePartHeight)) {
121125
loaded++;
122126
}
@@ -125,7 +129,11 @@ private int loadRelative(int number, int nbOfPartsLoadable, boolean outsideView)
125129
}
126130
}
127131
} else {
128-
for (int row = 0; row < colsRows.second; row++) {
132+
int firstRow = MathUtils.floor(yOffset / rowHeight);
133+
firstRow = MathUtils.min(firstRow - 1, 0);
134+
int lastRow = MathUtils.ceil((yOffset + pdfView.getHeight()) / rowHeight);
135+
lastRow = MathUtils.max(lastRow + 1, colsRows.second);
136+
for (int row = firstRow; row <= lastRow; row++) {
129137
if (loadCell(holder.page, documentPage, row, holder.col, pageRelativePartWidth, pageRelativePartHeight)) {
130138
loaded++;
131139
}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ public void setupLayout(PDFView pdfView) {
6060
width = HANDLE_LONG;
6161
height = HANDLE_SHORT;
6262
if (inverted) { // left
63-
align = ALIGN_LEFT;
63+
align = ALIGN_PARENT_LEFT;
6464
background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_left);
6565
} else { // right
66-
align = ALIGN_RIGHT;
66+
align = ALIGN_PARENT_RIGHT;
6767
background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_right);
6868
}
6969
} else {
7070
width = HANDLE_SHORT;
7171
height = HANDLE_LONG;
7272
if (inverted) { // top
73-
align = ALIGN_TOP;
73+
align = ALIGN_PARENT_TOP;
7474
background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_top);
7575
} else { // bottom
76-
align = ALIGN_BOTTOM;
76+
align = ALIGN_PARENT_BOTTOM;
7777
background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_bottom);
7878
}
7979
}
@@ -92,20 +92,15 @@ public void setupLayout(PDFView pdfView) {
9292

9393
addView(textView, tvlp);
9494

95-
lp.addRule(align, pdfView.getId());
96-
((ViewGroup) pdfView.getParent()).addView(this, lp);
95+
lp.addRule(align);
96+
pdfView.addView(this, lp);
9797

9898
this.pdfView = pdfView;
9999
}
100100

101101
@Override
102102
public void destroyLayout() {
103-
post(new Runnable() {
104-
@Override
105-
public void run() {
106-
((ViewGroup) pdfView.getParent()).removeView(DefaultScrollHandle.this);
107-
}
108-
});
103+
pdfView.removeView(this);
109104
}
110105

111106
@Override

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

Lines changed: 6 additions & 3 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.
@@ -31,6 +31,9 @@ private FileUtils() {
3131

3232
public static File fileFromAsset(Context context, String assetName) throws IOException {
3333
File outFile = new File(context.getCacheDir(), assetName + "-pdfview.pdf");
34+
if (assetName.contains("/")) {
35+
outFile.getParentFile().mkdirs();
36+
}
3437
copy(context.getAssets().open(assetName), outFile);
3538
return outFile;
3639
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ public static float min(float number, float min) {
7373
return number;
7474
}
7575

76+
public static int max(int number, int max) {
77+
if (number > max) {
78+
return max;
79+
}
80+
return number;
81+
}
82+
83+
public static int min(int number, int min) {
84+
if (number < min) {
85+
return min;
86+
}
87+
return number;
88+
}
89+
7690
/**
7791
* Methods from libGDX - https://github.com/libgdx/libgdx
7892
*/

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.1.2'
7+
classpath 'com.android.tools.build:gradle:2.1.3'
88
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
1010
}
1111
}
1212

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 commit comments

Comments
 (0)