"ui"
;
auto();
var
color =
"#000000"
;
var
_golDataSource;
var
_golHasBind =
false
;
var
_golFolder =
"./runJs/"
;
var
_golRunIndex = 0;
var
_golCardWidth = 0;
var
_golCardHeigth = 200
var
golRunComm =
null
;
var
_golThread;
var
_golStorage =
null
;
var
floaty_window_W;
var
floaty_window_H;
var
floaty_window_BtnStr;
var
key =
"default"
;
var
path_img =
"file://./res/assests/ewm.jpg"
_golCardWidth = parseInt(device.width * 0.155);
Main();
ui.layout(
<drawer id=
"drawer"
>
<vertical>
<appbar>
<toolbar bg=
"#FF5c50e6"
id=
"toolbar"
title=
"自动刷新"
paddingTop=
"2dp"
h=
"auto"
>
<button bg=
"#FF00CED1"
id=
"BtnExit"
layout_gravity=
"right"
textColor=
"#ffffff"
text=
"离开"
style=
"Widget.AppCompat.Button.Borderless.Colored"
w=
"auto"
/>
</toolbar>
<tabs id=
"tabs"
/>
</appbar>
<viewpager id=
"viewpager"
>
{
}
<frame>
<scroll>
<vertical>
<horizontal gravity=
"center_vertical"
>
<card w=
"{{_golCardWidth}}"
h=
"{{_golCardHeigth}}"
layout_width=
"0dp"
layout_weight=
"3"
margin=
"4"
cardCornerRadius=
"15dp"
cardBackgroundColor=
"#f5f5f5"
cardElevation=
"15dp"
gravity=
"left"
foreground=
"?selectableItemBackground"
>
<vertical>
<linear margin=
"0 40 0 0"
>
<View bg=
"#2196f3"
h=
"*"
w=
"10"
/>
<text id=
"name"
w=
"*"
h=
"40"
hint=
"欢迎自动刷新"
/>
</linear>
<button id=
"BtnStart"
text=
"开始刷新"
w=
"{{_golCardWidth}}"
/>
</vertical>
</card>
<card w=
"{{_golCardWidth}}"
h=
"{{_golCardHeigth}}"
layout_width=
"0dp"
layout_weight=
"3"
margin=
"4"
cardCornerRadius=
"15dp"
cardBackgroundColor=
"#f5f5f5"
cardElevation=
"15dp"
gravity=
"right"
foreground=
"?selectableItemBackground"
>
<vertical>
<linear margin=
"0 40 0 0"
>
<img w=
"30"
h=
"30"
src=
"@drawable/ic_person_black_48dp"
/>
<text id=
"name"
w=
"*"
h=
"40"
hint=
"自动点赞"
/>
</linear>
<button text=
"未完成"
w=
"{{_golCardWidth}}"
/>
</vertical>
</card>
</horizontal>
<horizontal gravity=
"center_vertical"
>
<card w=
"{{_golCardWidth}}"
h=
"{{_golCardHeigth}}"
layout_width=
"0dp"
layout_weight=
"3"
margin=
"4"
cardCornerRadius=
"15dp"
cardBackgroundColor=
"#f5f5f5"
cardElevation=
"15dp"
gravity=
"left"
foreground=
"?selectableItemBackground"
>
<vertical>
<linear margin=
"0 40 0 0"
>
<View bg=
"#2196f3"
h=
"*"
w=
"10"
/>
<text id=
"name"
w=
"*"
h=
"40"
hint=
"公众号'学生快乐编程'"
/>
</linear>
<button text=
"未完成"
w=
"{{_golCardWidth}}"
/>
</vertical>
</card>
<card w=
"{{_golCardWidth}}"
h=
"{{_golCardHeigth}}"
layout_width=
"0dp"
layout_weight=
"3"
margin=
"4"
cardCornerRadius=
"15dp"
cardBackgroundColor=
"#f5f5f5"
cardElevation=
"15dp"
gravity=
"right"
foreground=
"?selectableItemBackground"
>
<vertical>
<linear margin=
"0 40 0 0"
>
<img w=
"30"
h=
"30"
src=
"@drawable/ic_person_black_48dp"
/>
<text id=
"name"
w=
"*"
h=
"40"
hint=
"预留功能"
/>
</linear>
<button text=
"未完成"
w=
"{{_golCardWidth}}"
/>
</vertical>
</card>
</horizontal>
<vertical h=
"auto"
align=
"center"
marginTop=
"1"
>
<img layout_gravity=
"center"
src=
"{{path_img}}"
w=
"120"
h=
"120"
/>
<text w=
"auto"
glayout_gravity=
"center"
color=
"#111111"
size=
"13"
text=
"关注公众号:学生快乐编程"
/>
</vertical>
</vertical>
</scroll>
</frame>
{
}
<frame>
<vertical>
<horizontal weightSum=
"8"
bg=
'#FF5c50e6'
>
<button layout_width=
"0dp"
layout_weight=
"4"
id=
"BtnSave"
text=
"手动保存"
/>
<button layout_width=
"0dp"
layout_weight=
"4"
id=
"BtnBegin"
text=
"开始刷新"
/>
</horizontal>
<scroll>
<vertical>
<card id=
"card0"
w=
"*"
h=
"70"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#000080"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text id=
"appCnName0"
text=
""
textColor=
"#222222"
textSize=
"14sp"
maxLines=
"1"
/>
<text id=
"filepath0"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
<text id=
"app0"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
</vertical>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"排序"
/>
<input id=
"sortid0"
text=
""
textSize=
"13sp"
maxLines=
"1"
inputType=
"number"
/>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"(秒)"
/>
<input id=
"t0"
w=
"auto"
gravity=
"right"
textSize=
"13sp"
text=
""
inputType=
"number"
/>
<checkbox id=
"done0"
marginLeft=
"4"
marginRight=
"6"
checked=
"true"
/>
</horizontal>
</card>
<card id=
"card1"
w=
"*"
h=
"70"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#00008B"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text id=
"appCnName1"
text=
""
textColor=
"#222222"
textSize=
"14sp"
maxLines=
"1"
/>
<text id=
"filepath1"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
<text id=
"app1"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
</vertical>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"排序"
/>
<input id=
"sortid1"
text=
""
textSize=
"13sp"
maxLines=
"1"
inputType=
"number"
/>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"(秒)"
/>
<input id=
"t1"
w=
"auto"
gravity=
"right"
textSize=
"13sp"
text=
""
inputType=
"number"
/>
<checkbox id=
"done1"
marginLeft=
"4"
marginRight=
"6"
checked=
"false"
/>
</horizontal>
</card>
<card id=
"card2"
w=
"*"
h=
"70"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#0000CD"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text id=
"appCnName2"
text=
""
textColor=
"#222222"
textSize=
"14sp"
maxLines=
"1"
/>
<text id=
"filepath2"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
<text id=
"app2"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
</vertical>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"排序"
/>
<input id=
"sortid2"
text=
""
textSize=
"13sp"
maxLines=
"1"
inputType=
"number"
/>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"(秒)"
/>
<input id=
"t2"
w=
"auto"
gravity=
"right"
textSize=
"13sp"
text=
""
inputType=
"number"
/>
<checkbox id=
"done2"
marginLeft=
"4"
marginRight=
"6"
checked=
"false"
/>
</horizontal>
</card>
<card id=
"card3"
w=
"*"
h=
"70"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#0000FF"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text id=
"appCnName3"
text=
""
textColor=
"#222222"
textSize=
"14sp"
maxLines=
"1"
/>
<text id=
"filepath3"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
<text id=
"app3"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
</vertical>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"排序"
/>
<input id=
"sortid3"
textSize=
"13sp"
maxLines=
"1"
inputType=
"number"
/>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"(秒)"
/>
<input id=
"t3"
w=
"auto"
gravity=
"right"
textSize=
"13sp"
text=
""
inputType=
"number"
/>
<checkbox id=
"done3"
marginLeft=
"4"
marginRight=
"6"
checked=
"false"
/>
</horizontal>
</card>
<card id=
"card4"
w=
"*"
h=
"70"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#00BFFF"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text id=
"appCnName4"
text=
""
textColor=
"#222222"
textSize=
"14sp"
maxLines=
"1"
/>
<text id=
"filepath4"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
<text id=
"app4"
text=
""
textColor=
"#999999"
textSize=
"12sp"
maxLines=
"1"
/>
</vertical>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"排序"
/>
<input id=
"sortid4"
textSize=
"13sp"
maxLines=
"1"
inputType=
"number"
/>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"13"
text=
"(秒)"
/>
<input id=
"t4"
w=
"auto"
gravity=
"right"
textSize=
"13sp"
text=
""
inputType=
"number"
/>
<checkbox id=
"done4"
marginLeft=
"4"
marginRight=
"6"
checked=
"false"
/>
</horizontal>
</card>
</vertical>
</scroll>
</vertical>
</frame>
{
}
<frame>
<com.stardust.autojs.core.console.ConsoleView id=
"console"
h=
"*"
/>
</frame>
{
}
<frame>
<card id=
"card4"
w=
"*"
h=
"100"
margin=
"10 5"
cardCornerRadius=
"2dp"
cardElevation=
"1dp"
foreground=
"?selectableItemBackground"
>
<horizontal gravity=
"center_vertical"
>
<View bg=
"#00BFFF"
h=
"*"
w=
"10"
/>
<vertical padding=
"10 8"
h=
"auto"
w=
"0"
layout_weight=
"1"
>
<text w=
"auto"
color=
"#111111"
size=
"16"
text=
"1、需要启动无障碍服务。"
/>
<text w=
"auto"
color=
"#111111"
size=
"16"
text=
"2、允许app显示在其他应用的上层。"
/>
</vertical>
</horizontal>
</card>
</frame>
{
}
<frame>
<text w=
"auto"
gravity=
"right"
color=
"#111111"
size=
"16"
text=
" 第四页:关注公众号学生快乐编程"
/>
</frame>
</viewpager>
</vertical>
<vertical layout_gravity=
"left"
bg=
"#ffffff"
w=
"280"
>
<img w=
"280"
h=
"200"
scaleType=
"fitXY"
/>
<list id=
"menu"
>
<horizontal bg=
"?selectableItemBackground"
w=
"*"
>
<img w=
"50"
h=
"50"
padding=
"16"
src=
"{{this.icon}}"
tint=
"{{color}}"
/>
<text textColor=
"black"
textSize=
"15sp"
text=
"{{this.title}}"
layout_gravity=
"center"
/>
</horizontal>
</list>
</vertical>
</drawer>
);
ui.done0.on(
"check"
,
function
(checked) {
log(
"ck-"
+ checked);
if
(checked) {
ui.card0.attr(
"bg"
,
"#F5f5f5"
);
}
else
{
ui.card0.attr(
"bg"
,
"#999999"
);
}
});
activity.setSupportActionBar(ui.toolbar);
ui.viewpager.setTitles([
"主页"
,
"配置"
,
"日志"
,
"帮助"
,
"About"
]);
ui.tabs.setupWithViewPager(ui.viewpager);
ui.toolbar.setupWithDrawer(ui.drawer);
ui.viewpager.setOnPageChangeListener({
onPageSelected:
function
(index) {
if
(index == 1 && _golHasBind ==
false
) {
bindDdata();
}
else
if
(index == 2) {
ui.console.setConsole(runtime.console);
let
c =
new
android.util.SparseArray();
let
Log = android.util.Log;
c.put(Log.VERBOSE,
new
java.lang.Integer(colors.parseColor(
"#dfc0c0c0"
)));
c.put(Log.DEBUG,
new
java.lang.Integer(colors.parseColor(
"#cc000000"
)));
c.put(Log.INFO,
new
java.lang.Integer(colors.parseColor(
"#ff64dd17"
)));
c.put(Log.WARN,
new
java.lang.Integer(colors.parseColor(
"#ff2962ff"
)));
c.put(Log.ERROR,
new
java.lang.Integer(colors.parseColor(
"#ffd50000"
)));
c.put(Log.ASSERT,
new
java.lang.Integer(colors.parseColor(
"#ffff534e"
)));
ui.console.setColors(c);
}
}
})
function
Main() {
log(
"main"
);
engines.all().slice(1).forEach(script => {
if
(script.getSource().getName().indexOf(engines.myEngine().getSource())) {
toastLog(
"脚本正在运行中"
);
engines.myEngine().forceStop();
}
});
ui.statusBarColor(color);
_golDataSource = LoadConfig();
_golStorage = storages.create(
"asianbest.vip"
);
log(
"winW="
+ _golStorage.get(
"winW"
));
log(
"winH="
+ _golStorage.get(
"winH"
) +
"-btnText-"
+ _golStorage.get(
"btnText"
));
floaty_window_W = 120;
floaty_window_H = 120;
floaty_window_BtnStr =
"小化"
;
}
function
bindDdata() {
for
(
let
k = 0; k < _golDataSource.length; k++) {
ui[
"filepath"
+ k].setText(_golDataSource[k].filepath);
let
appEn = _golDataSource[k].app;
ui[
"app"
+ k].setText(appEn);
let
appCn = getAppName(appEn);
if
(
null
== appCn) {
ui[
"done"
+ k].checked =
false
;
ui[
"card"
+ k].attr(
"bg"
,
"#999999"
);
ui[
"appCnName"
+ k].setText(appEn);
}
else
{
ui[
"done"
+ k].checked =
true
;
ui[
"card"
+ k].attr(
"bg"
,
"#F5f5f5"
);
ui[
"appCnName"
+ k].setText(appCn);
}
let
isRun = _golDataSource[k].Run;
if
(
"0"
== isRun) {
ui[
"done"
+ k].checked =
false
;
ui[
"card"
+ k].attr(
"bg"
,
"#A9A9A9"
);
}
ui[
"sortid"
+ k].setText(_golDataSource[k].sortid);
ui[
"t"
+ k].setText(_golDataSource[k].t);
}
_golHasBind =
true
;
}
function
LoadConfig() {
let
_txtFile = _golFolder +
"config.txt"
;
if
(files.exists(_txtFile)) {
toast(
'读取文件'
+ _txtFile);
var
jsonStr = files.read(_txtFile);
setTimeout(() => {
toastLog(
"读取文件。"
);
}, 400);
var
commFun = require(_golFolder +
"CommonFun.js"
);
golRunComm =
new
commFun();
let
obj = golRunComm.ReSort(eval(
'('
+ jsonStr +
')'
));
setTimeout(() => {
toastLog(
"文件解析完成。"
);
}, 400);
return
obj;
}
}
ui.BtnSave.on(
"click"
,
function
() {
let
str =
"["
;
for
(
let
k = 0; k < _golDataSource.length; k++) {
str +=
"{\"filepath\":\""
+ ui[
"filepath"
+ k].text() +
"\","
;
str +=
"\"app\":\""
+ ui[
"app"
+ k].text() +
"\","
str +=
"\"sortid\":\""
+ ui[
"sortid"
+ k].text() +
"\","
;
str +=
"\"t\":\""
+ ui[
"t"
+ k].text() +
"\"}"
;
if
(k < _golDataSource.length - 1) {
str +=
","
;
}
}
str +=
"]"
;
_golDataSource = golRunComm.ReSort(eval(
'('
+ str +
')'
));
let
_txtFile = _golFolder +
"config.txt"
;
files.write(_txtFile, str);
setTimeout(() => {
toastLog(
"修改文件。"
);
}, 1500);
bindDdata();
setTimeout(() => {
toastLog(
"更新UI界面。"
);
}, 1500);
});
ui.BtnStart.on(
"click"
, () => {
ui.BtnStart.setText(
"暂停"
);
ui.BtnBegin.setText(
"暂停"
);
_golThread = threads.start(
function
() {
log(
"Start日志"
);
xuanfuchuang();
log(
"启动子线程"
);
ThreadStart();
});
});
ui.BtnBegin.on(
"click"
, () => {
ui.BtnStart.setText(
"暂停"
);
ui.BtnBegin.setText(
"暂停"
);
_golThread = threads.start(
function
() {
log(
"Start日志"
);
xuanfuchuang();
log(
"启动子线程"
);
ThreadStart();
});
});
ui.BtnExit.on(
"click"
, () => {
if
(_golThread && _golThread.isAlive()) {
log(
"线程"
+ _golThread.isAlive());
_golThread.interrupt();
}
ui.finish();
});
function
ThreadStart() {
log(
"线程启动>>"
+ _golDataSource[0].filepath);
Help(_golFolder + _golDataSource[_golRunIndex].filepath,
_golDataSource[_golRunIndex].app,
_golDataSource[_golRunIndex].t,
getAppName(_golDataSource[_golRunIndex].app));
}
function
Help(_path, _appName, _times, _cn) {
var
myObj = require(_path);
var
unlock =
new
myObj(_appName, _times, _cn, golRunComm);
unlock.RunApp();
Calc_golRunIndex();
ThreadStart();
}
function
xuanfuchuang() {
w = floaty.window(
<frame id=
"action"
bg=
"#90251911"
w=
"{{floaty_window_W}}"
h=
"{{floaty_window_H}}"
padding=
"2"
>
<linear w=
"*"
h=
'*'
>
<vertical gravity=
"left"
padding=
"-1"
>
<button id=
"Bmin"
text=
"{{floaty_window_BtnStr}}"
w=
"40"
h=
"40"
textSize=
"8sp"
/>
<button id=
"yidong"
text=
"移动"
w=
"40"
h=
"40"
textSize=
"8sp"
/>
<button id=
"tuichu"
text=
"退出"
w=
"40"
h=
"40"
textSize=
"8sp"
/>
</vertical>
<vertical padding=
"0"
>
<vertical>
<com.stardust.autojs.core.console.ConsoleView id=
"ConS"
margin=
"1"
textSize=
"8sp"
/>
</vertical>
</vertical>
</linear>
</frame>
);
setInterval(() => { }, 1000);
log(
"窗体位置"
+ _golStorage.get(
"winx"
) +
" pos "
+ _golStorage.get(
"winy"
));
if
(_golStorage.get(
"winx"
) && _golStorage.get(
"winy"
)) {
w.setPosition(_golStorage.get(
"winx"
), _golStorage.get(
"winy"
));
}
else
{
w.setPosition(5, 1000);
}
ui.run(() => {
w.ConS.setConsole(runtime.console);
});
w.tuichu.click(() => {
log(
"线程"
+ _golThread.isAlive());
ui.BtnStart.setText(
"重启"
);
ui.BtnBegin.setText(
"重启"
);
Calc_golRunIndex();
if
(_golThread && _golThread.isAlive()) {
_golThread.interrupt();
}
toastLog(
"退出线程 >>"
);
w.close();
});
var
x = 0, y = 0;
var
windowX, windowY;
var
downTime;
ui.run(
function
() {
windowWidth = w.getWidth();
windowHeight = w.getHeight();
}
);
w.Bmin.setOnTouchListener(
function
(view, event) {
switch
(event.getAction()) {
case
event.ACTION_DOWN:
x = event.getRawX();
y = event.getRawY();
windowX = w.getX();
windowY = w.getY();
return
true
;
case
event.ACTION_MOVE:
let
wx = windowX + (event.getRawX() - x);
let
wy = windowY + (event.getRawY() - y);
w.setPosition(wx, wy);
SaveFloatWinPos(wx, wy);
SaveFloatWinStates(190, 190, w.Bmin.text());
return
true
;
case
event.ACTION_UP:
if
(Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) {
if
(w.Bmin.text() ==
"小化"
) {
w.Bmin.setText(
"大化"
);
w.setSize(190, 190);
SaveFloatWinStates(190, 190, w.Bmin.text());
}
else
{
w.Bmin.setText(
"小化"
);
w.setSize(windowWidth, windowHeight);
SaveFloatWinStates(windowWidth, windowHeight, w.Bmin.text());
}
}
return
true
;
}
return
true
;
});
w.yidong.setOnTouchListener(
function
(view, event) {
switch
(event.getAction()) {
case
event.ACTION_DOWN:
x = event.getRawX();
y = event.getRawY();
aw = w.getWidth();
ah = w.getHeight();
windowX = w.getX();
windowY = w.getY();
downTime =
new
Date().getTime();
return
true
;
case
event.ACTION_MOVE:
w.setPosition(windowX + (event.getRawX() - x),
windowY + (event.getRawY() - y));
return
true
;
case
event.ACTION_UP:
SaveFloatWinPos(w.getX(), w.getY());
return
true
;
}
return
true
;
});
function
SaveFloatWinPos(_x, _y) {
_golStorage.put(
"winx"
, _x);
_golStorage.put(
"winy"
, _y);
};
function
SaveFloatWinStates(_winW, _winH, _btnStr) {
_golStorage.put(
"winW"
, _winW);
_golStorage.put(
"winH"
, _winH);
_golStorage.put(
"btnText"
, _btnStr);
};
}
function
Calc_golRunIndex() {
_golRunIndex++;
if
(_golRunIndex >= (_golDataSource.length)) {
_golRunIndex = 0;
}
};