mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
lets actually use a different toolbar at the pdf viewer
This commit is contained in:
@@ -2,15 +2,14 @@ package com.simplemobiletools.filemanager.pro.activities
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.print.PrintAttributes
|
import android.print.PrintAttributes
|
||||||
import android.print.PrintManager
|
import android.print.PrintManager
|
||||||
import android.view.WindowInsetsController
|
import android.view.WindowInsetsController
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.RelativeLayout
|
||||||
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
|
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.NavigationIcon
|
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||||
import com.simplemobiletools.commons.helpers.isRPlus
|
import com.simplemobiletools.commons.helpers.isRPlus
|
||||||
@@ -26,17 +25,15 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
useDynamicTheme = false
|
useDynamicTheme = false
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_pdf_viewer)
|
setContentView(R.layout.activity_pdf_viewer)
|
||||||
setupOptionsMenu()
|
|
||||||
refreshMenuItems()
|
|
||||||
|
|
||||||
if (checkAppSideloading()) {
|
if (checkAppSideloading()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
window.decorView.setBackgroundColor(getProperBackgroundColor())
|
window.decorView.setBackgroundColor(getProperBackgroundColor())
|
||||||
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
|
|
||||||
checkNotchSupport()
|
checkNotchSupport()
|
||||||
|
|
||||||
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
|
||||||
@@ -44,6 +41,7 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
pdf_viewer_toolbar.title = realFilePath.getFilenameFromPath()
|
pdf_viewer_toolbar.title = realFilePath.getFilenameFromPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupMenu()
|
||||||
checkIntent()
|
checkIntent()
|
||||||
if (isRPlus()) {
|
if (isRPlus()) {
|
||||||
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
|
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
|
||||||
@@ -52,26 +50,22 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
|
||||||
window.statusBarColor = Color.TRANSPARENT
|
window.statusBarColor = Color.TRANSPARENT
|
||||||
setTranslucentNavigation()
|
setTranslucentNavigation()
|
||||||
setupToolbar(pdf_viewer_toolbar, NavigationIcon.Arrow)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupMenu() {
|
||||||
pdf_viewer_toolbar.setOnMenuItemClickListener { menuItem ->
|
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
|
||||||
when (menuItem.itemId) {
|
|
||||||
R.id.menu_print -> printText()
|
|
||||||
else -> return@setOnMenuItemClickListener false
|
|
||||||
}
|
|
||||||
return@setOnMenuItemClickListener true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun refreshMenuItems() {
|
|
||||||
pdf_viewer_toolbar.menu.apply {
|
pdf_viewer_toolbar.menu.apply {
|
||||||
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
|
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
|
||||||
|
findItem(R.id.menu_print).setOnMenuItemClickListener {
|
||||||
|
printText()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pdf_viewer_toolbar.setNavigationOnClickListener {
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +116,15 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
top_shadow.animate().alpha(newAlpha).start()
|
top_shadow.animate().alpha(newAlpha).start()
|
||||||
|
pdf_viewer_appbar.animate().alpha(newAlpha).withStartAction {
|
||||||
|
if (newAlpha == 1f) {
|
||||||
|
pdf_viewer_appbar.beVisible()
|
||||||
|
}
|
||||||
|
}.withEndAction {
|
||||||
|
if (newAlpha == 0f) {
|
||||||
|
pdf_viewer_appbar.beGone()
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
|
||||||
// return false to also toggle scroll handle
|
// return false to also toggle scroll handle
|
||||||
return true
|
return true
|
||||||
|
@@ -1,43 +1,39 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/pdf_viewer_coordinator"
|
android:id="@+id/pdf_viewer_wrapper"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
|
<com.github.barteksc.pdfviewer.PDFView
|
||||||
|
android:id="@+id/pdf_viewer"
|
||||||
|
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/top_shadow_height"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="@drawable/gradient_background_flipped"
|
||||||
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/pdf_viewer_app_bar_layout"
|
android:id="@+id/pdf_viewer_appbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:elevation="0dp"
|
||||||
|
app:elevation="0dp">
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
android:id="@+id/pdf_viewer_toolbar"
|
android:id="@+id/pdf_viewer_toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="@color/color_primary"
|
|
||||||
app:menu="@menu/menu_pdf_viewer"
|
app:menu="@menu/menu_pdf_viewer"
|
||||||
app:title="@string/pdf_viewer"
|
app:navigationIcon="@drawable/ic_arrow_left_vector" />
|
||||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
</RelativeLayout>
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/pdf_viewer_wrapper"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
|
||||||
|
|
||||||
<com.github.barteksc.pdfviewer.PDFView
|
|
||||||
android:id="@+id/pdf_viewer"
|
|
||||||
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>
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
||||||
|
Reference in New Issue
Block a user