11package com.simplemobiletools.filemanager.pro.activities
22
33import android.content.Context
4+ import android.graphics.Color
5+ import android.graphics.drawable.ColorDrawable
46import android.os.Bundle
57import android.print.PrintAttributes
68import android.print.PrintManager
79import android.view.Menu
810import android.view.MenuItem
11+ import android.view.WindowInsetsController
12+ import android.view.WindowManager
913import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1014import com.simplemobiletools.commons.extensions.*
1115import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
16+ import com.simplemobiletools.commons.helpers.isPiePlus
17+ import com.simplemobiletools.commons.helpers.isRPlus
1218import com.simplemobiletools.filemanager.pro.R
19+ import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
20+ import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
1321import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
1422import kotlinx.android.synthetic.main.activity_pdf_viewer.*
1523
1624class PDFViewerActivity : SimpleActivity () {
17- var realFilePath = " "
25+ private var realFilePath = " "
26+ private var isFullScreen = false
1827
1928 override fun onCreate (savedInstanceState : Bundle ? ) {
29+ useDynamicTheme = false
30+
2031 super .onCreate(savedInstanceState)
2132 setContentView(R .layout.activity_pdf_viewer)
2233
2334 if (checkAppSideloading()) {
2435 return
2536 }
2637
38+ window.decorView.setBackgroundColor(getProperBackgroundColor())
39+ top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
40+ checkNotchSupport()
41+
2742 if (intent.extras?.containsKey(REAL_FILE_PATH ) == true ) {
2843 realFilePath = intent.extras?.get(REAL_FILE_PATH )?.toString() ? : " "
2944 }
3045
3146 checkIntent()
47+ if (isRPlus()) {
48+ window.insetsController?.setSystemBarsAppearance(0 , WindowInsetsController .APPEARANCE_LIGHT_STATUS_BARS )
49+ }
50+ }
51+
52+ override fun onResume () {
53+ super .onResume()
54+ supportActionBar?.setBackgroundDrawable(ColorDrawable (Color .TRANSPARENT ))
55+ window.statusBarColor = Color .TRANSPARENT
56+ setTranslucentNavigation()
3257 }
3358
3459 override fun onCreateOptionsMenu (menu : Menu ): Boolean {
@@ -37,7 +62,7 @@ class PDFViewerActivity : SimpleActivity() {
3762 findItem(R .id.menu_print).isVisible = realFilePath.isNotEmpty()
3863 }
3964
40- updateMenuItemColors(menu)
65+ updateMenuItemColors(menu, forceWhiteIcons = true )
4166 return true
4267 }
4368
@@ -56,17 +81,22 @@ class PDFViewerActivity : SimpleActivity() {
5681 return
5782 }
5883
59- val filename = getFilenameFromUri(uri)
60- if (filename.isNotEmpty()) {
61- title = filename
62- }
63-
6484 val primaryColor = getProperPrimaryColor()
6585 pdf_viewer.setBackgroundColor(getProperBackgroundColor())
6686 pdf_viewer.fromUri(uri)
6787 .scrollHandle(DefaultScrollHandle (this , primaryColor.getContrastColor(), primaryColor))
6888 .spacing(15 )
89+ .onTap { toggleFullScreen() }
6990 .load()
91+
92+ showSystemUI(true )
93+
94+ pdf_viewer_wrapper.onGlobalLayout {
95+ val filename = getFilenameFromUri(uri)
96+ if (filename.isNotEmpty()) {
97+ supportActionBar?.title = filename
98+ }
99+ }
70100 }
71101
72102 private fun printText () {
@@ -76,4 +106,28 @@ class PDFViewerActivity : SimpleActivity() {
76106 print (realFilePath.getFilenameFromPath(), adapter, PrintAttributes .Builder ().build())
77107 }
78108 }
109+
110+ private fun toggleFullScreen (): Boolean {
111+ isFullScreen = ! isFullScreen
112+ val newAlpha: Float
113+ if (isFullScreen) {
114+ newAlpha = 0f
115+ hideSystemUI(true )
116+ } else {
117+ newAlpha = 1f
118+ showSystemUI(true )
119+ }
120+
121+ top_shadow.animate().alpha(newAlpha).start()
122+
123+ // return false to also toggle scroll handle
124+ return true
125+ }
126+
127+ private fun checkNotchSupport () {
128+ if (isPiePlus()) {
129+ window.attributes.layoutInDisplayCutoutMode = WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
130+ window.addFlags(WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS )
131+ }
132+ }
79133}
0 commit comments