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

Commit a736804

Browse files
committed
Merge branch 'master' of https://github.com/barteksc/AndroidPdfViewer into pagefit
2 parents fe23883 + 690e2cf commit a736804

File tree

10 files changed

+130
-44
lines changed

10 files changed

+130
-44
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 3.1.0-beta.1 (2018-06-29)
2+
* Merge pull request #557 for snapping pages (scrolling page by page)
3+
* merge pull request #618 for night mode
4+
* Merge pull request #566 for `OnLongTapListener`
5+
* Update PdfiumAndroid to 1.9.0, which uses `c++_shared` instead of `gnustl_static`
6+
* Update Gradle Plugin
7+
* Update compile SDK and support library to 26
8+
* Change minimum SDK to 14
9+
110
## 3.0.0-beta.5 (2018-01-06)
211
* Fix issue with `Configurator#pages()` from #486
312
* Fix `IllegalStateException` from #464

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@ Library for displaying PDF documents on Android, with `animations`, `gestures`,
1010
It is based on [PdfiumAndroid](https://github.com/barteksc/PdfiumAndroid) for decoding PDF files. Works on API 11 (Android 3.0) and higher.
1111
Licensed under Apache License 2.0.
1212

13-
## What's new in 3.0.0-beta.1?
14-
* Add support for documents with different page sizes
15-
* Add support for links
16-
* Add support for defining page fit policy (fit width, height or both)
17-
* Update sample.pdf to contain different page sizes
18-
19-
3.0.0-beta.2 fixes rendering with maximum zoom, improves fit policies and updates PdfiumAndroid to 1.8.1
20-
21-
3.0.0-beta.3 fixes bug preventing `OnErrorListener` from being called
22-
23-
3.0.0-beta.4 fixes not loaded pages when using animated `PDFView#jumpTo()` and NPE in `canScrollVertically()` and `canScrollHorizontally()`
24-
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
13+
## What's new in 3.1.0-beta.1?
14+
* Merge pull request #557 for snapping pages (scrolling page by page)
15+
* merge pull request #618 for night mode
16+
* Merge pull request #566 for `OnLongTapListener`
17+
* Update PdfiumAndroid to 1.9.0, which uses `c++_shared` instead of `gnustl_static`
18+
* Update Gradle Plugin
19+
* Update compile SDK and support library to 26
20+
* Change minimum SDK to 14
2921

3022
## Changes in 3.0 API
3123
* Replaced `Contants.PRELOAD_COUNT` with `PRELOAD_OFFSET`
@@ -38,7 +30,7 @@ Licensed under Apache License 2.0.
3830

3931
Add to _build.gradle_:
4032

41-
`compile 'com.github.barteksc:android-pdf-viewer:3.0.0-beta.5'`
33+
`compile 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'`
4234

4335
or if you want to use more stable version:
4436

@@ -94,6 +86,7 @@ pdfView.fromAsset(String)
9486
.onRender(onRenderListener) // called after document is rendered for the first time
9587
// called on single tap, return true if handled, false to toggle scroll handle visibility
9688
.onTap(onTapListener)
89+
.onLongPress(onLongPressListener)
9790
.enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
9891
.password(null)
9992
.scrollHandle(null)
@@ -106,6 +99,7 @@ pdfView.fromAsset(String)
10699
.fitEachPage(false) // fit each page to the view, else smaller pages are scaled relative to largest page.
107100
.pageSnap(false) // snap pages to screen boundaries
108101
.pageFling(false) // make a fling change only a single page like ViewPager
102+
.nightMode(false) // toggle night mode
109103
.load();
110104
```
111105

android-pdf-viewer/build.gradle

Lines changed: 7 additions & 7 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.5'
16+
libraryVersion = '3.1.0-beta.1'
1717

1818
developerId = 'barteksc'
1919
developerName = 'Bartosz Schiller'
@@ -25,20 +25,20 @@ ext {
2525
}
2626

2727
android {
28-
compileSdkVersion 25
29-
buildToolsVersion '25.0.3'
28+
compileSdkVersion 26
3029

3130
defaultConfig {
32-
minSdkVersion 11
33-
targetSdkVersion 25
31+
minSdkVersion 14
32+
targetSdkVersion 26
3433
versionCode 1
35-
versionName "3.0.0-beta.5"
34+
versionName "3.1.0-beta.1"
3635
}
3736

3837
}
3938

4039
dependencies {
41-
compile 'com.github.barteksc:pdfium-android:1.8.2'
40+
implementation 'com.android.support:support-compat:26.1.0'
41+
api 'com.github.barteksc:pdfium-android:1.9.0'
4242
}
4343

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void onScrollEnd(MotionEvent event) {
189189

190190
@Override
191191
public void onLongPress(MotionEvent e) {
192-
192+
pdfView.callbacks.callOnLongPress(e);
193193
}
194194

195195
@Override

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import android.graphics.Bitmap;
2020
import android.graphics.Canvas;
2121
import android.graphics.Color;
22+
import android.graphics.ColorMatrix;
23+
import android.graphics.ColorMatrixColorFilter;
2224
import android.graphics.Paint;
2325
import android.graphics.Paint.Style;
2426
import android.graphics.PaintFlagsDrawFilter;
@@ -40,6 +42,7 @@
4042
import com.github.barteksc.pdfviewer.listener.OnDrawListener;
4143
import com.github.barteksc.pdfviewer.listener.OnErrorListener;
4244
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
45+
import com.github.barteksc.pdfviewer.listener.OnLongPressListener;
4346
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
4447
import com.github.barteksc.pdfviewer.listener.OnPageErrorListener;
4548
import com.github.barteksc.pdfviewer.listener.OnPageScrollListener;
@@ -179,6 +182,8 @@ enum ScrollDir {
179182

180183
private boolean doubletapEnabled = true;
181184

185+
private boolean nightMode = false;
186+
182187
private boolean pageSnap = true;
183188

184189
/** Pdfium core for loading and rendering PDFs */
@@ -374,6 +379,23 @@ public void setSwipeEnabled(boolean enableSwipe) {
374379
this.enableSwipe = enableSwipe;
375380
}
376381

382+
public void setNightMode(boolean nightMode) {
383+
this.nightMode = nightMode;
384+
if (nightMode) {
385+
ColorMatrix colorMatrixInverted =
386+
new ColorMatrix(new float[]{
387+
-1, 0, 0, 0, 255,
388+
0, -1, 0, 0, 255,
389+
0, 0, -1, 0, 255,
390+
0, 0, 0, 1, 0});
391+
392+
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrixInverted);
393+
paint.setColorFilter(filter);
394+
} else {
395+
paint.setColorFilter(null);
396+
}
397+
}
398+
377399
void enableDoubletap(boolean enableDoubletap) {
378400
this.doubletapEnabled = enableDoubletap;
379401
}
@@ -550,7 +572,7 @@ protected void onDraw(Canvas canvas) {
550572

551573
Drawable bg = getBackground();
552574
if (bg == null) {
553-
canvas.drawColor(Color.WHITE);
575+
canvas.drawColor(nightMode ? Color.BLACK : Color.WHITE);
554576
} else {
555577
bg.draw(canvas);
556578
}
@@ -1294,6 +1316,8 @@ public class Configurator {
12941316

12951317
private OnTapListener onTapListener;
12961318

1319+
private OnLongPressListener onLongPressListener;
1320+
12971321
private OnPageErrorListener onPageErrorListener;
12981322

12991323
private LinkHandler linkHandler = new DefaultLinkHandler(PDFView.this);
@@ -1322,6 +1346,8 @@ public class Configurator {
13221346

13231347
private boolean pageSnap = false;
13241348

1349+
private boolean nightMode = false;
1350+
13251351
private Configurator(DocumentSource documentSource) {
13261352
this.documentSource = documentSource;
13271353
}
@@ -1391,6 +1417,11 @@ public Configurator onTap(OnTapListener onTapListener) {
13911417
return this;
13921418
}
13931419

1420+
public Configurator onLongPress(OnLongPressListener onLongPressListener) {
1421+
this.onLongPressListener = onLongPressListener;
1422+
return this;
1423+
}
1424+
13941425
public Configurator linkHandler(LinkHandler linkHandler) {
13951426
this.linkHandler = linkHandler;
13961427
return this;
@@ -1451,6 +1482,11 @@ public Configurator pageFling(boolean pageFling) {
14511482
return this;
14521483
}
14531484

1485+
public Configurator nightMode(boolean nightMode) {
1486+
this.nightMode = nightMode;
1487+
return this;
1488+
}
1489+
14541490
public void load() {
14551491
if (!hasSize) {
14561492
waitingDocumentConfigurator = this;
@@ -1465,9 +1501,11 @@ public void load() {
14651501
PDFView.this.callbacks.setOnPageScroll(onPageScrollListener);
14661502
PDFView.this.callbacks.setOnRender(onRenderListener);
14671503
PDFView.this.callbacks.setOnTap(onTapListener);
1504+
PDFView.this.callbacks.setOnLongPress(onLongPressListener);
14681505
PDFView.this.callbacks.setOnPageError(onPageErrorListener);
14691506
PDFView.this.callbacks.setLinkHandler(linkHandler);
14701507
PDFView.this.setSwipeEnabled(enableSwipe);
1508+
PDFView.this.setNightMode(nightMode);
14711509
PDFView.this.enableDoubletap(enableDoubletap);
14721510
PDFView.this.setDefaultPage(defaultPage);
14731511
PDFView.this.setSwipeVertical(!swipeHorizontal);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class Callbacks {
6464
*/
6565
private OnTapListener onTapListener;
6666

67+
/**
68+
* Call back object to call when the user does a long tap gesture
69+
*/
70+
private OnLongPressListener onLongPressListener;
71+
6772
/**
6873
* Call back object to call when clicking link
6974
*/
@@ -153,6 +158,16 @@ public boolean callOnTap(MotionEvent event) {
153158
return onTapListener != null && onTapListener.onTap(event);
154159
}
155160

161+
public void setOnLongPress(OnLongPressListener onLongPressListener) {
162+
this.onLongPressListener = onLongPressListener;
163+
}
164+
165+
public void callOnLongPress(MotionEvent event) {
166+
if (onLongPressListener != null) {
167+
onLongPressListener.onLongPress(event);
168+
}
169+
}
170+
156171
public void setLinkHandler(LinkHandler linkHandler) {
157172
this.linkHandler = linkHandler;
158173
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2017 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.listener;
17+
18+
import android.view.MotionEvent;
19+
20+
/**
21+
* Implement this interface to receive events from PDFView
22+
* when view has been long pressed
23+
*/
24+
public interface OnLongPressListener {
25+
26+
/**
27+
* Called when the user has a long tap gesture, before processing scroll handle toggling
28+
*
29+
* @param e MotionEvent that registered as a confirmed long press
30+
*/
31+
void onLongPress(MotionEvent e);
32+
}

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11

22
buildscript {
33
repositories {
4+
google()
45
jcenter()
56
}
67
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.3'
8-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
8+
classpath 'com.android.tools.build:gradle:3.1.3'
9+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
10+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1011
}
1112
}
1213

1314
allprojects {
1415
repositories {
16+
google()
1517
jcenter()
1618
}
1719
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Nov 11 23:27:31 CET 2017
1+
#Wed Jun 27 20:37:56 CEST 2018
22
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-4.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

sample/build.gradle

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
buildscript {
22
repositories {
3+
google()
34
jcenter()
45
}
5-
dependencies {
6-
// replace with the current version of the android-apt plugin
7-
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
8-
}
96
}
107

118
repositories {
9+
google()
1210
jcenter()
1311
}
1412

1513
apply plugin: 'com.android.application'
16-
apply plugin: 'android-apt'
1714

1815
android {
19-
compileSdkVersion 25
20-
buildToolsVersion "25.0.3"
16+
compileSdkVersion 26
2117

2218
defaultConfig {
23-
minSdkVersion 11
24-
targetSdkVersion 25
19+
minSdkVersion 14
20+
targetSdkVersion 26
2521
versionCode 3
2622
versionName "3.0.0"
2723
}
2824

2925
}
3026

3127
dependencies {
32-
compile project(':android-pdf-viewer')
33-
compile 'com.android.support:appcompat-v7:25.3.1'
34-
provided 'org.androidannotations:androidannotations:4.0.0'
35-
compile 'org.androidannotations:androidannotations-api:4.0.0'
28+
implementation project(':android-pdf-viewer')
29+
implementation 'com.android.support:appcompat-v7:26.1.0'
30+
implementation 'org.androidannotations:androidannotations-api:4.4.0'
31+
annotationProcessor "org.androidannotations:androidannotations:4.4.0"
3632
}

0 commit comments

Comments
 (0)