From 96991b3e95f96c359c7959ec2578aa98d8acf99e Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Wed, 12 Mar 2025 15:38:58 +0800 Subject: [PATCH] =?UTF-8?q?6.6.2=20-=20Alpha4=20-=20=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=94=AF=E6=8C=81=E9=80=8F=E6=98=8E=E6=88=96?= =?UTF-8?q?=E5=8D=8A=E9=80=8F=E6=98=8E=E5=AF=BC=E8=88=AA=E6=A0=8F=E8=A7=86?= =?UTF-8?q?=E8=A7=89=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../autojs/ui/doc/DocumentationActivity.kt | 32 +++++++----- .../autojs/ui/doc/DocumentationFragment.kt | 38 +++++++------- .../org/autojs/autojs/ui/main/MainActivity.kt | 23 +++------ .../org/autojs/autojs/util/WebViewUtils.kt | 51 +++++++++++++++++++ .../res/layout/activity_documentation.xml | 32 +++--------- version.properties | 6 +-- 6 files changed, 106 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationActivity.kt b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationActivity.kt index b1282879..4ae62a2a 100644 --- a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationActivity.kt +++ b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationActivity.kt @@ -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" diff --git a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt index 80dd141a..81f7531e 100644 --- a/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt +++ b/app/src/main/java/org/autojs/autojs/ui/doc/DocumentationFragment.kt @@ -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 } } diff --git a/app/src/main/java/org/autojs/autojs/ui/main/MainActivity.kt b/app/src/main/java/org/autojs/autojs/ui/main/MainActivity.kt index ae061aaf..d1e7048b 100644 --- a/app/src/main/java/org/autojs/autojs/ui/main/MainActivity.kt +++ b/app/src/main/java/org/autojs/autojs/ui/main/MainActivity.kt @@ -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 } diff --git a/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt b/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt index 1dc77ddf..3de1e683 100644 --- a/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/WebViewUtils.kt @@ -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) + } + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_documentation.xml b/app/src/main/res/layout/activity_documentation.xml index d7dd32ba..5be45101 100644 --- a/app/src/main/res/layout/activity_documentation.xml +++ b/app/src/main/res/layout/activity_documentation.xml @@ -1,29 +1,13 @@ - - - - - - - - - - - - - - - - + + android:id="@+id/eweb_view" + android:layout_width="match_parent" + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/version.properties b/version.properties index a59e8073..caa91e23 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Tue Mar 11 20:47:13 CST 2025 -BUILD_TIME=1741697233189 +#Wed Mar 12 14:53:38 CST 2025 +BUILD_TIME=1741762418877 COMPILE_SDK_VERSION=35 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=35 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3014 +VERSION_BUILD=3018 VERSION_NAME=6.6.2 Alpha4 VSCODE_EXT_REQUIRED_VERSION=1.0.8