Skip to content

Commit 6798a1b

Browse files
committed
Add fullscreen toggle in PDF Viewer
1 parent a4b581f commit 6798a1b

File tree

7 files changed

+74
-58
lines changed

7 files changed

+74
-58
lines changed

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

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,62 @@
11
package com.simplemobiletools.filemanager.pro.activities
22

33
import android.content.Context
4-
import android.content.res.Configuration.UI_MODE_NIGHT_NO
4+
import android.graphics.Color
5+
import android.graphics.drawable.ColorDrawable
56
import android.os.Bundle
7+
import android.os.Handler
68
import android.print.PrintAttributes
79
import android.print.PrintManager
810
import android.view.Menu
911
import android.view.MenuItem
10-
import android.view.View
12+
import android.view.WindowInsetsController
1113
import android.view.WindowManager
12-
import android.widget.RelativeLayout
13-
import androidx.core.view.updateLayoutParams
1414
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1515
import com.simplemobiletools.commons.extensions.*
1616
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
1717
import com.simplemobiletools.commons.helpers.isPiePlus
18-
import com.simplemobiletools.commons.helpers.isSPlus
18+
import com.simplemobiletools.commons.helpers.isRPlus
1919
import com.simplemobiletools.filemanager.pro.R
20-
import com.simplemobiletools.filemanager.pro.extensions.config
21-
import com.simplemobiletools.filemanager.pro.extensions.getUiMode
2220
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
2321
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
22+
import com.simplemobiletools.filemanager.pro.helpers.HIDE_SYSTEM_UI_DELAY
2423
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
2524
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
2625

2726

2827
class PDFViewerActivity : SimpleActivity() {
2928
private var realFilePath = ""
30-
3129
private var isFullScreen = false
32-
private var pdfViewerHeight = -1
33-
private var positionOffset = 0f
3430

3531
override fun onCreate(savedInstanceState: Bundle?) {
32+
useDynamicTheme = false
33+
3634
super.onCreate(savedInstanceState)
3735
setContentView(R.layout.activity_pdf_viewer)
3836

3937
if (checkAppSideloading()) {
4038
return
4139
}
4240

41+
window.decorView.setBackgroundColor(getProperBackgroundColor())
42+
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
43+
checkNotchSupport()
44+
4345
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
4446
realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: ""
4547
}
4648

4749
checkIntent()
48-
setupNotch()
50+
if (isRPlus()) {
51+
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
52+
}
53+
}
54+
55+
override fun onResume() {
56+
super.onResume()
57+
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
58+
window.statusBarColor = Color.TRANSPARENT
59+
setTranslucentNavigation()
4960
}
5061

5162
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -54,7 +65,7 @@ class PDFViewerActivity : SimpleActivity() {
5465
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
5566
}
5667

57-
updateMenuItemColors(menu)
68+
updateMenuItemColors(menu, forceWhiteIcons = true)
5869
return true
5970
}
6071

@@ -73,18 +84,26 @@ class PDFViewerActivity : SimpleActivity() {
7384
return
7485
}
7586

76-
val filename = getFilenameFromUri(uri)
77-
if (filename.isNotEmpty()) {
78-
title = filename
79-
}
80-
8187
val primaryColor = getProperPrimaryColor()
8288
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
8389
pdf_viewer.fromUri(uri)
8490
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
8591
.spacing(15)
8692
.onTap { toggleFullScreen() }
8793
.load()
94+
95+
showSystemUI(true)
96+
97+
pdf_viewer_wrapper.onGlobalLayout {
98+
Handler(mainLooper).postDelayed({
99+
toggleFullScreen()
100+
}, HIDE_SYSTEM_UI_DELAY)
101+
102+
val filename = getFilenameFromUri(uri)
103+
if (filename.isNotEmpty()) {
104+
supportActionBar?.title = filename
105+
}
106+
}
88107
}
89108

90109
private fun printText() {
@@ -96,43 +115,23 @@ class PDFViewerActivity : SimpleActivity() {
96115
}
97116

98117
private fun toggleFullScreen(): Boolean {
99-
if (isFullScreen) exitFullScreen() else enterFullScreen()
100118
isFullScreen = !isFullScreen
101-
return true
102-
}
103-
104-
private fun enterFullScreen() {
105-
if (pdfViewerHeight == -1) {
106-
pdfViewerHeight = pdf_viewer.height
119+
val newAlpha: Float
120+
if (isFullScreen) {
121+
newAlpha = 0f
122+
hideSystemUI(true)
123+
} else {
124+
newAlpha = 1f
125+
showSystemUI(true)
107126
}
108-
positionOffset = pdf_viewer.positionOffset
109-
hideSystemUI(true)
110-
111-
pdf_viewer.updateLayoutParams<RelativeLayout.LayoutParams> {
112-
// hack to workaround pdf viewer height glitch
113-
this.height = pdf_viewer_wrapper.height + statusBarHeight + actionBarHeight
114-
}
115-
}
116127

117-
private fun exitFullScreen() {
118-
positionOffset = pdf_viewer.positionOffset
128+
top_shadow.animate().alpha(newAlpha).start()
119129

120-
showSystemUI(true)
121-
pdf_viewer.updateLayoutParams<RelativeLayout.LayoutParams> {
122-
this.height = pdfViewerHeight
123-
}
124-
pdf_viewer.post { pdf_viewer.positionOffset = positionOffset }
125-
126-
@Suppress("DEPRECATION")
127-
// use light status bar on material you
128-
if (isSPlus() && config.isUsingSystemTheme && getUiMode() == UI_MODE_NIGHT_NO) {
129-
val flags = window.decorView.systemUiVisibility
130-
window.decorView.systemUiVisibility = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
131-
}
130+
// return false to also toggle scroll handle
131+
return true
132132
}
133133

134-
135-
private fun setupNotch() {
134+
private fun checkNotchSupport() {
136135
if (isPiePlus()) {
137136
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
138137
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,28 @@ fun BaseSimpleActivity.toggleItemVisibility(oldPath: String, hide: Boolean, call
8080
}
8181
}
8282

83-
@Suppress("DEPRECATION")
8483
fun AppCompatActivity.showSystemUI(toggleActionBarVisibility: Boolean) {
8584
if (toggleActionBarVisibility) {
8685
supportActionBar?.show()
8786
}
88-
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
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
8991
}
9092

91-
@Suppress("DEPRECATION")
9293
fun AppCompatActivity.hideSystemUI(toggleActionBarVisibility: Boolean) {
9394
if (toggleActionBarVisibility) {
9495
supportActionBar?.hide()
9596
}
9697

97-
window.decorView.systemUiVisibility =
98+
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
9899
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
99-
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
100-
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
101-
View.SYSTEM_UI_FLAG_LOW_PROFILE or
102-
View.SYSTEM_UI_FLAG_FULLSCREEN or
103-
View.SYSTEM_UI_FLAG_IMMERSIVE
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
104105
}
105106

106107
fun Activity.getUiMode() = resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS
66

77
const val PATH = "path"
88
const val MAX_COLUMN_COUNT = 20
9+
const val HIDE_SYSTEM_UI_DELAY = 800L
910

1011
// shared preferences
1112
const val SHOW_HIDDEN = "show_hidden"
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)