From e4a787b85b8fc3ada19a3b491bd8b02789f61052 Mon Sep 17 00:00:00 2001 From: Pratyush Date: Thu, 12 May 2022 16:53:55 +0530 Subject: [PATCH] replace deprecated api uses --- .../app/grapheneos/pdfviewer/PdfViewer.java | 17 ++++------------- .../java/app/grapheneos/pdfviewer/ktx/View.kt | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt diff --git a/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java index e2d95629f..15b349313 100644 --- a/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java @@ -44,6 +44,7 @@ import app.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment; import app.grapheneos.pdfviewer.fragment.PasswordPromptFragment; import app.grapheneos.pdfviewer.fragment.JumpToPageFragment; +import app.grapheneos.pdfviewer.ktx.ViewKt; import app.grapheneos.pdfviewer.loader.DocumentPropertiesLoader; import app.grapheneos.pdfviewer.viewModel.PasswordStatus; @@ -331,8 +332,7 @@ public boolean onTapUp() { if (mUri != null) { binding.webview.evaluateJavascript("isTextSelected()", selection -> { if (!Boolean.parseBoolean(selection)) { - if ((getWindow().getDecorView().getSystemUiVisibility() & - View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { + if (getSupportActionBar().isShowing()) { hideSystemUi(); } else { showSystemUi(); @@ -569,21 +569,12 @@ public void onJumpToPageInDocument(final int selected_page) { } private void showSystemUi() { - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + ViewKt.showSystemUi(binding.getRoot()); getSupportActionBar().show(); } private void hideSystemUi() { - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | - View.SYSTEM_UI_FLAG_FULLSCREEN | - View.SYSTEM_UI_FLAG_IMMERSIVE); + ViewKt.hideSystemUi(binding.getRoot()); getSupportActionBar().hide(); } diff --git a/app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt b/app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt new file mode 100644 index 000000000..435e78ee5 --- /dev/null +++ b/app/src/main/java/app/grapheneos/pdfviewer/ktx/View.kt @@ -0,0 +1,19 @@ +package app.grapheneos.pdfviewer.ktx + +import android.view.View +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat + +private val systemBars = WindowInsetsCompat.Type.statusBars() + +fun View.hideSystemUi() { + val controller = ViewCompat.getWindowInsetsController(this) ?: return + controller.systemBarsBehavior = + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + controller.hide(systemBars) +} + +fun View.showSystemUi() { + ViewCompat.getWindowInsetsController(this)?.show(systemBars) +}