6.7.0 - Alpha10 - 控制台浮动窗口背景色彩行为相关 API (透明度/着色/基色) 更符合安卓设计规范 (issue #458)

This commit is contained in:
SuperMonster003
2025-11-02 20:08:23 +08:00
parent 908f6dec2d
commit 3439c0c224
8 changed files with 202 additions and 130 deletions

View File

@@ -61,6 +61,7 @@
"内置模块相关方法实参类型的异常消息增加类型摘要信息", "内置模块相关方法实参类型的异常消息增加类型摘要信息",
"控制台浮动窗口倒计时起始值由 6 秒增加到 9 秒", "控制台浮动窗口倒计时起始值由 6 秒增加到 9 秒",
"控制台浮动窗口内部实现进行无锁化及队列化处理以提升其参数设置效率与成功率", "控制台浮动窗口内部实现进行无锁化及队列化处理以提升其参数设置效率与成功率",
"控制台浮动窗口背景色彩行为相关 API (透明度/着色/基色) 更符合安卓设计规范 _[`issue #458`](http://issues.autojs6.com/458)_",
"文件管理器浮动按钮展开后点击菜单项时优化菜单收起时机", "文件管理器浮动按钮展开后点击菜单项时优化菜单收起时机",
"崩溃报告页面支持双指缩放调整字体大小并添加常用功能按钮", "崩溃报告页面支持双指缩放调整字体大小并添加常用功能按钮",
"应用启动器图标支持自适应图标特性 _[`issue #405`](http://issues.autojs6.com/405)_", "应用启动器图标支持自适应图标特性 _[`issue #405`](http://issues.autojs6.com/405)_",

View File

@@ -0,0 +1,5 @@
package org.autojs.autojs.annotation
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class OmniColor

View File

@@ -12,12 +12,14 @@ import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import org.autojs.autojs.runtime.api.ScreenMetrics import org.autojs.autojs.runtime.api.ScreenMetrics
import org.autojs.autojs.ui.enhancedfloaty.FloatyService import org.autojs.autojs.ui.enhancedfloaty.FloatyService
import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloaty.AbstractResizableExpandableFloaty import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloaty.AbstractResizableExpandableFloaty
import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloatyWindow import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloatyWindow
import org.autojs.autojs.util.DrawableUtils import org.autojs.autojs.util.ColorUtils
import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs.util.ViewUtils.setViewMeasure import org.autojs.autojs.util.ViewUtils.setViewMeasure
import org.autojs.autojs6.R import org.autojs.autojs6.R
import org.autojs.autojs6.databinding.FloatingConsoleExpandBinding import org.autojs.autojs6.databinding.FloatingConsoleExpandBinding
@@ -111,7 +113,12 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
text = mTitleText text = mTitleText
} }
titleBarView = expandedBinding.titleBar.apply { titleBarView = expandedBinding.titleBar.apply {
setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) applyTitleBackground(
this,
console.getTitleBackgroundColor(),
console.getTitleBackgroundTint(),
console.getTitleBackgroundAlpha(),
)
} }
expandedBinding.close.let { expandedBinding.close.let {
it.setOnClickListener { console.hide() } it.setOnClickListener { console.hide() }
@@ -140,6 +147,22 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
} }
} }
/**
* Apply color/tint/alpha to title bar background at once
* to prevent transition flash on first frame.
*
* zh-CN: 将 color/tint/alpha 一次性应用到标题栏背景, 防止首帧过渡闪现.
*/
private fun applyTitleBackground(view: LinearLayout, @ColorInt color: Int, @ColorInt tint: Int?, alpha: Double) {
val bg = view.background?.mutate()
ViewUtils.setBackgroundColor(view, color, false)
ViewCompat.setBackgroundTintList(view, tint?.let { ColorStateList.valueOf(it) })
bg?.alpha = ColorUtils.toUint8(alpha, true)
view.background = bg
}
private fun setUpConsole(window: ResizableExpandableFloatyWindow) { private fun setUpConsole(window: ResizableExpandableFloatyWindow) {
expandedBinding.console.apply { expandedBinding.console.apply {
setConsole(console) setConsole(console)
@@ -162,25 +185,23 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
fun getTitle(): String = mTitleText?.toString() ?: "" fun getTitle(): String = mTitleText?.toString() ?: ""
fun setTitleBackgroundColor(@ColorInt color: Int) { fun setTitleBackgroundColor(@ColorInt color: Int) = withTitleBarView {
console.configurator.setTitleBackgroundColor(color) ViewUtils.setBackgroundColor(it, color)
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } }
} }
fun setTitleBackgroundTint(tint: Int) { fun setTitleBackgroundTint(@ColorInt tint: Int?) = withTitleBarView {
console.configurator.setTitleBackgroundTint(tint) it.background?.mutate()?.clearColorFilter()
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } } ViewCompat.setBackgroundTintList(it, tint?.let { ColorStateList.valueOf(tint) })
} }
fun setTitleBackgroundAlpha(alpha: Int) { fun setTitleBackgroundAlpha(alpha: Float?) = withTitleBarView {
console.configurator.setTitleBackgroundAlpha(alpha) it.background?.mutate()?.alpha = ColorUtils.toUint8(alpha?.toDouble() ?: 1.0, true)
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } }
} }
fun setTitleIconsTint(color: Int) { fun setTitleIconsTint(color: Int?) {
mtTitleIconsTint = color mtTitleIconsTint = color
arrayOf(mMinimizeButton, mControllingButton, mCloseButton).filterNotNull().forEach { arrayOf(mMinimizeButton, mControllingButton, mCloseButton).filterNotNull().forEach { view ->
it.imageTintList = ColorStateList.valueOf(color) view.imageTintList = color?.let { ColorStateList.valueOf(it) }
} }
} }
@@ -198,8 +219,8 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
fun getTitleTextColor() = mTitleView?.textColors?.defaultColor ?: Color.BLACK fun getTitleTextColor() = mTitleView?.textColors?.defaultColor ?: Color.BLACK
private fun setTitleViewBackgroundColor(view: LinearLayout, color: Int) { private fun withTitleBarView(block: (LinearLayout) -> Unit) {
view.background = DrawableUtils.setDrawableColorFilterSrc(view.background, color) titleBarView?.let { it.post { block(it) } }
} }
internal fun setCloseButton(resId: Int) { internal fun setCloseButton(resId: Int) {

View File

@@ -3,7 +3,7 @@ package org.autojs.autojs.core.console
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.content.res.ColorStateList
import android.net.Uri import android.net.Uri
import android.os.CountDownTimer import android.os.CountDownTimer
import android.util.Log import android.util.Log
@@ -18,13 +18,11 @@ import android.view.Gravity.START
import android.view.Gravity.TOP import android.view.Gravity.TOP
import android.view.View import android.view.View
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.core.graphics.alpha import androidx.core.view.ViewCompat
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import androidx.core.view.doOnLayout import androidx.core.view.doOnLayout
import com.afollestad.materialdialogs.DialogAction import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import org.autojs.autojs.annotation.OmniColor
import org.autojs.autojs.annotation.ScriptInterface import org.autojs.autojs.annotation.ScriptInterface
import org.autojs.autojs.core.pref.Language import org.autojs.autojs.core.pref.Language
import org.autojs.autojs.core.ui.inflater.util.Gravities import org.autojs.autojs.core.ui.inflater.util.Gravities
@@ -33,13 +31,14 @@ import org.autojs.autojs.permission.DisplayOverOtherAppsPermission
import org.autojs.autojs.runtime.ScriptRuntime import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.runtime.api.AbstractConsole import org.autojs.autojs.runtime.api.AbstractConsole
import org.autojs.autojs.runtime.api.Mime import org.autojs.autojs.runtime.api.Mime
import org.autojs.autojs.runtime.api.augment.colors.Colors
import org.autojs.autojs.tool.UiHandler import org.autojs.autojs.tool.UiHandler
import org.autojs.autojs.ui.common.NotAskAgainDialog import org.autojs.autojs.ui.common.NotAskAgainDialog
import org.autojs.autojs.ui.enhancedfloaty.FloatyService import org.autojs.autojs.ui.enhancedfloaty.FloatyService
import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloatyWindow import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloatyWindow
import org.autojs.autojs.ui.enhancedfloaty.gesture.DragGesture import org.autojs.autojs.ui.enhancedfloaty.gesture.DragGesture
import org.autojs.autojs.util.ClipboardUtils import org.autojs.autojs.util.ClipboardUtils
import org.autojs.autojs.util.DrawableUtils import org.autojs.autojs.util.ColorUtils
import org.autojs.autojs.util.StringUtils.key import org.autojs.autojs.util.StringUtils.key
import org.autojs.autojs.util.ViewUtils import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs6.R import org.autojs.autojs6.R
@@ -381,11 +380,19 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
setGravity(getGravity()) setGravity(getGravity())
configurator.titleTextSize?.let { setTitleTextSize(it) } configurator.titleTextSize?.let { setTitleTextSize(it) }
configurator.titleTextColor?.let { setTitleTextColor(it) } configurator.titleTextColor?.let { setTitleTextColor(it) }
setTitleBackgroundAlpha(getTitleBackgroundAlpha())
setTitleBackgroundTint(getTitleBackgroundTint())
setTitleBackgroundColor(getTitleBackgroundColor()) setTitleBackgroundColor(getTitleBackgroundColor())
configurator.titleIconsTint?.let { setTitleIconsTint(it) } configurator.titleIconsTint?.let { setTitleIconsTint(it) }
configurator.contentTextSize?.let { setContentTextSize(it) } configurator.contentTextSize?.let { setContentTextSize(it) }
configurator.contentTextColors?.let { setContentTextColors(it) } configurator.contentTextColors?.let { setContentTextColors(it) }
setContentBackgroundAlpha(getContentBackgroundAlpha())
setContentBackgroundTint(getContentBackgroundTint())
setContentBackgroundColor(getContentBackgroundColor()) setContentBackgroundColor(getContentBackgroundColor())
setTouchable(isTouchable()) setTouchable(isTouchable())
} }
@@ -581,11 +588,14 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
} }
@ScriptInterface
fun getGravity() = configurator.gravity
@ScriptInterface @ScriptInterface
fun setGravity(gravity: String) = setGravity(Gravities.parse(gravity)) fun setGravity(gravity: String) = setGravity(Gravities.parse(gravity))
@ScriptInterface @ScriptInterface
fun getGravity() = configurator.gravity fun getTitleTextSize() = mConsoleFloaty.getTitleTextSize()
@ScriptInterface @ScriptInterface
fun setTitleTextSize(size: Float) { fun setTitleTextSize(size: Float) {
@@ -596,7 +606,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
@ScriptInterface @ScriptInterface
fun getTitleTextSize() = mConsoleFloaty.getTitleTextSize() fun getTitleTextColor() = mConsoleFloaty.getTitleTextColor()
@ScriptInterface @ScriptInterface
fun setTitleTextColor(color: Int) { fun setTitleTextColor(color: Int) {
@@ -607,46 +617,54 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
@ScriptInterface @ScriptInterface
fun getTitleTextColor() = mConsoleFloaty.getTitleTextColor() fun getTitleBackgroundColor() = configurator.titleBackgroundColor
@ScriptInterface @ScriptInterface
fun setTitleBackgroundColor(@ColorInt color: Int) { fun setTitleBackgroundColor(@ColorInt color: Int) {
configurator.setTitleBackgroundColor(color) configurator.setTitleBackgroundColor(color)
uiHandler.post { enqueueMutation(Stage.VIEW_ATTACHED) {
mConsoleFloaty.setTitleBackgroundColor(getTitleBackgroundColor()) mConsoleFloaty.titleBarView?.let { view ->
ViewUtils.setBackgroundColor(view, configurator.titleBackgroundColor)
}
} }
} }
@ScriptInterface @ScriptInterface
fun getTitleBackgroundColor() = configurator.titleBackgroundColor fun getTitleBackgroundTint() = configurator.titleBackgroundTint
@ScriptInterface @ScriptInterface
fun setTitleBackgroundTint(@ColorInt tint: Int) { fun setTitleBackgroundTint(@ColorInt tint: Int?) {
configurator.setTitleBackgroundTint(tint) configurator.setTitleBackgroundTint(tint)
uiHandler.post { enqueueMutation(Stage.VIEW_ATTACHED) {
mConsoleFloaty.setTitleBackgroundTint(tint) mConsoleFloaty.setTitleBackgroundTint(configurator.titleBackgroundTint)
} }
} }
@ScriptInterface @ScriptInterface
fun setTitleBackgroundAlpha(alpha: Int) { fun getTitleBackgroundAlpha() = configurator.titleBackgroundAlpha
@ScriptInterface
fun setTitleBackgroundAlpha(alpha: Double?) {
configurator.setTitleBackgroundAlpha(alpha) configurator.setTitleBackgroundAlpha(alpha)
uiHandler.post { enqueueMutation(Stage.VIEW_ATTACHED) {
mConsoleFloaty.setTitleBackgroundAlpha(alpha) mConsoleFloaty.setTitleBackgroundAlpha(configurator.titleBackgroundAlpha.toFloat())
} }
} }
@ScriptInterface @ScriptInterface
fun resetTitleBackgroundAlpha() = setTitleBackgroundAlpha(-1) fun resetTitleBackgroundAlpha() = setTitleBackgroundAlpha(DEFAULT_ALPHA)
@ScriptInterface @ScriptInterface
fun setTitleIconsTint(color: Int) { fun setTitleIconsTint(color: Int?) {
configurator.setTitleIconsTint(color) configurator.setTitleIconsTint(color)
uiHandler.post { enqueueMutation(Stage.VIEW_ATTACHED) {
mConsoleFloaty.setTitleIconsTint(color) mConsoleFloaty.setTitleIconsTint(color)
} }
} }
@ScriptInterface
fun getContentTextSize() = getFloatingConsoleView()?.textSize ?: 0f
@ScriptInterface @ScriptInterface
fun setContentTextSize(size: Float) { fun setContentTextSize(size: Float) {
configurator.setContentTextSize(size) configurator.setContentTextSize(size)
@@ -656,7 +674,9 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
@ScriptInterface @ScriptInterface
fun getContentTextSize() = getFloatingConsoleView()?.textSize ?: 0f fun getContentTextColors(): Map<Int, Int> {
return getFloatingConsoleView()?.textColors ?: emptyMap()
}
@ScriptInterface @ScriptInterface
fun setContentTextColors(colors: Array<out Int?>) { fun setContentTextColors(colors: Array<out Int?>) {
@@ -667,39 +687,43 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
@ScriptInterface @ScriptInterface
fun getContentTextColors(): Map<Int, Int> { fun getContentBackgroundColor() = configurator.contentBackgroundColor
return getFloatingConsoleView()?.textColors ?: emptyMap()
}
@ScriptInterface @ScriptInterface
fun setContentBackgroundColor(@ColorInt color: Int) { fun setContentBackgroundColor(@ColorInt color: Int) {
configurator.setContentBackgroundColor(color) configurator.setContentBackgroundColor(color)
uiHandler.post { enqueueMutation(Stage.VIEW_ATTACHED) {
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor()) ViewUtils.setBackgroundColor(getFloatingConsoleView(), configurator.contentBackgroundColor)
} }
} }
@ScriptInterface @ScriptInterface
fun getContentBackgroundColor() = configurator.contentBackgroundColor fun getContentBackgroundTint() = configurator.contentBackgroundTint
@ScriptInterface @ScriptInterface
fun setContentBackgroundTint(@ColorInt tint: Int) { fun setContentBackgroundTint(@ColorInt tint: Int?) {
configurator.setContentBackgroundTint(tint) configurator.setContentBackgroundTint(tint)
enqueueMutation(Stage.VIEW_ATTACHED) { enqueueMutation(Stage.VIEW_ATTACHED) {
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor()) val view = getFloatingConsoleView() ?: return@enqueueMutation
view.background?.mutate()?.clearColorFilter()
val tint = configurator.contentBackgroundTint
ViewCompat.setBackgroundTintList(view, tint?.let { ColorStateList.valueOf(it) })
} }
} }
@ScriptInterface @ScriptInterface
fun setContentBackgroundAlpha(alpha: Int) { fun getContentBackgroundAlpha() = configurator.contentBackgroundAlpha
@ScriptInterface
fun setContentBackgroundAlpha(alpha: Double?) {
configurator.setContentBackgroundAlpha(alpha) configurator.setContentBackgroundAlpha(alpha)
enqueueMutation(Stage.VIEW_ATTACHED) { enqueueMutation(Stage.VIEW_ATTACHED) {
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor()) getFloatingConsoleView()?.background?.mutate()?.alpha = ColorUtils.toUint8(configurator.contentBackgroundAlpha, true)
} }
} }
@ScriptInterface @ScriptInterface
fun resetContentBackgroundAlpha() = setContentBackgroundAlpha(-1) fun resetContentBackgroundAlpha() = setContentBackgroundAlpha(DEFAULT_ALPHA)
@ScriptInterface @ScriptInterface
fun setTextSize(size: Float) { fun setTextSize(size: Float) {
@@ -726,7 +750,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
} }
@ScriptInterface @ScriptInterface
fun setBackgroundAlpha(alpha: Int) { fun setBackgroundAlpha(alpha: Double?) {
setTitleBackgroundAlpha(alpha) setTitleBackgroundAlpha(alpha)
setContentBackgroundAlpha(alpha) setContentBackgroundAlpha(alpha)
} }
@@ -760,7 +784,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
@JvmOverloads @JvmOverloads
fun hideDelayed(exitOnCloseTimeout: Long = configurator.exitOnCloseTimeout) { fun hideDelayed(exitOnCloseTimeout: Long = configurator.exitOnCloseTimeout) {
configurator.initExitOnClose() configurator.resetExitOnClose()
uiHandler.post { uiHandler.post {
mCountDownTimer = object : CountDownTimer(exitOnCloseTimeout, 500) { mCountDownTimer = object : CountDownTimer(exitOnCloseTimeout, 500) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
@@ -797,14 +821,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private fun setCloseButton(resId: Int) = mConsoleFloaty.setCloseButton(resId) private fun setCloseButton(resId: Int) = mConsoleFloaty.setCloseButton(resId)
private fun setContentViewBackgroundColor(view: FloatingConsoleView?, color: Int) { private fun parseAlpha(alpha: Double?) = ColorUtils.toUint8(alpha ?: DEFAULT_ALPHA, true) / 255.0
view?.apply { background = DrawableUtils.setDrawableColorFilterSrc(background, color) }
}
private fun parseAlpha(alpha: Int, defaultRes: Int) = when {
alpha < 0 -> context.getColor(defaultRes).alpha
else -> alpha
}
private fun advanceStage(newStage: Stage) { private fun advanceStage(newStage: Stage) {
if (newStage.ordinal <= mStage.ordinal) return if (newStage.ordinal <= mStage.ordinal) return
@@ -883,17 +900,14 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private set private set
@Volatile @Volatile
private var internalTitleBackgroundColor: Int? = null var titleBackgroundColor: Int = context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES)
@Volatile @Volatile
private var internalTitleBackgroundAlpha: Int? = null var titleBackgroundAlpha: Double = DEFAULT_ALPHA
private set
@Volatile @Volatile
private var internalTitleBackgroundTint: Int? = null var titleBackgroundTint: Int? = null
val titleBackgroundColor: Int
get() = (internalTitleBackgroundColor ?: context.getColor(R.color.floating_console_title_bar_bg))
.calibrateWith(internalTitleBackgroundAlpha, internalTitleBackgroundTint)
@Volatile @Volatile
var titleIconsTint: Int? = null var titleIconsTint: Int? = null
@@ -908,20 +922,17 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private set private set
@Volatile @Volatile
private var internalContentBackgroundColor: Int? = null var contentBackgroundColor: Int = context.getColor(DEFAULT_CONTENT_BG_COLOR_RES)
@Volatile @Volatile
private var internalContentBackgroundAlpha: Int? = null var contentBackgroundAlpha: Double = DEFAULT_ALPHA
private set
@Volatile @Volatile
private var internalContentBackgroundTint: Int? = null var contentBackgroundTint: Int? = null
val contentBackgroundColor: Int
get() = (internalContentBackgroundColor ?: context.getColor(R.color.floating_console_content_bg))
.calibrateWith(internalContentBackgroundAlpha, internalContentBackgroundTint)
@Volatile @Volatile
var isTouchable: Boolean = true var isTouchable: Boolean = DEFAULT_TOUCHABLE
private set private set
@Volatile @Volatile
@@ -940,8 +951,8 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
position = Point(x, y) position = Point(x, y)
} }
fun setGravity(gravity: Int) = also { fun setGravity(gravity: Int?) = also {
this.gravity = gravity this.gravity = gravity ?: DEFAULT_GRAVITY
} }
fun setTitle(title: CharSequence?) = also { fun setTitle(title: CharSequence?) = also {
@@ -952,44 +963,44 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
titleTextSize = size titleTextSize = size
} }
fun setTitleTextColor(color: Int) = also { fun setTitleTextColor(@OmniColor color: Any?) = also {
titleTextColor = color titleTextColor = color?.let { Colors.toIntRhino(it) }
} }
fun setTitleBackgroundColor(color: Int) = also { fun setTitleBackgroundColor(@OmniColor color: Any?) = also {
internalTitleBackgroundColor = color titleBackgroundColor = color?.let { Colors.toIntRhino(it) } ?: context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES)
} }
fun setTitleBackgroundTint(tint: Int) = also { fun setTitleBackgroundTint(@OmniColor tint: Any?) = also {
internalTitleBackgroundTint = tint titleBackgroundTint = tint?.let { Colors.toIntRhino(it) }
} }
fun setTitleBackgroundAlpha(alpha: Int) = also { fun setTitleBackgroundAlpha(alpha: Double?) = also {
internalTitleBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_title_bar_bg) titleBackgroundAlpha = parseAlpha(alpha)
} }
fun setTitleIconsTint(color: Int) = also { fun setTitleIconsTint(@OmniColor color: Any?) = also {
titleIconsTint = color titleIconsTint = color?.let { Colors.toIntRhino(it) }
} }
fun setContentTextSize(size: Float) = also { fun setContentTextSize(size: Float) = also {
contentTextSize = size contentTextSize = size
} }
fun setContentTextColors(colors: Array<out Int?>) = also { fun setContentTextColors(colors: Array<out @OmniColor Any?>) = also {
contentTextColors = colors contentTextColors = colors.map { it?.let { Colors.toIntRhino(it) } }.toTypedArray()
} }
fun setContentBackgroundColor(color: Int) = also { fun setContentBackgroundColor(@OmniColor color: Any?) = also {
internalContentBackgroundColor = color contentBackgroundColor = color.let { Colors.toIntRhino(it) }
} }
fun setContentBackgroundTint(tint: Int) { fun setContentBackgroundTint(@OmniColor tint: Any?) {
internalContentBackgroundTint = tint contentBackgroundTint = tint?.let { Colors.toIntRhino(it) }
} }
fun setContentBackgroundAlpha(alpha: Int) = also { fun setContentBackgroundAlpha(alpha: Double?) = also {
internalContentBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_content_bg) contentBackgroundAlpha = parseAlpha(alpha)
} }
fun setTextSize(size: Float) = also { fun setTextSize(size: Float) = also {
@@ -997,22 +1008,22 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
setContentTextSize(size) setContentTextSize(size)
} }
fun setTextColor(color: Int) = also { fun setTextColor(@OmniColor color: Any?) = also {
setTitleTextColor(color) setTitleTextColor(color)
setContentTextColors(Array(6) { color }) setContentTextColors(Array(6) { color })
} }
fun setBackgroundColor(color: Int) = also { fun setBackgroundColor(@OmniColor color: Any?) = also {
setTitleBackgroundColor(color) setTitleBackgroundColor(color)
setContentBackgroundColor(color) setContentBackgroundColor(color)
} }
fun setBackgroundTint(color: Int) = also { fun setBackgroundTint(@OmniColor color: Any?) = also {
setTitleBackgroundTint(color) setTitleBackgroundTint(color)
setContentBackgroundTint(color) setContentBackgroundTint(color)
} }
fun setBackgroundAlpha(alpha: Int) = also { fun setBackgroundAlpha(alpha: Double?) = also {
setTitleBackgroundAlpha(alpha) setTitleBackgroundAlpha(alpha)
setContentBackgroundAlpha(alpha) setContentBackgroundAlpha(alpha)
} }
@@ -1042,21 +1053,21 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
title = null title = null
titleTextSize = null titleTextSize = null
titleTextColor = null titleTextColor = null
internalTitleBackgroundColor = null titleBackgroundColor = context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES)
internalTitleBackgroundAlpha = null titleBackgroundAlpha = DEFAULT_ALPHA
internalTitleBackgroundTint = null titleBackgroundTint = null
internalContentBackgroundColor = null contentBackgroundColor = context.getColor(DEFAULT_CONTENT_BG_COLOR_RES)
internalContentBackgroundAlpha = null contentBackgroundAlpha = DEFAULT_ALPHA
internalContentBackgroundTint = null contentBackgroundTint = null
titleIconsTint = null titleIconsTint = null
contentTextSize = null contentTextSize = null
contentTextColors = null contentTextColors = null
isTouchable = true isTouchable = DEFAULT_TOUCHABLE
isExitOnClose = false isExitOnClose = false
exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT
} }
internal fun initExitOnClose() { internal fun resetExitOnClose() {
setExitOnClose(false) setExitOnClose(false)
exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT
} }
@@ -1064,13 +1075,6 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
@JvmOverloads @JvmOverloads
fun show(isReset: Boolean = false) = this@ConsoleImpl.show(isReset) fun show(isReset: Boolean = false) = this@ConsoleImpl.show(isReset)
private fun Int.calibrateWith(alpha: Int?, tint: Int?): Int {
var result = this
alpha?.let { desired -> result = Color.argb(desired, result.red, result.green, result.blue) }
tint?.let { desired -> result = Color.argb(result.alpha, desired.red, desired.green, desired.blue) }
return result
}
} }
companion object { companion object {
@@ -1078,12 +1082,16 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private val TAG = ConsoleImpl::class.java.simpleName private val TAG = ConsoleImpl::class.java.simpleName
const val DEFAULT_TITLE = "" const val DEFAULT_TITLE = ""
const val DEFAULT_ALPHA = 1.0
const val DEFAULT_TOUCHABLE = true const val DEFAULT_TOUCHABLE = true
const val DEFAULT_TOUCH_THROUGH = true const val DEFAULT_TOUCH_THROUGH = true
const val DEFAULT_GRAVITY = Gravity.NO_GRAVITY const val DEFAULT_GRAVITY = Gravity.NO_GRAVITY
const val DEFAULT_EXIT_ON_CLOSE_TIMEOUT = 5000L const val DEFAULT_EXIT_ON_CLOSE_TIMEOUT = 5000L
const val DEFAULT_EXIT_ON_CLOSE = true const val DEFAULT_EXIT_ON_CLOSE = true
val DEFAULT_TITLE_BAR_BG_COLOR_RES = R.color.floating_console_title_bar_bg
val DEFAULT_CONTENT_BG_COLOR_RES = R.color.floating_console_content_bg
} }
} }

View File

@@ -21,7 +21,6 @@ import org.autojs.autojs.runtime.api.augment.AugmentableProxy
import org.autojs.autojs.runtime.api.augment.s13n.S13n import org.autojs.autojs.runtime.api.augment.s13n.S13n
import org.autojs.autojs.runtime.api.augment.util.Util import org.autojs.autojs.runtime.api.augment.util.Util
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
import org.autojs.autojs.util.ColorUtils
import org.autojs.autojs.util.ConsoleUtils import org.autojs.autojs.util.ConsoleUtils
import org.autojs.autojs.util.DisplayUtils import org.autojs.autojs.util.DisplayUtils
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
@@ -302,9 +301,7 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) {
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun build(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ConsoleImpl.Configurator = ensureArgumentsAtMost(args, 1) { fun build(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ConsoleImpl.Configurator = ensureArgumentsAtMost(args, 1) {
val (options) = it val (options) = it
val configurator = scriptRuntime.console.configurator.apply { val configurator = scriptRuntime.console.configurator
clearStates()
}
val opt = coerceObject(options, newNativeObject()) val opt = coerceObject(options, newNativeObject())
opt.entries.forEach { entry -> opt.entries.forEach { entry ->
@@ -390,21 +387,21 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setTitleBackgroundTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setTitleBackgroundTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setTitleBackgroundTint(S13n.color(arrayOf(it))) scriptRuntime.console.setTitleBackgroundTint(it?.let { S13n.color(arrayOf(it)) })
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setTitleBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setTitleBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setTitleBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) scriptRuntime.console.setTitleBackgroundAlpha(coerceNumber(it, 1.0))
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setTitleIconsTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setTitleIconsTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setTitleIconsTint(S13n.color(arrayOf(it))) scriptRuntime.console.setTitleIconsTint(it?.let { S13n.color(arrayOf(it)) })
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }
@@ -458,14 +455,14 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setContentBackgroundTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setContentBackgroundTint(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setContentBackgroundTint(S13n.color(arrayOf(it))) scriptRuntime.console.setContentBackgroundTint(it?.let { S13n.color(arrayOf(it)) })
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setContentBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setContentBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setContentBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) scriptRuntime.console.setContentBackgroundAlpha(coerceNumber(it, 1.0))
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }
@@ -500,7 +497,7 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) {
@JvmStatic @JvmStatic
@RhinoRuntimeFunctionInterface @RhinoRuntimeFunctionInterface
fun setBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) { fun setBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ProxyObject = ensureArgumentsOnlyOne(args) {
scriptRuntime.console.setBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) scriptRuntime.console.setBackgroundAlpha(coerceNumber(it, 1.0))
scriptRuntime.consoleProxyObject scriptRuntime.consoleProxyObject
} }

View File

@@ -14,6 +14,7 @@ import org.autojs.autojs.core.image.ColorTable
import org.autojs.autojs.theme.ThemeColor import org.autojs.autojs.theme.ThemeColor
import org.autojs.autojs.theme.ThemeColorManager import org.autojs.autojs.theme.ThemeColorManager
import java.math.RoundingMode import java.math.RoundingMode
import kotlin.math.abs
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.text.RegexOption.IGNORE_CASE import kotlin.text.RegexOption.IGNORE_CASE
@@ -48,12 +49,19 @@ object ColorUtils {
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun toUnit8(component: Double, takeNumOneAsPercent: Boolean = false) = when { fun toUint8(component: Double, takeNumOneAsPercent: Boolean = false): Int {
component < 1 -> (component * 255).roundToInt() val epsilon = 1e-9
component == 1.0 && takeNumOneAsPercent -> 255 return when {
else -> 255.coerceAtMost(component.roundToInt()) component == -1.0 -> 255
component < 1.0 - epsilon -> (component * 255.0).roundToInt().coerceIn(0, 255)
abs(component - 1.0) <= epsilon -> if (takeNumOneAsPercent) 255 else 1
else -> component.roundToInt().coerceIn(0, 255)
}
} }
@JvmStatic
fun toFraction(value: Number) = value.toDouble().coerceIn(0.0, 255.0) / 255.0
@JvmStatic @JvmStatic
fun toInt(num: Number) = toInt(toHex(num)) fun toInt(num: Number) = toInt(toHex(num))

View File

@@ -13,9 +13,13 @@ import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.content.res.Resources import android.content.res.Resources
import android.graphics.ColorFilter import android.graphics.ColorFilter
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.ShapeDrawable
import android.os.Build import android.os.Build
import android.os.Looper import android.os.Looper
import android.util.DisplayMetrics import android.util.DisplayMetrics
@@ -42,6 +46,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
@@ -96,6 +101,33 @@ object ViewUtils {
return view.findViewById(resId) return view.findViewById(resId)
} }
@JvmStatic
@JvmOverloads
fun setBackgroundColor(view: View?, color: Int, reAssignment: Boolean = true) {
view ?: return
val bg = view.background?.mutate()
when (bg) {
is GradientDrawable -> {
bg.clearColorFilter()
bg.setColor(color)
}
is ShapeDrawable -> {
bg.clearColorFilter()
bg.paint.color = color
}
is ColorDrawable -> {
bg.clearColorFilter()
bg.color = color
}
else -> bg?.let {
it.clearColorFilter()
DrawableCompat.setTintMode(it, SRC_IN)
DrawableCompat.setTint(it, color)
}
}
if (reAssignment) view.background = bg
}
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun getStatusBarHeight(context: Context, withFallback: Boolean = true): Int { fun getStatusBarHeight(context: Context, withFallback: Boolean = true): Int {

View File

@@ -1,5 +1,5 @@
#Sat Nov 01 13:14:47 CST 2025 #Sun Nov 02 19:59:28 CST 2025
BUILD_TIME=1761974087315 BUILD_TIME=1762084768045
COMPILE_SDK_VERSION=36 COMPILE_SDK_VERSION=36
IMAGE_QUANT_CMAKE_VERSION=3.22.1 IMAGE_QUANT_CMAKE_VERSION=3.22.1
IMAGE_QUANT_NDK_VERSION=26.1.10909125 IMAGE_QUANT_NDK_VERSION=26.1.10909125
@@ -27,6 +27,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=36 TARGET_SDK_VERSION=36
TARGET_SDK_VERSION_INRT=29 TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=3458 VERSION_BUILD=3465
VERSION_NAME=6.7.0 Alpha10 VERSION_NAME=6.7.0 Alpha10
VSCODE_EXT_REQUIRED_VERSION=1.0.8 VSCODE_EXT_REQUIRED_VERSION=1.0.8