change JavaScriptEngine to LoopBasedJavaScriptEngine

Everything works like Node.js. loop() will not need be called explicitly any more.
Including some changes:
* Every thread of script has a looper.
* Use a servant thread in gestures functions of GlobalActionAutomator and image available listener of ScreenCapture.
* For keeping events key and touch listener alive, add Loopers.waitWhenIdle to control whether or not Looper should quit when it has nothing to do
This commit is contained in:
hyb1996
2017-07-29 17:46:23 +08:00
parent 11b87d9a51
commit 12037ba488
21 changed files with 382 additions and 173 deletions

View File

@@ -0,0 +1,16 @@
## 控件
对于一般软件而言,其界面是由控件组成的。
一段文本、一张图片、一个列表都是一个控件(widget),文本用文本控件(TextView)显示,图片用图片控件(ImageView)显示。
此外还有一类特殊的控件,其本身不显示内容,而是作为其他控件的"容器"使用,决定在他里面的控件的位置和排放。这类控件称为"布局"(layout)。
常见的布局有线性布局(LinearLayout), 相对布局(RelativeLayout), 帧布局(FrameLayout), 表格布局(GridLayout)等。
例如线性布局,在他里面的控件是线性(垂直或平行)地摆放的。比如一个水平的线性布局,里面依次有一个文本控件和一个图片控件,那么显示时图片将会在文本的右边。
## 控件的属性
打开悬浮窗,找到

View File

@@ -8,7 +8,6 @@
events也是一个\[EventEmitter\](#EventEmitter)可以使用EventEmitter的所有函数这里只介绍其自身的函数。
注意events内置的触摸、按键事件必须调用loop()函数才能正常工作。例如:
```
events.observeKey();
events.onKeyDown("volume_up", function(event){
@@ -18,7 +17,6 @@ events.onKeyDown("menu", function(event){
toast("菜单键被按下了");
});
loop();
//后面的语句不会再执行了
```

View File

@@ -2,22 +2,6 @@ timer 模块暴露了一个全局的 API用于在某个未来时间段调用
Auto.js 中的计时器函数实现了与 Web 浏览器提供的定时器类似的 API除了它使用了一个不同的内部实现它是基于 Android Looper-Handler机制构建的。其实现机制与Node.js比较相似。
不同于Web浏览器和Node.js在Auto.js中必须显式地调用loop()函数开始Looper循环才能使所有计时器开始工作。loop()函数是一个"死循环", 在他之后的语句将不会被执行。
### loop()
开始Looper循环。使所有定时器工作所必须。
注意何时调用loop不会影响setTimeout等函数的计时例如
```
setTimout(function(){
toast("hello");
exit();
}, 2000);
sleep(1000);
loop();
```
这段代码将在运行后大约2秒显示"hello"。
### setImmediate(callback\[, ...args\])
* callback \<Function\> 在 Auto.js 循环的当前回合结束时要调用的函数。
* ...args \<any\> 当调用 callback 时要传入的可选参数。
@@ -49,12 +33,12 @@ callback 可能不会精确地在 delay 毫秒被调用。 Auto.js 不能保证
setImmediate()、setInterval() 和 setTimeout() 方法每次都会返回表示预定的计时器的id。 它们可用于取消定时器并防止触发。
### clearImmediate(id)#
### clearImmediate(id)
* id \<Number\> 一个 setImmediate() 返回的 id。
取消一个由 setImmediate() 创建的 Immediate 对象。
### clearInterval(id)#
### clearInterval(id)
* id \<Number\> 一个 setInterval() 返回的 id。
取消一个由 setInterval() 创建的 Timeout 对象。