Skip to content

Commit b9c3913

Browse files
authored
Merge pull request #592 from Naveen3Singh/fullscreen_toggle
Add fullscreen toggle in PDF Viewer
2 parents fbe32ae + 754a8fa commit b9c3913

File tree

6 files changed

+106
-9
lines changed

6 files changed

+106
-9
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
11
package com.simplemobiletools.filemanager.pro.activities
22

33
import android.content.Context
4+
import android.graphics.Color
5+
import android.graphics.drawable.ColorDrawable
46
import android.os.Bundle
57
import android.print.PrintAttributes
68
import android.print.PrintManager
79
import android.view.Menu
810
import android.view.MenuItem
11+
import android.view.WindowInsetsController
12+
import android.view.WindowManager
913
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1014
import com.simplemobiletools.commons.extensions.*
1115
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
16+
import com.simplemobiletools.commons.helpers.isPiePlus
17+
import com.simplemobiletools.commons.helpers.isRPlus
1218
import com.simplemobiletools.filemanager.pro.R
19+
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
20+
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
1321
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
1422
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
1523

1624
class 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
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ package com.simplemobiletools.filemanager.pro.extensions
22

33
import android.app.Activity
44
import android.content.Intent
5+
import android.content.res.Configuration
56
import android.net.Uri
7+
import android.view.View
8+
import androidx.appcompat.app.AppCompatActivity
69
import androidx.core.content.FileProvider
710
import com.simplemobiletools.commons.activities.BaseSimpleActivity
811
import com.simplemobiletools.commons.extensions.*
912
import com.simplemobiletools.commons.helpers.isNougatPlus
1013
import com.simplemobiletools.filemanager.pro.BuildConfig
1114
import com.simplemobiletools.filemanager.pro.helpers.*
1215
import java.io.File
13-
import java.util.*
1416

1517
fun Activity.sharePaths(paths: ArrayList<String>) {
1618
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
@@ -77,3 +79,29 @@ fun BaseSimpleActivity.toggleItemVisibility(oldPath: String, hide: Boolean, call
7779
}
7880
}
7981
}
82+
83+
fun AppCompatActivity.showSystemUI(toggleActionBarVisibility: Boolean) {
84+
if (toggleActionBarVisibility) {
85+
supportActionBar?.show()
86+
}
87+
88+
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
89+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
90+
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
91+
}
92+
93+
fun AppCompatActivity.hideSystemUI(toggleActionBarVisibility: Boolean) {
94+
if (toggleActionBarVisibility) {
95+
supportActionBar?.hide()
96+
}
97+
98+
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
99+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
100+
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
101+
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
102+
View.SYSTEM_UI_FLAG_LOW_PROFILE or
103+
View.SYSTEM_UI_FLAG_FULLSCREEN or
104+
View.SYSTEM_UI_FLAG_IMMERSIVE
105+
}
106+
107+
fun Activity.getUiMode() = resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<gradient
4+
android:angle="270"
5+
android:endColor="@android:color/transparent"
6+
android:startColor="@color/gradient_grey_start"/>
7+
</shape>

app/src/main/res/layout/activity_pdf_viewer.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent" />
1111

12+
<ImageView
13+
android:id="@+id/top_shadow"
14+
android:layout_width="match_parent"
15+
android:layout_height="@dimen/default_status_action_height"
16+
android:background="@drawable/gradient_background_flipped"
17+
android:contentDescription="@null" />
18+
1219
</RelativeLayout>

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<dimen name="grid_view_icon_size">50dp</dimen>
33
<dimen name="storage_free_space_text_size">46sp</dimen>
4+
<dimen name="default_status_action_height">86dp</dimen>
45
</resources>

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
22

3-
<style name="AppTheme" parent="AppTheme.Base"/>
3+
<style name="AppTheme" parent="AppTheme.Base" />
44

55
</resources>

0 commit comments

Comments
 (0)