-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxml2table.lua
202 lines (191 loc) · 4.52 KB
/
xml2table.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
require "import"
import "console"
import "android.app.*"
import "android.os.*"
import "android.widget.*"
import "android.view.*"
import "android.content.*"
import "com.androlua.*"
import "loadlayout3"
import "lj"
import "toast"
--activity.setTitle('XML转换器')
activity.setTheme(android.R.style.Theme_DeviceDefault_Light)
t={
LinearLayout;
id="l";
orientation="vertical";
{
LinearLayout;
layout_width="fill";
backgroundColor="0xffffffff";
{
Button;
layout_width="fill";
layout_weight=1;
id="open";
background="0";
text="转换";
onClick="click";
};
{
Button;
layout_width="fill";
layout_weight=1;
id="open";
background="0";
text="预览";
onClick="click2";
};
{
Button;
layout_width="fill";
layout_weight=1;
id="open";
background="0";
text="复制";
onClick="click3";
};
{
Button;
layout_width="fill";
layout_weight=1;
id="open";
background="0";
text="确定";
onClick="click4";
};
};
{
RelativeLayout;
layout_width="match_parent";
layout_height="match_parent";
{
LuaEditor;
id="edit";
};
{
LinearLayout;
layout_alignParentBottom="true";
layout_width="fill";
layout_height="6%h";
{
HorizontalScrollView;
background="#ffffff";
layout_width="fill";
layout_height="fill";
horizontalScrollBarEnabled=false;
{
LinearLayout;
id="bar3";
layout_height="fill";
layout_width="fill";
}
}
};
};
};
function xml2table(xml)
local xml,s=xml:gsub("</%w+>","}")
if s==0 then
return xml
end
xml=xml:gsub("<%?[^<>]+%?>","")
xml=xml:gsub("xmlns:android=%b\"\"","")
xml=xml:gsub("%w+:","")
xml=xml:gsub("\"([^\"]+)\"",function(s)return (string.format("\"%s\"",s:match("([^/]+)$")))end)
xml=xml:gsub("[\t ]+","")
xml=xml:gsub("\n+","\n")
xml=xml:gsub("^\n",""):gsub("\n$","")
xml=xml:gsub("<","{"):gsub("/>","}"):gsub(">",""):gsub("\n",",\n")
return (xml)
end
dlg=Dialog(activity,android.R.style.Theme_DeviceDefault_Light)
dlg.setTitle("布局表预览")
function show(s)
dlg.setContentView(loadlayout3(loadstring("return "..s)(),{}))
dlg.show()
end
function click()
local str=edit.getText().toString()
str=xml2table(str)
str=console.format(str)
edit.setText(str)
end
function click2()
local str=edit.getText().toString()
show(str)
end
function click3(s)
local cd = ClipData.newPlainText("label", edit.getText().toString())
cm.setPrimaryClip(cd)
Toast.makeText(activity,"已复制的剪切板",1000).show()
end
function click4()
local str=edit.getText().toString()
layout.main=loadstring("return "..str)()
activity.setContentView(loadlayout2(layout.main,{}))
dlg2.hide()
end
loadlayout(t)
dlg2=Dialog(activity,android.R.style.Theme_DeviceDefault_Light)
dlg2.setTitle("编辑代码")
dlg2.getWindow().setSoftInputMode(0x10)
dlg2.setContentView(l)
edit.setBasewordColor(0xff8dbdc9)--基词
edit.setPanelBackgroundColor(0xffffffff)--卡片颜色
edit.setPanelTextColor(0xFF03A9F4)--卡片字体颜色
edit.setStringColor(0xFF03A9F4)--字符串颜色
edit.setTextColor(0xFF383A3D)--文本颜色
edit.setUserwordColor(0xFF03A9F4)--数字
edit.setCommentColor(0xffa0a0a0)--注释颜色
edit.setKeywordColor(0xFF03A9F4)--if then等
local fh=io.open(activity.getLuaDir().."/Verify/set2.XY"):read("*a")
for t,c in fh:gmatch("(.-) ") do
button={
Button;
text=tostring(t);
layout_width="45dp";
layout_height="fill";
background="#ffffff";
textColor=0xFF03A9F4;
padding="5dp",
id="sssss1",
};
m31=loadlayout(button)
bar3.addView(m31)
波纹(sssss1,0xE7EAEEEE)
m31.onClick=function(v)
if v.text=="Fun" or v.text=="fun" or v.text=="function" or v.text=="Function" then
q.paste("function")
else
if v.text=="End" or v.text=="end" then
q.paste("end")
else
q.paste(v.Text)
end
end
end
m31.onLongClick=function(v)
if v.text=="Fun" or v.text=="fun" or v.text=="function" or v.text=="Function" then
q.paste("function")
else
if v.text=="End" or v.text=="end" then
q.paste("end")
else
q.paste(v.Text..v.text)
end
end
return true
end
end
function editlayout(txt)
edit.Text=txt
edit.format()
dlg2.show()
end
function onResume2()
local cd=cm.getPrimaryClip();
local msg=cd.getItemAt(0).getText()--.toString();
edit.setText(msg)
end