-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTong~.lua
More file actions
1347 lines (1268 loc) · 39.6 KB
/
Copy pathTong~.lua
File metadata and controls
1347 lines (1268 loc) · 39.6 KB
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
--Duo Helper
--增加功能:一文,音乐,日历等
--作者:Duo QQ:113530014
--更新:11.11大框架功能添加
-- 11.12现在Duo能与人类交流聊天了
-- 11.13优化细节
-- 11.17全新升级,AI更名为"小彤"(大家猜猜她是谁(^-^))
-- 11.20本人使用平板电脑编写,在手机上界面可能会有较大误差,现已修复界面漏洞
-- 11.26不主动联系你的人工智能不是好人工智能,加入自动聊天功能
-- 12.4优化自动回复
-- 1.17增加功能:一文,音乐,日历等
-- 2024.2.5更新api
require "import"
import "java.io.*"
import "android.os.*"
import "android.app.*"
import "android.view.*"
import "android.widget.*"
import "android.text.Html"
import "android.content.Context"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.View_*"
import "android.media.*"
import "android.view.*"
import "android.content.*"
import "java.io.*"
import "java.util.*"
import "android.content.Context"
import "android.provider.*"
import "android.graphics.drawable.GradientDrawable"
import "android.graphics.drawable.ColorDrawable"
import "androidx.cardview.widget.CardView"
import "android.widget.PopupMenu"
import "androidx.appcompat.widget.PopupMenu"
import "android.app.AlertDialog"
import "android.graphics.Paint"
--在此感谢→机不可失 提供的输入法不影响EditText视线方案
--activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
local uiManager=this.uiManager
local themeConfig=uiManager.themeConfig
local colors=themeConfig.getColors()
local MaterialCardView = luajava.bindClass "com.google.android.material.card.MaterialCardView"
local Slider = luajava.bindClass "com.google.android.material.slider.Slider"
local SwitchMaterial = luajava.bindClass "com.google.android.material.switchmaterial.SwitchMaterial"
local MaterialCheckBox = luajava.bindClass "com.google.android.material.checkbox.MaterialCheckBox"
local ShapeableImageView = luajava.bindClass "com.google.android.material.imageview.ShapeableImageView"
function 复制文本(内容) import "android.content.Context" activity.getSystemService(Context.CLIPBOARD_SERVICE).setText(tostring(内容)) end
大框架={
LinearLayout,
orientation="vertical";
layout_width="fill",
layout_height="fill",
layout_weiget="1",
background="#ffffffff",
id="background",
fitsSystemWindows=true;--防止输入法影响视图
{
LinearLayout;
layout_width="fill",
background="#ffffffff";
{
CircleImageView,
layout_width="45dp",
layout_height="45dp",
src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
};
{
TextView,
text="Duo Helper";
gravity="left|center";
layout_width="fill";
layout_height="45dp";
layout_marginTop="0dp";
textSize="20";
layout_left="1";
layout_marginLeft="2%w";
backgroundColor="#FFffffff";
textColor="#FF655478";
layout_marginBottom="0dp";
id="tittle"
};
};
{
LinearLayout,
layout_width="fill",
layout_height="fill",
layout_weight="1dp",
orientation="vertical",
--backgroundColor="#FFF2F3F5";
{
ScrollView,
id="scrollView",
layout_width="fill",
layout_height="fill",
backgroundColor="#FFF2F3F5";
{
LinearLayout,
paddingTop="15dp",
paddingLeft="15dp",
paddingRight="15dp",
layout_width="fill",
layout_height="fill",
background="#FFF2F3F5",
orientation="vertical",
id="lt",
},
},
},
{
LinearLayout,
layout_width="fill",
layout_height="65dp",
orientation="horizontal",
background='#FFF2F3F5';
{
LinearLayout;
layout_width="fill";
{
CardView;
layout_margin="10dp";
layout_height="43dp";
layout_width="fill";
radius='6dp';--卡片圆角
{
EditText;
id="edit";
layout_marginLeft='10dp';--布局左距
background="#FFFFFFFF";
layout_gravity="center";
gravity="left";
textSize="16sp",--文本大小
-- imeOptions="actionSearch";--设置键盘右下角操作
id="发送内容",
singleLine="true";
Hint="你好,我是小彤…";
layout_width="fill";
};
{
Button;
background="#FF10B124";
layout_height="48dp";
layout_gravity="center|right";
textColor="#FFFFFFFF";
layout_width="70dp";
text="发送";
id="sousuo";
onClick="发送",
};
{
LuaWebView;--浏览器控件
layout_width='0';--宽度
layout_height='0';--高度
id="webView",
};
},
};
};
}
activity.setContentView(loadlayout(大框架))
--↑fa1
--this.uiManager.getFragment(0).view.addView(loadlayout(大框架))
--↑fa2
begain=
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#FFF2F3F5',--背景颜色或图片路径
{
CardView;--卡片控件
layout_gravity='center';--重力
layout_height='20dp';--高度
CardBackgroundColor='#FF707070';--颜色
layout_marginBottom='10dp';
radius='5dp';--圆角
{
TextView;--文本控件
gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='fill';--高度
textColor='#FFFFFFFF';--文字颜色
text=(" "..os.date("%H")..":"..os.date("%M")..' 你添加了小彤现在可以开始聊天了 ');--显示文字
textSize='14dp';--文字大小
};
};
}
lt.addView(loadlayout(begain))
function system_help()
system_help_lay=
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#FFF2F3F5',--背景颜色或图片路径
{
CardView;--卡片控件
layout_gravity='center';--重力
layout_height='20dp';--高度
--layout_width="match";
CardBackgroundColor='#FF707070';--颜色
layout_marginBottom='10dp';
radius='5dp';--圆角
{
LinearLayout,--线性布局
orientation=0,--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
{
TextView;--文本控件
gravity='center';--重力
layout_width='fill';--宽度
layout_height='fill';--高度
textColor='#FFFFFFFF';--文字颜色
text="不会和她聊天?",
textSize='14dp';--文字大小
paddingLeft="10dp",
};
{
TextView;--文本控件
gravity='center';--重力
layout_width='fill';--宽度
layout_height='fill';--高度
textColor='#64B5F6';--文字颜色
text="聊天宝典",
textSize='14dp';--文字大小
paddingRight="10dp",
id="system_help_last_id",
onClick=function()
Ai_txt(ai_help_t)
end,
};
},
};
}
lt.addView(loadlayout(system_help_lay))
system_help_last_id.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG)
end
function Ai_txt(str)
RobotLayout=
{ LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{MaterialCardView,
layout_width="45dp",
layout_height="45dp",
tooltipText="小彤",
radius="50dp",
cardElevation=0,
onClick=function()
end,
{ CircleImageView,
id="systemtouxiang",
layout_width="fill",
layout_gravity="center";
layout_height="fill",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
};
},
{ LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
layout_marginLeft="10dp";
{MaterialCardView,
layout_height="wrap",
layout_width="wrap",
radius="10dp",
cardElevation=0,
cardBackgroundColor="#FFFFFFFF",
onClick=function()
--复制文本(xt_t.text)
--print("复制成功")
end,
id="Ai_txt_card",
{TextView,
text=str;
gravity="left|center";
textSize="15dp",
textStyle="bold",
padding="13dp",
id="xt_t",
textColor="#FF5B5B5B",
--textIsSelectable=true,--长按复制
},
},
};
}
lt.addView(loadlayout(RobotLayout))
Ai_txt_card.onLongClick=function()
复制文本(xt_t.text)
print("复制成功")
return true--防止触发点击事件
end
xt_t.setText(str)
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
--Ai_music(str)
function Me_txt(str)--*************************用户
MeLayout=
{ LinearLayout,
layout_width="fill",
gravity="top|right";
orientation="horizontal",
{
LinearLayout,
gravity="right";
orientation="horizontal",
layout_width="70%w",
{MaterialCardView,
layout_height="wrap",
layout_width="wrap",
radius="10dp",
cardElevation=0,
cardBackgroundColor="#FF10B124",
layout_marginBottom="20dp";
onClick=function()
end,
id="Me_txt_card",
{TextView,
text=str;
gravity="left|center";
textSize="15dp",
textStyle="bold",
padding="13dp",
textColor=colors.colorPrimary,
--textIsSelectable=true,--长按复制
},
},
};
{ CircleImageView,
id="usertouxiang",
layout_width="45dp",
layout_height="45dp",
src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="Duo",
layout_marginLeft="10dp";
};
}
lt.addView(loadlayout(MeLayout))
Me_txt_card.onLongClick=function()
--复制文本(xt_t.text)
--print("复制成功")
return true--防止触发点击事件
end
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
-------------#####################################
function Ai_web(str)
RobotLayout=
{
LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{
CircleImageView,
id="systemtouxiang",
layout_width="40dp",
layout_height="45dp",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
--src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="小彤",
layout_marginRight="10dp";
};
{
LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
{MaterialCardView,
layout_height="wrap",
layout_width="wrap",
radius="10dp",
cardElevation=0,
--cardBackgroundColor=colors.colorAccent,
onClick=function()
end,
{
LuaWebView;--浏览器控件
layout_width='fill';--宽度
layout_height='80%w';--高度
layout_margin="15dp";
id="浏览器",
};
},
};
}
lt.addView(loadlayout(RobotLayout))
浏览器.loadUrl(str)
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
function Ai_date(str)
RobotLayout=
{
LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{
CircleImageView,
id="systemtouxiang",
layout_width="45dp",
layout_height="45dp",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
--src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="小彤",
layout_marginRight="10dp";
};
{
LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
{MaterialCardView,
layout_height="wrap",
layout_width="70%w",
radius="10dp",
cardElevation=0,
--cardBackgroundColor=colors.colorAccent,
onClick=function()
end,
{ LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='70%w',--宽度
layout_height='wrap',--高度
{
DatePicker,--日期选择器
layout_width="70%w",
layout_height="wrap",
},
{TextView,
text="";
gravity="left|center";
textSize="15dp",
textStyle="bold",
padding="13dp",
id="xt_t",
textColor="#FF5B5B5B",
textIsSelectable=true,--长按复制
},
},
},
};
}
lt.addView(loadlayout(RobotLayout))
Http.get("https://xiaoapi.cn/API/lt_xiaoai.php?type=json&msg="..发送内容.text,function(链接状态,网页源码)
if 链接状态==200 then
if string.find(网页源码,"小爱")~=nil then 网页源码=string.gsub(网页源码,"小爱","小彤") end
if string.find(网页源码,"小米")~=nil then 网页源码=string.gsub(网页源码,"小米","Duo") end
xt_t.setText (网页源码:match([["txt": "(.-)",]]))
else
xt_t.setText ("额,这样我怎么回答你…")
end
end)
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
function Ai_story()
RobotLayout=
{
LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{
CircleImageView,
id="systemtouxiang",
layout_width="45dp",
layout_height="45dp",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
--src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="小彤",
layout_marginRight="10dp";
};
{
LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
{MaterialCardView,
layout_height="wrap",
layout_width="80%w",
radius="10dp",
cardElevation=0,
--cardBackgroundColor=colors.colorAccent,
onClick=function()
end,
{ LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='80%w',--宽度
layout_height='wrap',--高度
{TextView,
text="";
layout_gravity="center";
textSize="20dp",
textStyle="bold",
padding="13dp",
id="xt_story_title",
textColor="#FF5B5B5B",
},
{TextView,
text="";
gravity="left|center";
textSize="15dp",
padding="13dp",
id="xt_story",
textIsSelectable=true,--长按复制
},
},
},
};
}
lt.addView(loadlayout(RobotLayout))
url="https://meiriyiwen.com/random/iphone"
Http.get(url,nil,"UTF-8",nil,function(code,content,cookie,header)
if(code==200 and content)then
xt_story_title_t=content:match("%ph2%sclass%p%particleTitle%p%p%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s(.-)%p%ph2%p")
xt_story_t=string.gsub(string.gsub(string.gsub(content:match("%pdiv%sclass%p%particleContent%p%p%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s(.-)%p%pdiv%p"),"%pp%p",""),"%p%pp%p",""),"%p","")
--设置文字
xt_story_title.setText(xt_story_title_t)
xt_story.setText(xt_story_t)
else
xt_story.text="获取内容失败"..code
end
end)
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
function Ai_wl(str)
RobotLayout=
{
LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{
CircleImageView,
id="systemtouxiang",
layout_width="45dp",
layout_height="45dp",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
--src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="小彤",
layout_marginRight="10dp";
};
{
LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
{MaterialCardView,
layout_height="wrap",
layout_width="80%w",
radius="10dp",
cardElevation=0,
--cardBackgroundColor=colors.colorAccent,
onClick=function()
end,
{ LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='80%w',--宽度
layout_height='wrap',--高度
id="wl_l",
{TextView,
text="",
gravity="left|center";
textSize="15dp",
textStyle="bold",
padding="13dp",
id="xt_t",
textColor="#FF5B5B5B",
},
},
},
};
}
lt.addView(loadlayout(RobotLayout))
wl_r=math.random(1,4)
switch wl_r
case 1
wl_l.addView(loadlayout({Slider}))
xt_t.setText("无聊的话送你一个滑动条,滑动试试")
case 2
wl_l.addView(loadlayout({MaterialCheckBox}))
xt_t.setText("无聊的话送你一个复选框")
case 3
wl_l.addView(loadlayout({SwitchMaterial}))
xt_t.setText("无聊的话送你一个可爱的小开关")
case 4
wl_l.addView(loadlayout({ProgressBar}))
xt_t.setText("无聊的话送你一个进度条,看着它,一会就不无聊了")
end
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
end
function Ai_music(str)
play_i=false--默认暂停播放
RobotLayout=
{
LinearLayout,
layout_width="85%w",
layout_height="fill",
orientation="horizontal",
{
CircleImageView,
id="systemtouxiang",
layout_width="45dp",
layout_height="45dp",
src="https://ss0.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3250396690,2919604218&fm=253&gp=0.jpg";
--src="https://ncstatic.clewm.net/rsrc/2022/1111/21/df3aad15b7df8ab15b6daaeb6de4e3a2.png?x-oss-process=image/resize,w_270/format,gif/sharpen,100/quality,Q_80/interlace,1/auto-orient,1";
tooltipText="小彤",
layout_marginRight="10dp";
};
{
LinearLayout,
id="system";
layout_width="wrap",
layout_height="-2",
orientation="horizontal",
layout_marginBottom="20dp";
{MaterialCardView,
layout_height="wrap",
layout_width="80%w",
radius="10dp",
cardElevation=0,
--cardBackgroundColor=colors.colorAccent,
--onClick=function()
---end,
{
LinearLayout;
--Focusable=true,
gravity="center";
--FocusableInTouchMode=true,
id="bg",
{
LinearLayout,
layout_height="wrap_content",
layout_width="70%w",
orientation=1,
{TextView,
text="Duo Music";
layout_gravity="center";
textSize="15dp",
textStyle="bold",
padding="13dp",
id="mu_t",
textColor="#FF5B5B5B",
},
{
LinearLayout,
layout_height="match",
layout_width="fill",
orientation="horizontal",
gravity="center|bottom",
layout_margin="10dp",
layout_gravity="center",
{MaterialCardView,
layout_height="70dp",
layout_width="70dp",
radius="50dp",
cardElevation=0,
layout_margin="5dp",
layout_gravity="center",
--cardBackgroundColor="#5090CAF9",
onClick=function()
上一曲()
end,
{
ShapeableImageView;--圆形图片
src='img/to_left.png';--图片路径
layout_gravity="center",
layout_width='40dp';--布局宽度
layout_height='40dp';--布局高度
alpha=0.7,
},
},
{MaterialCardView,
layout_height="70dp",
layout_width="70dp",
radius="50dp",
cardElevation=0,
layout_margin="5dp",
layout_gravity="center",
cardBackgroundColor="#5090CAF9",
id="cen",
onClick=function()
play_i=not(play_i)
switch play_i
case true play_img.setImageBitmap(loadbitmap("img/pause.png"))
case false play_img.setImageBitmap(loadbitmap("img/play.png"))
end
on_pause()
end,
{
ShapeableImageView;--圆形图片
src='img/play.png';--图片路径
layout_gravity="center",
layout_width='35dp';--布局宽度
layout_height='35dp';--布局高度
id="play_img",
alpha=0.7,
},
},
{MaterialCardView,
layout_height="70dp",
layout_width="70dp",
radius="50dp",
cardElevation=0,
layout_margin="5dp",
layout_gravity="center",
--cardBackgroundColor="#5090CAF9",
onClick=function()
下一曲()
end,
{
ShapeableImageView;--圆形图片
src='img/to_right.png';--图片路径
layout_gravity="center",
layout_width='40dp';--布局宽度
layout_height='40dp';--布局高度
alpha=0.7,
},
},
},
{
RelativeLayout,
layout_width="fill_parent",
layout_height="fill_parent",
layout_margin="7dp",
gravity="top|bottom",
-- orientation="vertical",
{
LinearLayout,
layout_height="wrap_content",
layout_width="match_parent",
orientation="vertical",
id="mainLinearLayout1",
gravity="bottom|center",
layout_alignParentBottom=true,
{
LinearLayout,
layout_height="wrap_content",
layout_width="match_parent",
orientation="horizontal",
-- layout_below="mainImageView1",
id="mainLinearLayout2",
gravity="center|bottom",
layout_marginBottom="10dp",
{
TextView,
layout_height="wrap_content",
text="00:00",
id="tv_startTime",
layout_width="wrap_content"
},
{
SeekBar,
layout_height="wrap_content",
--style="progressBarStyleHorizontal",
layout_width="wrap_content",
id="mainProgressBar1",
id="pb_time",
layout_weight="1.0"
},
{
TextView,
layout_height="wrap_content",
text="00:00",
id="tv_endTime",
layout_width="wrap_content"
},
},
},
},
},
};
},
};
}
lt.addView(loadlayout(RobotLayout))
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
local arr=nil
local pd--扫描进度条变量,定义在这容易操作
local mp=MediaPlayer()
local t=nil
local isPlay=false
local curPlay=nil --当前正在播放的mp3的路径
local listpath="/storage/emulated/0/Duo Music/歌单.txt"
local tf=File(listpath)
local dur--歌曲长度
local cur--播放当前位置
local min,sec=0,0--分和秒
local curIdx=0--当前播放的mp3在列表中的索引
--播放音乐,不异步可控
--@mp MediaPlayer对象
--@path 歌曲完整路径
function play(mp,path)
mp.reset()
mp.setDataSource(path)
mp.prepare()
mp.start()
end
--异步调用代码块,获取文件夹下的所有mp3文件。并存在arr中
local _getList=[[
require "import"
import "java.io.*"
local path,arr=...
local name,t
function _get(path)
local f=File(path)
local l=f.listFiles()
for i=0,#l-1 do
t=l[i]
name= t.getName()
if t.isFile() and string.find(string.lower(name),"%.mp3$") and t.length()>1024*1024*0.3 then --歌曲大于0m才添加
arr.add(t)
end
if t.isFile() and string.find(string.lower(name),"%.m4a$") and t.length()>1024*1024*0.3 then --歌曲大于2m才添加
arr.add(t)
end
if t.isFile() and string.find(string.lower(name),"%.wav$") and t.length()>1024*1024*0.3 then --歌曲大于2m才添加
arr.add(t)
end
if t.isFile() and string.find(string.lower(name),"%.wma$") and t.length()>1024*1024*0.3 then --歌曲大于2m才添加
arr.add(t)
end
if t.isFile() and string.find(string.lower(name),"%.mp4$") and t.length()>1024*1024*0.3 then --歌曲大于2m才添加
arr.add(t)
end
if t.isDirectory() then
_get(t.toString())
end
end --for
end --_get
_get(path)--重要......
]]
--获取某文件夹下所有mp3文件。并存在arr中
function getList(path)
arr=ArrayList()
task( _getList,path,arr,getListFinish)
end
--回调函数,获取某文件夹下所有mp3文件完成时被调用
function getListFinish()
writeFile("/storage/emulated/0/Duo Music/歌单.txt",arr)
pd.cancel()
end
--写入文件
--@path 文件完整路径
--@list ArrayList
function writeFile(path,list)
local fw=FileWriter(path)
local bw=BufferedWriter(fw)
for i=0,list.size()-1
do
str=list.get(i).toString()
bw.write(str,0,utf8.len(str))
bw.newLine()
end
bw.flush()
bw.close()
end
--读文件
--path 完整路径
--return ArrayList
function readFile(path)
local al=ArrayList()
local fr=FileReader(path)
local br=BufferedReader(fr)
local ch=0
while(br.read()~=-1 )
do
al.add(br.readLine())
end
br.close()
return al
end
--显示歌曲列表
--@path 列表文件路径
--@mediaplayer
function showList(path,mp)
local al= readFile(path)
arr=al
local names={}
local paths={}
for i=0,al.size()-1 do
table.insert(paths,al.get(i))
table.insert(names,File(al.get(i)).getName())
end
local ad= AlertDialog.Builder(activity)
ad.setTitle("歌曲列表")
ad.setItems(String(names)
,DialogInterface.OnClickListener{
onClick=function(dialog,which)
curPlay=paths[which+1]
curIdx=which
play(mp,curPlay)
local tt=string.gsub(names[which+1],".mp3$","")--偷懒一下
mu_t.setText(tt)
end
})
ad.setNegativeButton( "取消", nil)
ad.setNeutralButton("扫描",{onClick=function() showEditDialog("输入路径以重新扫描.") end})
ad= ad.create()
local window = ad.getWindow()
local lp = window.getAttributes()
lp.alpha = 1.0
window.setAttributes(lp)
ad.show()
end
function showProcessBar(text)
pd = ProgressDialog
.show(activity, nil, text)
pd.setCancelable(false)
end
function showEditDialog(msg)
local edit=EditText(activity)
edit.setText("/storage/emulated/0/Duo Music/")
local dl =AlertDialog.Builder(activity)
dl.setTitle(msg)
dl.setView(edit)
dl.setPositiveButton("确定",
DialogInterface.OnClickListener{
onClick=function(dialog,which)
showProcessBar("扫描中…")
getList(edit.getText().toString())
end
})
dl.show()
end
if tf.exists()==false then--文件列表不存在
showEditDialog("初始化扫描音乐路径")
else
arr= readFile(listpath)
end
function updateTime(m,s)
if m<10 then m="0"..m end
if s<10 then s="0"..s end
tv_startTime.setText(m..":"..s)
pb_time.setProgress(mp.getCurrentPosition())
end
function _run(m,s)
function run()
s=s+1
if(s==60) then
m=m+1