6.7.0 - Alpha - android.graphics.Paint#setColor 支持正常解析 ColorInt/ColorHex/ColorName 等颜色参数

This commit is contained in:
SuperMonster003
2025-06-15 14:25:39 +08:00
parent 1c42267fee
commit 8838532d9f
4 changed files with 21 additions and 4 deletions

View File

@@ -0,0 +1,12 @@
package org.autojs.autojs.core.image
import android.graphics.Paint
import org.autojs.autojs.runtime.api.augment.colors.Colors
class RhinoPaint(paint: Paint) : Paint(paint) {
override fun setColor(color: Long) = setColor(Colors.toIntRhino(color))
fun setColor(color: Any?) = setColor(Colors.toIntRhino(color))
}

View File

@@ -1,8 +1,10 @@
package org.autojs.autojs.engine
import android.annotation.SuppressLint
import android.graphics.Paint
import android.util.Log
import android.view.View
import org.autojs.autojs.core.image.RhinoPaint
import org.autojs.autojs.core.ui.ViewExtras
import org.autojs.autojs.engine.module.AssetAndUrlModuleSourceProvider
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
@@ -207,6 +209,7 @@ open class RhinoJavaScriptEngine(private val scriptRuntime: ScriptRuntime, priva
override fun wrapAsJavaObject(cx: Context?, scope: Scriptable, javaObject: Any?, staticType: Class<*>?): Scriptable? {
return when (javaObject) {
is View -> ViewExtras.getNativeView(scope, /* view = */ javaObject, staticType, runtime)
is Paint -> super.wrapAsJavaObject(cx, scope, RhinoPaint(javaObject), staticType)
else -> super.wrapAsJavaObject(cx, scope, javaObject, staticType)
}
}