1919import android .graphics .Bitmap ;
2020import android .graphics .Canvas ;
2121import android .graphics .Color ;
22+ import android .graphics .ColorMatrix ;
23+ import android .graphics .ColorMatrixColorFilter ;
2224import android .graphics .Paint ;
2325import android .graphics .Paint .Style ;
2426import android .graphics .PaintFlagsDrawFilter ;
@@ -177,6 +179,8 @@ enum ScrollDir {
177179
178180 private boolean doubletapEnabled = true ;
179181
182+ private boolean nightMode = false ;
183+
180184 private boolean pageSnap = true ;
181185
182186 /** Pdfium core for loading and rendering PDFs */
@@ -372,6 +376,8 @@ public void setSwipeEnabled(boolean enableSwipe) {
372376 this .enableSwipe = enableSwipe ;
373377 }
374378
379+ public void setNightMode (boolean nightMode ) { this .nightMode = nightMode ; }
380+
375381 void enableDoubletap (boolean enableDoubletap ) {
376382 this .doubletapEnabled = enableDoubletap ;
377383 }
@@ -548,7 +554,11 @@ protected void onDraw(Canvas canvas) {
548554
549555 Drawable bg = getBackground ();
550556 if (bg == null ) {
551- canvas .drawColor (Color .WHITE );
557+ if (this .nightMode )
558+ canvas .drawColor (Color .BLACK );
559+ else
560+ canvas .drawColor (Color .WHITE );
561+
552562 } else {
553563 bg .draw (canvas );
554564 }
@@ -664,6 +674,25 @@ private void drawPart(Canvas canvas, PagePart part) {
664674 return ;
665675 }
666676
677+
678+ // NIGHT MODE !!!
679+ if ( this .nightMode ) {
680+ paint = new Paint ();
681+ ColorMatrix colorMatrix_Inverted =
682+ new ColorMatrix (new float [] {
683+ -1 , 0 , 0 , 0 , 255 ,
684+ 0 , -1 , 0 , 0 , 255 ,
685+ 0 , 0 , -1 , 0 , 255 ,
686+ 0 , 0 , 0 , 1 , 0 });
687+
688+
689+ ColorMatrixColorFilter filter = new ColorMatrixColorFilter (colorMatrix_Inverted );
690+ paint .setColorFilter (filter );
691+ }
692+ else
693+ paint = new Paint ();
694+ // NIGHT MODE !!!
695+
667696 canvas .drawBitmap (renderedBitmap , srcRect , dstRect , paint );
668697
669698 if (Constants .DEBUG_MODE ) {
@@ -1310,6 +1339,8 @@ public class Configurator {
13101339
13111340 private boolean pageSnap = false ;
13121341
1342+ private boolean nightMode = false ;
1343+
13131344 private Configurator (DocumentSource documentSource ) {
13141345 this .documentSource = documentSource ;
13151346 }
@@ -1434,6 +1465,11 @@ public Configurator pageFling(boolean pageFling) {
14341465 return this ;
14351466 }
14361467
1468+ public Configurator setNightMode (boolean nightMode ) {
1469+ this .nightMode = nightMode ;
1470+ return this ;
1471+ }
1472+
14371473 public void load () {
14381474 if (!hasSize ) {
14391475 waitingDocumentConfigurator = this ;
@@ -1451,6 +1487,7 @@ public void load() {
14511487 PDFView .this .callbacks .setOnPageError (onPageErrorListener );
14521488 PDFView .this .callbacks .setLinkHandler (linkHandler );
14531489 PDFView .this .setSwipeEnabled (enableSwipe );
1490+ PDFView .this .setNightMode (nightMode );
14541491 PDFView .this .enableDoubletap (enableDoubletap );
14551492 PDFView .this .setDefaultPage (defaultPage );
14561493 PDFView .this .setSwipeVertical (!swipeHorizontal );
0 commit comments