- Global - 全局对象
- Automator - 自动化
- AutoJs6 - 本体应用
- App - 通用应用
- Color - 颜色
- Image - 图像
- OCR - 光学字符识别
- Barcode - 条码
- QR Code - 二维码
- Keys - 按键
- Device - 设备
- Storage - 储存
- File - 文件
- Engine - 引擎
- Task - 任务
- Module - 模块
- Plugins - 插件
- Toast - 消息浮动框
- Notice - 消息通知
- Console - 控制台
- Shell
- Shizuku
- Media - 多媒体
- Sensor - 传感器
- Recorder - 记录器
- Timer - 定时器
- Thread - 线程
- Continuation - 协程
- Event - 事件监听
- Dialog - 对话框
- Floaty - 悬浮窗
- Canvas - 画布
- UI - 用户界面
- Web - 万维网
- HTTP
- Base64
- Crypto - 密文
- OpenCC - 中文转换
- Internationalization - 国际化
- Standardization - 标准化
- E4X
- UiSelector - 选择器
- UiObject - 控件节点
- UiObjectCollection - 控件集合
- UiObjectActions - 控件节点行为
- WebSocket
- EventEmitter - 事件发射器
- ImageWrapper - 包装图像类
- App - 应用枚举类
- Color - 颜色类
- Version - 版本工具类
- Polyfill - 代码填泥
- Arrayx - Array 扩展
- Numberx - Number 扩展
- Mathx - Math 扩展
- Glossaries - 术语
- HttpHeader - HTTP 标头
- HttpRequestMethods - HTTP 请求方法
- MimeType - MIME 类型
- NotificationChannel - 通知渠道
- Data Types - 数据类型
- Omnipotent Types - 全能类型
- Storage - 存储类
- AndroidBundle
- AndroidRect
- CryptoCipherOptions
- CryptoKey
- CryptoKeyPair
- ConsoleBuildOptions
- HttpRequestBuilderOptions
- HttpRequestHeaders
- HttpResponseBody
- HttpResponseHeaders
- HttpResponse
- InjectableWebClient
- InjectableWebView
- NoticeOptions
- NoticeChannelOptions
- NoticePresetConfiguration
- NoticeBuilder
- Okhttp3HttpUrl
- OcrOptions
- Okhttp3Request
- OpenCVPoint
- OpenCVRect
- OpenCVSize
- OpenCCConversion
AutoJs6 文档 - 6.6.4
标准化 (Standardization)#
此章节待补充或完善...
Marked by SuperMonster003 on Apr 9, 2023.
s13n 模块用于将多种不同类型的数据统一转换为标准类型.
例如在 AutoJs6 中, 一个颜色参数通常可接受 [ ColorHex / ColorInt / ColorName / Color / ThemeColor ] 等多种类型:
console.setBackgroundColor('orange');
console.setBackgroundColor('#663399');
console.setBackgroundColor(autojs.themeColor);
console.setBackgroundColor(Color('blue').setAlpha(0.75));
上述这些颜色设置方式均有效.
但安卓 API 中涉及颜色的参数往往只接受 ColorInt
类型:
activity.window.setStatusBarColor('orange'); /* 抛出异常. */
activity.window.setStatusBarColor(Color('orange')); /* 抛出异常. */
activity.window.setStatusBarColor(Color('orange').toInt()); /* 正常. */
activity.window.setStatusBarColor(colors.toInt('orange')); /* 效果同上. */
上述示例的颜色参数只能使用 ColorInt
, 对应 JavaScript 的 number
类型.
s13n 模块对颜色参数统一转换为 ColorInt
:
s13n.color('red'); /* 相当于 colors.toInt('red') . */
因此对于上述设置通知栏颜色的示例, 使用 s13n 模块即可不必关心参数原本的类型:
activity.window.setStatusBarColor(s13n.color('orange')); /* 正常. */
activity.window.setStatusBarColor(s13n.color(Color('orange'))); /* 正常. */
activity.window.setStatusBarColor(s13n.color(Color('orange').toInt())); /* 正常. */
activity.window.setStatusBarColor(s13n.color(Color('orange').toHex())); /* 正常. */
不过对于 AutoJs6 内置模块 (colors, device, images 等), 传参时无需使用 s13n 进行标准化.
因为在模块内部的实现代码中, 已经借助 s13n 进行了标准化操作.
例如以下代码片段是 console.setBackgroundColor
的内部实现代码:
function setBackgroundColor(c) {
return runtime.console.setBackgroundColor(s13n.color(c));
}
上述示例可以看出, s13n 模块对参数 c
进行了颜色标准化操作.
下表列出了 s13n 模块中不同方法接受类型与输出类型:
方法名称 | 描述 | 接受类型 | 输出类型 |
---|---|---|---|
color | 颜色 | OmniColor | ColorInt |
s13n
[m] color#
color(o)#
将颜色参数 o
标准化为 ColorInt.
s13n.color('red') === s13n.color('#F00'); // true
s13n.color('#FB663399') === s13n.color(0xFB663399); // true
[m] throwable#
throwable(o)#
- o { OmniThrowable }
- returns { java.lang.Throwable }
将可抛异常参数 o
标准化为 java.lang.Throwable 类型.
let a = s13n.throwable('error message');
let b = s13n.throwable(Error('error message'));
let c = (/* @IIFE */ () => {
try {
nothing++;
} catch (e) {
return s13n.throwable(e.rhinoException);
}
})();
[ a, b, c ].every(o => o instanceof java.lang.Throwable); // true