From 6dc86a0668757091f7cafb69a131011a930fe059 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Sat, 3 May 2025 19:52:51 +0800 Subject: [PATCH] =?UTF-8?q?6.6.3=20-=20Alpha2=20-=20=E4=BF=AE=E5=A4=8D=20A?= =?UTF-8?q?ndroid=2015=20=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A0=8F=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=97=A0=E6=B3=95=E5=8A=A8=E6=80=81=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E8=89=B2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 1 + .../java/org/autojs/autojs/util/ViewUtils.kt | 70 ++++++++++++++----- version.properties | 6 +- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 20055160..c12d24df 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -13,6 +13,7 @@ "主题色设置页面调色盘对话框可能无限叠加的问题", "无障碍服务关闭时音量加键停止所有脚本功能失效的问题", "APK 文件类型信息对话框可能无法获取应用名称及 SDK 信息的问题", + "Android 15 部分页面状态栏背景颜色可能无法动态跟随主题色的问题", "dialogs 模块无法正常使用 customView 属性的问题 _[`issue #364`](http://issues.autojs6.com/364)_", "console.setContentTextColor 方法导致日志字体颜色丢失默认值的问题 _[`issue #346`](http://issues.autojs6.com/346)_", "README.md 中部分语言日期格式不正确的问题" diff --git a/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt b/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt index 32564bde..dc77721e 100644 --- a/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt @@ -31,6 +31,7 @@ import android.widget.EditText import android.widget.FrameLayout import android.widget.ImageView import android.widget.Toast +import androidx.annotation.ColorInt import androidx.annotation.IdRes import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity @@ -66,6 +67,8 @@ object ViewUtils { ; } + private const val TAG_STATUS_BAR_SCRIM = "status_bar_scrim" + @JvmStatic var isKeepScreenOnWhenInForegroundEnabled get() = Pref.getBoolean(R.string.key_keep_screen_on_when_in_foreground_enabled, false) @@ -234,28 +237,61 @@ object ViewUtils { } @JvmStatic - fun setStatusBarBackgroundColor(activity: Activity, color: Int) { + fun setStatusBarBackgroundColor(activity: Activity, @ColorInt color: Int) { val window = activity.window - val decorView = window.decorView + val decorView = window.decorView as ViewGroup - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { - decorView.setOnApplyWindowInsetsListener { view, insets -> - val statusBarInsets = insets.getInsets(WindowInsets.Type.statusBars()) - val contentView: ViewGroup? = activity.findViewById(android.R.id.content) - val statusBarOverlay = View(activity).apply { - layoutParams = FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - statusBarInsets.top, // 状态栏高度 - ) - setBackgroundColor(color) - } - contentView?.addView(statusBarOverlay) - view.onApplyWindowInsets(insets) - } - } else { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) { @Suppress("DEPRECATION") window.statusBarColor = color + return } + + // @Hint by JetBrains AI Assistant on May 3, 2025. + // ! `View.setOnApplyWindowInsetsListener { ... }` is invoked repeatedly only in these cases: + // ! - The root view explicitly calls `requestApplyInsets()` + // ! - A configuration change occurs (rotation, navigation-mode switch, etc.) + // ! - WindowInsets change dynamically (IME/keyboard, gesture bar showing or hiding) + // ! Hence, only the first WindowInsets dispatch that happens during Activity startup + // ! actually paints the correct status-bar color. Subsequent calls to + // ! `setStatusBarBackgroundColor()` merely cache the new color but do NOT trigger + // ! another inset callback, so the visual change on the status bar is never observed. + // ! + // ! zh-CN: + // ! + // ! `View.setOnApplyWindowInsetsListener { ... }` 只在下列场景被重复触发: + // ! - 根视图调用 `requestApplyInsets()` + // ! - Configuration 变化 (旋转, 手势导航显示方式切换等) + // ! - WindowInsets 动态变化 (键盘, 手势指示条出现或隐藏) + // ! 因此, 仅在 Activity 启动时触发的一次 WindowInsets 分发可以正确设置背景色, + // ! 之后重复调用 `setStatusBarBackgroundColor()`, 代码只是把新颜色暂存, + // ! 并不会重新触发 Inset 回调, 导致无法观测到状态栏的颜色变化. + // ! + // # decorView.setOnApplyWindowInsetsListener { view, insets -> + // # val statusBarInsets = insets.getInsets(WindowInsets.Type.statusBars()) + // # val contentView: ViewGroup? = activity.findViewById(android.R.id.content) + // # val statusBarOverlay = View(activity).apply { + // # layoutParams = FrameLayout.LayoutParams( + // # FrameLayout.LayoutParams.MATCH_PARENT, + // # statusBarInsets.top, // 状态栏高度 + // # ) + // # setBackgroundColor(color) + // # } + // # contentView?.addView(statusBarOverlay) + // # view.onApplyWindowInsets(insets) + // # } + + val scrim = decorView.findViewWithTag(TAG_STATUS_BAR_SCRIM) ?: run { + View(activity).apply { + tag = TAG_STATUS_BAR_SCRIM + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + getStatusBarHeightByWindow(activity) + ) + decorView.addView(this) + } + } + scrim.setBackgroundColor(color) } @RequiresApi(Build.VERSION_CODES.O) diff --git a/version.properties b/version.properties index e861ed6c..e26a334b 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Sat May 03 18:25:45 CST 2025 -BUILD_TIME=1746267945206 +#Sat May 03 18:51:31 CST 2025 +BUILD_TIME=1746269491585 COMPILE_SDK_VERSION=35 JAVA_VERSION=23 JAVA_VERSION_MIN_RADICAL=0 @@ -18,5 +18,5 @@ RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 TARGET_SDK_VERSION=35 TARGET_SDK_VERSION_INRT=29 VERSION_BUILD=3185 -VERSION_NAME=6.6.3 Alpha +VERSION_NAME=6.6.3 Alpha2 VSCODE_EXT_REQUIRED_VERSION=1.0.8