diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt index c2571d58..79656bb5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt @@ -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) + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt index 6dd00a83..11ae2436 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Activity.kt @@ -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) { 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) diff --git a/app/src/main/res/drawable/gradient_background_flipped.xml b/app/src/main/res/drawable/gradient_background_flipped.xml new file mode 100644 index 00000000..e8481212 --- /dev/null +++ b/app/src/main/res/drawable/gradient_background_flipped.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/layout/activity_pdf_viewer.xml b/app/src/main/res/layout/activity_pdf_viewer.xml index f6d0d427..ec6fffb1 100644 --- a/app/src/main/res/layout/activity_pdf_viewer.xml +++ b/app/src/main/res/layout/activity_pdf_viewer.xml @@ -9,4 +9,11 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index fc0c4d8a..0f28f618 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,5 @@ 50dp 46sp + 86dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0be50415..9c3b80f3 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,5 +1,5 @@ -