From 10a3a8eec0c3f0a46354fc9c63fcd96801c3b531 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Sat, 24 Jan 2026 16:23:43 +0800 Subject: [PATCH] =?UTF-8?q?6.7.0=20-=20Alpha18=20-=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?dialogs.build=20=E6=96=B9=E6=B3=95=20"linkify"=20=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E5=8A=9F=E8=83=BD=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 3 +- .../runtime/api/augment/dialogs/Dialogs.kt | 72 +++++++++++++------ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index bee40794..b248025d 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -1,7 +1,7 @@ { "$data": { "v6.7.0": { - "released_date": "2026/01/22", + "released_date": "2026/01/24", "feature": [ "插件中心功能, 支持插件的安装/卸载/更新等操作 (入口: 主页抽屉按钮/主页标签页)", "Paddle OCR (PP-OCRv5) 插件, 用于光学字符识别", @@ -61,6 +61,7 @@ "无法使用 console/toast 等方法显示 BigInt 数据类型的问题", "部分全局对象可能丢失 JavaScript 原型属性及方法的问题", "使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题", + "dialogs.build 方法 linkify 选项参数功能失效的问题", "dialogs.build 方法无法使用 MaterialDialog.Builder 原生选项参数的问题", "dialogs.build 方法可能破坏对象参数原有数据的问题", "canvas 元素控件 setMaxFps 方法内部帧率计算错误", diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/dialogs/Dialogs.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/dialogs/Dialogs.kt index 346bc7c5..262585e0 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/dialogs/Dialogs.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/dialogs/Dialogs.kt @@ -43,7 +43,7 @@ import org.autojs.autojs.util.RhinoUtils.isUiThread import org.autojs.autojs.util.RhinoUtils.js_eval import org.autojs.autojs.util.RhinoUtils.newBaseFunction import org.autojs.autojs.util.RhinoUtils.newNativeObject -import org.autojs.autojs.util.StringUtils.uppercaseFirstChar +import org.autojs.autojs.util.StringUtils.looseMatches import org.autojs.autojs6.R import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.Context @@ -93,9 +93,36 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { "alwaysCallMultiChoiceCallback" to PropertyConverter.BOOLEAN, ) - private val presetLinkifyMasks = listOf("all", "emailAddresses", "mapAddresses", "phoneNumbers", "webUrls") + @Suppress("DEPRECATION") + private val linkifyMasksMappings = listOf( + "webUrls" to Linkify.WEB_URLS, + "web" to Linkify.WEB_URLS, + "url" to Linkify.WEB_URLS, + "urls" to Linkify.WEB_URLS, - private val presetAnimations = listOf("default", "activity", "dialog", "inputMethod", "toast", "translucent") + "emailAddresses" to Linkify.EMAIL_ADDRESSES, + "email" to Linkify.EMAIL_ADDRESSES, + + "phoneNumbers" to Linkify.PHONE_NUMBERS, + "phone" to Linkify.PHONE_NUMBERS, + "tel" to Linkify.PHONE_NUMBERS, + + "mapAddresses" to Linkify.MAP_ADDRESSES, + "addresses" to Linkify.MAP_ADDRESSES, + "address" to Linkify.MAP_ADDRESSES, + "street" to Linkify.MAP_ADDRESSES, + + "all" to Linkify.ALL, + ) + + private val animationMappings = listOf( + "default" to android.R.style.Animation, + "activity" to android.R.style.Animation_Activity, + "dialog" to android.R.style.Animation_Dialog, + "inputMethod" to android.R.style.Animation_InputMethod, + "toast" to android.R.style.Animation_Toast, + "translucent" to android.R.style.Animation_Translucent, + ) private val customJsPropertiesForBuild: Set = setOf( "animation", @@ -606,18 +633,19 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { } private fun applyBuiltDialogProperties(scriptRuntime: ScriptRuntime, dialog: JsDialog, properties: NativeObject) { - if (!properties.prop("linkify").isJsString() && Context.toBoolean(properties.prop("linkify"))) { + if (!properties.prop("linkify").isJsNullish() && Context.toBoolean(properties.prop("linkify"))) { + val linkifyRaw = when (properties.prop("linkify")) { + true -> "all" + else -> properties.inquire("linkify", transformer = ::coerceString) + } val autoLinkMask = run { - var linkify = when (properties.prop("linkify")) { - true -> "all" - else -> properties.inquire("linkify", ::coerceString, "all") - } - if (presetLinkifyMasks.contains(linkify)) { - linkify = linkify.replace(Regex("[A-Z]"), "_$&").uppercase() - } - runCatching { Linkify::class.java.getDeclaredField(linkify).get(null) }.getOrElse { e -> - throw IllegalArgumentException("Unknown property linkify ${linkify.jsBrief()} of argument properties for dialogs.build", e) - }.let(::coerceIntNumber) + linkifyRaw?.let { + linkifyMasksMappings.firstOrNull { + it.first.looseMatches(linkifyRaw) + }?.second + } ?: throw IllegalArgumentException( + "Unknown property linkify ${linkifyRaw.jsBrief()} of argument properties for dialogs.build", + ) } dialog.contentView?.let { view -> val text = view.text @@ -742,20 +770,18 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) { // # } if (!properties.prop("animation").isJsNullish() && Context.toBoolean(properties.prop("animation"))) { - val animation = when (properties.prop("animation")) { + val animationRaw = when (properties.prop("animation")) { true -> "default" else -> properties.inquire("animation", ::coerceString, "default") } - require(presetAnimations.contains(animation)) { "Unknown linkify: $animation" } + val animationStyle = animationMappings.firstOrNull { + it.first.looseMatches(animationRaw) + }?.second ?: throw IllegalArgumentException( + "Unknown property animation ${animationRaw.jsBrief()} of argument properties for dialogs.build", + ) dialog.window?.let { win -> UI.postRhinoRuntime(scriptRuntime, newBaseFunction("action", { - if (animation == "default") { - win.setWindowAnimations(android.R.style.Animation) - } else { - val suffix = animation.replace('-', '_').uppercaseFirstChar() - val animationStyle = android.R.style::class.java.getDeclaredField("Animation_$suffix").getInt(null) - win.setWindowAnimations(animationStyle) - } + win.setWindowAnimations(animationStyle) }, NOT_CONSTRUCTABLE)) } }