From be2439be6560e86501c82fa9a4c8dca96247182f Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 20 Aug 2019 12:23:38 -0400 Subject: [PATCH] add padding to account for fullscreen mode --- app/src/main/assets/viewer.css | 6 +++++- app/src/main/assets/viewer.html | 1 + app/src/main/assets/viewer.js | 9 +++++++++ .../java/org/grapheneos/pdfviewer/PdfViewer.java | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/viewer.css b/app/src/main/assets/viewer.css index 66fc2b2..4793185 100644 --- a/app/src/main/assets/viewer.css +++ b/app/src/main/assets/viewer.css @@ -1,8 +1,12 @@ -body, canvas { +body, canvas, #padding { padding: 0; margin: 0; } +#padding { + background: black; +} + .textLayer { position: absolute; left: 0; diff --git a/app/src/main/assets/viewer.html b/app/src/main/assets/viewer.html index c4f1125..bea4678 100644 --- a/app/src/main/assets/viewer.html +++ b/app/src/main/assets/viewer.html @@ -7,6 +7,7 @@ +
diff --git a/app/src/main/assets/viewer.js b/app/src/main/assets/viewer.js index 6e11442..a4c616a 100644 --- a/app/src/main/assets/viewer.js +++ b/app/src/main/assets/viewer.js @@ -189,6 +189,15 @@ function isTextSelected() { return window.getSelection().toString() !== ""; } +function updateInset() { + const padding = document.getElementById("padding"); + const windowInsetTop = channel.getWindowInsetTop() / window.devicePixelRatio + "px"; + padding.style.paddingTop = windowInsetTop; + textLayerDiv.style.top = windowInsetTop; +} + +updateInset(); + pdfjsLib.getDocument("https://localhost/placeholder.pdf").promise.then(function(newDoc) { pdfDoc = newDoc; channel.setNumPages(pdfDoc.numPages); diff --git a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java index 64f77d8..2ef8b6f 100644 --- a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java @@ -91,6 +91,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private int mZoomLevel = 2; private int mDocumentOrientationDegrees; private int mDocumentState; + private int windowInsetTop; private List mDocumentProperties; private InputStream mInputStream; @@ -99,6 +100,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader private Toast mToast; private class Channel { + @JavascriptInterface + public int getWindowInsetTop() { + return windowInsetTop; + } + @JavascriptInterface public int getPage() { return mPage; @@ -147,6 +153,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader setContentView(R.layout.webview); mWebView = findViewById(R.id.webview); + + mWebView.setOnApplyWindowInsetsListener((view, insets) -> { + windowInsetTop = insets.getSystemWindowInsetTop(); + mWebView.evaluateJavascript("updateInset()", null); + return insets; + }); + final WebSettings settings = mWebView.getSettings(); settings.setAllowContentAccess(false); settings.setAllowFileAccess(false);