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

Skip to content

Commit 119129b

Browse files
committed
Merge branch 'master' of https://github.com/alierdogan7/AndroidPdfViewer into alierdogan7-master
2 parents b5a4544 + fddf135 commit 119129b

File tree

1 file changed

+38
-1
lines changed
  • android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer

1 file changed

+38
-1
lines changed

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

Lines changed: 38 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;
@@ -178,6 +180,8 @@ enum ScrollDir {
178180

179181
private boolean doubletapEnabled = true;
180182

183+
private boolean nightMode = false;
184+
181185
private boolean pageSnap = true;
182186

183187
/** Pdfium core for loading and rendering PDFs */
@@ -373,6 +377,8 @@ public void setSwipeEnabled(boolean enableSwipe) {
373377
this.enableSwipe = enableSwipe;
374378
}
375379

380+
public void setNightMode(boolean nightMode) { this.nightMode = nightMode; }
381+
376382
void enableDoubletap(boolean enableDoubletap) {
377383
this.doubletapEnabled = enableDoubletap;
378384
}
@@ -549,7 +555,11 @@ protected void onDraw(Canvas canvas) {
549555

550556
Drawable bg = getBackground();
551557
if (bg == null) {
552-
canvas.drawColor(Color.WHITE);
558+
if (this.nightMode)
559+
canvas.drawColor(Color.BLACK);
560+
else
561+
canvas.drawColor(Color.WHITE);
562+
553563
} else {
554564
bg.draw(canvas);
555565
}
@@ -665,6 +675,25 @@ private void drawPart(Canvas canvas, PagePart part) {
665675
return;
666676
}
667677

678+
679+
// NIGHT MODE !!!
680+
if ( this.nightMode ) {
681+
paint = new Paint();
682+
ColorMatrix colorMatrix_Inverted =
683+
new ColorMatrix(new float[] {
684+
-1, 0, 0, 0, 255,
685+
0, -1, 0, 0, 255,
686+
0, 0, -1, 0, 255,
687+
0, 0, 0, 1, 0});
688+
689+
690+
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix_Inverted);
691+
paint.setColorFilter(filter);
692+
}
693+
else
694+
paint = new Paint();
695+
// NIGHT MODE !!!
696+
668697
canvas.drawBitmap(renderedBitmap, srcRect, dstRect, paint);
669698

670699
if (Constants.DEBUG_MODE) {
@@ -1313,6 +1342,8 @@ public class Configurator {
13131342

13141343
private boolean pageSnap = false;
13151344

1345+
private boolean nightMode = false;
1346+
13161347
private Configurator(DocumentSource documentSource) {
13171348
this.documentSource = documentSource;
13181349
}
@@ -1442,6 +1473,11 @@ public Configurator pageFling(boolean pageFling) {
14421473
return this;
14431474
}
14441475

1476+
public Configurator setNightMode(boolean nightMode) {
1477+
this.nightMode = nightMode;
1478+
return this;
1479+
}
1480+
14451481
public void load() {
14461482
if (!hasSize) {
14471483
waitingDocumentConfigurator = this;
@@ -1460,6 +1496,7 @@ public void load() {
14601496
PDFView.this.callbacks.setOnPageError(onPageErrorListener);
14611497
PDFView.this.callbacks.setLinkHandler(linkHandler);
14621498
PDFView.this.setSwipeEnabled(enableSwipe);
1499+
PDFView.this.setNightMode(nightMode);
14631500
PDFView.this.enableDoubletap(enableDoubletap);
14641501
PDFView.this.setDefaultPage(defaultPage);
14651502
PDFView.this.setSwipeVertical(!swipeHorizontal);

0 commit comments

Comments
 (0)