From c7c96d2faae82a1f54793f367aac72fe5325cd97 Mon Sep 17 00:00:00 2001 From: Naveen Date: Fri, 3 Jun 2022 22:23:26 +0530 Subject: [PATCH] Add fullscreen mode in PDF Viewer --- .../pro/activities/PDFViewerActivity.kt | 63 ++++++++++++++++++- .../filemanager/pro/extensions/Activity.kt | 29 ++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt index c2571d58..4e79d8d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt @@ -1,20 +1,36 @@ package com.simplemobiletools.filemanager.pro.activities import android.content.Context +import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.os.Bundle import android.print.PrintAttributes import android.print.PrintManager import android.view.Menu import android.view.MenuItem +import android.view.View +import android.view.WindowManager +import android.widget.RelativeLayout +import androidx.core.view.updateLayoutParams import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.REAL_FILE_PATH +import com.simplemobiletools.commons.helpers.isPiePlus +import com.simplemobiletools.commons.helpers.isSPlus import com.simplemobiletools.filemanager.pro.R +import com.simplemobiletools.filemanager.pro.extensions.config +import com.simplemobiletools.filemanager.pro.extensions.getUiMode +import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI +import com.simplemobiletools.filemanager.pro.extensions.showSystemUI import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter import kotlinx.android.synthetic.main.activity_pdf_viewer.* + class PDFViewerActivity : SimpleActivity() { - var realFilePath = "" + private var realFilePath = "" + + private var systemUiVisible = true + private var pdfViewerHeight = -1 + private var positionOffset = 0f override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -29,6 +45,7 @@ class PDFViewerActivity : SimpleActivity() { } checkIntent() + setupFullScreenView() } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -76,4 +93,48 @@ class PDFViewerActivity : SimpleActivity() { print(realFilePath.getFilenameFromPath(), adapter, PrintAttributes.Builder().build()) } } + + private fun setupFullScreenView() { + pdf_viewer.setOnClickListener { + if (systemUiVisible) enterFullScreen() else exitFullScreen() + systemUiVisible = !systemUiVisible + } + setupNotch() + } + + private fun enterFullScreen() { + if (pdfViewerHeight == -1) { + pdfViewerHeight = pdf_viewer.height + } + positionOffset = pdf_viewer.positionOffset + hideSystemUI(true) + + pdf_viewer.updateLayoutParams { + // hack to workaround pdf viewer height glitch + this.height = pdf_viewer_wrapper.height + statusBarHeight + actionBarHeight + } + } + + private fun exitFullScreen() { + showSystemUI(true) + pdf_viewer.updateLayoutParams { + this.height = pdfViewerHeight + } + pdf_viewer.post { pdf_viewer.positionOffset = positionOffset } + + @Suppress("DEPRECATION") + // use light status bar on material you + if (isSPlus() && config.isUsingSystemTheme && getUiMode() == UI_MODE_NIGHT_NO) { + val flags = window.decorView.systemUiVisibility + window.decorView.systemUiVisibility = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + } + } + + + private fun setupNotch() { + if (isPiePlus()) { + window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt index 6dd00a83..50d6ff0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt @@ -2,7 +2,10 @@ package com.simplemobiletools.filemanager.pro.extensions import android.app.Activity import android.content.Intent +import android.content.res.Configuration import android.net.Uri +import android.view.View +import androidx.appcompat.app.AppCompatActivity import androidx.core.content.FileProvider import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* @@ -10,7 +13,6 @@ import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.filemanager.pro.BuildConfig import com.simplemobiletools.filemanager.pro.helpers.* import java.io.File -import java.util.* fun Activity.sharePaths(paths: ArrayList) { sharePathsIntent(paths, BuildConfig.APPLICATION_ID) @@ -77,3 +79,28 @@ fun BaseSimpleActivity.toggleItemVisibility(oldPath: String, hide: Boolean, call } } } + +@Suppress("DEPRECATION") +fun AppCompatActivity.showSystemUI(toggleActionBarVisibility: Boolean) { + if (toggleActionBarVisibility) { + supportActionBar?.show() + } + window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE +} + +@Suppress("DEPRECATION") +fun AppCompatActivity.hideSystemUI(toggleActionBarVisibility: Boolean) { + if (toggleActionBarVisibility) { + supportActionBar?.hide() + } + + window.decorView.systemUiVisibility = + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or + View.SYSTEM_UI_FLAG_LOW_PROFILE or + View.SYSTEM_UI_FLAG_FULLSCREEN or + View.SYSTEM_UI_FLAG_IMMERSIVE +} + +fun Activity.getUiMode() = resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)