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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
defaultConfig {
applicationId = "app.grapheneos.pdfviewer"
minSdk = 26
targetSdk = 35
targetSdk = 36
versionCode = 32
versionName = versionCode.toString()
}
Expand Down
32 changes: 31 additions & 1 deletion app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
Expand All @@ -38,6 +41,8 @@

import com.google.android.material.snackbar.Snackbar;

import org.json.JSONObject;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -265,6 +270,23 @@ public void onLoaded() {
public String getPassword() {
return mEncryptedDocumentPassword != null ? mEncryptedDocumentPassword : "";
}

@JavascriptInterface
public String getInsets() {
WindowInsetsCompat wic = ViewCompat.getRootWindowInsets(binding.getRoot());
int types = WindowInsetsCompat.Type.statusBars()
| WindowInsetsCompat.Type.navigationBars()
| WindowInsetsCompat.Type.displayCutout();
Insets insets = (wic != null) ? wic.getInsetsIgnoringVisibility(types) : Insets.NONE;

HashMap<String, Integer> insetMap = new HashMap<>(4);
insetMap.put("top", insets.top + binding.toolbar.getHeight());
insetMap.put("right", insets.right);
insetMap.put("bottom", insets.bottom);
insetMap.put("left", insets.left);

return new JSONObject(insetMap).toString();
}
}

private void showWebViewCrashed() {
Expand All @@ -279,11 +301,19 @@ private void showWebViewCrashed() {
@SuppressLint({"SetJavaScriptEnabled"})
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
WindowCompat.enableEdgeToEdge(getWindow());

binding = PdfviewerBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);

ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), (v, insets) -> {
if (mUri != null) {
binding.webview.evaluateJavascript("updateInsets()", null);
}
return insets;
});

viewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(PdfViewModel.class);

viewModel.getOutline().observe(this, requested -> {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/res/layout/pdfviewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -18,12 +23,6 @@

</com.google.android.material.appbar.AppBarLayout>

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<ScrollView
android:id="@+id/webview_alert_layout"
android:layout_width="match_parent"
Expand Down
98 changes: 50 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"@stylistic/eslint-plugin": "^5.4.0",
"esbuild": "^0.25.10",
"eslint": "^9.37.0",
"pdfjs-dist": "^5.4.149"
"pdfjs-dist": "^5.4.296"
}
}
Loading