forked from icegreentee/magireco_autoBattle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
floatUI.js
13681 lines (12942 loc) · 608 KB
/
floatUI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var floatUI = {}
//缓解报毒问题
function deObStr(s) {
return s.replace(/cwvqlu/gi, ss => ss.split("").map(c => String.fromCharCode(c.charCodeAt(0)-2)).join(""));
}
//悬浮窗logo
importClass(java.lang.Runnable);
importClass(android.animation.ObjectAnimator)
importClass(android.animation.PropertyValuesHolder)
importClass(android.animation.ValueAnimator)
importClass(android.animation.AnimatorSet)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.TranslateAnimation)
importClass(android.animation.ObjectAnimator)
importClass(android.animation.TimeInterpolator)
importClass(android.os.Bundle)
importClass(android.view.View)
importClass(android.view.Window)
importClass(android.view.Gravity)
importClass(android.graphics.Point)
importClass(android.content.IntentFilter)
importClass(android.content.Intent)
importClass(android.view.animation.AccelerateDecelerateInterpolator)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.AnticipateInterpolator)
importClass(android.view.animation.AnticipateOvershootInterpolator)
importClass(android.view.animation.BounceInterpolator)
importClass(android.view.animation.CycleInterpolator)
importClass(android.view.animation.DecelerateInterpolator)
importClass(android.view.animation.LinearInterpolator)
importClass(android.view.animation.OvershootInterpolator)
importClass(android.view.animation.PathInterpolator)
importClass(android.widget.Button)
importClass(android.widget.ImageView)
importClass(android.widget.TextView)
// 捕获异常时打log记录详细的调用栈
//(不能先声明为空函数再赋值,否则不会正常工作)
function logException(e) {
try { throw e; } catch (caught) {
Error.captureStackTrace(caught, logException);
//log(e, caught.stack); //输出挤在一行里了,不好看
log(e);
log(caught.stack);
}
}
var enableAutoService = () => {};
var origFunc = {
click: function () {return click.apply(this, arguments)},
swipe: function () {return swipe.apply(this, arguments)},
press: function () {return press.apply(this, arguments)},
buildDialog: function() {return dialogs.build.apply(this, arguments)},
}
var mustRoot = false;
var OCR = null, ocr = null;
const extFilesDir = context.getExternalFilesDir(null).getAbsolutePath(); //用于中转存放可执行文件
//注意:这个函数只会返回打包时的版本,而不是在线更新后的版本!
function getProjectVersion() {
var conf = ProjectConfig.Companion.fromProjectDir(engines.myEngine().cwd());
if (conf) return conf.versionName;
}
//sync锁的是this对象,于是A函数锁定后B函数得等A函数返回
//这个syncer就不会让B函数等待A函数返回
//必须是syncer.syn(func)这样调用
var syncer = {
lockers: [],
renewLockerIfDead: sync(function (locker, renewLock, renewThread, force) {
if (force || locker.thread == null || !locker.thread.isAlive()) {
if (renewLock) locker.lock = threads.lock();
if (renewThread) locker.thread = threads.currentThread();
}
}),
syn: function (func) {
let currentLocker = {lock: threads.lock(), thread: null};
this.lockers.push(currentLocker);
let syncerobj = this;
return function () {
let ret = undefined;
try {
while (!currentLocker.lock.tryLock(1000, java.util.concurrent.TimeUnit.MILLISECONDS)) {
syncerobj.renewLockerIfDead(currentLocker, true, true, false);
}
syncerobj.renewLockerIfDead(currentLocker, false, true, true);
ret = func.apply(this, arguments);
} finally {
while (currentLocker.lock.getHoldCount() > 0) currentLocker.lock.unlock();
}
return ret;
}
}
}
// 为了解决报毒问题,CwvqLU Pro V9 内测版 9.0.11-0 混淆了类名和activity名
var lowestObVerCode = 9101100;
var splashActivityName = deObStr("com.stardust.cwvqlu.inrt.SplashActivity");
if (parseInt(app[deObStr("cwvqlu")].versionCode) >= lowestObVerCode) {
splashActivityName = context.getPackageName()+".SplashActivity";
}
function restartApp() {
//重启本app,但因为进程没退出,所以无障碍服务应该还能保持启用;缺点是每重启一次貌似都会泄漏一点内存
events.on("exit", function () {
app.launch(context.getPackageName());
toast("app已重启");
});
engines.stopAll();
}
//记录当前版本是否测试过助战的文件(已经去掉,留下注释)
//var supportPickingTestRecordPath = files.join(engines.myEngine().cwd(), "support_picking_tested");
//停止shell脚本监工(在algo_init中初始化)
var stopFatalKillerShellScript = () => {};
var stopFatalKillerShellScriptThread = null;
var tasks = algo_init();
// touch capture, will be initialized in main
var capture = () => { };
// 停止脚本线程,尤其是防止停止自己的时候仍然继续往下执行少许语句(同上,会在main函数中初始化)
var stopThread = () => { };
// (不)使用Shizuku/root执行shell命令
var shizukuShell = () => { };
var rootShell = () => { };
var privShell = () => { };
var normalShell = () => { };
// 检查root或adb权限
var requestShellPrivilege = () => { };
var requestShellPrivilegeThread = null;
// 嗑药数量限制和统计
//绿药或红药,每次消耗1个
//魔法石,每次碎5钻
const drugCosts = [1, 1, 5, 1, 1];
var updateDrugLimit = () => { };
var updateDrugConsumingStats = () => { };
var isDrugEnabled = () => { };
var isDrugEnough = () => { };
// 周回数统计
var updateCycleCount = () => { };
floatUI.storage = null;
floatUI.floatyHangWorkaroundLock = threads.lock();
// available script list
floatUI.scripts = [
{
name: "副本周回(剧情/活动通用)",
fn: tasks.default,
},
{
name: "半自动辅助开荒(临时)",
fn: tasks.openUp,
availableForJP: true,
},
{
name: "镜层周回",
fn: tasks.mirrors,
availableForJP: true,
},
{
name: "自动点击行动盘(识图,连携)",
fn: tasks.CVAutoBattle,
availableForJP: true,
},
{
name: "点屏幕左下角保持亮屏",
fn: tasks.keepJPScreenOn,
availableForJP: true,
},
{
name: "复活日服脚本",
fn: tasks.unlockAccessibilitySvc,
},
{
name: "绕过GooglePlay检测",
fn: tasks.fakeJPInstallSource,
},
{
name: "音频减速降调bug临时修正",
fn: tasks.fixAudioSampleRate,
},
{
name: "安装CA证书",
fn: tasks.installCACert,
},
{
name: "安装本地服务器",
fn: tasks.localServerGuide,
},
{
name: "自动点击行动盘(无脑123盘)",
fn: tasks.simpleAutoBattle,
},
{
name: "理子活动脚本",
fn: tasks.dungeonEvent,
},
{
name: "录制闪退重开选关动作",
fn: tasks.recordSteps,
},
{
name: "重放选关动作",
fn: tasks.replaySteps,
},
{
name: "导入动作录制数据",
fn: tasks.importSteps,
},
{
name: "导出动作录制数据",
fn: tasks.exportSteps,
},
{
name: "清除动作录制数据",
fn: tasks.clearSteps,
},
{
name: "文字抓取",
fn: tasks.captureText,
},
{
name: "测试助战自动选择",
fn: tasks.testSupportSel,
},
{
name: "测试闪退自动重开",
fn: tasks.testReLaunch,
availableForJP: true,
},
{
name: "活动周回,自动重开(备用)",
fn: tasks.reopen,
}
];
floatUI.presetOpLists = [
{
name: "不使用预设数据",
content: null,
},
{
name: "日服主线2-1-4普通本(水波祭)",
content: "{\"package_name\":\"com.aniplex.magireco\",\"date\":\"2022-9-7_19-1-1\","
+"\"isGeneric\":true,\"defaultSleepTime\":1500,\"isEventTypeBRANCH\":fal"
+"se,\"steps\":[{\"action\":\"click\",\"click\":{\"point\":{\"x\":1533,\"y\":976"
+",\"pos\":\"bottom\"}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000}}"
+",{\"action\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"c"
+"enter\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"a"
+"ction\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"cente"
+"r\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"actio"
+"n\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"center\"},"
+"{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"action\":\""
+"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"center\"},{\"x\""
+":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"action\":\"clic"
+"k\",\"click\":{\"point\":{\"x\":1160,\"y\":201,\"pos\":\"center\"}}},{\"action"
+"\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1159,\"y\":820,\"pos\":\"center\"},{"
+"\"x\":1170,\"y\":206,\"pos\":\"center\"}],\"duration\":2000}},{\"action\":\"s"
+"wipe\",\"swipe\":{\"points\":[{\"x\":1152,\"y\":843,\"pos\":\"center\"},{\"x\":"
+"1131,\"y\":218,\"pos\":\"center\"}],\"duration\":2000}},{\"action\":\"click"
+"\",\"click\":{\"point\":{\"x\":1122,\"y\":190,\"pos\":\"center\"}}},{\"action\""
+":\"sleep\",\"sleep\":{\"sleepTime\":3000}},{\"action\":\"click\",\"click\":{"
+"\"point\":{\"x\":1193,\"y\":570,\"pos\":\"top\"}}},{\"action\":\"sleep\",\"slee"
+"p\":{\"sleepTime\":3000}},{\"action\":\"checkText\",\"checkText\":{\"text\""
+":\"BATTLE 4\",\"boundsCenter\":{\"x\":304,\"y\":514,\"pos\":\"top\"},\"found\""
+":{\"kill\":false,\"stopScript\":false,\"nextAction\":\"ignore\"},\"notFou"
+"nd\":{\"kill\":true,\"stopScript\":false,\"nextAction\":\"fail\"}}},{\"act"
+"ion\":\"checkText\",\"checkText\":{\"text\":\"第2章\",\"boundsCenter\":{\"x\":3"
+"05,\"y\":250,\"pos\":\"top\"},\"found\":{\"kill\":false,\"stopScript\":false"
+",\"nextAction\":\"ignore\"},\"notFound\":{\"kill\":true,\"stopScript\":fal"
+"se,\"nextAction\":\"fail\"}}},{\"action\":\"checkText\",\"checkText\":{\"te"
+"xt\":\"1話\",\"boundsCenter\":{\"x\":303,\"y\":296,\"pos\":\"top\"},\"found\":{\""
+"kill\":false,\"stopScript\":false,\"nextAction\":\"ignore\"},\"notFound\""
+":{\"kill\":true,\"stopScript\":false,\"nextAction\":\"fail\"}}},{\"action"
+"\":\"checkText\",\"checkText\":{\"text\":\"ふたりの親友を訪ねて\",\"boundsCenter\":{\""
+"x\":305,\"y\":436,\"pos\":\"top\"},\"found\":{\"kill\":false,\"stopScript\":f"
+"alse,\"nextAction\":\"success\"},\"notFound\":{\"kill\":true,\"stopScript"
+"\":false,\"nextAction\":\"fail\"}}}]}",
},
{
name: "日服门票活动剧情[BATTLE 1]",
content: "{\"date\":\"2022-9-7_19-25-10\",\"defaultSleepTime\":1500,\"isEventType"
+"BRANCH\":false,\"isGeneric\":true,\"package_name\":\"com.aniplex.magir"
+"eco\",\"steps\":[{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"bottom\""
+",\"x\":1608,\"y\":743}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000"
+"}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"top\",\"x\":982,\"y\":"
+"172}}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"po"
+"s\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"a"
+"ction\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\""
+"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"sw"
+"ipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y"
+"\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swip"
+"e\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"p"
+"os\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"durat"
+"ion\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\","
+"\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,"
+"\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\""
+"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":["
+"{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}}"
+",{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"to"
+"p\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\""
+":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":107"
+"0,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\""
+"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915}"
+",{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"d"
+"uration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"t"
+"op\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2"
+"000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":10"
+"70,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"point"
+"s\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306"
+"}]}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"bottom\",\"x\":1092"
+",\"y\":775}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000}},{\"acti"
+"on\":\"checkText\",\"checkText\":{\"boundsCenter\":{\"pos\":\"top\",\"x\":305"
+",\"y\":467},\"found\":{\"kill\":false,\"nextAction\":\"ignore\",\"stopScrip"
+"t\":false},\"notFound\":{\"kill\":true,\"nextAction\":\"fail\",\"stopScrip"
+"t\":false},\"text\":\"ストーリークエスト\"}},{\"action\":\"checkText\",\"checkText\""
+":{\"boundsCenter\":{\"pos\":\"top\",\"x\":298,\"y\":515},\"found\":{\"kill\":f"
+"alse,\"nextAction\":\"success\",\"stopScript\":false},\"notFound\":{\"kil"
+"l\":true,\"nextAction\":\"fail\",\"stopScript\":false},\"text\":\"BATTLE 1"
+"\"}}]}",
},
{
name: "国服主线2-1-4普通本(水波祭)",
content: "{\"package_name\":\"com.bilibili.madoka.bilibili\",\"date\":\"2021-9-3_"
+"11-1-1\",\"isGeneric\":true,\"defaultSleepTime\":1500,\"isEventTypeBRA"
+"NCH\":false,\"steps\":[{\"action\":\"click\",\"click\":{\"point\":{\"x\":1563"
+",\"y\":845,\"pos\":\"bottom\"}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime"
+"\":3000}},{\"action\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,"
+"\"pos\":\"center\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":20"
+"00}},{\"action\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos"
+"\":\"center\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}}"
+",{\"action\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"c"
+"enter\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"a"
+"ction\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1338,\"y\":823,\"pos\":\"cente"
+"r\"},{\"x\":1350,\"y\":182,\"pos\":\"center\"}],\"duration\":2000}},{\"actio"
+"n\":\"click\",\"click\":{\"point\":{\"x\":1160,\"y\":201,\"pos\":\"center\"}}},"
+"{\"action\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1159,\"y\":820,\"pos\":\"ce"
+"nter\"},{\"x\":1170,\"y\":206,\"pos\":\"center\"}],\"duration\":2000}},{\"ac"
+"tion\":\"swipe\",\"swipe\":{\"points\":[{\"x\":1152,\"y\":843,\"pos\":\"center"
+"\"},{\"x\":1131,\"y\":218,\"pos\":\"center\"}],\"duration\":2000}},{\"action"
+"\":\"click\",\"click\":{\"point\":{\"x\":1122,\"y\":190,\"pos\":\"center\"}}},{"
+"\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000}},{\"action\":\"click\",\""
+"click\":{\"point\":{\"x\":1193,\"y\":570,\"pos\":\"top\"}}},{\"action\":\"slee"
+"p\",\"sleep\":{\"sleepTime\":3000}},{\"action\":\"checkText\",\"checkText\""
+":{\"text\":\"BATTLE 4\",\"boundsCenter\":{\"x\":304,\"y\":514,\"pos\":\"top\"}"
+",\"found\":{\"kill\":false,\"stopScript\":false,\"nextAction\":\"ignore\"}"
+",\"notFound\":{\"kill\":true,\"stopScript\":false,\"nextAction\":\"fail\"}"
+"}},{\"action\":\"checkText\",\"checkText\":{\"text\":\"第2章\",\"boundsCenter"
+"\":{\"x\":305,\"y\":250,\"pos\":\"top\"},\"found\":{\"kill\":false,\"stopScrip"
+"t\":false,\"nextAction\":\"ignore\"},\"notFound\":{\"kill\":true,\"stopScr"
+"ipt\":false,\"nextAction\":\"fail\"}}},{\"action\":\"checkText\",\"checkTe"
+"xt\":{\"text\":\"1话\",\"boundsCenter\":{\"x\":303,\"y\":296,\"pos\":\"top\"},\"f"
+"ound\":{\"kill\":false,\"stopScript\":false,\"nextAction\":\"success\"},\""
+"notFound\":{\"kill\":true,\"stopScript\":false,\"nextAction\":\"fail\"}}}"
+"]}",
},
{
name: "国服门票活动剧情[BATTLE 1]",
content: "{\"date\":\"2022-2-14_4-12-10\",\"defaultSleepTime\":1500,\"isEventType"
+"BRANCH\":false,\"isGeneric\":true,\"package_name\":\"com.bilibili.mado"
+"ka.bilibili\",\"steps\":[{\"action\":\"click\",\"click\":{\"point\":{\"pos\":"
+"\"bottom\",\"x\":1620,\"y\":549}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTi"
+"me\":3000}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"top\",\"x\":1"
+"008,\"y\":182}}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"point"
+"s\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306"
+"}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\""
+":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"act"
+"ion\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\""
+":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swip"
+"e\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":"
+"915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\""
+":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos"
+"\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duratio"
+"n\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x"
+"\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"p"
+"oints\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\""
+":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\""
+"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{"
+"\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\""
+",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\""
+"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,"
+"\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"sw"
+"ipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{"
+"\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"dur"
+"ation\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top"
+"\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":200"
+"0,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070"
+",\"y\":306}]}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"bottom\","
+"\"x\":1092,\"y\":775}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000}"
+"},{\"action\":\"checkText\",\"checkText\":{\"boundsCenter\":{\"pos\":\"top\""
+",\"x\":305,\"y\":467},\"found\":{\"kill\":false,\"nextAction\":\"ignore\",\"s"
+"topScript\":false},\"notFound\":{\"kill\":true,\"nextAction\":\"fail\",\"s"
+"topScript\":false},\"text\":\"剧情副本\"}},{\"action\":\"checkText\",\"checkTe"
+"xt\":{\"boundsCenter\":{\"pos\":\"top\",\"x\":298,\"y\":515},\"found\":{\"kill"
+"\":false,\"nextAction\":\"success\",\"stopScript\":false},\"notFound\":{\""
+"kill\":true,\"nextAction\":\"fail\",\"stopScript\":false},\"text\":\"BATTL"
+"E 1\"}}]}"
},
{
name: "国服[由比鹤乃篇①]活动剧情",
content: "{\"date\":\"2022-2-14_4-12-10\",\"defaultSleepTime\":1500,\"isEventType"
+"BRANCH\":false,\"isGeneric\":true,\"package_name\":\"com.bilibili.mado"
+"ka.bilibili\",\"steps\":[{\"action\":\"click\",\"click\":{\"point\":{\"pos\":"
+"\"bottom\",\"x\":1620,\"y\":549}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTi"
+"me\":3000}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"top\",\"x\":1"
+"008,\"y\":182}}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"point"
+"s\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306"
+"}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\""
+":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"act"
+"ion\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\""
+":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swip"
+"e\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":"
+"915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\""
+":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos"
+"\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duratio"
+"n\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x"
+"\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"p"
+"oints\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\""
+":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\""
+"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{"
+"\"action\":\"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\""
+",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\""
+"swipe\",\"swipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,"
+"\"y\":915},{\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"sw"
+"ipe\":{\"duration\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{"
+"\"pos\":\"top\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"dur"
+"ation\":2000,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top"
+"\",\"x\":1070,\"y\":306}]}},{\"action\":\"swipe\",\"swipe\":{\"duration\":200"
+"0,\"points\":[{\"pos\":\"top\",\"x\":1070,\"y\":915},{\"pos\":\"top\",\"x\":1070"
+",\"y\":306}]}},{\"action\":\"click\",\"click\":{\"point\":{\"pos\":\"bottom\","
+"\"x\":1092,\"y\":775}}},{\"action\":\"sleep\",\"sleep\":{\"sleepTime\":3000}"
+"},{\"action\":\"checkText\",\"checkText\":{\"boundsCenter\":{\"pos\":\"top\""
+",\"x\":305,\"y\":467},\"found\":{\"kill\":false,\"nextAction\":\"ignore\",\"s"
+"topScript\":false},\"notFound\":{\"kill\":true,\"nextAction\":\"fail\",\"s"
+"topScript\":false},\"text\":\"剧情副本\"}},{\"action\":\"checkText\",\"checkTe"
+"xt\":{\"boundsCenter\":{\"pos\":\"top\",\"x\":298,\"y\":515},\"found\":{\"kill"
+"\":false,\"nextAction\":\"success\",\"stopScript\":false},\"notFound\":{\""
+"kill\":true,\"nextAction\":\"fail\",\"stopScript\":false},\"text\":\"由比鹤乃篇"
+"①\"}}]}",
},
];
//当前正在运行的线程
var currentTask = null;
var currentTaskName = "未运行任何脚本";
var currentTaskCycles = 0;
var currentTaskDrugConsumed = {};
const TASK_STOPPED = 0;
const TASK_RUNNING = 1;
const TASK_PAUSING = 2;
const TASK_PAUSED = 3;
const TASK_RESUMING = 4;
var isCurrentTaskPaused = threads.atomic(TASK_STOPPED);
//被打开的所有对话框(用于在线程退出时dismiss)
var openedDialogs = {openedDialogCount: 0};
var openedDialogsLock = threads.lock();
//运行脚本时隐藏UI控件,防止误触
floatUI.toolBarMenuItems = [];
floatUI.lockToolbarMenu = function (isLocked) {
ui.run(() => {
activity.setSupportActionBar(isLocked?null:ui.toolbar);
let menu = ui["toolbar"].getMenu();
menu.close();
if (isLocked) {
for (let i=0; i<menu.size(); i++) floatUI.toolBarMenuItems.push(menu.getItem(i));
menu.clear();
} else {
menu.clear();
while (floatUI.toolBarMenuItems.length > 0) {
menu.add(floatUI.toolBarMenuItems[0].getTitle())
.setIcon(floatUI.toolBarMenuItems[0].getIcon())
.setShowAsAction(android.view.MenuItem.SHOW_AS_ACTION_WITH_TEXT);
floatUI.toolBarMenuItems.splice(0, 1);
}
}
});
}
var lockUI = syncer.syn(function (isLocked) {
//隐藏或显示设置界面
updateUI("swipe", "setVisibility", isLocked?View.GONE:View.VISIBLE);
updateUI("running_stats", "setVisibility", isLocked?View.VISIBLE:View.GONE);
updateUI("lockToolbarMenu", "lockToolbarMenu", isLocked);
});
function getUIContent(key) {
switch (ui[key].getClass().getSimpleName()) {
case "JsEditText":
return ui[key].getText() + "";
case "Switch":
case "CheckBox":
return ui[key].isChecked()?"已启用":"已停用";
case "JsSpinner":
return ui[key].getSelectedItem();
case "RadioGroup": {
let name = "";
let text = "";
let id = ui[key].getCheckedRadioButtonId();
if (id >= 0) {
name = idmap[ui[key].getCheckedRadioButtonId()];
text = ui[name].getText();
}
return text;
}
}
}
function setUIContent(key, value) {
switch (ui[key].getClass().getSimpleName()) {
case "JsEditText":
ui[key].setText(value);
break;
case "Switch":
case "CheckBox":
ui[key].setChecked(value);
break;
case "JsSpinner":
ui[key].setSelection(value);
break;
case "RadioGroup":
if (value !== undefined && ui[value])
ui[value].setChecked(true);
break;
default:
throw new Error("setUIContent: unknown ui[key].getClass().getSimpleName() return value");
}
}
//监视当前任务的线程
var monitoredTask = null;
var bypassPopupCheck = threads.atomic(0);
//下面三个变量本来在algo_init闭包内、在startScreenCapture函数之前声明,现在移动到这里
var canCaptureScreen = false;
var requestScreenCaptureSuccess = false;
var hasScreenCaptureError = false;
var syncedReplaceCurrentTask = syncer.syn(function(taskItem, callback) {
if (currentTask != null && currentTask.isAlive()) {
stopThread(currentTask);
isCurrentTaskPaused.set(TASK_STOPPED);
toastLog("已停止之前的脚本");
}
//确保之前的脚本已经停下后新开一个线程执行callback
if (callback != null) {
threads.start(callback);
}
if (monitoredTask != null && monitoredTask.isAlive()) {
monitoredTask.join();
}
monitoredTask = threads.start(function () {
if (!limit.doNotToggleForegroundService) {
$settings.setEnabled("foreground_service", true);
log("已开启前台服务");
updateUI("foreground", "setChecked", $settings.isEnabled("foreground_service", false));
}
try {
currentTaskName = taskItem.name;
currentTask = threads.start(taskItem.fn);
currentTask.waitFor();
//由被运行的脚本线程自己执行isCurrentTaskPaused.set(TASK_RUNNING)
//如果被运行的脚本不(需要)支持暂停,那就不设置TASK_RUNNING
} catch (e) {logException(e);}
if (currentTask != null && currentTask.isAlive()) {
lockUI(true);
currentTask.join();
isCurrentTaskPaused.set(TASK_STOPPED);
lockUI(false);
}
//之前可能在STATE_TEAM状态下设置了跳过isGameDead里的掉线弹窗检查,现在恢复成不跳过
bypassPopupCheck.set(0);
log("关闭所有无主对话框...");
try {
openedDialogsLock.lock();//先加锁,dismiss会等待解锁后再开始删
for (let key in openedDialogs) {
if (key != "openedDialogCount") {
try {
openedDialogs[key].node.dialog.dismiss();
} catch (e) {
logException(e);
delete openedDialogs[key];
}
}
}
} catch (e) {
logException(e);
throw e;
} finally {
openedDialogsLock.unlock();
}
//等待dismiss删完,如果不等删完的话,下一次启动的脚本调用对话框又会死锁
log("等待无主对话框全部清空...");
while (true) {
let remaining = 0;
try {
openedDialogsLock.lock();
for (let key in openedDialogs) {
if (key != "openedDialogCount") {
remaining++;
}
}
} catch (e) {
logException(e);
throw e;
} finally {
openedDialogsLock.unlock();
}
if (remaining == 0) break;
sleep(100);
}
log("无主对话框已全部清空");
if (!limit.doNotToggleForegroundService) {
try {
$images.stopScreenCapture();
} catch (e) {
logException(e);
}
try {
captureScreen();
} catch (e) {
//截屏权限确实被停用了
canCaptureScreen = false;
requestScreenCaptureSuccess = false;
hasScreenCaptureError = false;
}
$settings.setEnabled("foreground_service", false);
log("已停止前台服务");
updateUI("foreground", "setChecked", $settings.isEnabled("foreground_service", false));
}
floatUI.storage.remove("last_limit_json");
//停止shell脚本监工(在参数修改触发adjust函数后就应该已经停止了)
if (limit.autoRecover) stopFatalKillerShellScript();
//释放OCR
if (ocr != null) {
ocr.release();
ocr = null;
}
//回收所有图片
tasks.recycleAllImages();
});
monitoredTask.waitFor();
});
//syncedReplaceCurrentTask函数也需要新开一个线程来执行,
//如果在UI线程直接调用,第二次调用就会卡在monitoredTask.join()这里
function replaceCurrentTask(taskItem, callback) {
//确保前一个脚本停下后会新开一个线程执行callback
try {
threads.start(function () {syncedReplaceCurrentTask(taskItem, callback);}).waitFor();
} catch (e) {
logException(e);
}
}
function replaceSelfCurrentTask(taskItem, callback) {
replaceCurrentTask(taskItem, callback);
stopThread();
}
floatUI.main = function () {
// space between buttons compare to button size
var space_factor = 1.5;
// size for icon compare to button size
var logo_factor = 7.0 / 11;
// button size in dp
var button_size = 44;
// submenu definition
var menu_list = [
{
logo: "@drawable/ic_camera_enhance_black_48dp",
color: "#009687",
fn: snapshotWrap,
},
{
logo: "@drawable/ic_more_horiz_black_48dp",
color: "#ee534f",
fn: taskWrap,
},
{
logo: "@drawable/ic_play_arrow_black_48dp",
color: "#40a5f3",
fn: defaultWrap,
},
{
logo: "@drawable/ic_clear_black_48dp",
color: "#fbd834",
fn: cancelWrap,
},
{
logo: "@drawable/ic_settings_black_48dp",
color: "#bfc1c0",
fn: settingsWrap,
},
];
stopThread = function (thread) {
var isSelf = false;
if (thread == null) {
thread = threads.currentThread();
isSelf = true;
}
if (ui.isUiThread()) {
if (isSelf) {
log("不能停止UI线程!");
} else threads.start(function () {
stopThread(thread);
});
} else {
while (isSelf || (thread != null && thread.isAlive())) {
try {thread.interrupt();} catch (e) {};
sleep(200);
}
}
}
function snapshotWrap() {
if (auto.root == null) {
log("auto.root == null");
toastLog("快照失败,无障碍服务是否开启?");
return;
}
toastLog("开始快照");
try {
var text = recordElement(auto.root, 0, "");
} catch (e) {
toastLog("快照出错");
logException(e);
return;
}
var d = new Date();
var timestamp =
"" +
d.getFullYear() +
"-" +
(d.getMonth() + 1) +
"-" +
d.getDate() +
"_" +
d.getHours() +
"-" +
d.getMinutes() +
"-" +
d.getSeconds();
var path = files.getSdcardPath();
path = files.join(path, "auto_magireco");
path = files.join(path, timestamp + ".xml");
files.ensureDir(path);
files.write(path, text);
toastLog("快照保存至" + path);
}
function defaultWrap() {
checkRotationGlitch();
toastLog("执行 " + floatUI.scripts[limit.default].name + " 脚本");
replaceCurrentTask(floatUI.scripts[limit.default]);
}
function taskWrap() {
checkRotationGlitch();
layoutTaskPopup();
task_popup.container.setVisibility(View.VISIBLE);
floaty_setTouchable("task_popup", true);
}
function cancelWrap() {
toastLog("停止脚本");
replaceCurrentTask({name:"未运行任何脚本", fn: function () {}});
}
//检测getWindowSize的转屏方向是不是出现错误
function checkRotationGlitch() {
let sz = getWindowSize();
if (sz.y > sz.x) {
try {
if (auto.root != null && auto.root.packageName() != context.getPackageName()) {
threads.start(function () {
for (let i=0; i<3; i++) {
toastLog("警告:\n检测到竖屏");
sleep(2000);
toast("如果实际上并不是竖屏,\n请强行停止脚本运行,或重启手机");
sleep(2000);
}
});
}
} catch (e) {
logException(e);
};
}
}
// get to main activity
function settingsScrollToTop(isPaused) {
//scrollview内容有变动时滚动回顶端
ui.run(function() {
//尝试过OnGlobalLayoutListener,但仍然没解决问题;
//可能是这个事件被触发过很多次,然后就不知道应该在第几次触发时注销Listener
ui["content"].postDelayed(function () {
ui["content"].smoothScrollTo(0, 0);
if (isPaused) {
ui["task_paused_vertical"].setVisibility(View.VISIBLE);
}
}, 600);
});
}
function openSettingsRunnable() {
if (!isCurrentTaskPaused.compareAndSet(TASK_RUNNING, TASK_PAUSING)) {
replaceCurrentTask(
{name:"未运行任何脚本", fn: function () {}},
function () {
//确保之前的脚本停下来后才会新开一个线程执行这个回调
toastLog("打开脚本设置\n(没有脚本正在运行中)");
backtoMain();
settingsScrollToTop(false);
}
);
return;
}
toastLog("正在暂停脚本...");
let lastTime = new Date().getTime();
while (true) {
let breakLoop = false;
switch (isCurrentTaskPaused.get()) {
case TASK_PAUSING:
sleep(200);
if (new Date().getTime() > lastTime + 4000) {
toast("小提示:\n有对话框时,无法暂停脚本");
lastTime = new Date().getTime();
}
break;
case TASK_PAUSED:
breakLoop = true;
break;
default:
toastLog("遇到意外情况,无法暂停脚本");
return;
}
if (breakLoop) break;
}
toastLog("脚本已暂停");
lockUI(false);
settingsScrollToTop(true);
backtoMain();
while (true) {
switch (isCurrentTaskPaused.get()) {
case TASK_PAUSED:
case TASK_RESUMING:
sleep(200);
break;
case TASK_RUNNING:
toastLog("继续运行脚本");
updateUI("task_paused_vertical", "setVisibility", View.GONE);
lockUI(true);
return;
break;
case TASK_STOPPED:
log("脚本已停止运行");
updateUI("task_paused_vertical", "setVisibility", View.GONE);
//monitoredTask会执行lockUI(false)
return;
break;
default:
toastLog("遇到意外情况,无法暂停脚本");
return;
}
}
}
var openSettingsThread = null;
function settingsWrap() {syncer.syn(function () {
if (openSettingsThread != null && openSettingsThread.isAlive()) {
if (isCurrentTaskPaused.get() == TASK_PAUSED) {
toastLog("打开脚本设置\n(脚本已暂停)");
backtoMain();
settingsScrollToTop(true);
} else {
toastLog("脚本尚未暂停\n请稍后再试");
return;
}
} else {
openSettingsThread = threads.start(openSettingsRunnable);
}
})();};
//切换悬浮窗靠左/靠右,切换后X轴方向会反转。
function toggleFloatyGravityLeftRight(floatyRawWindow, isRight) {
let field = floatyRawWindow.getClass().getDeclaredField("mWindow");
field.setAccessible(true);
mWindow = field.get(floatyRawWindow);
let layoutParams = mWindow.getWindowLayoutParams();
let gravity = layoutParams.gravity;
if (isRight == null) {
gravity ^= android.view.Gravity.LEFT | android.view.Gravity.RIGHT;
} else {
gravity &= ~(isRight ? android.view.Gravity.LEFT : android.view.Gravity.RIGHT);
gravity |= isRight ? android.view.Gravity.RIGHT : android.view.Gravity.LEFT;
}
gravity &= ~(android.view.Gravity.RELATIVE_LAYOUT_DIRECTION);
layoutParams.gravity = gravity;
mWindow.updateWindowLayoutParams(layoutParams);
}
var isGravityRight = false;
//绕过Android 12出现setTouchable(false)无效的问题
var floatyObjs = {};
var isFloatyTouchable = {};
var floatySize = {};
function registerFloatyObj(key, obj) {
floatyObjs[key] = obj;
isFloatyTouchable[key] = true;
floatySize[key] = {width: floatyObjs[key].getWidth(), height: floatyObjs[key].getHeight()}; //有时候会返回0
}
function floaty_getWidth(key) {
return floatySize[key].width;
}
function floaty_getHeight(key) {
return floatySize[key].height;
}
function floaty_setSize(key, width, height) {
floatySize[key] = {width: width, height: height};
if (isFloatyTouchable[key]) floatyObjs[key].setSize(width, height);
}
function floaty_setTouchable(key, touchable) {
var retryRecordSize = (newTouchable) => {
//有时候registerFloatyObj记录下来的原大小是0,这里试图重新记录
let size = floatySize[key];
if (size.width <= 1 || size.height <= 1) {
size = {width: floatyObjs[key].getWidth(), height: floatyObjs[key].getHeight()};
log("retryRecordSize", "key", key, "touchable", touchable, "isFloatyTouchable[key]", isFloatyTouchable[key], "size", size);
}
if (size.width > 1 && size.height > 1) {
floatySize[key] = size;
if (!newTouchable) floatyObjs[key].setSize(1, 1);
} else {
ui.post(() => {retryRecordSize(newTouchable);}, 500);
}
}
let oldVal = isFloatyTouchable[key] ? true : false;
let newVal = touchable ? true : false;
floatyObjs[key].setTouchable(newVal);
retryRecordSize(newVal);
if (oldVal == newVal) {
return;
}
isFloatyTouchable[key] = newVal;
if (newVal) {
let size = floatySize[key];
floatyObjs[key].setSize(size.width, size.height);
}
}
var task_popup = floaty.rawWindow(
<frame id="container" w="*" h="*">
<relative w="*" h="*" bg="#f8f8f8" margin="0 15 15 0" padding="2" >
<vertical id="list_title" bg="#4fb3ff" w="match_parent" h="wrap_content" layout_alignParentTop="true" >
<text text="选择需要执行的脚本" textSize="16" padding="4 2" textColor="#ffffff" />
</vertical>
<list id="list" w="match_parent" layout_below="list_title" layout_above="list_reminder" >
<text
id="name"
text="{{name}}"
textSize="16"
h="45"
gravity="center"
margin="0 1"
w="*"
bg="#ffffff"
/>
</list>
<vertical id="list_reminder" bg="#4fb3ff" w="match_parent" h="wrap_content" layout_alignParentBottom="true" >
<text text="如果没看到想要的,可以继续往下拖动找找看" textSize="16" padding="4 2" textColor="#ffffff" />
</vertical>
</relative>
<frame id="close_button" w="30" h="30" layout_gravity="top|right">
<img w="30" h="30" src="#881798" circle="true" />
<img
w="21"
h="21"
src="@drawable/ic_close_black_48dp"
tint="#ffffff"
layout_gravity="center"
/>
</frame>
</frame>
);
function layoutTaskPopup() {
var sz = getWindowSize();
floaty_setSize("task_popup", parseInt(sz.x * 3 / 4), parseInt(sz.y * 3 / 4));
task_popup.setPosition(parseInt(sz.x / 8), parseInt(sz.y / 8));
}
task_popup.container.setVisibility(View.INVISIBLE);
ui.post(() => {