From 3439c0c224c63a7a77e099fc062a4ecd02cb5164 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Sun, 2 Nov 2025 20:08:23 +0800 Subject: [PATCH] =?UTF-8?q?6.7.0=20-=20Alpha10=20-=20=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E6=B5=AE=E5=8A=A8=E7=AA=97=E5=8F=A3=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E8=89=B2=E5=BD=A9=E8=A1=8C=E4=B8=BA=E7=9B=B8=E5=85=B3=20API=20?= =?UTF-8?q?(=E9=80=8F=E6=98=8E=E5=BA=A6/=E7=9D=80=E8=89=B2/=E5=9F=BA?= =?UTF-8?q?=E8=89=B2)=20=E6=9B=B4=E7=AC=A6=E5=90=88=E5=AE=89=E5=8D=93?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E8=A7=84=E8=8C=83=20(issue=20#458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 1 + .../org/autojs/autojs/annotation/OmniColor.kt | 5 + .../autojs/core/console/ConsoleFloaty.kt | 53 +++-- .../autojs/autojs/core/console/ConsoleImpl.kt | 202 +++++++++--------- .../runtime/api/augment/console/Console.kt | 17 +- .../java/org/autojs/autojs/util/ColorUtils.kt | 16 +- .../java/org/autojs/autojs/util/ViewUtils.kt | 32 +++ version.properties | 6 +- 8 files changed, 202 insertions(+), 130 deletions(-) create mode 100644 app/src/main/java/org/autojs/autojs/annotation/OmniColor.kt diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 4f0863c7..1b33ea9b 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -61,6 +61,7 @@ "内置模块相关方法实参类型的异常消息增加类型摘要信息", "控制台浮动窗口倒计时起始值由 6 秒增加到 9 秒", "控制台浮动窗口内部实现进行无锁化及队列化处理以提升其参数设置效率与成功率", + "控制台浮动窗口背景色彩行为相关 API (透明度/着色/基色) 更符合安卓设计规范 _[`issue #458`](http://issues.autojs6.com/458)_", "文件管理器浮动按钮展开后点击菜单项时优化菜单收起时机", "崩溃报告页面支持双指缩放调整字体大小并添加常用功能按钮", "应用启动器图标支持自适应图标特性 _[`issue #405`](http://issues.autojs6.com/405)_", diff --git a/app/src/main/java/org/autojs/autojs/annotation/OmniColor.kt b/app/src/main/java/org/autojs/autojs/annotation/OmniColor.kt new file mode 100644 index 00000000..e560b527 --- /dev/null +++ b/app/src/main/java/org/autojs/autojs/annotation/OmniColor.kt @@ -0,0 +1,5 @@ +package org.autojs.autojs.annotation + +@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION) +@Retention(AnnotationRetention.RUNTIME) +annotation class OmniColor diff --git a/app/src/main/java/org/autojs/autojs/core/console/ConsoleFloaty.kt b/app/src/main/java/org/autojs/autojs/core/console/ConsoleFloaty.kt index 5bf68c2e..cc1c049a 100644 --- a/app/src/main/java/org/autojs/autojs/core/console/ConsoleFloaty.kt +++ b/app/src/main/java/org/autojs/autojs/core/console/ConsoleFloaty.kt @@ -12,12 +12,14 @@ import android.widget.LinearLayout import android.widget.TextView import androidx.annotation.ColorInt import androidx.core.content.res.ResourcesCompat +import androidx.core.view.ViewCompat import androidx.core.view.isVisible import org.autojs.autojs.runtime.api.ScreenMetrics import org.autojs.autojs.ui.enhancedfloaty.FloatyService import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloaty.AbstractResizableExpandableFloaty 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.autojs6.R import org.autojs.autojs6.databinding.FloatingConsoleExpandBinding @@ -111,7 +113,12 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda text = mTitleText } titleBarView = expandedBinding.titleBar.apply { - setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) + applyTitleBackground( + this, + console.getTitleBackgroundColor(), + console.getTitleBackgroundTint(), + console.getTitleBackgroundAlpha(), + ) } expandedBinding.close.let { 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) { expandedBinding.console.apply { setConsole(console) @@ -162,25 +185,23 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda fun getTitle(): String = mTitleText?.toString() ?: "" - fun setTitleBackgroundColor(@ColorInt color: Int) { - console.configurator.setTitleBackgroundColor(color) - titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } } + fun setTitleBackgroundColor(@ColorInt color: Int) = withTitleBarView { + ViewUtils.setBackgroundColor(it, color) } - fun setTitleBackgroundTint(tint: Int) { - console.configurator.setTitleBackgroundTint(tint) - titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } } + fun setTitleBackgroundTint(@ColorInt tint: Int?) = withTitleBarView { + it.background?.mutate()?.clearColorFilter() + ViewCompat.setBackgroundTintList(it, tint?.let { ColorStateList.valueOf(tint) }) } - fun setTitleBackgroundAlpha(alpha: Int) { - console.configurator.setTitleBackgroundAlpha(alpha) - titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } } + fun setTitleBackgroundAlpha(alpha: Float?) = withTitleBarView { + it.background?.mutate()?.alpha = ColorUtils.toUint8(alpha?.toDouble() ?: 1.0, true) } - fun setTitleIconsTint(color: Int) { + fun setTitleIconsTint(color: Int?) { mtTitleIconsTint = color - arrayOf(mMinimizeButton, mControllingButton, mCloseButton).filterNotNull().forEach { - it.imageTintList = ColorStateList.valueOf(color) + arrayOf(mMinimizeButton, mControllingButton, mCloseButton).filterNotNull().forEach { view -> + 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 - private fun setTitleViewBackgroundColor(view: LinearLayout, color: Int) { - view.background = DrawableUtils.setDrawableColorFilterSrc(view.background, color) + private fun withTitleBarView(block: (LinearLayout) -> Unit) { + titleBarView?.let { it.post { block(it) } } } internal fun setCloseButton(resId: Int) { diff --git a/app/src/main/java/org/autojs/autojs/core/console/ConsoleImpl.kt b/app/src/main/java/org/autojs/autojs/core/console/ConsoleImpl.kt index 89111554..f3bc64e6 100644 --- a/app/src/main/java/org/autojs/autojs/core/console/ConsoleImpl.kt +++ b/app/src/main/java/org/autojs/autojs/core/console/ConsoleImpl.kt @@ -3,7 +3,7 @@ package org.autojs.autojs.core.console import android.annotation.SuppressLint import android.content.Context import android.content.Intent -import android.graphics.Color +import android.content.res.ColorStateList import android.net.Uri import android.os.CountDownTimer import android.util.Log @@ -18,13 +18,11 @@ import android.view.Gravity.START import android.view.Gravity.TOP import android.view.View import androidx.annotation.ColorInt -import androidx.core.graphics.alpha -import androidx.core.graphics.blue -import androidx.core.graphics.green -import androidx.core.graphics.red +import androidx.core.view.ViewCompat import androidx.core.view.doOnLayout import com.afollestad.materialdialogs.DialogAction import com.afollestad.materialdialogs.MaterialDialog +import org.autojs.autojs.annotation.OmniColor import org.autojs.autojs.annotation.ScriptInterface import org.autojs.autojs.core.pref.Language 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.api.AbstractConsole 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.ui.common.NotAskAgainDialog import org.autojs.autojs.ui.enhancedfloaty.FloatyService import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloatyWindow import org.autojs.autojs.ui.enhancedfloaty.gesture.DragGesture 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.ViewUtils import org.autojs.autojs6.R @@ -381,11 +380,19 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { setGravity(getGravity()) configurator.titleTextSize?.let { setTitleTextSize(it) } configurator.titleTextColor?.let { setTitleTextColor(it) } + + setTitleBackgroundAlpha(getTitleBackgroundAlpha()) + setTitleBackgroundTint(getTitleBackgroundTint()) setTitleBackgroundColor(getTitleBackgroundColor()) + configurator.titleIconsTint?.let { setTitleIconsTint(it) } configurator.contentTextSize?.let { setContentTextSize(it) } configurator.contentTextColors?.let { setContentTextColors(it) } + + setContentBackgroundAlpha(getContentBackgroundAlpha()) + setContentBackgroundTint(getContentBackgroundTint()) setContentBackgroundColor(getContentBackgroundColor()) + setTouchable(isTouchable()) } @@ -581,11 +588,14 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } } + @ScriptInterface + fun getGravity() = configurator.gravity + @ScriptInterface fun setGravity(gravity: String) = setGravity(Gravities.parse(gravity)) @ScriptInterface - fun getGravity() = configurator.gravity + fun getTitleTextSize() = mConsoleFloaty.getTitleTextSize() @ScriptInterface fun setTitleTextSize(size: Float) { @@ -596,7 +606,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } @ScriptInterface - fun getTitleTextSize() = mConsoleFloaty.getTitleTextSize() + fun getTitleTextColor() = mConsoleFloaty.getTitleTextColor() @ScriptInterface fun setTitleTextColor(color: Int) { @@ -607,46 +617,54 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } @ScriptInterface - fun getTitleTextColor() = mConsoleFloaty.getTitleTextColor() + fun getTitleBackgroundColor() = configurator.titleBackgroundColor @ScriptInterface fun setTitleBackgroundColor(@ColorInt color: Int) { configurator.setTitleBackgroundColor(color) - uiHandler.post { - mConsoleFloaty.setTitleBackgroundColor(getTitleBackgroundColor()) + enqueueMutation(Stage.VIEW_ATTACHED) { + mConsoleFloaty.titleBarView?.let { view -> + ViewUtils.setBackgroundColor(view, configurator.titleBackgroundColor) + } } } @ScriptInterface - fun getTitleBackgroundColor() = configurator.titleBackgroundColor + fun getTitleBackgroundTint() = configurator.titleBackgroundTint @ScriptInterface - fun setTitleBackgroundTint(@ColorInt tint: Int) { + fun setTitleBackgroundTint(@ColorInt tint: Int?) { configurator.setTitleBackgroundTint(tint) - uiHandler.post { - mConsoleFloaty.setTitleBackgroundTint(tint) + enqueueMutation(Stage.VIEW_ATTACHED) { + mConsoleFloaty.setTitleBackgroundTint(configurator.titleBackgroundTint) } } @ScriptInterface - fun setTitleBackgroundAlpha(alpha: Int) { + fun getTitleBackgroundAlpha() = configurator.titleBackgroundAlpha + + @ScriptInterface + fun setTitleBackgroundAlpha(alpha: Double?) { configurator.setTitleBackgroundAlpha(alpha) - uiHandler.post { - mConsoleFloaty.setTitleBackgroundAlpha(alpha) + enqueueMutation(Stage.VIEW_ATTACHED) { + mConsoleFloaty.setTitleBackgroundAlpha(configurator.titleBackgroundAlpha.toFloat()) } } @ScriptInterface - fun resetTitleBackgroundAlpha() = setTitleBackgroundAlpha(-1) + fun resetTitleBackgroundAlpha() = setTitleBackgroundAlpha(DEFAULT_ALPHA) @ScriptInterface - fun setTitleIconsTint(color: Int) { + fun setTitleIconsTint(color: Int?) { configurator.setTitleIconsTint(color) - uiHandler.post { + enqueueMutation(Stage.VIEW_ATTACHED) { mConsoleFloaty.setTitleIconsTint(color) } } + @ScriptInterface + fun getContentTextSize() = getFloatingConsoleView()?.textSize ?: 0f + @ScriptInterface fun setContentTextSize(size: Float) { configurator.setContentTextSize(size) @@ -656,7 +674,9 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } @ScriptInterface - fun getContentTextSize() = getFloatingConsoleView()?.textSize ?: 0f + fun getContentTextColors(): Map { + return getFloatingConsoleView()?.textColors ?: emptyMap() + } @ScriptInterface fun setContentTextColors(colors: Array) { @@ -667,39 +687,43 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } @ScriptInterface - fun getContentTextColors(): Map { - return getFloatingConsoleView()?.textColors ?: emptyMap() - } + fun getContentBackgroundColor() = configurator.contentBackgroundColor @ScriptInterface fun setContentBackgroundColor(@ColorInt color: Int) { configurator.setContentBackgroundColor(color) - uiHandler.post { - setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor()) + enqueueMutation(Stage.VIEW_ATTACHED) { + ViewUtils.setBackgroundColor(getFloatingConsoleView(), configurator.contentBackgroundColor) } } @ScriptInterface - fun getContentBackgroundColor() = configurator.contentBackgroundColor + fun getContentBackgroundTint() = configurator.contentBackgroundTint @ScriptInterface - fun setContentBackgroundTint(@ColorInt tint: Int) { + fun setContentBackgroundTint(@ColorInt tint: Int?) { configurator.setContentBackgroundTint(tint) 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 - fun setContentBackgroundAlpha(alpha: Int) { + fun getContentBackgroundAlpha() = configurator.contentBackgroundAlpha + + @ScriptInterface + fun setContentBackgroundAlpha(alpha: Double?) { configurator.setContentBackgroundAlpha(alpha) enqueueMutation(Stage.VIEW_ATTACHED) { - setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor()) + getFloatingConsoleView()?.background?.mutate()?.alpha = ColorUtils.toUint8(configurator.contentBackgroundAlpha, true) } } @ScriptInterface - fun resetContentBackgroundAlpha() = setContentBackgroundAlpha(-1) + fun resetContentBackgroundAlpha() = setContentBackgroundAlpha(DEFAULT_ALPHA) @ScriptInterface fun setTextSize(size: Float) { @@ -726,7 +750,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { } @ScriptInterface - fun setBackgroundAlpha(alpha: Int) { + fun setBackgroundAlpha(alpha: Double?) { setTitleBackgroundAlpha(alpha) setContentBackgroundAlpha(alpha) } @@ -760,7 +784,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { @JvmOverloads fun hideDelayed(exitOnCloseTimeout: Long = configurator.exitOnCloseTimeout) { - configurator.initExitOnClose() + configurator.resetExitOnClose() uiHandler.post { mCountDownTimer = object : CountDownTimer(exitOnCloseTimeout, 500) { 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 setContentViewBackgroundColor(view: FloatingConsoleView?, color: Int) { - 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 parseAlpha(alpha: Double?) = ColorUtils.toUint8(alpha ?: DEFAULT_ALPHA, true) / 255.0 private fun advanceStage(newStage: Stage) { if (newStage.ordinal <= mStage.ordinal) return @@ -883,17 +900,14 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { private set @Volatile - private var internalTitleBackgroundColor: Int? = null + var titleBackgroundColor: Int = context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES) @Volatile - private var internalTitleBackgroundAlpha: Int? = null + var titleBackgroundAlpha: Double = DEFAULT_ALPHA + private set @Volatile - private var internalTitleBackgroundTint: Int? = null - - val titleBackgroundColor: Int - get() = (internalTitleBackgroundColor ?: context.getColor(R.color.floating_console_title_bar_bg)) - .calibrateWith(internalTitleBackgroundAlpha, internalTitleBackgroundTint) + var titleBackgroundTint: Int? = null @Volatile var titleIconsTint: Int? = null @@ -908,20 +922,17 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { private set @Volatile - private var internalContentBackgroundColor: Int? = null + var contentBackgroundColor: Int = context.getColor(DEFAULT_CONTENT_BG_COLOR_RES) @Volatile - private var internalContentBackgroundAlpha: Int? = null + var contentBackgroundAlpha: Double = DEFAULT_ALPHA + private set @Volatile - private var internalContentBackgroundTint: Int? = null - - val contentBackgroundColor: Int - get() = (internalContentBackgroundColor ?: context.getColor(R.color.floating_console_content_bg)) - .calibrateWith(internalContentBackgroundAlpha, internalContentBackgroundTint) + var contentBackgroundTint: Int? = null @Volatile - var isTouchable: Boolean = true + var isTouchable: Boolean = DEFAULT_TOUCHABLE private set @Volatile @@ -940,8 +951,8 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { position = Point(x, y) } - fun setGravity(gravity: Int) = also { - this.gravity = gravity + fun setGravity(gravity: Int?) = also { + this.gravity = gravity ?: DEFAULT_GRAVITY } fun setTitle(title: CharSequence?) = also { @@ -952,44 +963,44 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { titleTextSize = size } - fun setTitleTextColor(color: Int) = also { - titleTextColor = color + fun setTitleTextColor(@OmniColor color: Any?) = also { + titleTextColor = color?.let { Colors.toIntRhino(it) } } - fun setTitleBackgroundColor(color: Int) = also { - internalTitleBackgroundColor = color + fun setTitleBackgroundColor(@OmniColor color: Any?) = also { + titleBackgroundColor = color?.let { Colors.toIntRhino(it) } ?: context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES) } - fun setTitleBackgroundTint(tint: Int) = also { - internalTitleBackgroundTint = tint + fun setTitleBackgroundTint(@OmniColor tint: Any?) = also { + titleBackgroundTint = tint?.let { Colors.toIntRhino(it) } } - fun setTitleBackgroundAlpha(alpha: Int) = also { - internalTitleBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_title_bar_bg) + fun setTitleBackgroundAlpha(alpha: Double?) = also { + titleBackgroundAlpha = parseAlpha(alpha) } - fun setTitleIconsTint(color: Int) = also { - titleIconsTint = color + fun setTitleIconsTint(@OmniColor color: Any?) = also { + titleIconsTint = color?.let { Colors.toIntRhino(it) } } fun setContentTextSize(size: Float) = also { contentTextSize = size } - fun setContentTextColors(colors: Array) = also { - contentTextColors = colors + fun setContentTextColors(colors: Array) = also { + contentTextColors = colors.map { it?.let { Colors.toIntRhino(it) } }.toTypedArray() } - fun setContentBackgroundColor(color: Int) = also { - internalContentBackgroundColor = color + fun setContentBackgroundColor(@OmniColor color: Any?) = also { + contentBackgroundColor = color.let { Colors.toIntRhino(it) } } - fun setContentBackgroundTint(tint: Int) { - internalContentBackgroundTint = tint + fun setContentBackgroundTint(@OmniColor tint: Any?) { + contentBackgroundTint = tint?.let { Colors.toIntRhino(it) } } - fun setContentBackgroundAlpha(alpha: Int) = also { - internalContentBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_content_bg) + fun setContentBackgroundAlpha(alpha: Double?) = also { + contentBackgroundAlpha = parseAlpha(alpha) } fun setTextSize(size: Float) = also { @@ -997,22 +1008,22 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { setContentTextSize(size) } - fun setTextColor(color: Int) = also { + fun setTextColor(@OmniColor color: Any?) = also { setTitleTextColor(color) setContentTextColors(Array(6) { color }) } - fun setBackgroundColor(color: Int) = also { + fun setBackgroundColor(@OmniColor color: Any?) = also { setTitleBackgroundColor(color) setContentBackgroundColor(color) } - fun setBackgroundTint(color: Int) = also { + fun setBackgroundTint(@OmniColor color: Any?) = also { setTitleBackgroundTint(color) setContentBackgroundTint(color) } - fun setBackgroundAlpha(alpha: Int) = also { + fun setBackgroundAlpha(alpha: Double?) = also { setTitleBackgroundAlpha(alpha) setContentBackgroundAlpha(alpha) } @@ -1042,21 +1053,21 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { title = null titleTextSize = null titleTextColor = null - internalTitleBackgroundColor = null - internalTitleBackgroundAlpha = null - internalTitleBackgroundTint = null - internalContentBackgroundColor = null - internalContentBackgroundAlpha = null - internalContentBackgroundTint = null + titleBackgroundColor = context.getColor(DEFAULT_TITLE_BAR_BG_COLOR_RES) + titleBackgroundAlpha = DEFAULT_ALPHA + titleBackgroundTint = null + contentBackgroundColor = context.getColor(DEFAULT_CONTENT_BG_COLOR_RES) + contentBackgroundAlpha = DEFAULT_ALPHA + contentBackgroundTint = null titleIconsTint = null contentTextSize = null contentTextColors = null - isTouchable = true + isTouchable = DEFAULT_TOUCHABLE isExitOnClose = false exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT } - internal fun initExitOnClose() { + internal fun resetExitOnClose() { setExitOnClose(false) exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT } @@ -1064,13 +1075,6 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { @JvmOverloads 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 { @@ -1078,12 +1082,16 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() { private val TAG = ConsoleImpl::class.java.simpleName const val DEFAULT_TITLE = "" + const val DEFAULT_ALPHA = 1.0 const val DEFAULT_TOUCHABLE = true const val DEFAULT_TOUCH_THROUGH = true const val DEFAULT_GRAVITY = Gravity.NO_GRAVITY const val DEFAULT_EXIT_ON_CLOSE_TIMEOUT = 5000L 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 + } } diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/console/Console.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/console/Console.kt index c443ed46..a89d67ee 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/console/Console.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/console/Console.kt @@ -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.util.Util import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException -import org.autojs.autojs.util.ColorUtils import org.autojs.autojs.util.ConsoleUtils import org.autojs.autojs.util.DisplayUtils import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE @@ -302,9 +301,7 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) { @RhinoRuntimeFunctionInterface fun build(scriptRuntime: ScriptRuntime, args: Array): ConsoleImpl.Configurator = ensureArgumentsAtMost(args, 1) { val (options) = it - val configurator = scriptRuntime.console.configurator.apply { - clearStates() - } + val configurator = scriptRuntime.console.configurator val opt = coerceObject(options, newNativeObject()) opt.entries.forEach { entry -> @@ -390,21 +387,21 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) { @JvmStatic @RhinoRuntimeFunctionInterface fun setTitleBackgroundTint(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setTitleBackgroundTint(S13n.color(arrayOf(it))) + scriptRuntime.console.setTitleBackgroundTint(it?.let { S13n.color(arrayOf(it)) }) scriptRuntime.consoleProxyObject } @JvmStatic @RhinoRuntimeFunctionInterface fun setTitleBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setTitleBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) + scriptRuntime.console.setTitleBackgroundAlpha(coerceNumber(it, 1.0)) scriptRuntime.consoleProxyObject } @JvmStatic @RhinoRuntimeFunctionInterface fun setTitleIconsTint(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setTitleIconsTint(S13n.color(arrayOf(it))) + scriptRuntime.console.setTitleIconsTint(it?.let { S13n.color(arrayOf(it)) }) scriptRuntime.consoleProxyObject } @@ -458,14 +455,14 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) { @JvmStatic @RhinoRuntimeFunctionInterface fun setContentBackgroundTint(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setContentBackgroundTint(S13n.color(arrayOf(it))) + scriptRuntime.console.setContentBackgroundTint(it?.let { S13n.color(arrayOf(it)) }) scriptRuntime.consoleProxyObject } @JvmStatic @RhinoRuntimeFunctionInterface fun setContentBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setContentBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) + scriptRuntime.console.setContentBackgroundAlpha(coerceNumber(it, 1.0)) scriptRuntime.consoleProxyObject } @@ -500,7 +497,7 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) { @JvmStatic @RhinoRuntimeFunctionInterface fun setBackgroundAlpha(scriptRuntime: ScriptRuntime, args: Array): ProxyObject = ensureArgumentsOnlyOne(args) { - scriptRuntime.console.setBackgroundAlpha(ColorUtils.toUnit8(coerceNumber(it, 1.0), true)) + scriptRuntime.console.setBackgroundAlpha(coerceNumber(it, 1.0)) scriptRuntime.consoleProxyObject } diff --git a/app/src/main/java/org/autojs/autojs/util/ColorUtils.kt b/app/src/main/java/org/autojs/autojs/util/ColorUtils.kt index 66469271..8c54020f 100644 --- a/app/src/main/java/org/autojs/autojs/util/ColorUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/ColorUtils.kt @@ -14,6 +14,7 @@ import org.autojs.autojs.core.image.ColorTable import org.autojs.autojs.theme.ThemeColor import org.autojs.autojs.theme.ThemeColorManager import java.math.RoundingMode +import kotlin.math.abs import kotlin.math.roundToInt import kotlin.text.RegexOption.IGNORE_CASE @@ -48,12 +49,19 @@ object ColorUtils { @JvmStatic @JvmOverloads - fun toUnit8(component: Double, takeNumOneAsPercent: Boolean = false) = when { - component < 1 -> (component * 255).roundToInt() - component == 1.0 && takeNumOneAsPercent -> 255 - else -> 255.coerceAtMost(component.roundToInt()) + fun toUint8(component: Double, takeNumOneAsPercent: Boolean = false): Int { + val epsilon = 1e-9 + return when { + 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 fun toInt(num: Number) = toInt(toHex(num)) 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 9f2a4d7c..60dcf7f0 100644 --- a/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/ViewUtils.kt @@ -13,9 +13,13 @@ import android.content.res.Configuration.UI_MODE_NIGHT_YES import android.content.res.Resources import android.graphics.ColorFilter import android.graphics.PorterDuff +import android.graphics.PorterDuff.Mode.SRC_IN import android.graphics.PorterDuffColorFilter import android.graphics.Rect +import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable +import android.graphics.drawable.GradientDrawable +import android.graphics.drawable.ShapeDrawable import android.os.Build import android.os.Looper import android.util.DisplayMetrics @@ -42,6 +46,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar +import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat @@ -96,6 +101,33 @@ object ViewUtils { 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 @JvmOverloads fun getStatusBarHeight(context: Context, withFallback: Boolean = true): Int { diff --git a/version.properties b/version.properties index 6ab19c26..c3d96cfe 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ -#Sat Nov 01 13:14:47 CST 2025 -BUILD_TIME=1761974087315 +#Sun Nov 02 19:59:28 CST 2025 +BUILD_TIME=1762084768045 COMPILE_SDK_VERSION=36 IMAGE_QUANT_CMAKE_VERSION=3.22.1 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 TARGET_SDK_VERSION=36 TARGET_SDK_VERSION_INRT=29 -VERSION_BUILD=3458 +VERSION_BUILD=3465 VERSION_NAME=6.7.0 Alpha10 VSCODE_EXT_REQUIRED_VERSION=1.0.8