我有一个朋友,他非常好学。一天,他发现了一个全是漂亮妹妹的网页(๐॔˃̶ᗜ˂̶๐॓)

他想了想,妹子太多。得留下来慢慢看,于是他决定敲一点简单的代码完成他的愿望。


致命分析

打开网页,先不要康漂亮妹妹。在页脚发现【推荐】栏目。

嗯~,可以利用这个作为一个突破口。

打开开发者工具,康康漂亮妹纸的图片写法。嗯~,可以嫖。

于是他决定开发一款APP。将推荐栏目作为首页推荐,点击后加载所有漂亮妹妹的图片。

由于【推荐】栏目随机,这也恰好实现了首页栏目的推荐随机~

我的朋友还想顺便写一个一键保存所有图片功能……

理论存在,实践开始

我们决定使用lua编程语言开发,小而轻量。手机端即可操作,童叟无欺,老少皆宜~

开发语言: lua

开发工具: AndroidLua+

开发环境: Android手机

布局工具: AluaJ助手

布局页面

布局一个滑动窗体,可以左右切换栏目与图片表

左侧栏目用于显示栏目内容及封面,右侧为所有图片列表

查看框架布局代码
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
{
LinearLayout;
layout_height="match_parent";
layout_width="match_parent";
orientation="vertical";
{
CardView;
layout_height="wrap_content";
backgroundColor="0xFF2196F3";
radius="0dp";
CardElevation="3dp";
layout_width="match_parent";
{
LinearLayout;
layout_width="match_parent";
layout_marginTop=result;
{
LinearLayout;
orientation="horizontal";
gravity="center";
layout_height="56dp";
layout_width="match_parent";
{
LinearLayout;
layout_height="match_parent";
gravity="center";
{
CardView;
layout_height="80dp";
PreventCornerOverlap=false;
layout_marginLeft="-15dp";
CardElevation="0dp";
background="#00000000";
radius="40dp";
UseCompatPadding=false;
layout_width="80dp";
{
ImageView;
layout_height="match_parent";
layout_margin="-10dp";
id="btn";
background="#00000000";
padding="38dp";
src="icon/navnav.png";
layout_width="match_parent";
};
};
};
{
TextView;
gravity="center|left";
singleLine=true;
layout_marginLeft="-15dp";
layout_width="match_parent";
text=activity.getTitle();
id="title";
textSize="19dp";
ellipsize="end";
layout_height="match_parent";
layout_weight="1";
textColor="#FFFFFF";
};
{
CardView;
layout_height="65dp";
PreventCornerOverlap=false;
CardElevation="0dp";
layout_marginRight="-17dp";
background="#00000000";
radius="33dp";
UseCompatPadding=false;
layout_width="65dp";
{
ImageView;
layout_height="match_parent";
layout_margin="-10dp";
id="btn1";
background="#00000000";
padding="28dp";
src="icon/ic_package_variant.png";
layout_width="match_parent";
};
};
{
CardView;
layout_height="65dp";
PreventCornerOverlap=false;
CardElevation="0dp";
layout_marginRight="-19dp";
background="#00000000";
radius="33dp";
UseCompatPadding=false;
layout_width="65dp";
{
ImageView;
layout_height="match_parent";
layout_margin="-10dp";
id="btn2";
background="#00000000";
padding="28dp";
src="icon/ic_right.png";
layout_width="match_parent";
};
};
{
CardView;
layout_height="65dp";
PreventCornerOverlap=false;
CardElevation="0dp";
layout_marginRight="-10dp";
background="#00000000";
radius="33dp";
UseCompatPadding=false;
layout_width="65dp";
{
TextView;
layout_height="0dp";
id="menu";
layout_marginLeft="-145dp";
layout_marginTop="10dp";
layout_width="0dp";
};
{
ImageView;
layout_height="match_parent";
layout_margin="-10dp";
id="btn3";
background="#00000000";
padding="31dp";
src="icon/abc_ic_menu_moreoverflow_mtrl_alpha.png";
layout_width="match_parent";
};
};
};
};
};
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
{
PageView;--滑动窗体
id="img_hd",
pages={
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#f1e8ae8',--背景颜色或图片路径
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='wrap';--高度
CardBackgroundColor='0';--颜色
radius='8dp';--圆角
{
GridView,--网格控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
gravity="center",--重力居中
numColumns="1",--设置列数
overScrollMode="2",--去除滑动圆弧形
verticalScrollBarEnabled=false,--隐藏滑条
id="fm_wg",--控件ID
};
};
{
CardView;--卡片控件
layout_margin='16dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='4.5%h';--高度
CardBackgroundColor='#c000000';--颜色
radius='5dp';--圆角
id="f5",
{
TextView;--文本控件
gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='fill';--高度
textColor='#87000000';--文字颜色
text='loading...';--显示文字
textSize='14dp';--文字大小
id="tip";
textIsSelectable=false--长按复制
};
};
{
CardView;--卡片控件
layout_margin='16dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='4.5%h';--高度
CardBackgroundColor='#c000000';--颜色
radius='5dp';--圆角
id="download",
{
TextView;--文本控件
gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='fill';--高度
textColor='#87000000';--文字颜色
text='批量下载图片';--显示文字
textSize='14dp';--文字大小
textIsSelectable=false--长按复制
};
};
};
--
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#00FFFFFF',--背景颜色或图片路径
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='5dp';--阴影
layout_width='fill';--宽度
layout_height='fill';--高度
CardBackgroundColor='#ffffffff';--颜色
radius='8dp';--圆角
{
GridView,--网格控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
gravity="center",--重力居中
numColumns="1",--设置列数
overScrollMode="2",--去除滑动圆弧形
verticalScrollBarEnabled=true,--隐藏滑条
id="bzwg",--控件ID
};
{
CardView;--卡片控件
layout_margin='0dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='wrap';--高度
CardBackgroundColor='0';--颜色
radius='0dp';--圆角
id="tips",
{
TextView;--文本控件
gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='wrap';--高度
textColor='#32000000';--文字颜色
text='你还没选择妹子呢┐(´-`)┌';--显示文字
textSize='14dp';--文字大小
textIsSelectable=false--长按复制
};
};
};
};
--
};
};
};
};
封面适配
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
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#00FFFFFF',--背景颜色或图片路径
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='5dp';--阴影
layout_width='fill';--宽度
layout_height='20%h';--高度
CardBackgroundColor='#ffffffff';--颜色
radius='8dp';--圆角
{
ImageView;--图片控件
id="tp_fm";
-- src='https://c2cpicdw.qpic.cn/offpic_new//2697808752-3475747673-7E9ACC2E12FF6A70FF8B35FAACE2A8B0/0';--图片路径
layout_width='fill';--宽度
layout_height='wrap';--高度
scaleType='centerCrop';--图片显示类型
};
{
CardView;--卡片控件
layout_margin='0dp';--边距
layout_gravity='bottom';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='wrap';--高度
CardBackgroundColor='#ffffff';--颜色
radius='0dp';--圆角
{
TextView;--文本控件
id="text",
gravity='right';--重力
layout_marginRight='15px';--右距
layout_marginBottom='12px';--底距
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='14sp';--高度
textColor='#4c000000';--文字颜色
textSize='14dp';--文字大小
textIsSelectable=false--长按复制
};
};
};
};

图片列表布局适配
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
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#00FFFFFF',--背景颜色或图片路径
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='5dp';--阴影
layout_width='wrap';--宽度
layout_minheight='20%h';--高度
layout_height='fill';--高度
CardBackgroundColor='#ffffffff';--颜色
radius='8dp';--圆角
{
ImageView;--图片控件
id="tp",
src='';--图片路径
layout_width='wrap';--宽度
layout_height='fill';--高度
scaleType='fitXY';--图片显示类型
};
};
};

到这里就帮助我的好朋友完成了布局

主函数调用及爬虫配置

程序启动开始爬取推荐
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
list={[1]="163690361614072",[2]="163971663641960",[3]="164103476922468",[4]="164103767225808",[5]="163826289956514",[6]="163842588189291",[7]="163819406521636"}
url="http://w.advancedinsulation.com.cn:61/qq.php?t="..list[math.random(1,7)];
Http.get(url,nil,nil,nil,function(code,content)
if code==200 then
title=content:gmatch([[<title>(.-)</title>]])
content=content:match([[随机推荐(.-)section]])
p=content:gmatch([[php.-t=(.-)']])
t=content:gmatch([[<p>(.-)</p>]])
p_tab={}
t_tab={}
for i in p do
table.insert(p_tab,i)
end
for s in t do
table.insert(t_tab,s)
end
adp=LuaAdapter(activity,data,item_fm)
f5_s(t_tab,p_tab)
fm_wg.Adapter=adp
fm_wg.onItemClick=function(p,v,i,s)
img_forcode(tostring("遍历表"..i+1))
--print(p_tab[s])
img_hd.showPage(2)
end
fm_wg.onItemLongClick=function(p,v,i,s)
弹出消息("已复制链接")
activity.getSystemService(Context.CLIPBOARD_SERVICE).setText('http://w.advancedinsulation.com.cn:61/qq.php?t='..p_tab[s])
return true
end
f5.onClick=function()--点击事件
adp.clear()--清空适配器
f5_s(t_tab,p_tab)
end;
else
print(code)
end
end)
f5_s刷新函数
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
function f5_s(tab_t,tab_p)
for i=1,#tab_p do
if i==1 then
url_code('http://w.advancedinsulation.com.cn:61/qq.php?t='..tab_p[i])
code_b=tostring("遍历表"..i)
task(500,function()--1000毫秒=1秒
--print("我是"..code_b..遍历表1[1])
adp.add{tp_fm=遍历表1[1],text="--"..tab_t[1]}
end)
elseif i==2 then
url_code('http://w.advancedinsulation.com.cn:61/qq.php?t='..tab_p[i])
code_b=tostring("遍历表"..i)
task(1000,function()--1000毫秒=1秒
--print("我是"..code_b..遍历表2[1])
adp.add{tp_fm=遍历表2[1],text="--"..tab_t[2]}
end)
elseif i==3 then
url_code('http://w.advancedinsulation.com.cn:61/qq.php?t='..tab_p[i])
code_b=tostring("遍历表"..i)
task(1000,function()--1000毫秒=1秒
--print("我是"..code_b..遍历表3[1])
adp.add{tp_fm=遍历表3[1],text="--"..tab_t[3]}
end)
end
end
end
url_code获取推荐链接页面的所有图片
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
function url_code(url)
--url="http://w.advancedinsulation.com.cn:61/qq.php?t=163690361614072"
if a_tab==0 then
a_tab=a_tab+1
Http.get(url,nil,nil,nil,function(code,content)
if code==200 then
遍历=content:gmatch([[<img.-src="(.-)"]])
for i in 遍历 do
if string.sub(i,0,5)=="https" then
table.insert(遍历表1,i)
elseif
string.sub(i,0,5)=="http:" then
string.gsub(i,"http","https")
table.insert(遍历表1,i)
else
table.insert(遍历表1,"https"..i)
end
end
--print(#遍历表1)
--响应失败
else
print(code)
end
end)
elseif a_tab==1 then
a_tab=a_tab+1
Http.get(url,nil,nil,nil,function(code,content)
if code==200 then
遍历=content:gmatch([[<img.-src="(.-)"]])
for i in 遍历 do
if string.sub(i,0,5)=="https" then
table.insert(遍历表2,i)
elseif
string.sub(i,0,5)=="http:" then
string.gsub(i,"http","https")
table.insert(遍历表2,i)
else
table.insert(遍历表2,"https"..i)
end
end
--print(#遍历表2)
--响应失败
else
print(code)
end
end)
elseif a_tab==2 then
Http.get(url,nil,nil,nil,function(code,content)
if code==200 then
遍历=content:gmatch([[<img.-src="(.-)"]])
for i in 遍历 do
if string.sub(i,0,5)=="https" then
table.insert(遍历表3,i)
elseif
string.sub(i,0,5)=="http:" then
string.gsub(i,"http","https")
table.insert(遍历表3,i)
else
table.insert(遍历表3,"https"..i)
end
tip.setText("——不能加载太多,不然身体受不了——")
end
-- print(#遍历表3)
--响应失败
else
print(code)
end
end)
end --判断结束
end--函数结束
img_forcode加载所有图片函数
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
function img_forcode(for_img)
--print(for_img..#for_img)
if for_img=="遍历表1" then
for s=1,#for_img do
--print("imy"..遍历表1[s])
adp2=LuaAdapter(activity,data,item)
for s=1 , #遍历表1 do
adp2.add{tp=遍历表1[s]}
tips.setVisibility(View.GONE)
end
bzwg.Adapter=adp2
bzwg.onItemClick=function(l,v,p,s)
图片链接(遍历表1[s])--调用一个包下载图片,需要包tptc
end
end
elseif for_img=="遍历表2" then
for s=1,#for_img do
--print("imt"..遍历表2[s])
adp2=LuaAdapter(activity,data,item)
for s=1 , #遍历表2 do
adp2.add{tp=遍历表2[s]}
tips.setVisibility(View.GONE)
end
bzwg.Adapter=adp2
bzwg.onItemClick=function(l,v,p,s)
图片链接(遍历表2[s])
end
end
elseif for_img=="遍历表3" then
for s=1,#for_img do
--print("ims"..遍历表3[s])
adp2=LuaAdapter(activity,data,item)
for s=1 , #遍历表3 do
adp2.add{tp=遍历表3[s]}
tips.setVisibility(View.GONE)
end
bzwg.Adapter=adp2
bzwg.onItemClick=function(l,v,p,s)
图片链接(遍历表3[s])
end
end
end
end

需要引用的文件及声明的数据
1
2
3
4
5
6
7
8
9
import "content"
import "item"
import "item_fm"
import "tptc"

a_tab=0
遍历表1={}
遍历表2={}
遍历表3={}
创建文件保存位置文件夹
1
2
3
4
5
6
7
8
9
10
--文件写入
import"java.io.File"
if File("/sdcard/DCIM/meizT/").exists()
and File("/sdcard/DCIM/meizT/批量下载/").exists()
then
--文件存在事件
else
File("/sdcard/DCIM/meizT/").mkdir()--不存在 则创建
File("/sdcard/DCIM/meizT/批量下载/").mkdir()--不存在 则创建
end

封装的方法

这是封装了一个图片展示的弹窗界面

import这个文件后只需要传入图片url即可: 图片链接(url)

效果详见最后的gif动画

原来是在FusionAPP上使用,分享图片功能正常。但是拿到AndLua+上面奇奇怪怪的,就阉割了,把分享图片改成了分享图片url。

写得略微有点潦草,应该将文件保存路径写成path传入。但是懒得改,文件保存的路径记得改改哦!

图片展示封装tptc
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
import "android.content.*"
import "android.content.Intent"
import "android.net.Uri"
function 弹出消息(文本)
tcxx={
LinearLayout;--线性布局
orientation='vertical';--布局方向
layout_width='fill';--布局宽度
layout_height='fill';--布局高度
{
CardView;--卡片控件
layout_width='wrap';--卡片宽度
layout_height='wrap';--卡片高度
CardBackgroundColor='#aaeeeeee';--卡片颜色
elevation=0;--阴影属性
radius='12dp';--卡片圆角
{
TextView;
layout_width="wrap";--布局宽度
layout_height="wrap";--布局高度
background="#cc000000";--背景颜色
padding="8dp";--布局填充
textSize="15sp";--文字大小
TextColor="#ffeeeeee";--文字颜色
gravity="center";--布局居中
id="wenzi";--控件ID
};
};
};
local toast=Toast.makeText(activity,"文本",Toast.LENGTH_SHORT).setView(loadlayout(tcxx))
toast.setGravity(Gravity.BOTTOM,0,120)
wenzi.Text=tostring(""..文本.."")
toast.show()
end
function 分享文件(路径)
路径=tostring(路径)
弹出消息("已复制链接.")
activity.getSystemService(Context.CLIPBOARD_SERVICE).setText(路径)
end
function 图片链接(path)
弹窗框架=
--创建布局在这里
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#00FFFFFF',--背景颜色或图片路径
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='wrap';--宽度
layout_height='wrap';--高度
CardBackgroundColor='#ffffffff';--颜色
radius='8dp';--圆角
id="tckp",
{
ImageView;--图片控件
src=path;--图片路径
layout_width='fill';--宽度
layout_height='fill';--高度
scaleType='centerCrop';--图片显示类型
};
};
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0';--阴影
layout_width='fill';--宽度
layout_height='10%w';--高度
CardBackgroundColor='#ffffffff';--颜色
radius='8dp';--圆角
{
CardView;--卡片控件
layout_gravity='left|center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0';--阴影
layout_width='5%w';--宽度
layout_height='5%w';--高度
CardBackgroundColor='0';--颜色
radius='0dp';--圆角
layout_marginLeft='2%w';--左距
id="fx";
onClick=function()
local sj=os.date("%M-%S")
Http.download(path,"/sdcard/DCIM/meizT/"..'cytp-'..sj..".jpg",function(a)
end)
分享文件("/sdcard/DCIM/meizT/"..'cytp-'..sj..".jpg")
end;
{
ImageView;--图片控件
src='icon/fx.png';--图片路径
layout_width='fill';--宽度
layout_height='fill';--高度
scaleType='fitXY';--图片显示类型
};
};
{
CardView;--卡片控件
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0';--阴影
layout_width='5%w';--宽度
layout_height='5%w';--高度
CardBackgroundColor='0';--颜色
radius='0';--圆角
onClick=function()
弹出消息("图片已保存到/sdcard/DCIM/meizT.")
Http.download(path,"/sdcard/DCIM/meizT/"..'cytp-'..os.date("%M-%S")..".jpg",function(a)
end)
a.dismiss()
end;

{
ImageView;--图片控件
src='icon/xz.png';--图片路径
layout_width='fill';--宽度
layout_height='fill';--高度
scaleType='fitXY';--图片显示类型
};
};
{
CardView;--卡片控件
layout_gravity='center|right';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0';--阴影
layout_width='5%w';--宽度
layout_height='5%w';--高度
CardBackgroundColor='0';--颜色
radius='0';--圆角
layout_marginRight='2%w';--右距
--id="gb";
onClick=function()--点击事件
a.dismiss()
end;
{
ImageView;--图片控件
id="gb";
src='icon/gb.png';--图片路径
layout_width='fill';--宽度
layout_height='fill';--高度
scaleType='fitXY';--图片显示类型
};
};
};
--
};

import"android.graphics.drawable.ColorDrawable"
--.setCancelable(false)--禁用返回键
a=AlertDialog.Builder(this).show()
a.getWindow().setContentView(loadlayout(弹窗框架));
a.getWindow().setBackgroundDrawable(ColorDrawable(0x00000000));

function 振幅动画(id,mo,v,e,b,xx,yy)
e= e/100
b=b/500
sj = math.random(-v,v)
eee = v
vvti=Ticker()
vvti.Period=5
vvti.onTick=function()
v = math.sin(sj)
bod = (-eee - eee)*v
eee = eee - b
sj =sj + e
if eee <0 then
vvti.stop()
end
if mo==1 then
id.setRotation(bod)
elseif mo==2 then
id.setRotationX(bod)
elseif mo==3 then
id.setRotationY(bod)
end
end
if xx~=nil then
id.setPivotX(xx)
end
if yy~=nil then
id.setPivotY(yy)
end
vvti.start()
end
--控件id,摆动模式,摆动最大角度,重力值,阻力值,旋转中心点X坐标,旋转中心点Y坐标
振幅动画(tckp,2,5,3,5,nil,nil)

end

封装的下载弹窗及下载实现功能,需要传入文件夹名字以及网页链接

这俩参数会通过一个弹窗界面由用户输入,只需要在需要弹出下载框时import本文件即可

同样不是普遍适用,除保存的位置需要注意外就没啥了

截取的图片规则仅参考了本项目所用到的网页,对于其他网页可能不是很好用

批量下载封装downimg
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
function 弹出消息(文本)
tcxx={
LinearLayout;--线性布局
orientation='vertical';--布局方向
layout_width='fill';--布局宽度
layout_height='fill';--布局高度
{
CardView;--卡片控件
layout_width='wrap';--卡片宽度
layout_height='wrap';--卡片高度
CardBackgroundColor='#aaeeeeee';--卡片颜色
elevation=0;--阴影属性
radius='12dp';--卡片圆角
{
TextView;
layout_width="wrap";--布局宽度
layout_height="wrap";--布局高度
background="#cc000000";--背景颜色
padding="8dp";--布局填充
textSize="15sp";--文字大小
TextColor="#ffeeeeee";--文字颜色
gravity="center";--布局居中
id="wenzi";--控件ID
};
};
};
local toast=Toast.makeText(activity,"文本",Toast.LENGTH_SHORT).setView(loadlayout(tcxx))
toast.setGravity(Gravity.BOTTOM,0,120)
wenzi.Text=tostring(""..文本.."")
toast.show()
end
下载弹窗=
{--布局
LinearLayout;
orientation="vertical";
Focusable=true,
FocusableInTouchMode=true,
{
TextView;--文本控件
gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_height='40dp';--高度
textColor='#ff51acf6';--文字颜色
text='下载文件';--显示文字
textSize='20';--文字大小
layout_weight="1.0";
layout_marginTop="fill";--边顶
};
{
LinearLayout,--线性布局
orientation='vertical',--方向
layout_width='fill',--宽度
layout_height='wrap',--高度
background='#00FFFFFF',--背景颜色或图片路径
{
LinearLayout;
orientation='horizontal';--重力属性
layout_width='fill';--布局宽度
layout_height='50dp';--布局高度
gravity='center';--默认居中
backgroundColor="#FFFFFFFF";--背景色
{
CardView;--卡片控件
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='12%w';--高度
CardBackgroundColor='0';--颜色
radius='8dp';--圆角
{
CardView;--卡片控件
layout_margin='0dp';--边距
layout_gravity='center|left';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='65%w';--宽度
layout_height='12%w';--高度
CardBackgroundColor='#2a000000';--颜色
radius='8dp';--圆角
{
EditText;--编辑框控件
id="edit_name";
singleLine=true,--设置单行输入
layout_width='fill';--编辑框宽度
layout_height='fill';--编辑框高度
textSize='12sp';--文字大小
hintTextColor='#FF7D7D7D';--提示文字颜色
textColor='#FF000000';--输入文字的颜色
Hint='名称';--设置编辑框为空时的提示文字
background='#ffefefef';
layout_marginLeft='0dp';--布局左距
layout_marginRight='0dp';--布局右距
};
};

};
};
{--名称
LinearLayout;
orientation='horizontal';--重力属性
layout_width='fill';--布局宽度
layout_height='wrap';--布局高度
gravity='center';--默认居中
backgroundColor="#FFFFFFFF";--背景色
{
CardView;--卡片控件
layout_marginTop='15dp';--顶距
layout_margin='8dp';--边距
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='fill';--宽度
layout_height='12%w';--高度
CardBackgroundColor='0';--颜色
radius='8dp';--圆角
{
CardView;--卡片控件
layout_margin='0dp';--边距
layout_gravity='center|left';--重力
--左:left 右:right 中:center 顶:top 底:bottom
elevation='0dp';--阴影
layout_width='65%w';--宽度
layout_height='12%w';--高度
CardBackgroundColor='#2a000000';--颜色
radius='8dp';--圆角
{
EditText;--编辑框控件
id="edit";
singleLine=true,--设置单行输入
layout_width='fill';--编辑框宽度
layout_height='fill';--编辑框高度
textSize='12sp';--文字大小
hintTextColor='#FF7D7D7D';--提示文字颜色
textColor='#FF000000';--输入文字的颜色
Hint='输入完整链接';--设置编辑框为空时的提示文字
background='#ffefefef';
layout_marginLeft='0dp';--布局左距
layout_marginRight='0dp';--布局右距
};
};
{
TextView;--文本控件
gravity='center|right';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='fill';--宽度
layout_marginRight='5%w';--右距
layout_height='fill';--高度
textColor='#eb000000';--文字颜色
text='http';--显示文字
textSize='17dp';--文字大小
-- textIsSelectable=true--长按复制
};

};
};
};
{
CardView;--卡片控件
layout_marginRight='6dp';--右距
layout_margin='8dp';--边距
elevation='1dp';--阴影
layout_width='fill';--宽度
layout_height='3dp';--高度
CardBackgroundColor='#FFDFDFDF';--颜色
radius='5dp';--圆角
id="button";
{
TextView;--文本控件
--gravity='center';--重力
layout_height='fill';--高度
background='#FF5B81FE',--背景颜色或图片路径
text='';--显示文字
id="jv";

};
};

{
LinearLayout;
orientation='horizontal';--重力属性
layout_width='fill';--布局宽度
layout_height='fill';--布局高度
{

TextView;--文本控件

gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='43.5%w';--宽度
textColor='#ff51acf6';--文字颜色
text='取消';--显示文字
textSize='15dp';--文字大小
style="?android:attr/borderlessButtonStyle";
onClick=function()
弹窗.dismiss()
end
};
{
TextView;--文本控件
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='43.5%w';--宽度
textColor='#ff51acf6';--文字颜色
text='下载';--显示文字
textSize='15dp';--文字大小
style="?android:attr/borderlessButtonStyle";
id="xuanz2";
};
{
TextView;--文本控件
layout_gravity='center';--重力
--左:left 右:right 中:center 顶:top 底:bottom
layout_width='43.5%w';--宽度
textColor='#ff51acf6';--文字颜色
text='完成';--显示文字
textSize='15dp';--文字大小
style="?android:attr/borderlessButtonStyle";
id="wc";

};
};
};
弹窗=AlertDialog.Builder(this).setView(loadlayout(下载弹窗)).show()
wc.setVisibility(View.GONE)
loop_tab={}
function down_stop(c)--总长度
弹出消息('文件已保存在/DCIM/meizT/批量下载/下!')
--dialog1.dismiss()--关闭对话框
xuanz2.setVisibility(View.GONE)
wc.setVisibility(View.VISIBLE)
end
wc.onClick=function()--点击事件
弹窗.dismiss()
wc.setVisibility(View.GONE)
xuanz2.setVisibility(View.VISIBLE)
end;
function down_img()
for s=1,#loop_tab do
task(1000,function()--1000毫秒=1秒
xuanz2.setText(s.."/"..#loop_tab)
path=tostring(loop_tab[s])
--弹出消息(path)
Http.download(path,"/sdcard/DCIM/meizT/批量下载/"..edit_name.Text.."/"..'meizT-'..s..".jpg",function(a)
end)
jv.Width=s/#loop_tab*965
if s==#loop_tab then
down_stop()
end
end)
end
end
function down_url(url)
--local headers={["User-Agent"]="Mozilla/5.0 (Linux; Android 7.0; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.116 Mobile Safari/537.36 T7/10.3 SearchCraft/2.6.2 (Baidu; P1 7.0)"}
Http.get(url_d,nil,nil,nil,function(code,content,headers)
if code==200 then
import"java.io.File"
if File("/sdcard/DCIM/meizT/批量下载/"..edit_name.Text).exists()
then
--文件存在事件
else
File("/sdcard/DCIM/meizT/批量下载/"..edit_name.Text).mkdir()--不存在 则创建
end
loop=content:gmatch([[<img.-src="(.-)"]]) --图片截取规则
for i in loop do

if string.sub(i,0,4)!="http" then
--string.gsub(i,"http","https")
table.insert(loop_tab,"http:"..i)
else
table.insert(loop_tab,i)
end
end
--弹出消息(#loop_tab)
down_img()
else
弹出消息("链接网站响应失败\n"..url..code)
end
end)
end
xuanz2.onClick=function()
if edit_name.Text!=nil and edit_name.Text!=""
and edit.Text!=nil and edit.Text!="" then
url_d=edit.Text
down_url(url_d)
else
弹出消息("名称不能为空!")
end
end

开源文件

好了,我相信我的朋友一定学废了吧!

在这里贴出完整的开源项目及APK文件和效果图片

首页

加载页及单图下载(有动画)

下载