利用多线程实现了一个类似toast()的,但是可以在显示时间和显示位置都相互独立的功能。
感觉资源占用很大,可否优化?
顺带一问,如何让悬浮窗口有圆角?
/* flash() 可以互不干扰地持续在屏幕位置上显示信息
*/
for (let i = 0; i < 10; i++) {
flash(i, 300, 300 + i * 100, 2000);
sleep(500);
}
toastLog("End of pops.");
function flash(txt, x, y, t) {
th = threads.start(function() {
new Flash(txt, x, y, t).show();
});
th.waitFor();
}
function Flash(txt, x, y, t) {
this.txt = txt.toString();
this.x = x || device.width / 2;
this.y = y || device.height * 4 / 5;
this.t = t || 2000;
this.w = floaty.rawWindow(
<frame gravity="center" bg="#ff0000" w="20" h="20">
<text id="text">text
</text>
</frame>
);
this.show = function() {
this.w.text.setText(this.txt);
this.w.setPosition(this.x, this.y);
//setTimeout(this.w.close(), this.t);
sleep(this.t);
this.w.close();
};
}