19
19
import android .graphics .Bitmap ;
20
20
import android .graphics .Canvas ;
21
21
import android .graphics .Color ;
22
+ import android .graphics .ColorMatrix ;
23
+ import android .graphics .ColorMatrixColorFilter ;
22
24
import android .graphics .Paint ;
23
25
import android .graphics .Paint .Style ;
24
26
import android .graphics .PaintFlagsDrawFilter ;
@@ -178,6 +180,8 @@ enum ScrollDir {
178
180
179
181
private boolean doubletapEnabled = true ;
180
182
183
+ private boolean nightMode = false ;
184
+
181
185
private boolean pageSnap = true ;
182
186
183
187
/** Pdfium core for loading and rendering PDFs */
@@ -373,6 +377,8 @@ public void setSwipeEnabled(boolean enableSwipe) {
373
377
this .enableSwipe = enableSwipe ;
374
378
}
375
379
380
+ public void setNightMode (boolean nightMode ) { this .nightMode = nightMode ; }
381
+
376
382
void enableDoubletap (boolean enableDoubletap ) {
377
383
this .doubletapEnabled = enableDoubletap ;
378
384
}
@@ -549,7 +555,11 @@ protected void onDraw(Canvas canvas) {
549
555
550
556
Drawable bg = getBackground ();
551
557
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
+
553
563
} else {
554
564
bg .draw (canvas );
555
565
}
@@ -665,6 +675,25 @@ private void drawPart(Canvas canvas, PagePart part) {
665
675
return ;
666
676
}
667
677
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
+
668
697
canvas .drawBitmap (renderedBitmap , srcRect , dstRect , paint );
669
698
670
699
if (Constants .DEBUG_MODE ) {
@@ -1313,6 +1342,8 @@ public class Configurator {
1313
1342
1314
1343
private boolean pageSnap = false ;
1315
1344
1345
+ private boolean nightMode = false ;
1346
+
1316
1347
private Configurator (DocumentSource documentSource ) {
1317
1348
this .documentSource = documentSource ;
1318
1349
}
@@ -1442,6 +1473,11 @@ public Configurator pageFling(boolean pageFling) {
1442
1473
return this ;
1443
1474
}
1444
1475
1476
+ public Configurator setNightMode (boolean nightMode ) {
1477
+ this .nightMode = nightMode ;
1478
+ return this ;
1479
+ }
1480
+
1445
1481
public void load () {
1446
1482
if (!hasSize ) {
1447
1483
waitingDocumentConfigurator = this ;
@@ -1460,6 +1496,7 @@ public void load() {
1460
1496
PDFView .this .callbacks .setOnPageError (onPageErrorListener );
1461
1497
PDFView .this .callbacks .setLinkHandler (linkHandler );
1462
1498
PDFView .this .setSwipeEnabled (enableSwipe );
1499
+ PDFView .this .setNightMode (nightMode );
1463
1500
PDFView .this .enableDoubletap (enableDoubletap );
1464
1501
PDFView .this .setDefaultPage (defaultPage );
1465
1502
PDFView .this .setSwipeVertical (!swipeHorizontal );
0 commit comments