Skip to content

Commit af9b7d8

Browse files
committed
Initial sources commit
1 parent 29e21c4 commit af9b7d8

40 files changed

+3989
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
target/
2+
build/
3+
lint.xml
4+
bin/
5+
gen/
6+
.settings
7+
.project
8+
.classpath
9+
out
10+
gen-external-apklibs/
11+
classes/
12+
13+
# Local configuration file (sdk path, etc)
14+
local.properties
15+
16+
# Android Studio
17+
.idea/
18+
*/out
19+
!*/build/apk/
20+
*/production/
21+
*.iws
22+
*.ipr
23+
*.iml
24+
*~
25+
*.swp
26+
27+
# gradle
28+
.gradle
29+
30+
.DS_Store

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
3+
# Android PdfViewer
4+
5+
Library for displaying PDF documents on Android, with `animations`, `gestures`, `zoom` and `double tap` support.
6+
It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 and higher.
7+
Licensed under Apache License 2.0.
8+
9+
## Installation
10+
11+
Add to _build.gradle_:
12+
13+
`compile 'com.github.barteksc:android-pdf-viewer:1.0.0'`
14+
15+
Library is available in jcenter repository, probably it'll be in Maven Central soon.
16+
17+
## Include PDFView in your layout
18+
19+
``` xml
20+
<com.github.barteksc.pdfviewer.PDFView
21+
android:id="@+id/pdfView"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"/>
24+
```
25+
26+
## Load a PDF file
27+
28+
``` java
29+
pdfView.fromAsset(pdfName)
30+
.pages(0, 2, 1, 3, 3, 3)
31+
.defaultPage(1)
32+
.showMinimap(false)
33+
.enableSwipe(true)
34+
.onDraw(onDrawListener)
35+
.onLoad(onLoadCompleteListener)
36+
.onPageChange(onPageChangeListener)
37+
.onError(onErrorListener)
38+
.load();
39+
```
40+
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
43+
44+
## Show scrollbar
45+
46+
Use **ScrollBar** class to place scrollbar view near **PDFView**
47+
48+
1. in layout XML (it's important that the parent view is **RelativeLayout**)
49+
50+
``` xml
51+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
52+
android:layout_width="match_parent"
53+
android:layout_height="match_parent">
54+
55+
<com.github.barteksc.pdfviewer.PDFView
56+
android:id="@+id/pdfView"
57+
android:layout_width="match_parent"
58+
android:layout_height="match_parent"
59+
android:layout_toLeftOf="@+id/scrollBar"/>
60+
61+
<com.github.barteksc.pdfviewer.ScrollBar
62+
android:id="@+id/scrollBar"
63+
android:layout_width="wrap_content"
64+
android:layout_height="match_parent"
65+
android:layout_alignParentRight="true"
66+
android:layout_alignParentEnd="true" />
67+
68+
</RelativeLayout>
69+
```
70+
2. in activity or fragment
71+
``` java
72+
73+
@Override
74+
protected void onCreate(Bundle savedInstanceState) {
75+
super.onCreate(savedInstanceState);
76+
77+
...
78+
79+
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
80+
ScrollBar scrollBar = (ScrollBar) findViewById(R.id.scrollBar);
81+
pdfView.setScrollBar(scrollBar);
82+
}
83+
84+
```
85+
86+
Scrollbar styling:
87+
``` xml
88+
<com.github.barteksc.pdfviewpager.view.ScrollBar
89+
android:layout_width="wrap_content"
90+
android:layout_height="match_parent"
91+
app:sb_handlerColor="..." <!-- scrollbar handler color -->
92+
app:sb_indicatorColor="..." <!-- background color of current page indicator -->
93+
app:sb_indicatorTextColor="..." <!-- text color of current page indicator -->
94+
android:background="..." <!-- scrollbar background -->
95+
/>
96+
```
97+
98+
## Additional options
99+
100+
### Bitmap quality
101+
By default, generated bitmaps are _compressed_ with `RGB_565` format to reduce memory consumption.
102+
Rendering with `ARGB_8888` can be forced by using `pdfView.useBestQuality(true)` method.
103+
104+
### Double tap zooming
105+
There are three zoom levels: min (default 1), mid (default 1.75) and max (default 3). On first double tap,
106+
view is zoomed to mid level, on second to max level, and on third returns to min level.
107+
If you are between mid and max levels, double tapping causes zooming to max and so on.
108+
109+
Zoom levels can be changed using following methods:
110+
111+
``` java
112+
void setMinZoom(float zoom);
113+
void setMidZoom(float zoom);
114+
void setMaxZoom(float zoom);
115+
```
116+
117+
## License
118+
119+
Created with the help of android-pdfview by [Joan Zapata](http://joanzapata.com/)
120+
```
121+
Copyright 2016 Bartosz Schiller
122+
123+
Licensed under the Apache License, Version 2.0 (the "License");
124+
you may not use this file except in compliance with the License.
125+
You may obtain a copy of the License at
126+
127+
http://www.apache.org/licenses/LICENSE-2.0
128+
129+
Unless required by applicable law or agreed to in writing, software
130+
distributed under the License is distributed on an "AS IS" BASIS,
131+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132+
See the License for the specific language governing permissions and
133+
limitations under the License.
134+
```

android-pdf-viewer/build.gradle

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apply plugin: 'com.android.library'
2+
3+
ext {
4+
bintrayRepo = 'maven'
5+
bintrayName = 'android-pdf-viewer'
6+
7+
publishedGroupId = 'com.github.barteksc'
8+
libraryName = 'AndroidPdfViewer'
9+
artifact = 'android-pdf-viewer'
10+
11+
libraryDescription = 'Android view for displaying PDFs rendered with PdfiumAndroid'
12+
13+
siteUrl = 'https://github.com/barteksc/AndroidPdfViewer'
14+
gitUrl = 'https://github.com/barteksc/AndroidPdfViewer.git'
15+
16+
libraryVersion = '1.0.0'
17+
18+
developerId = 'barteksc'
19+
developerName = 'Bartosz Schiller'
20+
developerEmail = '[email protected]'
21+
22+
licenseName = 'The Apache Software License, Version 2.0'
23+
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
24+
allLicenses = ["Apache-2.0"]
25+
}
26+
27+
android {
28+
compileSdkVersion 23
29+
buildToolsVersion '23.0.2'
30+
31+
defaultConfig {
32+
minSdkVersion 11
33+
targetSdkVersion 23
34+
versionCode 1
35+
versionName "1.0.0"
36+
}
37+
38+
}
39+
40+
dependencies {
41+
compile 'com.github.barteksc:pdfium-android:1.0.2'
42+
}
43+
44+
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
45+
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.github.barteksc.pdfviewer">
4+
5+
</manifest>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/**
2+
* Copyright 2016 Bartosz Schiller
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.barteksc.pdfviewer;
17+
18+
import android.animation.Animator;
19+
import android.animation.Animator.AnimatorListener;
20+
import android.animation.ValueAnimator;
21+
import android.animation.ValueAnimator.AnimatorUpdateListener;
22+
import android.graphics.PointF;
23+
import android.view.animation.DecelerateInterpolator;
24+
25+
26+
/**
27+
* This manager is used by the PDFView to launch animations.
28+
* It uses the ValueAnimator appeared in API 11 to start
29+
* an animation, and call moveTo() on the PDFView as a result
30+
* of each animation update.
31+
*/
32+
class AnimationManager {
33+
34+
/**
35+
* PDF View
36+
*/
37+
private PDFView pdfView;
38+
39+
private ValueAnimator animation;
40+
41+
public AnimationManager(PDFView pdfView) {
42+
this.pdfView = pdfView;
43+
}
44+
45+
public void startXAnimation(float xFrom, float xTo) {
46+
if (animation != null) {
47+
animation.cancel();
48+
}
49+
animation = ValueAnimator.ofFloat(xFrom, xTo);
50+
animation.setInterpolator(new DecelerateInterpolator());
51+
animation.addUpdateListener(new XAnimation());
52+
animation.setDuration(400);
53+
animation.start();
54+
}
55+
56+
public void startYAnimation(float yFrom, float yTo) {
57+
if (animation != null) {
58+
animation.cancel();
59+
}
60+
animation = ValueAnimator.ofFloat(yFrom, yTo);
61+
animation.setInterpolator(new DecelerateInterpolator());
62+
animation.addUpdateListener(new YAnimation());
63+
animation.setDuration(400);
64+
animation.start();
65+
}
66+
67+
public void startZoomAnimation(float zoomFrom, float zoomTo) {
68+
if (animation != null) {
69+
animation.cancel();
70+
}
71+
animation = ValueAnimator.ofFloat(zoomFrom, zoomTo);
72+
animation.setInterpolator(new DecelerateInterpolator());
73+
ZoomAnimation zoomAnim = new ZoomAnimation();
74+
animation.addUpdateListener(zoomAnim);
75+
animation.addListener(zoomAnim);
76+
animation.setDuration(400);
77+
animation.start();
78+
}
79+
80+
public void stopAll() {
81+
if (animation != null) {
82+
animation.cancel();
83+
animation = null;
84+
}
85+
}
86+
87+
class XAnimation implements AnimatorUpdateListener {
88+
89+
@Override
90+
public void onAnimationUpdate(ValueAnimator animation) {
91+
float offset = (Float) animation.getAnimatedValue();
92+
pdfView.moveTo(offset, pdfView.getCurrentYOffset());
93+
}
94+
95+
}
96+
97+
class YAnimation implements AnimatorUpdateListener {
98+
99+
@Override
100+
public void onAnimationUpdate(ValueAnimator animation) {
101+
float offset = (Float) animation.getAnimatedValue();
102+
pdfView.moveTo(pdfView.getCurrentXOffset(), offset);
103+
}
104+
105+
}
106+
107+
class ZoomAnimation implements AnimatorUpdateListener, AnimatorListener {
108+
109+
@Override
110+
public void onAnimationUpdate(ValueAnimator animation) {
111+
float zoom = (Float) animation.getAnimatedValue();
112+
pdfView.zoomCenteredTo(zoom, new PointF(pdfView.getWidth() / 2, pdfView.getHeight() / 2));
113+
}
114+
115+
@Override
116+
public void onAnimationCancel(Animator animation) {
117+
}
118+
119+
@Override
120+
public void onAnimationEnd(Animator animation) {
121+
pdfView.loadPages();
122+
}
123+
124+
@Override
125+
public void onAnimationRepeat(Animator animation) {
126+
}
127+
128+
@Override
129+
public void onAnimationStart(Animator animation) {
130+
}
131+
132+
}
133+
134+
}

0 commit comments

Comments
 (0)