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

Commit 828f720

Browse files
committed
Fix not loaded pages when using animated PDFView#jumpTo()
Fix NPE in canScrollVertically and canScrollHorizontally Update PdfiumAndroid Update README and CHANGELOG Update version
1 parent a475957 commit 828f720

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0-beta.4 (2017-12-15)
2+
* Fix not loaded pages when using animated `PDFView#jumpTo()`
3+
* Fix NPE in `canScrollVertically()` and `canScrollHorizontally()`
4+
15
## 3.0.0-beta.3 (2017-11-18)
26
* Fix bug preventing `OnErrorListener` from being called
37

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Licensed under Apache License 2.0.
2020

2121
3.0.0-beta.3 fixes bug preventing `OnErrorListener` from being called
2222

23+
3.0.0-beta.4 fixes not loaded pages when using animated `PDFView#jumpTo()` and NPE in `canScrollVertically()` and `canScrollHorizontally()`
24+
2325
## Changes in 3.0 API
2426
* Replaced `Contants.PRELOAD_COUNT` with `PRELOAD_OFFSET`
2527
* Removed `PDFView#fitToWidth()` (variant without arguments)
@@ -31,11 +33,11 @@ Licensed under Apache License 2.0.
3133

3234
Add to _build.gradle_:
3335

34-
`compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.3'`
36+
`compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.4'`
3537

3638
or if you want to use more stable version:
3739

38-
`compile 'com.github.barteksc:android-pdf-viewer:2.8.1'`
40+
`compile 'com.github.barteksc:android-pdf-viewer:2.8.2'`
3941

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

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

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

3838
}
3939

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

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

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import android.animation.Animator;
1919
import android.animation.Animator.AnimatorListener;
20+
import android.animation.AnimatorListenerAdapter;
2021
import android.animation.ValueAnimator;
2122
import android.animation.ValueAnimator.AnimatorUpdateListener;
2223
import android.graphics.PointF;
@@ -48,17 +49,21 @@ public AnimationManager(PDFView pdfView) {
4849
public void startXAnimation(float xFrom, float xTo) {
4950
stopAll();
5051
animation = ValueAnimator.ofFloat(xFrom, xTo);
52+
XAnimation xAnimation = new XAnimation();
5153
animation.setInterpolator(new DecelerateInterpolator());
52-
animation.addUpdateListener(new XAnimation());
54+
animation.addUpdateListener(xAnimation);
55+
animation.addListener(xAnimation);
5356
animation.setDuration(400);
5457
animation.start();
5558
}
5659

5760
public void startYAnimation(float yFrom, float yTo) {
5861
stopAll();
5962
animation = ValueAnimator.ofFloat(yFrom, yTo);
63+
YAnimation yAnimation = new YAnimation();
6064
animation.setInterpolator(new DecelerateInterpolator());
61-
animation.addUpdateListener(new YAnimation());
65+
animation.addUpdateListener(yAnimation);
66+
animation.addListener(yAnimation);
6267
animation.setDuration(400);
6368
animation.start();
6469
}
@@ -104,24 +109,44 @@ public void stopFling() {
104109
scroller.forceFinished(true);
105110
}
106111

107-
class XAnimation implements AnimatorUpdateListener {
112+
class XAnimation extends AnimatorListenerAdapter implements AnimatorUpdateListener {
108113

109114
@Override
110115
public void onAnimationUpdate(ValueAnimator animation) {
111116
float offset = (Float) animation.getAnimatedValue();
112117
pdfView.moveTo(offset, pdfView.getCurrentYOffset());
118+
pdfView.loadPageByOffset();
119+
}
120+
121+
@Override
122+
public void onAnimationCancel(Animator animation) {
123+
pdfView.loadPages();
113124
}
114125

126+
@Override
127+
public void onAnimationEnd(Animator animation) {
128+
pdfView.loadPages();
129+
}
115130
}
116131

117-
class YAnimation implements AnimatorUpdateListener {
132+
class YAnimation extends AnimatorListenerAdapter implements AnimatorUpdateListener {
118133

119134
@Override
120135
public void onAnimationUpdate(ValueAnimator animation) {
121136
float offset = (Float) animation.getAnimatedValue();
122137
pdfView.moveTo(pdfView.getCurrentXOffset(), offset);
138+
pdfView.loadPageByOffset();
139+
}
140+
141+
@Override
142+
public void onAnimationCancel(Animator animation) {
143+
pdfView.loadPages();
123144
}
124145

146+
@Override
147+
public void onAnimationEnd(Animator animation) {
148+
pdfView.loadPages();
149+
}
125150
}
126151

127152
class ZoomAnimation implements AnimatorUpdateListener, AnimatorListener {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
444444

445445
@Override
446446
public boolean canScrollHorizontally(int direction) {
447+
if (pdfFile == null) {
448+
return true;
449+
}
450+
447451
if (swipeVertical) {
448452
if (direction < 0 && currentXOffset < 0) {
449453
return true;
@@ -462,6 +466,10 @@ public boolean canScrollHorizontally(int direction) {
462466

463467
@Override
464468
public boolean canScrollVertically(int direction) {
469+
if (pdfFile == null) {
470+
return true;
471+
}
472+
465473
if (swipeVertical) {
466474
if (direction < 0 && currentYOffset < 0) {
467475
return true;

0 commit comments

Comments
 (0)