Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit af4d4b2

Browse files
committed
Fix issue with Configurator#pages() from DImuthuUpe#486
Fix IllegalStateException from DImuthuUpe#464 Fix not detecting links Add ProGuard info to README Update version Update README and CHANGELOG
1 parent 828f720 commit af4d4b2

File tree

6 files changed

+65
-16
lines changed

6 files changed

+65
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.0.0-beta.5 (2018-01-06)
2+
* Fix issue with `Configurator#pages()` from #486
3+
* Fix `IllegalStateException` from #464
4+
* Fix not detecting links reported in #447
5+
16
## 3.0.0-beta.4 (2017-12-15)
27
* Fix not loaded pages when using animated `PDFView#jumpTo()`
38
* Fix NPE in `canScrollVertically()` and `canScrollHorizontally()`

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Licensed under Apache License 2.0.
2222

2323
3.0.0-beta.4 fixes not loaded pages when using animated `PDFView#jumpTo()` and NPE in `canScrollVertically()` and `canScrollHorizontally()`
2424

25+
3.0.0-beta.5 fixes:
26+
* Issue with `Configurator#pages()` from #486
27+
* `IllegalStateException` from #464
28+
* Not detecting links reported in #447
29+
2530
## Changes in 3.0 API
2631
* Replaced `Contants.PRELOAD_COUNT` with `PRELOAD_OFFSET`
2732
* Removed `PDFView#fitToWidth()` (variant without arguments)
@@ -33,14 +38,21 @@ Licensed under Apache License 2.0.
3338

3439
Add to _build.gradle_:
3540

36-
`compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.4'`
41+
`compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'`
3742

3843
or if you want to use more stable version:
3944

4045
`compile 'com.github.barteksc:android-pdf-viewer:2.8.2'`
4146

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

49+
## ProGuard
50+
If you are using ProGuard, add following rule to proguard config file:
51+
52+
```proguard
53+
-keep class com.shockwave.**
54+
```
55+
4456
## Include PDFView in your layout
4557

4658
``` xml

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 = '3.0.0-beta.4'
16+
libraryVersion = '3.0.0-beta.5'
1717

1818
developerId = 'barteksc'
1919
developerName = 'Bartosz Schiller'
@@ -32,7 +32,7 @@ android {
3232
minSdkVersion 11
3333
targetSdkVersion 25
3434
versionCode 1
35-
versionName "3.0.0-beta.4"
35+
versionName "3.0.0-beta.5"
3636
}
3737

3838
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private boolean checkLinkTapped(float x, float y) {
9797
for (PdfDocument.Link link : pdfFile.getPageLinks(page)) {
9898
RectF mapped = pdfFile.mapRectToDevice(page, pageX, pageY, (int) pageSize.getWidth(),
9999
(int) pageSize.getHeight(), link.getBounds());
100+
fixCoords(mapped);
100101
if (mapped.contains(mappedX, mappedY)) {
101102
pdfView.callbacks.callLinkHandler(new LinkTapEvent(x, y, mappedX, mappedY, mapped, link));
102103
return true;
@@ -105,6 +106,28 @@ private boolean checkLinkTapped(float x, float y) {
105106
return false;
106107
}
107108

109+
/** Fix different coordinate axis */
110+
private void fixCoords(RectF rect) {
111+
if (rect.top > rect.bottom) {
112+
swapTopBottom(rect);
113+
}
114+
if (rect.left > rect.right) {
115+
swapLeftRight(rect);
116+
}
117+
}
118+
119+
private void swapTopBottom(RectF rect) {
120+
float tmp = rect.top;
121+
rect.top = rect.bottom;
122+
rect.bottom = tmp;
123+
}
124+
125+
private void swapLeftRight(RectF rect) {
126+
float tmp = rect.left;
127+
rect.left = rect.right;
128+
rect.right = tmp;
129+
}
130+
108131
@Override
109132
public boolean onDoubleTap(MotionEvent e) {
110133
if (!pdfView.isDoubletapEnabled()) {

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,15 @@ ScrollHandle getScrollHandle() {
215215
/** Spacing between pages, in px */
216216
private int spacingPx = 0;
217217

218-
/** pages numbers used when calling onDrawAllListener */
218+
/** Pages numbers used when calling onDrawAllListener */
219219
private List<Integer> onDrawPagesNums = new ArrayList<>(10);
220220

221+
/** Holds info whether view has been added to layout and has width and height */
222+
private boolean hasSize = false;
223+
224+
/** Holds last used Configurator that should be loaded when view has size */
225+
private Configurator waitingDocumentConfigurator;
226+
221227
/** Construct the initial view */
222228
public PDFView(Context context, AttributeSet set) {
223229
super(context, set);
@@ -372,6 +378,7 @@ void onPageError(PageRenderingException ex) {
372378
}
373379

374380
public void recycle() {
381+
waitingDocumentConfigurator = null;
375382

376383
animationManager.stopAll();
377384
dragPinchManager.disable();
@@ -429,6 +436,10 @@ protected void onDetachedFromWindow() {
429436

430437
@Override
431438
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
439+
hasSize = true;
440+
if (waitingDocumentConfigurator != null) {
441+
waitingDocumentConfigurator.load();
442+
}
432443
if (isInEditMode() || state != State.SHOWN) {
433444
return;
434445
}
@@ -1282,6 +1293,10 @@ public Configurator pageFitPolicy(FitPolicy pageFitPolicy) {
12821293
}
12831294

12841295
public void load() {
1296+
if (!hasSize) {
1297+
waitingDocumentConfigurator = this;
1298+
return;
1299+
}
12851300
PDFView.this.recycle();
12861301
PDFView.this.callbacks.setOnLoadComplete(onLoadCompleteListener);
12871302
PDFView.this.callbacks.setOnError(onErrorListener);
@@ -1303,16 +1318,11 @@ public void load() {
13031318
PDFView.this.setSpacing(spacing);
13041319
PDFView.this.setPageFitPolicy(pageFitPolicy);
13051320

1306-
PDFView.this.post(new Runnable() {
1307-
@Override
1308-
public void run() {
1309-
if (pageNumbers != null) {
1310-
PDFView.this.load(documentSource, password, pageNumbers);
1311-
} else {
1312-
PDFView.this.load(documentSource, password);
1313-
}
1314-
}
1315-
});
1321+
if (pageNumbers != null) {
1322+
PDFView.this.load(documentSource, password, pageNumbers);
1323+
} else {
1324+
PDFView.this.load(documentSource, password);
1325+
}
13161326
}
13171327
}
13181328
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public SizeF getPageSize(int pageIndex) {
129129
}
130130

131131
public SizeF getScaledPageSize(int pageIndex, float zoom) {
132-
int docPage = documentPage(pageIndex);
133-
SizeF size = getPageSize(docPage);
132+
SizeF size = getPageSize(pageIndex);
134133
return new SizeF(size.getWidth() * zoom, size.getHeight() * zoom);
135134
}
136135

0 commit comments

Comments
 (0)