Merge pull request #592 from Naveen3Singh/fullscreen_toggle
Add fullscreen toggle in PDF Viewer
This commit is contained in:
commit
b9c3913949
|
@ -1,22 +1,33 @@
|
|||
package com.simplemobiletools.filemanager.pro.activities
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.print.PrintAttributes
|
||||
import android.print.PrintManager
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowInsetsController
|
||||
import android.view.WindowManager
|
||||
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.isRPlus
|
||||
import com.simplemobiletools.filemanager.pro.R
|
||||
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 isFullScreen = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
useDynamicTheme = false
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pdf_viewer)
|
||||
|
||||
|
@ -24,11 +35,25 @@ class PDFViewerActivity : SimpleActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
window.decorView.setBackgroundColor(getProperBackgroundColor())
|
||||
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
|
||||
checkNotchSupport()
|
||||
|
||||
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
||||
realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: ""
|
||||
}
|
||||
|
||||
checkIntent()
|
||||
if (isRPlus()) {
|
||||
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
window.statusBarColor = Color.TRANSPARENT
|
||||
setTranslucentNavigation()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
|
@ -37,7 +62,7 @@ class PDFViewerActivity : SimpleActivity() {
|
|||
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
|
||||
}
|
||||
|
||||
updateMenuItemColors(menu)
|
||||
updateMenuItemColors(menu, forceWhiteIcons = true)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -56,17 +81,22 @@ class PDFViewerActivity : SimpleActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
val filename = getFilenameFromUri(uri)
|
||||
if (filename.isNotEmpty()) {
|
||||
title = filename
|
||||
}
|
||||
|
||||
val primaryColor = getProperPrimaryColor()
|
||||
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
|
||||
pdf_viewer.fromUri(uri)
|
||||
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
|
||||
.spacing(15)
|
||||
.onTap { toggleFullScreen() }
|
||||
.load()
|
||||
|
||||
showSystemUI(true)
|
||||
|
||||
pdf_viewer_wrapper.onGlobalLayout {
|
||||
val filename = getFilenameFromUri(uri)
|
||||
if (filename.isNotEmpty()) {
|
||||
supportActionBar?.title = filename
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun printText() {
|
||||
|
@ -76,4 +106,28 @@ class PDFViewerActivity : SimpleActivity() {
|
|||
print(realFilePath.getFilenameFromPath(), adapter, PrintAttributes.Builder().build())
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleFullScreen(): Boolean {
|
||||
isFullScreen = !isFullScreen
|
||||
val newAlpha: Float
|
||||
if (isFullScreen) {
|
||||
newAlpha = 0f
|
||||
hideSystemUI(true)
|
||||
} else {
|
||||
newAlpha = 1f
|
||||
showSystemUI(true)
|
||||
}
|
||||
|
||||
top_shadow.animate().alpha(newAlpha).start()
|
||||
|
||||
// return false to also toggle scroll handle
|
||||
return true
|
||||
}
|
||||
|
||||
private fun checkNotchSupport() {
|
||||
if (isPiePlus()) {
|
||||
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,29 @@ fun BaseSimpleActivity.toggleItemVisibility(oldPath: String, hide: Boolean, call
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun AppCompatActivity.showSystemUI(toggleActionBarVisibility: Boolean) {
|
||||
if (toggleActionBarVisibility) {
|
||||
supportActionBar?.show()
|
||||
}
|
||||
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
}
|
||||
|
||||
fun AppCompatActivity.hideSystemUI(toggleActionBarVisibility: Boolean) {
|
||||
if (toggleActionBarVisibility) {
|
||||
supportActionBar?.hide()
|
||||
}
|
||||
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
|
||||
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)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:angle="270"
|
||||
android:endColor="@android:color/transparent"
|
||||
android:startColor="@color/gradient_grey_start"/>
|
||||
</shape>
|
|
@ -9,4 +9,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/top_shadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/default_status_action_height"
|
||||
android:background="@drawable/gradient_background_flipped"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<dimen name="grid_view_icon_size">50dp</dimen>
|
||||
<dimen name="storage_free_space_text_size">46sp</dimen>
|
||||
<dimen name="default_status_action_height">86dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<resources>
|
||||
|
||||
<style name="AppTheme" parent="AppTheme.Base"/>
|
||||
<style name="AppTheme" parent="AppTheme.Base" />
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue