-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.lua
355 lines (342 loc) · 9.64 KB
/
file.lua
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
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "android.app.*"
import "android.graphics.Typeface"
import "android.content.Intent"
import "android.content.Context"
import "android.content.pm.PackageManager"
import "android.graphics.drawable.ColorDrawable"
import "android.content.Intent"
import "java.io.File"
import "other"
import "Dialog"
import "toast"
import "main6"
import "com.androlua.LuaAdapter"
import "android.graphics.drawable.StateListDrawable"
import "android.graphics.drawable.GradientDrawable"
import "com.androlua.LuaUtil"
title,StartPath,filterTypes=...
local a=io.open(activity.getLuaDir().."/Verify/set4.XY"):read("*a")
local ip=a:match("2(.-)"..'"')
if ip=="开" then
颜色1=0xff303030
颜色2=0xff212121
颜色3=0xffffffff
颜色4=0xffffffff
颜色5=0xff303030
颜色6=0x5FFFFFFF
else
颜色1=0xFF03A9F4
颜色3=0xff303030
颜色4=0xffffffff
颜色5=0x5FFFFFFF
颜色2=0xFFF2F1F6
颜色6=0xff303030
end
item={
import "android.widget.*";
LinearLayout;
layout_height="fill";
layout_width="fill";
{
LinearLayout;
layout_width="match_parent";
layout_height="70dp";
gravity="center";
{
CardView;
radius=25;
layout_height="50dp";
layout_width="340dp";
CardElevation="0dp";
backgroundColor="0xffffffff";
{
LinearLayout;
orientation="horizontal";
layout_width="match_parent";
layout_height="match_parent";
{
ImageView;
src="file.png";
layout_marginLeft="10dp";
layout_gravity="center";
id="img";
};
{
TextView;
layout_height="20dp";
id="file";
layout_marginLeft="10dp";
layout_width="250dp";
layout_gravity="center";
};
};
};
};
};
layout={
import "android.widget.*";
LinearLayout;
backgroundColor="0xFFF2F1F6";
layout_height="fill";
orientation="vertical";
layout_width="fill";
{
LinearLayout;
backgroundColor="0xffffffff";
layout_height="56dp";
orientation="vertical";
layout_width="match_parent";
{
TextView;
layout_marginTop="5dp";
text="选择源码(*.alp)";
layout_marginLeft="10dp";
textSize="16sp";
textColor="0xFF03A9F4";
};
{
TextView;
layout_marginTop="5dp";
layout_marginLeft="10dp";
singleLine=true;
textColor="0xFF03A9F4";
text="路径";
focusable=true;
ellipsize="marquee";
layout_width="300dp";
focusableInTouchMode=true;
id="cp";
};
};
{
LinearLayout;
layout_height="match_parent";
layout_width="match_parent";
{
ListView;
id="lv",
layout_height="match_parent";
DividerHeight=0;--设置无隔断线
layout_width="match_parent";
};
};
};
activity.setContentView(layout)
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS).setStatusBarColor(0xffffffff);
if tonumber(Build.VERSION.SDK) >= 23 then
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
end
--导入类
local context=activity or service
local LuaBitmap=luajava.bindClass "com.androlua.LuaBitmap"
local function loadbitmap(path)
if not path:find("^https*://") and not path:find("%.%a%a%a%a?$") then
path=path..".png"
end
if path:find("^https*://") then
return LuaBitmap.getHttpBitmap(context,path)
elseif not path:find("^/") then
return LuaBitmap.getLocalBitmap(context,string.format("%s/%s",luajava.luadir,path))
else
return LuaBitmap.getLocalBitmap(context,path)
end
end
import "android.graphics.Typeface"
local Text_Type=Typeface.defaultFromStyle(Typeface.BOLD)
local sd = StateListDrawable()
import "android.graphics.Color"
import "android.content.res.ColorStateList"
import "android.graphics.drawable.RippleDrawable"
import "android.content.Context"
appt={C_Bacgg=function(mBinding,radiu,InsideColor,S,S2,T1)
local drawable = GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,{});
drawable.setCornerRadius(radiu);
drawable.setColor(颜色5)
drawable.setStroke(3, 0xCFB0B0B0)
drawable.setGradientType(GradientDrawable.RECTANGLE);
mBinding.setTextColor(T1)
mBinding.setTypeface(Text_Type)
return drawable
end}
美化按钮1=function(mBinding,radiu,InsideColor,T1)
stateList = {
{android.R.attr.state_pressed},
{android.R.attr.state_focused},
{android.R.attr.state_activated},
{android.R.attr.selectableItemBackground},
};
sd.addState({ android.R.attr.state_enabled}, appt.C_Bacgg(mBinding,radiu,InsideColor,S,S2,T1))
pressedColor =InsideColor --Color.parseColor("#7ab946ff");
stateColorList ={
pressedColor,
pressedColor,
pressedColor,
normalColor
};
colorStateList = ColorStateList(stateList, stateColorList);
rippleDrawable = RippleDrawable(colorStateList,sd,nil);
mBinding.setBackground(rippleDrawable);
end
function getExtension(str)
return str:match(".+%.(%w+)$")
end
import "android.widget.ArrayAdapter"
import "android.widget.LinearLayout"
import "android.widget.TextView"
import "java.io.File"
import "android.widget.ListView"
import "android.app.AlertDialog"
function ChoicePath(StartPath,callback)
data={}
adp=LuaAdapter(activity,data,item)
lv.setAdapter(adp)
function SetItem(path)
path=tostring(path)
adp.clear()--清空适配器
cp.Text=tostring(path)--设置当前路径
switch path
case "/"
case "/storage/emulated/0"
default
adp.add{file="返回上级目录",img="folder.png"}
end
ls=File(path).listFiles()
if ls~=nil then
ls=luajava.astable(File(path).listFiles()) --全局文件列表变量
table.sort(ls,function(a,b)
return (a.isDirectory()~=b.isDirectory() and a.isDirectory()) or ((a.isDirectory()==b.isDirectory()) and a.Name<b.Name)
end)
else
ls={}
end
for index,c in ipairs(ls) do
if c.isDirectory() then--如果是文件夹则
adp.add{file=c.Name,img=loadbitmap(activity.getLuaDir().."/folder.png")}
elseif c.isFile() then--如果是文件则
adp.add{file=c.Name,img=loadbitmap(activity.getLuaDir().."/file.png")}
end
end
end
lv.onItemClick=function(l,v,p,s)--列表点击事件
项目=tostring(v.tag.file.Text)
switch tostring(cp.Text)
case "/storage/emulated/0"
路径=ls[p+1]
default
路径=ls[p]
end
switch 项目
case "返回上级目录"
SetItem(File(cp.Text).getParentFile())
default
switch 路径.isDirectory()
case true
SetItem(路径)
default
switch 路径.isFile()
case true
switch getExtension(tostring(路径))
case "alp"
local sc={
CardView;
radius=30;
layout_width="match_parent";
--orientation="vertical";
layout_height="match_parent";
{
CardView;
layout_gravity="center";
layout_height="280dp";
layout_width="match_parent";
backgroundColor=颜色2,
radius=20;
{
TextView;
layout_marginLeft="25dp";
layout_marginTop="10dp";
textSize="20sp";
textColor="0xFF03A9F4";
text="提示";
};
{
TextView;
textSize="15sp";
textColor=颜色6,
layout_marginLeft="25dp";
text="是否导入此工程?";
layout_marginTop="45dp";
};
{
LinearLayout;
layout_marginBottom="50dp";
layout_gravity="bottom";
layout_marginTop="20dp";
layout_width="match_parent";
layout_height="50dp";
{
Button;
text="取消";
layout_gravity="center";
layout_marginLeft="20dp";
id="取消导入工程";
layout_height="40dp";
};
{
LinearLayout;
layout_width="match_parent";
gravity="right";
layout_height="match_parent";
{
Button;
layout_marginRight="20dp";
layout_gravity="center";
text="导入";
layout_height="40dp";
id="确定导入工程";
};
};
};
};
};
dialog2= AlertDialog.Builder(this)
dialog3=dialog2.show()
dialog3.getWindow().setContentView(loadlayout(sc));
dialog3.getWindow().setBackgroundDrawable(ColorDrawable(0x00000000));
local dialogWindow = dialog3.getWindow();
dialogWindow.setGravity(Gravity.BOTTOM);
dialog3.getWindow().getAttributes().width=(activity.Width);
dialog3.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
美化按钮1(取消导入工程,10,0x7E000000,0x7E000000)
美化按钮1(确定导入工程,10,0x7a00bfff,0x7a00bfff)
function 取消导入工程.onClick()
dialog3.dismiss()
end
function 确定导入工程.onClick()
import "java.io.File"
local a=File(tostring(路径)).getName()
local b=a:match("(.-).alp")
local c=项目文件夹.."/"..a
local d=项目文件夹.."/"..b..".zip"
local e=项目文件夹.."/"..b
LuaUtil.copyDir(tostring(路径),c)
File(c).renameTo(File(d))
LuaUtil.unZip(d,e)
os.remove(d)
dialog3.dismiss()
activity.result{true}
end
default
print"暂不支持导入此工程"
end
end
end
end
end
SetItem(StartPath)
end
ChoicePath("/storage/emulated/0",
function(path)
end)