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

Skip to content

Commit db69148

Browse files
committed
Improved rendering speed and accuracy
Use Android gesture detector Add continuous scroll Add fling scroll gesture for velocity based scrolling Remove Scrollbar Add scroll handle Update README and CHANGELOG Update version
1 parent cf31a3b commit db69148

36 files changed

+1389
-1676
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## 2.0.0 (2016-08-14)
2+
* few API changes
3+
* improved rendering speed and accuracy
4+
* added continuous scroll - now it behaves like Adobe Reader and others
5+
* added `fling` scroll gesture for velocity based scrolling
6+
* added scroll handle as a replacement for scrollbar
7+
8+
### Changes in 2.0 API
9+
* `Configurator#defaultPage(int)` and `PDFView#jumpTo(int)` now require page index (i.e. starting from 0)
10+
* `OnPageChangeListener#onPageChanged(int, int)` is called with page index (i.e. starting from 0)
11+
* removed scrollbar
12+
* added scroll handle as a replacement for scrollbar, use with `Configurator#scrollHandle()`
13+
* added `OnPageScrollListener` listener due to continuous scroll, register with `Configurator#onPageScroll()`
14+
* default scroll direction is vertical, so `Configurator#swipeVertical()` was changed to `Configurator#swipeHorizontal()`
15+
* removed minimap and mask configuration
16+
117
## 1.4.0 (2016-07-25)
218
* Fix NPE and IndexOutOfBound bugs when rendering parts
319
* Merge pull request by [paulo-sato-daitan](https://github.com/paulo-sato-daitan) for disabling page change animation

README.md

Lines changed: 33 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,27 @@ 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.4.0?
10-
* Fix NPE and IndexOutOfBound bugs when rendering parts
11-
* Merge pull request by [paulo-sato-daitan](https://github.com/paulo-sato-daitan) for disabling page change animation
12-
* Merge pull request by [Miha-x64](https://github.com/Miha-x64) for drawing background if set on `PDFView`
13-
14-
Next release is coming soon, it will introduce continuous scroll through whole document
15-
and some incompatibilities with current API (only few small).
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+
## Changes in 2.0 API
17+
* `Configurator#defaultPage(int)` and `PDFView#jumpTo(int)` now require page index (i.e. starting from 0)
18+
* `OnPageChangeListener#onPageChanged(int, int)` is called with page index (i.e. starting from 0)
19+
* removed scrollbar
20+
* added scroll handle as a replacement for scrollbar, use with `Configurator#scrollHandle()`
21+
* added `OnPageScrollListener` listener due to continuous scroll, register with `Configurator#onPageScroll()`
22+
* default scroll direction is vertical, so `Configurator#swipeVertical()` was changed to `Configurator#swipeHorizontal()`
23+
* removed minimap and mask configuration
1624

1725
## Installation
1826

1927
Add to _build.gradle_:
2028

21-
`compile 'com.github.barteksc:android-pdf-viewer:1.4.0'`
29+
`compile 'com.github.barteksc:android-pdf-viewer:2.0.0'`
2230

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

@@ -42,105 +50,41 @@ or
4250
pdfView.fromAsset(String)
4351
.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
4452
.enableSwipe(true)
53+
.swipeHorizontal(false)
4554
.enableDoubletap(true)
46-
.swipeVertical(false)
47-
.defaultPage(1)
48-
.showMinimap(false)
55+
.defaultPage(0)
4956
.onDraw(onDrawListener)
5057
.onLoad(onLoadCompleteListener)
5158
.onPageChange(onPageChangeListener)
59+
.onPageScroll(onPageScrollListener)
5260
.onError(onErrorListener)
5361
.enableAnnotationRendering(false)
5462
.password(null)
55-
.showPageWithAnimation(true)
63+
.scrollHandle(null)
5664
.load();
5765
```
5866

5967
* `enableSwipe` is optional, it allows you to block changing pages using swipe
6068
* `pages` is optional, it allows you to filter and order the pages of the PDF as you need
6169
* `onDraw` is also optional, and allows you to draw something on a provided canvas, above the current page
6270

63-
## Show scrollbar
71+
## Scroll handle
6472

65-
Use **ScrollBar** class to place scrollbar view near **PDFView**
73+
Scroll handle is replacement for **ScrollBar** from 1.x branch.
6674

67-
1. in layout XML (it's important that the parent view is **RelativeLayout**):
75+
If you want to use **ScrollHandle**, it's important that the parent view is **RelativeLayout**.
6876

69-
Vertically:
70-
``` xml
71-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
72-
android:layout_width="match_parent"
73-
android:layout_height="match_parent">
74-
75-
<com.github.barteksc.pdfviewer.PDFView
76-
android:id="@+id/pdfView"
77-
android:layout_width="match_parent"
78-
android:layout_height="match_parent"
79-
android:layout_toLeftOf="@+id/scrollBar"/>
80-
81-
<com.github.barteksc.pdfviewer.ScrollBar
82-
android:id="@+id/scrollBar"
83-
android:layout_width="wrap_content"
84-
android:layout_height="match_parent"
85-
android:layout_alignParentRight="true"
86-
android:layout_alignParentEnd="true" />
87-
88-
</RelativeLayout>
89-
```
90-
Horizontally:
91-
``` xml
92-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
93-
android:layout_width="match_parent"
94-
android:layout_height="match_parent"
95-
xmlns:app="http://schemas.android.com/apk/res-auto">
96-
97-
<com.github.barteksc.pdfviewer.PDFView
98-
android:id="@+id/pdfView"
99-
android:layout_width="match_parent"
100-
android:layout_height="match_parent"/>
101-
102-
<com.github.barteksc.pdfviewer.ScrollBar
103-
android:id="@+id/scrollBar"
104-
android:layout_width="match_parent"
105-
android:layout_height="wrap_content"
106-
app:sb_horizontal="true"
107-
android:layout_alignParentBottom="true" />
108-
109-
</RelativeLayout>
110-
```
111-
2. in activity or fragment
112-
``` java
113-
114-
@Override
115-
protected void onCreate(Bundle savedInstanceState) {
116-
super.onCreate(savedInstanceState);
117-
118-
...
119-
120-
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
121-
ScrollBar scrollBar = (ScrollBar) findViewById(R.id.scrollBar);
122-
pdfView.setScrollBar(scrollBar);
123-
}
124-
```
125-
126-
`scrollBar.setHorizontal(true);` or `app:sb_horizontal="true"` may be used to set **ScrollBar** in horizontal mode.
127-
128-
129-
Scrollbar styling:
130-
``` xml
131-
<com.github.barteksc.pdfviewpager.view.ScrollBar
132-
android:layout_width="wrap_content"
133-
android:layout_height="match_parent"
134-
app:sb_handlerColor="..." <!-- scrollbar handler color -->
135-
app:sb_indicatorColor="..." <!-- background color of current page indicator -->
136-
app:sb_indicatorTextColor="..." <!-- text color of current page indicator -->
137-
app:sb_horizontal="true|false|reference" <!-- whether to set horizontal mode -->
138-
android:background="..." <!-- scrollbar background -->
139-
/>
140-
```
77+
To use scroll handle just register it using method `Configurator#scrollHandle()`.
78+
This method accepts implementations of **ScrollHandle** interface.
79+
80+
There is default implementation shipped with AndroidPdfViewer, and you can use it with
81+
`.scrollHandle(new DefaultScrollHandle(this))`.
82+
**DefaultScrollHandle** is placed on the right (when scrolling vertically) or on the bottom (when scrolling horizontally).
83+
By using constructor with second argument (`new DefaultScrollHandle(this, true)`), handle can be placed left or top.
84+
85+
You can also create custom scroll handles, just implement **ScrollHandle** interface.
86+
All methods are documented as Javadoc comments on interface [source](https://github.com/barteksc/AndroidPdfViewer/tree/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/scroll/ScrollHandle.java).
14187

142-
**ScrollBarPageIndicator** is added to scrollbar automatically and is shown while dragging scrollbar handler,
143-
displaying number of page on current position. Its position is automatically calculated based on **ScrollBar**'s position.
14488

14589
## Additional options
14690

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 = '1.4.0'
16+
libraryVersion = '2.0.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 "1.4.0"
35+
versionName "2.0.0"
3636
}
3737

3838
}

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

Lines changed: 82 additions & 18 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.
@@ -21,6 +21,7 @@
2121
import android.animation.ValueAnimator.AnimatorUpdateListener;
2222
import android.graphics.PointF;
2323
import android.view.animation.DecelerateInterpolator;
24+
import android.widget.Scroller;
2425

2526

2627
/**
@@ -31,21 +32,21 @@
3132
*/
3233
class AnimationManager {
3334

34-
/**
35-
* PDF View
36-
*/
3735
private PDFView pdfView;
3836

3937
private ValueAnimator animation;
4038

39+
private Scroller scroller;
40+
41+
private ValueAnimator flingAnimation;
42+
4143
public AnimationManager(PDFView pdfView) {
4244
this.pdfView = pdfView;
45+
scroller = new Scroller(pdfView.getContext(), null, true);
4346
}
4447

4548
public void startXAnimation(float xFrom, float xTo) {
46-
if (animation != null) {
47-
animation.cancel();
48-
}
49+
stopAll();
4950
animation = ValueAnimator.ofFloat(xFrom, xTo);
5051
animation.setInterpolator(new DecelerateInterpolator());
5152
animation.addUpdateListener(new XAnimation());
@@ -54,34 +55,50 @@ public void startXAnimation(float xFrom, float xTo) {
5455
}
5556

5657
public void startYAnimation(float yFrom, float yTo) {
57-
if (animation != null) {
58-
animation.cancel();
59-
}
58+
stopAll();
6059
animation = ValueAnimator.ofFloat(yFrom, yTo);
6160
animation.setInterpolator(new DecelerateInterpolator());
6261
animation.addUpdateListener(new YAnimation());
6362
animation.setDuration(400);
6463
animation.start();
6564
}
6665

67-
public void startZoomAnimation(float zoomFrom, float zoomTo) {
68-
if (animation != null) {
69-
animation.cancel();
70-
}
66+
public void startZoomAnimation(float centerX, float centerY, float zoomFrom, float zoomTo) {
67+
stopAll();
7168
animation = ValueAnimator.ofFloat(zoomFrom, zoomTo);
7269
animation.setInterpolator(new DecelerateInterpolator());
73-
ZoomAnimation zoomAnim = new ZoomAnimation();
70+
ZoomAnimation zoomAnim = new ZoomAnimation(centerX, centerY);
7471
animation.addUpdateListener(zoomAnim);
7572
animation.addListener(zoomAnim);
7673
animation.setDuration(400);
7774
animation.start();
7875
}
7976

77+
public void startFlingAnimation(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) {
78+
stopAll();
79+
flingAnimation = ValueAnimator.ofFloat(0, 1);
80+
FlingAnimation flingAnim = new FlingAnimation();
81+
flingAnimation.addUpdateListener(flingAnim);
82+
flingAnimation.addListener(flingAnim);
83+
scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
84+
flingAnimation.setDuration(scroller.getDuration());
85+
flingAnimation.start();
86+
}
87+
8088
public void stopAll() {
8189
if (animation != null) {
8290
animation.cancel();
8391
animation = null;
8492
}
93+
stopFling();
94+
}
95+
96+
public void stopFling() {
97+
if (flingAnimation != null) {
98+
scroller.forceFinished(true);
99+
flingAnimation.cancel();
100+
flingAnimation = null;
101+
}
85102
}
86103

87104
class XAnimation implements AnimatorUpdateListener {
@@ -106,10 +123,18 @@ public void onAnimationUpdate(ValueAnimator animation) {
106123

107124
class ZoomAnimation implements AnimatorUpdateListener, AnimatorListener {
108125

126+
private final float centerX;
127+
private final float centerY;
128+
129+
public ZoomAnimation(float centerX, float centerY) {
130+
this.centerX = centerX;
131+
this.centerY = centerY;
132+
}
133+
109134
@Override
110135
public void onAnimationUpdate(ValueAnimator animation) {
111136
float zoom = (Float) animation.getAnimatedValue();
112-
pdfView.zoomCenteredTo(zoom, new PointF(pdfView.getWidth() / 2, pdfView.getHeight() / 2));
137+
pdfView.zoomCenteredTo(zoom, new PointF(centerX, centerY));
113138
}
114139

115140
@Override
@@ -119,6 +144,7 @@ public void onAnimationCancel(Animator animation) {
119144
@Override
120145
public void onAnimationEnd(Animator animation) {
121146
pdfView.loadPages();
147+
hideHandle();
122148
}
123149

124150
@Override
@@ -131,4 +157,42 @@ public void onAnimationStart(Animator animation) {
131157

132158
}
133159

160+
class FlingAnimation implements AnimatorUpdateListener, AnimatorListener {
161+
@Override
162+
public void onAnimationUpdate(ValueAnimator animation) {
163+
if (!scroller.isFinished()) {
164+
scroller.computeScrollOffset();
165+
pdfView.moveTo(scroller.getCurrX(), scroller.getCurrY());
166+
pdfView.loadPageByOffset();
167+
}
168+
}
169+
170+
@Override
171+
public void onAnimationStart(Animator animation) {
172+
173+
}
174+
175+
@Override
176+
public void onAnimationEnd(Animator animation) {
177+
pdfView.loadPages();
178+
hideHandle();
179+
}
180+
181+
@Override
182+
public void onAnimationCancel(Animator animation) {
183+
184+
}
185+
186+
@Override
187+
public void onAnimationRepeat(Animator animation) {
188+
189+
}
190+
}
191+
192+
private void hideHandle() {
193+
if (pdfView.getScrollHandle() != null) {
194+
pdfView.getScrollHandle().hideDelayed();
195+
}
196+
}
197+
134198
}

0 commit comments

Comments
 (0)