From d61e47cf6bd83030480a69a74ca2c391d2c27dfc Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Tue, 30 Jan 2018 11:45:54 +0800 Subject: [PATCH] docs --- app/src/main/assets/docs/all.html | 6 +- app/src/main/assets/docs/app.html | 6 +- app/src/main/assets/docs/console.html | 6 +- .../docs/coordinates-based-automation.html | 6 +- app/src/main/assets/docs/device.html | 6 +- app/src/main/assets/docs/dialogs.html | 6 +- app/src/main/assets/docs/documentation.html | 108 +- app/src/main/assets/docs/engines.html | 6 +- app/src/main/assets/docs/events.html | 6 +- app/src/main/assets/docs/files.html | 6 +- app/src/main/assets/docs/floaty.html | 6 +- app/src/main/assets/docs/globals.html | 6 +- app/src/main/assets/docs/http.html | 6 +- app/src/main/assets/docs/images.html | 34 +- app/src/main/assets/docs/index.html | 12 +- app/src/main/assets/docs/keys.html | 6 +- app/src/main/assets/docs/modules.html | 6 +- app/src/main/assets/docs/overview.html | 40 +- app/src/main/assets/docs/qa.html | 60 +- app/src/main/assets/docs/shell.html | 6 +- app/src/main/assets/docs/storages.html | 6 +- app/src/main/assets/docs/threads.html | 6 +- app/src/main/assets/docs/timers.html | 6 +- app/src/main/assets/docs/ui.html | 6 +- app/src/main/assets/docs/util.html | 6 +- .../assets/docs/widgets-based-automation.html | 1115 ++++++++++------- 26 files changed, 914 insertions(+), 575 deletions(-) diff --git a/app/src/main/assets/docs/all.html b/app/src/main/assets/docs/all.html index ef9bb41b..051d0aa2 100644 --- a/app/src/main/assets/docs/all.html +++ b/app/src/main/assets/docs/all.html @@ -19,7 +19,7 @@
@@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/app.html b/app/src/main/assets/docs/app.html index 7281f318..59b6b380 100644 --- a/app/src/main/assets/docs/app.html +++ b/app/src/main/assets/docs/app.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/console.html b/app/src/main/assets/docs/console.html index b0fdec83..2eb3bb30 100644 --- a/app/src/main/assets/docs/console.html +++ b/app/src/main/assets/docs/console.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/coordinates-based-automation.html b/app/src/main/assets/docs/coordinates-based-automation.html index 476444ae..ab7783c3 100644 --- a/app/src/main/assets/docs/coordinates-based-automation.html +++ b/app/src/main/assets/docs/coordinates-based-automation.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/device.html b/app/src/main/assets/docs/device.html index bcf64df1..7d0daeb8 100644 --- a/app/src/main/assets/docs/device.html +++ b/app/src/main/assets/docs/device.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/dialogs.html b/app/src/main/assets/docs/dialogs.html index ffe2d8bb..f982d373 100644 --- a/app/src/main/assets/docs/dialogs.html +++ b/app/src/main/assets/docs/dialogs.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/documentation.html b/app/src/main/assets/docs/documentation.html index a4201ebd..c9412291 100644 --- a/app/src/main/assets/docs/documentation.html +++ b/app/src/main/assets/docs/documentation.html @@ -2,7 +2,7 @@ - About this Documentation | Auto.js 3.0.0 文档 + 关于本文档 | Auto.js 3.0.0 文档 @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • @@ -72,10 +72,11 @@

    目录

    -

    About this Documentation#

    +

    关于本文档#

    -

    The goal of this documentation is to comprehensively explain the Node.js -API, both from a reference as well as a conceptual point of view. Each -section describes a built-in module or high-level concept.

    -

    Where appropriate, property types, method arguments, and the arguments -provided to event handlers are detailed in a list underneath the topic -heading.

    -

    Every .html document has a corresponding .json document presenting -the same information in a structured manner. This feature is -experimental, and added for the benefit of IDEs and other utilities that -wish to do programmatic things with the documentation.

    -

    Every .html and .json file is generated based on the corresponding -.md file in the doc/api/ folder in Node.js's source tree. The -documentation is generated using the tools/doc/generate.js program. -The HTML template is located at doc/template.html.

    -

    If errors are found in this documentation, please submit an issue -or see the contributing guide for directions on how to submit a patch.

    -

    Stability Index#

    - -

    Throughout the documentation are indications of a section's -stability. The Node.js API is still somewhat changing, and as it -matures, certain parts are more reliable than others. Some are so -proven, and so relied upon, that they are unlikely to ever change at -all. Others are brand new and experimental, or known to be hazardous -and in the process of being redesigned.

    -

    The stability indices are as follows:

    -
    Stability: 0 - Deprecated This feature is known to be problematic, and changes may be planned. Do not rely on it. Use of the feature may cause warnings to be emitted. Backwards compatibility across major versions should not be expected.
    Stability: 1 - Experimental This feature is still under active development and subject to non-backwards compatible changes, or even removal, in any future version. Use of the feature is not recommended in production environments. Experimental features are not subject to the Node.js Semantic Versioning model.

    Note: Caution must be used when making use of Experimental features, -particularly within modules that may be used as dependencies (or dependencies -of dependencies) within a Node.js application. End users may not be aware that -experimental features are being used, and therefore may experience unexpected -failures or behavioral changes when changes occur. To help avoid such surprises, -Experimental features may require a command-line flag to explicitly enable -them, or may cause a process warning to be emitted. By default, such warnings -are printed to stderr and may be handled by attaching a listener to the -process.on('warning') event.

    -
    Stability: 2 - Stable The API has proven satisfactory. Compatibility with the npm ecosystem is a high priority, and will not be broken unless absolutely necessary.

    JSON Output#

    -
    Stability: 1 - Experimental

    Every HTML file in the markdown has a corresponding JSON file with the -same data.

    -

    This feature was added in Node.js v0.6.12. It is experimental.

    -

    Syscalls and man pages#

    -

    System calls like open(2) and read(2) define the interface between user programs -and the underlying operating system. Node functions which simply wrap a syscall, -like fs.open(), will document that. The docs link to the corresponding man -pages (short for manual pages) which describe how the syscalls work.

    -

    Note: some syscalls, like lchown(2), are BSD-specific. That means, for -example, that fs.lchown() only works on macOS and other BSD-derived systems, -and is not available on Linux.

    -

    Most Unix syscalls have Windows equivalents, but behavior may differ on Windows -relative to Linux and macOS. For an example of the subtle ways in which it's -sometimes impossible to replace Unix syscall semantics on Windows, see Node -issue 4760.

    +

    本文档为Auto.js的文档,解释了Auto.js各个模块的API的使用方法、作用和例子。

    +

    文档借助Node.js的文档构建工具生成,并在github上开源(https://github.com/hyb1996/AutoJs-Docs ),目前由开发者维护。

    +

    API稳定性#

    +

    由于Auto.js处于活跃的更新和开发状态,API可能随时有变动,我们用Stability来标记模块、函数的稳定性。这些标记包括:

    +
    Stability: 0 - Deprecated 弃用的函数、模块或特性,在未来的更新中将很快会被移除或更改。应该在脚本中移除对这些函数的使用,以免后续出现意料之外的问题。
    Stability: 1 - Experimental 实验性的函数、模块或特性,在未来的更新中可能会更改或移除。应该谨慎使用这些函数或模块,或者仅用作临时或试验用途。
    Stability: 2 - Stable 稳定的函数、模块或特性,在未来的更新中这些模块已有的函数一般不会被更改,会保证后向兼容性。

    如何阅读本文档#

    +

    先看一个例子,下面是基于控件的操作模拟的章节中input函数的部分说明。

    +

    input([i, ]text)#

    +
    +

    input表示函数名,括号内的[i, ]text为函数的参数。下面是参数列表,"number"表示参数i的类型为数值,"string"表示参数text的类型为字符串。

    +

    例如input(1, "啦啦啦"),执行这个语句会在屏幕上的第2个输入框处输入"啦啦啦"。

    +

    方括号[ ]表示参数为可选参数。也就是说,可以省略i直接调用input。例如input("嘿嘿嘿"),按照文档,这个语句会在屏幕上所有输入框输入"嘿嘿嘿"。

    +

    调用有可选参数的函数时请不要写上方括号。

    +

    我们再看第二个例子。图片和图色处理中detectsColor函数的部分说明。

    +

    images.detectsColor(image, color, x, y[, threshold = 16, algorithm = "diff"])#

    +
    +

    同样地,[, threshold = 16, algorithm = "rgb"]为可选参数,并且,等于号=后面的值为参数的默认值。也就是如果不指定该参数,则该参数将会为这个值。

    +

    例如 images.detectsColor(captureScreen(), "#112233", 100, 200) 相当于 images.detectsColor(captureScreen(), "#112233", 100, 200, 16, "rgb"), +而images.detectsColor(captureScreen(), "#112233", 100, 200, 64) 相当于images.detectsColor(captureScreen(), "#112233", 100, 200, 64, "rgb")

    +

    调用有可选参数及默认值的函数时请不要写上方括号和等于号。

    diff --git a/app/src/main/assets/docs/engines.html b/app/src/main/assets/docs/engines.html index a73b78e4..b2689de1 100644 --- a/app/src/main/assets/docs/engines.html +++ b/app/src/main/assets/docs/engines.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/events.html b/app/src/main/assets/docs/events.html index d9e69e0a..4d6d08b0 100644 --- a/app/src/main/assets/docs/events.html +++ b/app/src/main/assets/docs/events.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/files.html b/app/src/main/assets/docs/files.html index 4c6ba494..851ed9ac 100644 --- a/app/src/main/assets/docs/files.html +++ b/app/src/main/assets/docs/files.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/floaty.html b/app/src/main/assets/docs/floaty.html index 731b9ca0..50ca5fc3 100644 --- a/app/src/main/assets/docs/floaty.html +++ b/app/src/main/assets/docs/floaty.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/globals.html b/app/src/main/assets/docs/globals.html index 2d272f68..afa82ee4 100644 --- a/app/src/main/assets/docs/globals.html +++ b/app/src/main/assets/docs/globals.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/http.html b/app/src/main/assets/docs/http.html index 37700cfd..1e09b8b1 100644 --- a/app/src/main/assets/docs/http.html +++ b/app/src/main/assets/docs/http.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • diff --git a/app/src/main/assets/docs/images.html b/app/src/main/assets/docs/images.html index 6762bc6b..21735e25 100644 --- a/app/src/main/assets/docs/images.html +++ b/app/src/main/assets/docs/images.html @@ -19,7 +19,7 @@
    @@ -28,7 +28,7 @@
  • Q&A - 常见问题
  • App - 应用
  • Console - 控制台
  • -
  • CoordinatesBasedAutomation - 基于坐标的触摸模拟
  • +
  • CoordinatesBasedAutomation - 基于坐标的操作
  • Device - 设备
  • Dialogs - 对话框
  • Engines - 脚本引擎
  • @@ -40,7 +40,7 @@
  • Images - 图片与图色处理
  • Keys - 按键模拟
  • Modules - 模块
  • -
  • WidgetsBasedAutomation - 基于控件的触摸模拟
  • +
  • WidgetsBasedAutomation - 基于控件的操作
  • Shell - Shell命令
  • Storages - 本地存储
  • Threads - 多线程
  • @@ -251,13 +251,18 @@ if(point){ });

    该函数也可以作为全局函数使用。

    images.findColorEquals(img, color[, x, y, width, height])#

    -

    严格找色的简便方法。找色时要求颜色完全相等才匹配。

    -

    相当于

    -
    images.findColor(img, color, {
    -   region: [x, y, width, height],
    -   threshold: 0
    -});
    -

    该函数也可以作为全局函数使用。

    +
    +

    在图片img指定区域中找到颜色和color完全相等的某个点,并返回该点的左边;如果没有找到,则返回null

    +

    找色区域通过x, y, width, height指定,如果不指定找色区域,则在整张图片中寻找。

    +

    该函数也可以作为全局函数使用。

    示例: (通过找QQ红点的颜色来判断是否有未读消息)

    requestScreenCapture();
    @@ -276,11 +281,14 @@ if(p){
     
  • x <number> 要检测的位置横坐标
  • y <number> 要检测的位置纵坐标
  • threshold <number> 颜色相似度临界值,默认为16。取值范围为0~255。
  • -
  • algorithm <string> 颜色匹配算法,包括:
  • UiSelector.waitFor()#

    +

    等待屏幕上出现符合条件的控件;在满足该条件的控件出现之前,该函数会一直保持阻塞。

    +

    例如要等待包含"哈哈哈"的文本控件出现的代码为:

    +
    textContains("哈哈哈").waitFor();
    +

    UiSelector.filter(f)#

    -

    找到所有符合条件的控件并设置文字选中区域,只对文本控件和输入框有效。相当于untilFind().setSelection()。参见setSelection

    -

    setText(text)#

    -
    -

    UiCollection#

    -

    UiCollection, 控件集合, 通过选择器的find(), untilFind()方法返回的对象。可以对其进行操作或者获取其信息。

    -

    UiCollection.size()#

    -

    返回集合中的控件数。

    -

    UiCollection.get(i)#

    -
    -

    返回集合中第i+1个控件(UiObject)。

    -

    UiCollection.each(func)#

    -
    -

    遍历集合。例如:

    -
    var c = clickable();
    -c.each(function(o){
    -    log(o.text());
    +

    为当前选择器附加自定义的过滤条件。

    +

    例如,要找出屏幕上所有文本长度为10的文本控件的代码为:

    +
    var uc = className("TextView").filter(function(w){
    +    return w.text().length == 10;
     });
    -

    empty()#

    -

    返回控件集合是否为空。

    -

    nonEmpty()#

    -

    返回控件集合是否非空。

    -

    UiCollection.filter(filter)#

    +

    UiObject#

    +

    UiObject表示一个控件,可以通过这个对象获取到控件的属性,也可以对控件进行点击、长按等操作。

    +

    获取一个UiObject通常通过选择器的findOne(), findOnce()等函数,也可以通过UiCollection来获取,或者通过UiObject.child(), UiObject.parent()等函数来获取一个控件的子控件或父控件。

    +

    UiObject.click()#

    -

    过滤出控件集合中符合条件的子控件。例如要过滤出所有子控件数目为1的控件为:

    -
    var newCollection = collection.filter(function(obj){
    -    return obj.childCount() == 1;
    -});
    -

    UiCollection.find(selector)#

    +

    点击该控件,并返回是否点击成功。

    +

    如果该函数返回false,可能是该控件不可点击(clickable为false),当前界面无法响应该点击等。

    +

    UiObject.longClick()#

    -

    根据selector所确定的条件在该控件集合的控件和子控件找到所有符合条件的控件并返回控件集合。

    -

    注意这会递归地遍历控件集合里所有的控件以及他们的子控件。和filter函数不同。

    -

    例如:

    -
    var names = id("name");
    -var clickableNames = names.find(clickable());
    -

    UiCollection.findOne(selector)#

    +

    长按该控件,并返回是否点击成功。

    +

    如果该函数返回false,可能是该控件不可点击(longClickable为false),当前界面无法响应该点击等。

    +

    UiObject.setText(text)#

    -

    根据selector所确定的条件在该控件集合中找到一个符合条件的控件并返回控件。若找不到则返回null。

    -

    UiCollection.click()#

    -

    点击集合中所有控件,并返回是否全部点击成功。

    -

    UiCollection.longClick()#

    -

    长按集合中所有控件,并返回是否全部操作成功。

    -

    UiCollection.copy()#

    -

    对集合中所有控件执行复制操作,并返回是否全部操作成功。

    -

    UiCollection.paste()#

    -

    对集合中所有控件执行粘贴操作,并返回是否全部操作成功。

    -

    UiCollection.select()#

    -

    对集合中所有控件执行选中操作,并返回是否全部操作成功。

    -

    UiCollection.cut()#

    -

    对集合中所有控件执行剪切操作,并返回是否全部操作成功。

    -

    UiCollection.collapse()#

    -

    对集合中所有控件执行折叠操作,并返回是否全部操作成功。

    -

    UiCollection.expand()#

    -

    对集合中所有控件执行展开操作,并返回是否全部操作成功。

    -

    UiCollection.show()#

    +

    设置输入框控件的文本内容,并返回是否设置成功。

    +

    该函数只对可编辑的输入框(editable为true)有效。

    +

    UiObject.copy()#

    +
    +

    对输入框文本的选中内容进行复制,并返回是否操作成功。

    +

    该函数只能用于输入框控件,并且当前输入框控件有选中的文本。可以通过setSelection()函数来设置输入框选中的内容。

    +
    var et = className("EditText").findOne();
    +//选中前两个字
    +et.setSelection(0, 2);
    +//对选中内容进行复制
    +if(et.copy()){
    +    toast("复制成功");
    +}else{
    +    toast("复制失败");
    +}
    +

    UiObject.cut()#

    +

    对输入框文本的选中内容进行剪切,并返回是否操作成功。

    +

    该函数只能用于输入框控件,并且当前输入框控件有选中的文本。可以通过setSelection()函数来设置输入框选中的内容。

    +

    UiObject.paste()#

    +
    +

    对输入框控件进行粘贴操作,把剪贴板内容粘贴到输入框中,并返回是否操作成功。

    +
    //设置剪贴板内容为“你好”
    +setClip("你好");
    +var et = className("EditText").findOne();
    +et.paste();
    +

    UiObject.setSelection(start, end)#

    +
    +

    对输入框控件设置选中的文字内容,并返回是否操作成功。

    +

    索引是从0开始计算的;并且,选中内容不包含end位置的字符。例如,如果一个输入框内容为"123456789",要选中"4567"的文字的代码为et.setSelection(3, 7)

    +

    该函数也可以用来设置光标位置,只要参数的end等于start,即可把输入框光标设置在start的位置。例如et.setSelection(1, 1)会把光标设置在第一个字符的后面。

    +

    UiObject.scrollForward()#

    +
    +

    对控件执行向前滑动的操作,并返回是否操作成功。

    +

    向前滑动包括了向右和向下滑动。如果一个控件既可以向右滑动和向下滑动,那么执行scrollForward()的行为是未知的(这是因为Android文档没有指出这一点,同时也没有充分的测试可供参考)。

    +

    UiObject.scrollBackward()#

    +
    +

    对控件执行向后滑动的操作,并返回是否操作成功。

    +

    向后滑动包括了向右和向下滑动。如果一个控件既可以向右滑动和向下滑动,那么执行scrollForward()的行为是未知的(这是因为Android文档没有指出这一点,同时也没有充分的测试可供参考)。

    +

    UiObject.select()#

    +
    +

    对控件执行"选中"操作,并返回是否操作成功。"选中"和isSelected()的属性相关,但该操作十分少用。

    +

    UiObject.collapse()#

    +
    +

    对控件执行折叠操作,并返回是否操作成功。

    +

    UiObject.expand()#

    +
    +

    对控件执行操作,并返回是否操作成功。

    +

    UiObject.show()#

    对集合中所有控件执行显示操作,并返回是否全部操作成功。

    -

    UiCollection.scrollForward()#

    -

    对集合中所有控件执行向前滑的操作,并返回是否全部操作成功。

    -

    UiCollection.scrollBackward()#

    -

    对集合中所有控件执行向后滑的操作,并返回是否全部操作成功。

    -

    UiCollection.scrollUp()#

    +

    UiObject.scrollUp()#

    对集合中所有控件执行向上滑的操作,并返回是否全部操作成功。

    -

    UiCollection.scrollDown()#

    +

    UiObject.scrollDown()#

    对集合中所有控件执行向下滑的操作,并返回是否全部操作成功。

    -

    UiCollection.scrollLeft()#

    +

    UiObject.scrollLeft()#

    对集合中所有控件执行向左滑的操作,并返回是否全部操作成功。

    -

    UiCollection.scrollRight()#

    -

    对集合中所有控件执行向右滑的操作,并返回是否全部操作成功。

    -

    UiCollection.contextClick()#

    -

    UiCollection.setSelection(start, end)#

    +

    UiObject.scrollRight()#

    +

    children()#

    -

    对集合中所有控件设置文字选中区域,并返回是否全部操作成功。

    -

    UiCollection.setText(text)#

    +

    返回该控件的所有子控件组成的控件集合。可以用于遍历一个控件的子控件,例如:

    +
    className("AbsListView").findOne().children()
    +    .forEach(function(child){
    +        log(child.className());
    +    });
    +

    childCount()#

    -

    UiObject#

    -

    控件, 选择器的findOne方法返回的对象。和UiCollection有相似的方法,不再赘述。除此之外还有以下方法。

    +

    返回子控件数目。

    child(i)#

    -

    返回第i+1个子控件(UiObject)。

    -

    parent()#

    -

    返回父控件(UiObject)。

    -

    children()#

    -

    返回该控件的所有子控件组成的控件集合。

    -

    childCount()#

    -

    返回子控件数目。

    +

    返回第i+1个子控件。如果i>=控件数目或者小于0,则抛出异常。

    +

    需要注意的是,由于布局捕捉的问题,该函数可能返回null,也就是可能获取不到某个子控件。

    +

    遍历子控件的示例:

    +
    var list = className("AbsListView").findOne();
    +for(var i = 0; i < list.childCount(); i++){
    +    var child = list.child(i);
    +    log(child.className());
    +}
    +

    parent()#

    +
    +

    返回该控件的父控件。如果该控件没有父控件,返回null

    bounds()#

    -

    返回控件在屏幕上的范围,其值是一个[Rect]对象。

    -

    boundsInParent()#

    -

    返回控件在父控件中的范围,其值是一个[Rect]对象。

    +
    +

    返回控件在屏幕上的范围,其值是一个Rect对象。

    +

    示例:

    +
    var b = text("Auto.js").findOne().bounds();
    +toast("控件在屏幕上的范围为" + b);
    +

    如果一个控件本身无法通过click()点击,那么我们可以利用bounds()函数获取其坐标,再利用坐标点击。例如:

    +
    var b = desc("打开侧拉菜单").findOne().bounds();
    +click(b.centerX(), b.centerY());
    +//如果使用root权限,则用 Tap(b.centerX(), b.centerY());
    +

    boundsInParent()#

    +
    +

    返回控件在父控件中的范围,其值是一个Rect对象。

    drawingOrder()#

    -

    返回控件的绘制次序。

    +
    +

    返回控件在父控件中的绘制次序。该函数在安卓7.0及以上才有效,7.0以下版本调用会返回0。

    id()#

    -

    返回控件的id,可能为null。

    +
    +

    获取控件的id,如果一个控件没有id,则返回null

    text()#

    -

    返回控件的文本,如果控件没有文本,返回""。

    -

    findByText(text)#

    -

    根据文本text在子控件中递归地寻找并返回文本或描述(desc)包含这段文本text的控件,返回它们组成的集合。。

    -

    find(selector)#

    +

    获取控件的文本,如果控件没有文本,返回""

    +

    findByText(str)#

    -

    根据选择器selector在子控件中递归地寻找符合条件的控件,返回它们组成的集合。

    -

    findOne#

    -

    find(selector)#

    +

    根据文本text在子控件中递归地寻找并返回文本或描述(desc)包含这段文本str的控件,返回它们组成的集合。

    +

    该函数会在当前控件的子控件,孙控件,曾孙控件...中搜索text或desc包含str的控件,并返回它们组合的集合。

    +

    findOne(selector)#

    -

    根据选择器selector在子控件中递归地寻找一个符合条件的控件。找不到则返回null。

    +

    根据选择器selector在该控件的子控件、孙控件...中搜索符合该选择器条件的控件,并返回找到的第一个控件;如果没有找到符合条件的控件则返回null

    +

    例如,对于酷安动态列表,我们可以遍历他的子控件(每个动态列表项),并在每个子控件中依次寻找点赞数量和图标,对于点赞数量小于10的点赞:

    +
    //找出动态列表
    +var list = id("recycler_view").findOne();
    +//遍历动态
    +list.children().forEach(function(child){
    +    //找出点赞图标
    +    var like = child.findOne(id("feed_action_view_like"));
    +    //找出点赞数量
    +    var likeCount = child.findOne(id("text_view"));
    +    //如果这两个控件没有找到就不继续了
    +    if(like == null || likeCount == null){
    +        return;
    +    }
    +    //判断点赞数量是否小于10
    +    if(parseInt(likeCount.text()) < 10){
    +        //点赞
    +        like.click();
    +    }
    +});
    +

    find(selector)#

    +
    +

    根据选择器selector在该控件的子控件、孙控件...中搜索符合该选择器条件的控件,并返回它们组合的集合。

    +

    UiCollection#

    +

    UiCollection, 控件集合, 通过选择器的find(), untilFind()方法返回的对象。

    +

    UiCollection"继承"于数组,实际上是一个UiObject的数组,因此可以使用数组的函数和属性,例如使用length属性获取UiCollection的大小,使用forEach函数来遍历UiCollection。

    +

    例如,采用forEach遍历屏幕上所有的文本控件并打印出文本内容的代码为:

    +
    console.show();
    +className("TextView").find().forEach(function(tv){
    +    if(tv.text() != ""){
    +        log(tv.text());
    +    }
    +});
    +

    也可以使用传统的数组遍历方式:

    +
    console.show();
    +var uc = className("TextView").find();
    +for(var i = 0; i < uc.length; i++){
    +    var tv = uc[i];
    +    if(tv.text() != ""){
    +        log(tv.text());
    +    }
    +}
    +

    UiCollection的每一个元素都是UiObject,我们可以取出他的元素进行操作,例如取出第一个UiObject并点击的代码为ui[0].click()。如果想要对该集合的所有元素进行操作,可以直接在集合上调用相应的函数,例如uc.click(),该代码会对集合上所有UiObject执行点击操作并返回是否全部点击成功。

    +

    因此,UiCollection具有所有UiObject对控件操作的函数,包括click(), longClick(), scrollForward()等等,不再赘述。

    +

    UiCollection.size()#

    +
    +

    返回集合中的控件数。

    +

    历史遗留函数,相当于属性length。

    +

    UiCollection.get(i)#

    +
    +

    返回集合中第i+1个控件(UiObject)。

    +

    历史遗留函数,建议直接使用数组下标的方式访问元素。

    +

    UiCollection.each(func)#

    +
    +

    遍历集合。

    +

    历史遗留函数,相当于forEach。参考forEach

    +

    empty()#

    +
    +

    返回控件集合是否为空。

    +

    nonEmpty()#

    +
    +

    返回控件集合是否非空。

    +

    UiCollection.find(selector)#

    +
    +

    根据selector所确定的条件在该控件集合的控件、子控件、孙控件...中找到所有符合条件的控件并返回找到的控件集合。

    +

    注意这会递归地遍历控件集合里所有的控件以及他们的子控件。和数组的filter函数不同。

    +

    例如:

    +
    var names = id("name").find();
    +//在集合
    +var clickableNames = names.find(clickable());
    +

    UiCollection.findOne(selector)#

    +
    +

    根据选择器selector在该控件集合的控件的子控件、孙控件...中搜索符合该选择器条件的控件,并返回找到的第一个控件;如果没有找到符合条件的控件则返回null

    Rect#

    -

    UiObject.bounds(), UiObject.boundsInParent()返回的对象。表示一个长方形。

    +

    UiObject.bounds(), UiObject.boundsInParent()返回的对象。表示一个长方形(范围)。

    Rect.left#

    -

    长方形左边界的x坐标、

    +
    +

    长方形左边界的x坐标、

    Rect.right#

    -

    长方形左边界的x坐标、

    +
    +

    长方形右边界的x坐标、

    Rect.top#

    -

    长方形上边界的y坐标、

    +
    +

    长方形上边界的y坐标、

    Rect.bottom#

    -

    长方形下边界的y坐标、

    +
    +

    长方形下边界的y坐标、

    Rect.centerX()#

    -

    长方形中点x坐标。

    +
    +

    长方形中点x坐标。

    Rect.centerY()#

    -

    长方形中点y坐标。

    +
    +

    长方形中点y坐标。

    Rect.width()#

    -

    长方形宽度。通常可以作为控件宽度。

    +
    +

    长方形宽度。通常可以作为控件宽度。

    Rect.height()#

    -

    长方形高度。通常可以作为控件高度。

    +
    +

    长方形高度。通常可以作为控件高度。

    Rect.contains(r)#

    -

    返回是否包含另一个长方形r。

    +

    返回是否包含另一个长方形r。包含指的是,长方形r在该长方形的里面(包含边界重叠的情况)。

    Rect.intersect(r)#

    返回是否和另一个长方形相交。

    +

    UiSelector进阶#

    +

    未完待续。