6.6.2 - Alpha4 - 文档页面支持透明或半透明导航栏视觉效果
This commit is contained in:
@@ -5,28 +5,38 @@ import android.os.Bundle
|
||||
import android.webkit.WebView
|
||||
import org.autojs.autojs.ui.BaseActivity
|
||||
import org.autojs.autojs.util.DocsUtils.getUrl
|
||||
import org.autojs.autojs.util.WebViewUtils
|
||||
import org.autojs.autojs6.databinding.ActivityDocumentationBinding
|
||||
|
||||
/**
|
||||
* Created by Stardust on Oct 24, 2017.
|
||||
* Modified by SuperMonster003 as of May 26, 2022.
|
||||
* Transformed by SuperMonster003 on May 26, 2023.
|
||||
*/
|
||||
class DocumentationActivity : BaseActivity() {
|
||||
|
||||
private var binding: ActivityDocumentationBinding? = null
|
||||
override val handleStatusBarThemeColorAutomatically = false
|
||||
|
||||
private lateinit var mWebView: WebView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityDocumentationBinding.inflate(layoutInflater)
|
||||
setContentView(binding!!.root)
|
||||
setupViews()
|
||||
ActivityDocumentationBinding.inflate(layoutInflater).also { binding ->
|
||||
setContentView(binding.root)
|
||||
binding.ewebView.also { ewebView ->
|
||||
ewebView.webView.also { webView ->
|
||||
mWebView = webView
|
||||
WebViewUtils.adaptDarkMode(this@DocumentationActivity, webView)
|
||||
WebViewUtils.excludeWebViewFromStatusBarAndNavigationBar(ewebView)
|
||||
webView.loadUrl(intent.getStringExtra(EXTRA_URL) ?: getUrl("index.html"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupViews() {
|
||||
mWebView = binding!!.ewebView.webView.also {
|
||||
it.loadUrl(intent.getStringExtra(EXTRA_URL) ?: getUrl("index.html"))
|
||||
}
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingSuperCall")
|
||||
@@ -35,16 +45,10 @@ class DocumentationActivity : BaseActivity() {
|
||||
if (mWebView.canGoBack()) {
|
||||
mWebView.goBack()
|
||||
} else {
|
||||
// super.onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
const val EXTRA_URL = "url"
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import org.autojs.autojs.event.BackPressedHandler
|
||||
@@ -12,10 +13,8 @@ import org.autojs.autojs.ui.main.MainActivity
|
||||
import org.autojs.autojs.ui.main.QueryEvent
|
||||
import org.autojs.autojs.ui.main.ViewPagerFragment
|
||||
import org.autojs.autojs.ui.main.ViewStatesManageable
|
||||
import org.autojs.autojs.ui.widget.NestedWebView
|
||||
import org.autojs.autojs.util.DocsUtils.getUrl
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs.util.WebViewUtils.Companion.adaptDarkMode
|
||||
import org.autojs.autojs.util.WebViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.FragmentOnlineDocsBinding
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
@@ -29,12 +28,13 @@ import org.greenrobot.eventbus.Subscribe
|
||||
open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressedHandler, ViewStatesManageable {
|
||||
|
||||
private var binding: FragmentOnlineDocsBinding? = null
|
||||
private var webView: NestedWebView? = null
|
||||
|
||||
private var mIndexUrl: String? = null
|
||||
private var mPreviousQuery: String? = null
|
||||
private var mIsCurrentPageDocs = false
|
||||
|
||||
private lateinit var mWebView: WebView
|
||||
|
||||
init {
|
||||
arguments = Bundle()
|
||||
}
|
||||
@@ -50,9 +50,12 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
webView = binding!!.ewebView.webView.also {
|
||||
adaptDarkMode(requireContext(), it)
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it)
|
||||
binding!!.ewebView.also { ewebView ->
|
||||
ewebView.webView.also { webView ->
|
||||
mWebView = webView
|
||||
WebViewUtils.adaptDarkMode(requireContext(), webView)
|
||||
WebViewUtils.excludeWebViewFromNavigationBar(ewebView)
|
||||
}
|
||||
}
|
||||
restoreViewStates()
|
||||
(activity as? MainActivity)?.apply {
|
||||
@@ -64,7 +67,7 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
|
||||
private fun loadMainPage() {
|
||||
arguments?.let { mIndexUrl = it.getString(ARGUMENT_URL, getUrl("index.html")) }
|
||||
mIndexUrl?.let { webView?.loadUrl(it) }
|
||||
mIndexUrl?.let { mWebView.loadUrl(it) }
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@@ -73,8 +76,8 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
}
|
||||
|
||||
override fun onBackPressed(activity: Activity): Boolean {
|
||||
webView.let {
|
||||
if (it?.canGoBack() == true) {
|
||||
mWebView.let {
|
||||
if (it.canGoBack()) {
|
||||
it.goBack()
|
||||
return true
|
||||
}
|
||||
@@ -88,13 +91,13 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
fun onQuerySummit(event: QueryEvent) = when {
|
||||
!isShown -> {}
|
||||
event === QueryEvent.CLEAR -> {
|
||||
webView?.clearMatches()
|
||||
mWebView.clearMatches()
|
||||
mPreviousQuery = null
|
||||
}
|
||||
event.isFindForward -> webView?.findNext(false)
|
||||
event.query == mPreviousQuery -> webView?.findNext(true)
|
||||
event.isFindForward -> mWebView.findNext(false)
|
||||
event.query == mPreviousQuery -> mWebView.findNext(true)
|
||||
else -> {
|
||||
webView?.findAllAsync(event.query)
|
||||
mWebView.findAllAsync(event.query)
|
||||
mPreviousQuery = event.query
|
||||
}
|
||||
}
|
||||
@@ -107,7 +110,6 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
webView = null
|
||||
}
|
||||
|
||||
override fun onPageShow() {
|
||||
@@ -122,17 +124,17 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
|
||||
override fun saveViewStates() {
|
||||
Bundle().let {
|
||||
webView?.saveState(it)
|
||||
mWebView.saveState(it)
|
||||
arguments?.putBundle("savedWebViewState", it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun restoreViewStates() {
|
||||
arguments?.getBundle("savedWebViewState")?.let { webView?.restoreState(it) } ?: loadMainPage()
|
||||
arguments?.getBundle("savedWebViewState")?.let { mWebView.restoreState(it) } ?: loadMainPage()
|
||||
}
|
||||
|
||||
private fun setTabViewClickListeners(tabView: TabLayout.TabView) {
|
||||
tabView.setOnClickListener { if (mIsCurrentPageDocs) webView?.scrollTo(0, 0) }
|
||||
tabView.setOnClickListener { if (mIsCurrentPageDocs) mWebView.scrollTo(0, 0) }
|
||||
tabView.setOnLongClickListener { if (mIsCurrentPageDocs) true.also { loadMainPage() } else false }
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,6 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
|
||||
override val handleStatusBarThemeColorAutomatically = false
|
||||
|
||||
private var binding: ActivityMainBinding? = null
|
||||
|
||||
private lateinit var mViewPager: ViewPager
|
||||
private lateinit var mFab: ThemeColorFloatingActionButton
|
||||
private lateinit var mTab: TabLayout
|
||||
@@ -135,7 +133,6 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
|
||||
ActivityMainBinding.inflate(layoutInflater).also {
|
||||
val drawerLayout = it.drawerLayout
|
||||
binding = it
|
||||
setContentView(it.root)
|
||||
mViewPager = it.viewpager
|
||||
mFab = it.fab.apply { ViewUtils.excludeFloatingActionButtonFromNavigationBar(this) }
|
||||
@@ -235,7 +232,7 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
.apply {
|
||||
setOnFragmentInstantiateListener { pos: Int, fragment: Fragment ->
|
||||
val viewPagerFragment = fragment as ViewPagerFragment
|
||||
viewPagerFragment.setFab(mFab)
|
||||
viewPagerFragment.fab = mFab
|
||||
if (pos == mViewPager.currentItem) {
|
||||
viewPagerFragment.onPageShow()
|
||||
}
|
||||
@@ -299,21 +296,15 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
}
|
||||
|
||||
private fun setUpStatusBarIconLight() {
|
||||
if (shouldChangeStatusBarIconLight()) {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (sIsActionBarDrawerOpened) {
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
} else {
|
||||
setUpStatusBarIconLightByThemeColor()
|
||||
}
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
if (sIsActionBarDrawerOpened) {
|
||||
setUpStatusBarIconLightByNightMode()
|
||||
} else {
|
||||
setUpStatusBarIconLightByThemeColor()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldChangeStatusBarIconLight(): Boolean {
|
||||
return ViewUtils.isNightModeEnabled == ViewUtils.isStatusBarIconDark(this)
|
||||
}
|
||||
|
||||
fun rebirth() {
|
||||
packageManager.getLaunchIntentForPackage(packageName)?.let {
|
||||
startActivity(Intent.makeRestartActivityTask(it.component))
|
||||
@@ -364,7 +355,6 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
override fun getOnActivityResultDelegateMediator() = mActivityResultMediator
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("DEPRECATION")
|
||||
override fun onBackPressed() {
|
||||
val fragment = mPagerAdapter.getStoredFragment(mViewPager.currentItem)
|
||||
if ((fragment as? BackPressedHandler)?.onBackPressed(this) == true) {
|
||||
@@ -457,7 +447,6 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
mSearchViewItem = null
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,20 @@ import android.content.Context
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import android.os.Build.VERSION_CODES.TIRAMISU
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.webkit.WebSettingsCompat
|
||||
import androidx.webkit.WebViewFeature.ALGORITHMIC_DARKENING
|
||||
import androidx.webkit.WebViewFeature.FORCE_DARK
|
||||
import androidx.webkit.WebViewFeature.isFeatureSupported
|
||||
import org.autojs.autojs.ui.widget.EWebView
|
||||
import org.intellij.lang.annotations.Language
|
||||
|
||||
/**
|
||||
* Created by SuperMonster003 on Aug 26, 2022.
|
||||
* Modified by SuperMonster003 as of Mar 12, 2025.
|
||||
*/
|
||||
class WebViewUtils {
|
||||
|
||||
companion object {
|
||||
@@ -47,6 +56,48 @@ class WebViewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun excludeWebViewFromNavigationBar(ewebView: EWebView) {
|
||||
excludeWebViewFromSystemBars(ewebView, excludeStatusBar = false, excludeNavigationBar = true)
|
||||
}
|
||||
|
||||
fun excludeWebViewFromStatusBarAndNavigationBar(ewebView: EWebView) {
|
||||
excludeWebViewFromSystemBars(ewebView, excludeStatusBar = true, excludeNavigationBar = true)
|
||||
}
|
||||
|
||||
@Suppress("SameParameterValue")
|
||||
private fun excludeWebViewFromSystemBars(ewebView: EWebView, excludeStatusBar: Boolean, excludeNavigationBar: Boolean) {
|
||||
val webView = ewebView.webView
|
||||
var mSystemBarInsets: Insets? = null
|
||||
ewebView.setOnApplyWindowInsetsListener { v, insets ->
|
||||
@Suppress("DEPRECATION")
|
||||
val systemBarInsets = WindowInsetsCompat.toWindowInsetsCompat(insets).systemWindowInsets.also {
|
||||
mSystemBarInsets = it
|
||||
}
|
||||
if (excludeStatusBar) {
|
||||
v.setPadding(0, systemBarInsets.top, 0, 0)
|
||||
}
|
||||
if (excludeNavigationBar) {
|
||||
webView.setPadding(0, 0, 0, systemBarInsets.bottom)
|
||||
}
|
||||
insets
|
||||
}
|
||||
if (excludeNavigationBar) {
|
||||
webView.webViewClient = object : WebViewClient() {
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
super.onPageFinished(view, url)
|
||||
val systemBarInsets = mSystemBarInsets ?: return
|
||||
// @Hint by SuperMonster003 on Mar 12, 2025.
|
||||
// ! Inject JavaScript code for document body with adding a bottom padding
|
||||
// ! to ensure that content won't be covered by nav bar when scrolling to the end.
|
||||
// ! zh-CN: 注入 JavaScript, 为 body 添加底部 padding, 确保滚动到底部时导航栏不遮挡内容.
|
||||
@Language("JavaScript")
|
||||
val jsCode = """document.body.style.paddingBottom = "${systemBarInsets.bottom}px";"""
|
||||
webView.evaluateJavascript(jsCode, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!--<com.google.android.material.appbar.AppBarLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:theme="@style/AppTheme.AppBarOverlay">-->
|
||||
|
||||
<!-- <org.autojs.autojs.theme.widget.ThemeColorToolbar-->
|
||||
<!-- android:id="@+id/toolbar"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="?attr/actionBarSize"-->
|
||||
<!-- android:theme="@style/ToolBarStyle"-->
|
||||
<!-- android:background="?attr/colorPrimary"-->
|
||||
<!-- app:popupTheme="@style/AppTheme.PopupOverlay" />-->
|
||||
|
||||
<!--</com.google.android.material.appbar.AppBarLayout>-->
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.autojs.autojs.ui.widget.EWebView
|
||||
android:id="@+id/eweb_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:id="@+id/eweb_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
Reference in New Issue
Block a user