diff --git a/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java index 936f70851..c1c505439 100644 --- a/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java @@ -130,6 +130,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private String mEncryptedDocumentPassword; private List mDocumentProperties; private InputStream mInputStream; + private boolean invertedMode = false; private PdfviewerBinding binding; private TextView mTextView; @@ -416,8 +417,17 @@ public void onPageFinished(WebView view, String url) { mDocumentState = STATE_LOADED; invalidateOptionsMenu(); loadPdfWithPassword(mEncryptedDocumentPassword); + + if (invertedMode) injectDarkThemeCss(view); + } + private void injectDarkThemeCss(WebView view) { + String js = "javascript:(function() {" + + "document.body.style.filter = 'invert(1) hue-rotate(180deg)';" + + "})()"; + view.evaluateJavascript(js, null); } + @Override public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { if (detail.didCrash()) { @@ -730,7 +740,7 @@ public boolean onPrepareOptionsMenu(@NonNull Menu menu) { R.id.action_next, R.id.action_previous, R.id.action_first, R.id.action_last, R.id.action_rotate_clockwise, R.id.action_rotate_counterclockwise, R.id.action_view_document_properties, R.id.action_share, R.id.action_save_as, - R.id.action_outline)); + R.id.action_toggle_inverted_mode, R.id.action_outline)); if (BuildConfig.DEBUG) { ids.add(R.id.debug_action_toggle_text_layer_visibility); ids.add(R.id.debug_action_crash_webview); @@ -759,6 +769,7 @@ public boolean onPrepareOptionsMenu(@NonNull Menu menu) { enableDisableMenuItem(menu.findItem(R.id.action_next), mPage < mNumPages); enableDisableMenuItem(menu.findItem(R.id.action_previous), mPage > 1); enableDisableMenuItem(menu.findItem(R.id.action_save_as), mUri != null); + enableDisableMenuItem(menu.findItem(R.id.action_toggle_inverted_mode), mUri != null); enableDisableMenuItem(menu.findItem(R.id.action_view_document_properties), mDocumentProperties != null); @@ -821,6 +832,9 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } else if (itemId == R.id.action_save_as) { saveDocument(); + }else if (itemId == R.id.action_toggle_inverted_mode) { + invertedMode = !invertedMode; + loadPdf(); } else if (itemId == R.id.debug_action_toggle_text_layer_visibility) { binding.webview.evaluateJavascript("toggleTextLayerVisibility()", null); return true; diff --git a/app/src/main/res/menu/pdf_viewer.xml b/app/src/main/res/menu/pdf_viewer.xml index 16cd9b289..37d3f342d 100644 --- a/app/src/main/res/menu/pdf_viewer.xml +++ b/app/src/main/res/menu/pdf_viewer.xml @@ -72,6 +72,12 @@ android:icon="@drawable/ic_outline_bulletlist_24dp" android:title="@string/action_outline" /> + + + Share Save as Outline + Toggle inverted mode Properties Close