Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private String mEncryptedDocumentPassword;
private List<CharSequence> mDocumentProperties;
private InputStream mInputStream;
private boolean invertedMode = false;

private PdfviewerBinding binding;
private TextView mTextView;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/pdf_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
android:icon="@drawable/ic_outline_bulletlist_24dp"
android:title="@string/action_outline" />

<item
android:id="@+id/action_toggle_inverted_mode"
android:icon="@drawable/ic_outline_bulletlist_24dp"
android:title="@string/action_toggle_inverted_mode" />


<item
android:id="@+id/action_view_document_properties"
android:title="@string/action_view_document_properties"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="action_share">Share</string>
<string name="action_save_as">Save as</string>
<string name="action_outline">Outline</string>
<string name="action_toggle_inverted_mode">Toggle inverted mode</string>
<string name="action_view_document_properties">Properties</string>
<string name="action_close">Close</string>

Expand Down