Add fullscreen mode in PDF Viewer

This commit is contained in:
Naveen 2022-06-03 22:23:26 +05:30
parent 72500d1478
commit c7c96d2faa
2 changed files with 90 additions and 2 deletions

View File

@ -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<RelativeLayout.LayoutParams> {
// hack to workaround pdf viewer height glitch
this.height = pdf_viewer_wrapper.height + statusBarHeight + actionBarHeight
}
}
private fun exitFullScreen() {
showSystemUI(true)
pdf_viewer.updateLayoutParams<RelativeLayout.LayoutParams> {
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)
}
}
}

View File

@ -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<String>) {
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)