|
42 | 42 | import com.github.barteksc.pdfviewer.listener.OnDrawListener; |
43 | 43 | import com.github.barteksc.pdfviewer.listener.OnErrorListener; |
44 | 44 | import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener; |
| 45 | +import com.github.barteksc.pdfviewer.listener.OnLongPressListener; |
45 | 46 | import com.github.barteksc.pdfviewer.listener.OnPageChangeListener; |
46 | 47 | import com.github.barteksc.pdfviewer.listener.OnPageErrorListener; |
47 | 48 | import com.github.barteksc.pdfviewer.listener.OnPageScrollListener; |
48 | 49 | import com.github.barteksc.pdfviewer.listener.OnRenderListener; |
49 | 50 | import com.github.barteksc.pdfviewer.listener.OnTapListener; |
50 | | -import com.github.barteksc.pdfviewer.listener.OnLongPressListener; |
51 | 51 | import com.github.barteksc.pdfviewer.model.PagePart; |
52 | 52 | import com.github.barteksc.pdfviewer.scroll.ScrollHandle; |
53 | 53 | import com.github.barteksc.pdfviewer.source.AssetSource; |
@@ -377,7 +377,22 @@ public void setSwipeEnabled(boolean enableSwipe) { |
377 | 377 | this.enableSwipe = enableSwipe; |
378 | 378 | } |
379 | 379 |
|
380 | | - public void setNightMode(boolean nightMode) { this.nightMode = nightMode; } |
| 380 | + public void setNightMode(boolean nightMode) { |
| 381 | + this.nightMode = nightMode; |
| 382 | + if (nightMode) { |
| 383 | + ColorMatrix colorMatrixInverted = |
| 384 | + new ColorMatrix(new float[]{ |
| 385 | + -1, 0, 0, 0, 255, |
| 386 | + 0, -1, 0, 0, 255, |
| 387 | + 0, 0, -1, 0, 255, |
| 388 | + 0, 0, 0, 1, 0}); |
| 389 | + |
| 390 | + ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrixInverted); |
| 391 | + paint.setColorFilter(filter); |
| 392 | + } else { |
| 393 | + paint.setColorFilter(null); |
| 394 | + } |
| 395 | + } |
381 | 396 |
|
382 | 397 | void enableDoubletap(boolean enableDoubletap) { |
383 | 398 | this.doubletapEnabled = enableDoubletap; |
@@ -555,11 +570,7 @@ protected void onDraw(Canvas canvas) { |
555 | 570 |
|
556 | 571 | Drawable bg = getBackground(); |
557 | 572 | if (bg == null) { |
558 | | - if (this.nightMode) |
559 | | - canvas.drawColor(Color.BLACK); |
560 | | - else |
561 | | - canvas.drawColor(Color.WHITE); |
562 | | - |
| 573 | + canvas.drawColor(nightMode ? Color.BLACK : Color.WHITE); |
563 | 574 | } else { |
564 | 575 | bg.draw(canvas); |
565 | 576 | } |
@@ -675,25 +686,6 @@ private void drawPart(Canvas canvas, PagePart part) { |
675 | 686 | return; |
676 | 687 | } |
677 | 688 |
|
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 | | - |
697 | 689 | canvas.drawBitmap(renderedBitmap, srcRect, dstRect, paint); |
698 | 690 |
|
699 | 691 | if (Constants.DEBUG_MODE) { |
@@ -1473,7 +1465,7 @@ public Configurator pageFling(boolean pageFling) { |
1473 | 1465 | return this; |
1474 | 1466 | } |
1475 | 1467 |
|
1476 | | - public Configurator setNightMode(boolean nightMode) { |
| 1468 | + public Configurator nightMode(boolean nightMode) { |
1477 | 1469 | this.nightMode = nightMode; |
1478 | 1470 | return this; |
1479 | 1471 | } |
|
0 commit comments