6.7.0 - Alpha10 - 修复 console.build 多次调用重置问题及 (title/content)BackgroundColor 导致透明度或着色选项被覆盖问题 (issue #458)

This commit is contained in:
SuperMonster003
2025-10-31 09:58:59 +08:00
parent 6221196950
commit b8ecf3cc11
6 changed files with 85 additions and 47 deletions

View File

@@ -12,10 +12,6 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.alpha
import androidx.core.graphics.blue
import androidx.core.graphics.green
import androidx.core.graphics.red
import org.autojs.autojs.runtime.api.ScreenMetrics
import org.autojs.autojs.ui.enhancedfloaty.FloatyService
import org.autojs.autojs.ui.enhancedfloaty.ResizableExpandableFloaty.AbstractResizableExpandableFloaty
@@ -26,6 +22,7 @@ import org.autojs.autojs6.R
import org.autojs.autojs6.databinding.FloatingConsoleExpandBinding
import org.autojs.autojs6.databinding.FloatingWindowCollapseBinding
import kotlin.math.roundToInt
import androidx.core.view.isVisible
/**
* Created by Stardust on Apr 20, 2017.
@@ -124,7 +121,7 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
expandedBinding.moveOrResize.let {
it.setOnClickListener {
mMoveCursor?.run {
if (visibility == View.VISIBLE) {
if (isVisible) {
visibility = View.GONE
mResizer?.visibility = View.GONE
} else {
@@ -167,17 +164,18 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
fun getTitle(): String = mTitleText?.toString() ?: ""
fun setTitleBackgroundColor(@ColorInt color: Int) {
console.configurator.titleBackgroundColor = color
titleBarView?.apply { post { setTitleViewBackgroundColor(this, color) } }
console.configurator.setTitleBackgroundColor(color)
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } }
}
fun setTitleBackgroundTint(tint: Int) {
setTitleBackgroundColor(Color.argb(console.configurator.titleBackgroundColor.alpha, tint.red, tint.green, tint.blue))
console.configurator.setTitleBackgroundTint(tint)
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } }
}
fun setTitleBackgroundAlpha(alpha: Int) {
val bg = console.configurator.titleBackgroundColor
setTitleBackgroundColor(Color.argb(parseAlpha(alpha), bg.red, bg.green, bg.blue))
console.configurator.setTitleBackgroundAlpha(alpha)
titleBarView?.apply { post { setTitleViewBackgroundColor(this, console.configurator.titleBackgroundColor) } }
}
fun setTitleIconsTint(color: Int) {
@@ -205,11 +203,6 @@ class ConsoleFloaty(private val console: ConsoleImpl) : AbstractResizableExpanda
view.background = DrawableUtils.setDrawableColorFilterSrc(view.background, color)
}
private fun parseAlpha(alpha: Int) = when {
alpha < 0 -> console.configurator.titleBackgroundColor.alpha
else -> alpha
}
internal fun setCloseButton(resId: Int) {
mCloseButton?.apply {
post { setImageDrawable(ResourcesCompat.getDrawable(console.uiHandler.applicationContext.resources, resId, null)) }

View File

@@ -388,15 +388,15 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
isShowing = true
configurator.title?.let { setTitle(it) }
configurator.position?.run { setPosition(x, y, true) }
setGravity(configurator.gravity)
setGravity(getGravity())
configurator.titleTextSize?.let { setTitleTextSize(it) }
configurator.titleTextColor?.let { setTitleTextColor(it) }
setTitleBackgroundColor(configurator.titleBackgroundColor)
setTitleBackgroundColor(getTitleBackgroundColor())
configurator.titleIconsTint?.let { setTitleIconsTint(it) }
configurator.contentTextSize?.let { setContentTextSize(it) }
configurator.contentTextColors?.let { setContentTextColors(it) }
setContentBackgroundColor(configurator.contentBackgroundColor)
setTouchable(configurator.isTouchable)
setContentBackgroundColor(getContentBackgroundColor())
setTouchable(isTouchable())
mLockWindowCreated.wait(mDefaultSafeDelay)
}
}
@@ -603,7 +603,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
@ScriptInterface
fun setTitleBackgroundColor(@ColorInt color: Int) = runWithWindow({ configurator.setTitleBackgroundColor(color) }) {
mConsoleFloaty.setTitleBackgroundColor(color)
mConsoleFloaty.setTitleBackgroundColor(getTitleBackgroundColor())
}
@ScriptInterface
@@ -647,7 +647,7 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
@ScriptInterface
fun setContentBackgroundColor(@ColorInt color: Int) = runWithWindow({ configurator.setContentBackgroundColor(color) }) {
setContentViewBackgroundColor(getFloatingConsoleView(), color)
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor())
}
@ScriptInterface
@@ -655,18 +655,12 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
@ScriptInterface
fun setContentBackgroundTint(@ColorInt tint: Int) = runWithWindow({ configurator.setContentBackgroundTint(tint) }) {
val alpha = configurator.contentBackgroundColor.alpha
val niceAlpha = parseAlpha(alpha, R.color.floating_console_content_bg)
val color = Color.argb(niceAlpha, tint.red, tint.green, tint.blue)
setContentViewBackgroundColor(getFloatingConsoleView(), color)
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor())
}
@ScriptInterface
fun setContentBackgroundAlpha(alpha: Int) = runWithWindow({ configurator.setContentBackgroundAlpha(alpha) }) {
val bg = configurator.contentBackgroundColor
val niceAlpha = parseAlpha(alpha, R.color.floating_console_content_bg)
val color = Color.argb(niceAlpha, bg.red, bg.green, bg.blue)
setContentViewBackgroundColor(getFloatingConsoleView(), color)
setContentViewBackgroundColor(getFloatingConsoleView(), getContentBackgroundColor())
}
@ScriptInterface
@@ -851,8 +845,17 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private set
@Volatile
var titleBackgroundColor: Int = context.getColor(R.color.floating_console_title_bar_bg)
internal set
private var internalTitleBackgroundColor: Int? = null
@Volatile
private var internalTitleBackgroundAlpha: Int? = null
@Volatile
private var internalTitleBackgroundTint: Int? = null
val titleBackgroundColor: Int
get() = (internalTitleBackgroundColor ?: context.getColor(R.color.floating_console_title_bar_bg))
.calibrateWith(internalTitleBackgroundAlpha, internalTitleBackgroundTint)
@Volatile
var titleIconsTint: Int? = null
@@ -867,8 +870,17 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
private set
@Volatile
var contentBackgroundColor: Int = context.getColor(R.color.floating_console_content_bg)
private set
private var internalContentBackgroundColor: Int? = null
@Volatile
private var internalContentBackgroundAlpha: Int? = null
@Volatile
private var internalContentBackgroundTint: Int? = null
val contentBackgroundColor: Int
get() = (internalContentBackgroundColor ?: context.getColor(R.color.floating_console_content_bg))
.calibrateWith(internalContentBackgroundAlpha, internalContentBackgroundTint)
@Volatile
var isTouchable: Boolean = true
@@ -907,16 +919,15 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
}
fun setTitleBackgroundColor(color: Int) = also {
titleBackgroundColor = color
internalTitleBackgroundColor = color
}
fun setTitleBackgroundTint(tint: Int) = also {
titleBackgroundColor = titleBackgroundColor.run { Color.argb(alpha, tint.red, tint.green, tint.blue) }
internalTitleBackgroundTint = tint
}
fun setTitleBackgroundAlpha(alpha: Int) = also {
val niceAlpha = parseAlpha(alpha, R.color.floating_console_title_bar_bg)
titleBackgroundColor = titleBackgroundColor.run { Color.argb(niceAlpha, red, green, blue) }
internalTitleBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_title_bar_bg)
}
fun setTitleIconsTint(color: Int) = also {
@@ -932,16 +943,15 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
}
fun setContentBackgroundColor(color: Int) = also {
contentBackgroundColor = color
internalContentBackgroundColor = color
}
fun setContentBackgroundTint(tint: Int) {
contentBackgroundColor = contentBackgroundColor.run { Color.argb(alpha, tint.red, tint.green, tint.blue) }
internalContentBackgroundTint = tint
}
fun setContentBackgroundAlpha(alpha: Int) = also {
val niceAlpha = parseAlpha(alpha, R.color.floating_console_content_bg)
contentBackgroundColor = contentBackgroundColor.run { Color.argb(niceAlpha, red, green, blue) }
internalContentBackgroundAlpha = parseAlpha(alpha, R.color.floating_console_content_bg)
}
fun setTextSize(size: Float) = also {
@@ -987,6 +997,27 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
isTouchable = !touchThrough
}
fun clearStates() {
size = null
position = null
gravity = DEFAULT_GRAVITY
title = null
titleTextSize = null
titleTextColor = null
internalTitleBackgroundColor = null
internalTitleBackgroundAlpha = null
internalTitleBackgroundTint = null
internalContentBackgroundColor = null
internalContentBackgroundAlpha = null
internalContentBackgroundTint = null
titleIconsTint = null
contentTextSize = null
contentTextColors = null
isTouchable = true
isExitOnClose = false
exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT
}
internal fun initExitOnClose() {
setExitOnClose(false)
exitOnCloseTimeout = DEFAULT_EXIT_ON_CLOSE_TIMEOUT
@@ -995,6 +1026,13 @@ 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 {
@@ -1010,4 +1048,4 @@ open class ConsoleImpl(val uiHandler: UiHandler) : AbstractConsole() {
}
}
}

View File

@@ -10,6 +10,8 @@ import org.autojs.autojs.core.console.ConsoleImpl.Companion.DEFAULT_EXIT_ON_CLOS
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.extension.AnyExtensions.jsBrief
import org.autojs.autojs.extension.FlexibleArray
import org.autojs.autojs.extension.FlexibleArray.Companion.component1
import org.autojs.autojs.extension.FlexibleArray.Companion.component2
import org.autojs.autojs.extension.ScriptableExtensions.hasProp
import org.autojs.autojs.extension.ScriptableExtensions.prop
import org.autojs.autojs.extension.ScriptableObjectExtensions.inquire
@@ -300,7 +302,9 @@ class Console(scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRuntime) {
@RhinoRuntimeFunctionInterface
fun build(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ConsoleImpl.Configurator = ensureArgumentsAtMost(args, 1) {
val (options) = it
val configurator = scriptRuntime.console.configurator
val configurator = scriptRuntime.console.configurator.apply {
clearStates()
}
val opt = coerceObject(options, newNativeObject())
opt.entries.forEach { entry ->