- 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
全能类型 (Omnipotent Types)#
此章节待补充或完善...
Marked by SuperMonster003 on Apr 9, 2023.
全能类型是一种聚合类型.
AutoJs6 模块中, 一个参数往往接受多种不同的类型, 这些类型均可体现这个参数的含义. 这样的类型成为全能类型.
如对于 颜色 (color)
, 有 ColorHex 和 ColorName 等多种类型可以表示, 它们都可以作为实参传入方法中:
/* 需要为 console 悬浮窗设置一个浅蓝色标题. */
/* 以下 4 种方法分别传入不同类型的参数, 但实现了同样的效果. */
console.setTitleTextColor('light-blue'); /* ColorName 类型. */
console.setTitleTextColor('#ADD8E6'); /* ColorHex 类型. */
console.setTitleTextColor(Color('#ADD8E6').toInt()); /* ColorInt 类型. */
console.setTitleTextColor(Color('#ADD8E6')); /* Color 类型. */
console.show(); /* 显示控制台悬浮窗. */
上述示例中 console.setTitleTextColor
的方法签名可以写成以下形式:
console.setTitleTextColor(color: OmniColor): void
其中使用 OmniColor
这个全能类型代表了颜色聚合类型.
OmniColor#
颜色聚合类型.
类型 | 简述 | 示例 |
---|---|---|
ColorHex | 颜色代码 | #663399 |
ColorInt | 颜色整数 | -10079335 |
ColorName | 颜色名称 | 'rebecca-purple' |
Color | 颜色类 | Color('#663399') |
ThemeColor | 主题颜色类 | autojs.themeColor |
OmniColor
不仅可用于参数传入方法中, 还可以作为 XML 元素的属性值:
'ui';
ui.layout(<vertical>
<button text="click to start" color="#006400"/>
</vertical>);
上述示例设置按钮布局的文字颜色为深绿色, 使用了 ColorHex 作为颜色值.
使用 ColorName 作为颜色值也可达到相同的效果:
'ui';
ui.layout(<vertical>
<button text="click to start" color="dark-green"/>
</vertical>);
使用 ColorInt 作为颜色值同样可以达到相同的效果:
'ui';
ui.layout(<vertical>
<button text="click to start" color="-16751616"/>
</vertical>);
如需使用主题色作为颜色值, 需要使用一对花括号以及绑定全局作用域的表达式:
'ui';
ui.layout(<vertical>
<button text="click to start" color="{{autojs.themeColor}}"/>
</vertical>);
OmniIntent#
Intent 聚合类型.
类型 | 简述 | 示例 |
---|---|---|
Intent | 意图类 | new Intent().setAction( ... ) / app.intent({ ... }) |
IntentOptions | 意图选项 | { action: ... , className: ... , data: ... } |
IntentShortFormForActivity | 意图活动简称 | docs / home / settings / console / about |
IntentUriString | 意图 URI 字符串 | 'https://msn.com' / 'msn.com' |
OmniVibrationPattern#
振动模式聚合类型.
类型 | 简述 | 示例 |
---|---|---|
number[] | 传统振动模式 (按数字代表的启停间隔振动) | [ 0, 200, 0, 200, 0, 200 ] |
string | 文本 (按文本对应的摩斯电码振动) | 'hello' |
用于模拟 SOS (紧急求救信号) 的示例:
device.vibrate([ 100, 100, 100, 100, 100, 300, 300, 100, 300, 100, 300, 300, 100, 100, 100, 100, 100 ], 0);
device.vibrate('SOS'); /* 效果同上. */
OmniRegion#
区域聚合类型.
类型 | 简述 | 示例 |
---|---|---|
number[] | 数字数组, [ X 坐标, Y 坐标, 宽, 高 ] | [ 0, 0, 200, 400 ] |
OpenCVRect | org.opencv.core.Rect 类型 |
1. images.buildRegion(img, [ 0, 0, 200, 400 ]) 2. new org.opencv.core.Rect(x, y, w, h) |
AndroidRect | android.graphics.Rect 类型 |
1. pickup(/\w+/, 'bounds') 2. new android.graphics.Rect(left, top, right, bottom) |
将一个 500 × 500 的图片裁剪其中心区域 300 × 300 的示例:
let img = images.read('...');
let imgWidth = img.getWidth(); // 500
let imgHeight = img.getHeight(); // 500
let clipWidth = 300;
let clipHeight = 300;
let clipX = (imgWidth - clipWidth) / 2;
let clipY = (imgHeight - clipHeight) / 2;
/* 使用 number[] 作为区域. */
images.clip(img, [ clipX, clipY, clipWidth, clipHeight ]);
/* 使用 OpenCVRect 作为区域. */
images.clip(img, new org.opencv.core.Rect(clipX, clipY, clipWidth, clipHeight));
/* 使用 AndroidRect 作为区域. */
let left = clipX;
let top = clipY;
let right = clipX + clipWidth;
let bottom = clipY + clipHeight;
images.clip(img, new android.graphics.Rect(left, top, right, bottom));
/* AndroidRect 结合控件的应用. */
/* 假设屏幕的活动窗口中存在一个控件, id 为 aim, 它的控件矩形区域恰好为所需区域. */
let bounds = pickup({ id: 'aim' }, 'bounds');
images.clip(img, bounds); /* bounds 是一个 AndroidRect 实例. */
OmniThrowable#
可抛异常聚合类型.
类型 | 简述 | 示例 |
---|---|---|
Error | AutoJs6 内置错误类型 | 1. Error('error') 2. TypeError('error') |
java.lang.Throwable | Throwable 及其所有子类型 |
1. new java.lang.Exception('error') 2. try { a++ } catch(e) { e.rhinoException } |
string | 字符串, 表示异常消息, 将被包装为 java.lang.Exception 实例 |
'An error has occurred' |
使用 console.printAllStackTrace 打印详细栈追踪的示例:
try {
a++;
} catch (e) {
console.printAllStackTrace(e); /* Error 实例. */
console.printAllStackTrace(e.rhinoException); /* java.lang.Throwable 实例. */
console.printAllStackTrace(e.message); /* 字符串变量. */
}