-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayoutHelper.lua
More file actions
63 lines (56 loc) · 1.58 KB
/
LayoutHelper.lua
File metadata and controls
63 lines (56 loc) · 1.58 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
local LayoutHelper={}
LayoutHelper._VERSION="1.1(alpha01)"
LayoutHelper._VERSION_CODE=1101
import "android.text.TextUtils"
import "android.util.TypedValue"
import "android.content.Context"
import "android.util.DisplayMetrics"
local ScaleType=ImageView.ScaleType
local OnClickListener=View.OnClickListener
local context=activity or service
local wm =context.getSystemService(Context.WINDOW_SERVICE)
local outMetrics = DisplayMetrics()
wm.getDefaultDisplay().getMetrics(outMetrics)
local W = outMetrics.widthPixels
local H = outMetrics.heightPixels
LayoutHelper.W=W
LayoutHelper.H=H
LayoutHelper.PERCENT_W=W/100
LayoutHelper.PERCENT_H=H/100
local dm=context.getResources().getDisplayMetrics()
LayoutHelper.dm=dm
--LayoutHelper.id=0x7f000000
luajava.ids=luajava.ids or {id=0x7f000000}
local ids=luajava.ids
LayoutHelper.scaleTypes=ScaleType.values()
LayoutHelper.ltrs={}
function LayoutHelper.getClickListener(root,v)
local listener
if LayoutHelper.ltrs[v] then
listener=LayoutHelper.ltrs[v]
else
local l=rawget(root,v)
if type(l)=="function" then
listener=OnClickListener{onClick=l}
elseif type(l)=="userdata" then
listener=l
else
listener=OnClickListener{onClick=function(a)(root[v])(a)end}
end
LayoutHelper.ltrs[v]=listener
end
return listener
end
function LayoutHelper.newId(idName)
ids.id=ids.id+1
return ids.id
end
local ver = luajava.bindClass("android.os.Build").VERSION.SDK_INT;
function LayoutHelper.setBackground(view,bg)
if ver<16 then
view.setBackgroundDrawable(bg)
else
view.setBackground(bg)
end
end
return LayoutHelper