6.6.2 - Alpha3 - 修复 Android 15 状态栏背景色与主题色不一致的问题
This commit is contained in:
@@ -84,7 +84,7 @@ public class ScreenCaptureRequester extends SimpleActivityLifecycleCallbacks imp
|
||||
// ! 5. 通过 MediaProjection#createVirtualDisplay 调用启动媒体投影的屏幕捕获会话
|
||||
// ! 总结就是, 要保证: 先授权, 再启动服务, 再录屏的顺序.
|
||||
// !
|
||||
// ! 原代码在 ScreenCaptureRequesterImpl#requst 中 startService 会有时序问题, 此时用户还没授权完成时, Android 14+ 启动前台服务实测会崩溃.
|
||||
// ! 原代码在 ScreenCaptureRequesterImpl#requst 中 startService 会有时序问题, 此时用户还没授权完成时, Android 14 启动前台服务实测会崩溃.
|
||||
// ! 改成 bindService 并等待 onServiceConnected 回调.
|
||||
// !
|
||||
// ! en-US (translated by JetBrains AI Assistant on Jul 28, 2024):
|
||||
@@ -99,7 +99,7 @@ public class ScreenCaptureRequester extends SimpleActivityLifecycleCallbacks imp
|
||||
// ! In summary, ensure the sequence: authorize first, then start the service, and finally start the screen recording.
|
||||
// !
|
||||
// ! The original code in ScreenCaptureRequesterImpl#request's startService may have timing issues,
|
||||
// ! if the user has not yet completed authorization, starting the foreground service on Android 14+ will crash.
|
||||
// ! if the user has not yet completed authorization, starting the foreground service on Android 14 will crash.
|
||||
// ! Change it to bindService and wait for the onServiceConnected callback.
|
||||
if (requestCode == REQUEST_CODE_MEDIA_PROJECTION) {
|
||||
Context applicationContext = getApplication().getApplicationContext();
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.graphics.Paint
|
||||
import android.view.View
|
||||
import org.autojs.autojs.util.ColorUtils
|
||||
import org.autojs.autojs.util.ViewUtils
|
||||
import org.autojs.autojs6.R
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
@@ -47,7 +48,7 @@ object ThemeColorManager {
|
||||
ThemeColorWidgetReferenceManager.add(object : ThemeColorMutableReference {
|
||||
val weakReference = WeakReference(activity)
|
||||
override fun setThemeColor(color: ThemeColor) {
|
||||
activity.window.navigationBarColor = color.colorPrimary
|
||||
ViewUtils.setNavigationBarBackgroundColor(activity, color.colorPrimary)
|
||||
}
|
||||
|
||||
override fun isNull() = weakReference.get() == null
|
||||
@@ -97,14 +98,15 @@ object ThemeColorManager {
|
||||
|
||||
fun add(activity: Activity) {
|
||||
activityRefs.add(WeakReference(activity))
|
||||
activity.window.statusBarColor = currentThemeColor.colorPrimary
|
||||
ViewUtils.setStatusBarBackgroundColor(activity, currentThemeColor.colorPrimary)
|
||||
}
|
||||
|
||||
fun setColor(color: Int) {
|
||||
activityRefs.iterator().let {
|
||||
while (it.hasNext()) {
|
||||
it.next().get()?.apply { window.statusBarColor = color } ?: it.remove()
|
||||
}
|
||||
val iterator = activityRefs.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next().get()?.also { activity ->
|
||||
ViewUtils.setStatusBarBackgroundColor(activity, color)
|
||||
} ?: iterator.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.content.ContextWrapper
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.graphics.Rect
|
||||
@@ -18,9 +17,13 @@ import android.os.Build
|
||||
import android.os.Looper
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowManager
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -164,8 +167,8 @@ object ViewUtils {
|
||||
return hasSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun setStatusBarIconLight(activity: Activity, isLight: Boolean) {
|
||||
@Suppress("DEPRECATION")
|
||||
when {
|
||||
isStatusBarIconLight(activity) == isLight -> return
|
||||
isLight -> removeSystemUiVisibility(activity, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
|
||||
@@ -173,6 +176,54 @@ object ViewUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun setStatusBarBackgroundColor(activity: Activity, color: Int) {
|
||||
val window = activity.window
|
||||
val decorView = window.decorView
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
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 {
|
||||
@Suppress("DEPRECATION")
|
||||
window.statusBarColor = color
|
||||
}
|
||||
}
|
||||
|
||||
fun setNavigationBarBackgroundColor(activity: Activity, color: Int) {
|
||||
val window = activity.window
|
||||
val decorView = window.decorView
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
decorView.setOnApplyWindowInsetsListener { view, insets ->
|
||||
val navBarInsets = insets.getInsets(WindowInsets.Type.navigationBars())
|
||||
val contentView: ViewGroup? = activity.findViewById(android.R.id.content)
|
||||
val navBarOverlay = View(activity).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
navBarInsets.bottom, // 导航栏高度
|
||||
).apply { gravity = Gravity.BOTTOM }
|
||||
setBackgroundColor(color)
|
||||
}
|
||||
contentView?.addView(navBarOverlay)
|
||||
view.onApplyWindowInsets(insets)
|
||||
}
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
window.navigationBarColor = color
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendWindowFlags(activity: Activity, flags: Int) {
|
||||
activity.window.addFlags(flags)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user