Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
Latest commit
254 lines (219 loc) · 6.97 KB
/
Copy pathmain.lua
File metadata and controls
254 lines (219 loc) · 6.97 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
require"import"
import"android.app.*"
import"android.os.*"
import"android.widget.*"
import"android.view.*"
import"android.text.util.Linkify"
import"android.graphics.Point"
import"com.onegravity.rteditor.RTEditorMovementMethod"
import"res"
import"cjson"
require"helper"
require"init"
import"ScaleUtil"
---https://docs.github.com/zh/rest/licenses/licenses?apiVersion=2022-11-28#get-all-commonly-used-licenses--status-codes
URL_API_GITHUB_LICENSES="https://api.github.com/licenses"
URL_CHOOSEALICENSE="https://choosealicense.com/"
NAX_AUTO_SEARCH_LIMIT=100
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
activity.setContentView(loadlayout("layout"))
localfilteringText=""
functiononCreateOptionsMenu(menu)
menu.add(0,1,0,"选择开源许可证网站")
localhelpMenu=menu.addSubMenu("帮助")
helpMenu.add(0,3,0,"认识开源许可证")
menu.add(0,2,0,"关于")
end
functiononOptionsItemSelected(item)
localid=item.getItemId()
ifid==1then
openChooseALicenseWebsite()
elseifid==2then
showAboutDialog()
elseifid==3then
openInBrowser("https://oschina.gitee.io/opensource-guide/guide/第二部分:学习和使用开源项目/第 3 小节:认识开源许可证/")
end
end
functiononConfigurationChanged(newConfig)
localscreenWidthDp=newConfig.screenWidthDp
ifscreenWidthDp>960then
setLayoutParams(mainLayout,{width=ScaleUtil.dp2px(960)})
else
setLayoutParams(mainLayout,{width=-1})
end
end
functionopenChooseALicenseWebsite()
openInBrowser(URL_CHOOSEALICENSE)
end
functionshowAboutDialog()
localdialog=AlertDialog.Builder(this)
.setTitle(appname)
.setIcon(R.drawable.icon)
.setMessage("")
.setPositiveButton(android.R.string.ok,nil)
--.setNeutralButton("法律信息...",nil)
.setNegativeButton("开源仓库",nil)
.show()
localmessageView=dialog.findViewById(android.R.id.message)
localneutralButton=dialog.getButton(Dialog.BUTTON_NEUTRAL)
localnegativeButton=dialog.getButton(Dialog.BUTTON_NEGATIVE)
messageView.setAutoLinkMask(Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES)
messageView.setTextIsSelectable(true)
messageView.setMovementMethod(RTEditorMovementMethod.getInstance())
messageView.setText([[
软件版本: v]]..("%s (%s)"):format(appver,appcode)..[[
开源许可: MIT
反馈邮箱: jesse205@qq.com
使用 GitHub License API 获取许可证数据的,并有序地暂时出来,供用户快速选择的 Android 客户端。
免责声明:
1. 本软件中的网站、内容与本软件无关。本软件仅作为许可证提供方(GitHub、Choose an open source license)的浏览器使用。
2. 我们大多数人不是律师。本软件以及网站不提供法律咨询。如果您对代码的最佳许可证或与代码相关的任何其他法律问题有任何疑问,您可以进一步研究或咨询专业人员。
用户协议:
1. 禁止违反当地法律与法规
隐私政策:
1. 本程序只会申请联网权限,其余权限均为默认权限
2. 本程序不会上传为提供网络服务的信息(如:IP)以外的任何信息。]])
--设置为文本后需要取消自动连接,否则会点击重复
messageView.setAutoLinkMask(0)
messageView.requestFocus()
negativeButton.onClick=function(view)
openInBrowser("https://gitee.com/AideLua/LicenseGallery")
end
end
---@classLicenseItem
---@fieldkeystring
---@fieldnamestring
---@fieldspdx_idstring|nil
---@fieldnode_idstring
---@fieldurlstring|nil
---所有许可数据
---@typeLicenseItem[]
localdata={}
---已过滤数据
---@typeLicenseItem[]
localfilteredData={}
localadapter=luajava.override(BaseAdapter,{
getCount=function(super)
returnint(#filteredData)
end,
getItem=function(super,position)
returnfilteredData[position+1]
end,
getItemId=function(super,position)
returnlong(position)
end,
getView=function(super,position, convertView, parent)
local_,view=xpcall(function()
localids
localview=convertView
localitemData=filteredData[position+1]
ifnotviewthen
ids={}
view=loadlayout("itemLayout",ids)
view.tag=ids
else
ids=view.tag
end
ids.title.text=itemData.name
ids.summary.text=itemData.spdx_idor"未知"
view.alpha=itemData.spdx_idand1or0.6
returnview
end,
function(errMsg)
print(errMsg)
returnView(activity)
end)
returnview
end,
isEnabled=function(super,position)
returnnotnotfilteredData[position+1].spdx_id
end
})
listView.setAdapter(adapter)
listView.onItemClick=function(parent,view,position,id)
localitemData=filteredData[position+1]
activity.newActivity("sub/LicenseViewer/main.lua",{itemData.spdx_id,itemData.key})
end
listView.onCreateContextMenu=function(menu,v,menuInfo)
localitemData=filteredData[menuInfo.position+1]
menu.setHeaderTitle(itemData.spdx_id)
localexportMenu=menu.addSubMenu("复制")
exportMenu.add(0,0,0,"复制名称")
.setOnMenuItemClickListener(function()
copyAndToast(itemData.name)
end)
exportMenu.add(0,3,0,"复制 SPDX ID")
.setEnabled(notnotitemData.spdx_id)
.setOnMenuItemClickListener(function()
copyAndToast(itemData.spdx_id)
end)
--[[
menu.add(0,2,0,"许可证网址")
.setEnabled(not not itemData.url)
.setOnMenuItemClickListener(function()
openInBrowser(itemData.url)
end)]]
end
searchButton.onClick=function()
searchItems(searchEdit.text)
end
searchEdit.onEditorAction=function(view,actionId,event)
ifeventthen
searchItems(tostring(view.text))
end
end
searchEdit.addTextChangedListener({
onTextChanged=function(text)
if#data<NAX_AUTO_SEARCH_LIMITthen
searchItems(tostring(text))
end
end
})
---@paramtextstring
functionsearchItems(text)
filteringText=text
localloweredText=string.lower(text)
table.clear(filteredData)
fori=1,#datado
localitem=data[i]
ifstring.lower(item.name):find(loweredText)
orstring.lower(item.spdx_id):find(loweredText) then
table.insert(filteredData,item)
end
end
adapter.notifyDataSetChanged()
end
---设置正加载状态
functionsetLoading(state)
ifstatethen
progressBar.visibility=View.VISIBLE
else
progressBar.visibility=View.GONE
end
end
---拉取许可证
functionfetchAllLicenses()
localurl=URL_API_GITHUB_LICENSES
ifisInternetCacheContent(url) then
handleAllLicense(readInternetCacheContent(url))
else
setLoading(true)
Http.get(url,function(code,content,cookie,header)
ifcode==200then
saveInternetCacheContent(url,content)
handleAllLicense(content)
else
toast("网络错误:"..code)
end
setLoading(false)
end)
end
end
functionhandleAllLicense(content)
data=cjson.decode(content)
searchItems(filteringText)
setLoading(false)
end
fetchAllLicenses()
rootLayout.setOnTouchListener(newTouchChildOnTouchListener(listView))
onConfigurationChanged(activity.getResources().getConfiguration())