-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.go
202 lines (191 loc) · 6.19 KB
/
ui.go
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
package faithdroid
type UIController interface {
NewView(viewName string, VID string)
ViewSetAttr(VID string, attr string, value string)
ViewGetAttr(VID string, attr string) string
Append2RootView(VID string)
RunUIThread(fnID string)
GetPkg() string
GetCurrentFActivity() *Activity
}
type FBaseView struct {
FBase
srcCachedBackground,srcCachedForeground string
}
type FBase struct {
VID, ClassName string
UI string
}
type IView interface {
GetViewId() string
}
func (v FBase) GetViewId() string {
return v.VID
}
func (v *FBaseView) Show() {
GlobalVars.UIs[v.UI].Append2RootView(v.VID)
}
func (v *FBaseView) Background(s string) {
if len(s) > len("https://") && s[:len("http")] == "http" {
go DownloadNetFile(s, "/data/data/"+GlobalVars.UIs[v.UI].GetPkg()+"/tmp/", func(f string) {
fnID := NewToken()
fn := func(string) string {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Background", "file://"+f)
return ""
}
GlobalVars.EventHandlersMapLock.Lock()
GlobalVars.EventHandlersMap[fnID] = fn
GlobalVars.EventHandlersMapLock.Unlock()
GlobalVars.UIs[v.UI].RunUIThread(fnID)
})
return
}
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Background", s)
}
func (v *FBaseView) CachedBackground(s string) {
if len(s) > len("https://") && s[:len("http")] == "http" {
go CacheNetFile(s, "/data/data/"+GlobalVars.UIs[v.UI].GetPkg()+"/cacheDir/", func(f string) {
if v.srcCachedBackground=="file://"+f{
return
}
fnID := NewToken()
fn := func(string) string {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Background", "file://"+f)
v.srcCachedBackground = "file://" + f
return ""
}
GlobalVars.EventHandlersMapLock.Lock()
GlobalVars.EventHandlersMap[fnID] = fn
GlobalVars.EventHandlersMapLock.Unlock()
GlobalVars.UIs[v.UI].RunUIThread(fnID)
})
return
}
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Background", s)
}
func (v *FBaseView) Foreground(s string) {
if len(s) > len("https://") && s[:len("http")] == "http" {
go DownloadNetFile(s, "/data/data/"+GlobalVars.UIs[v.UI].GetPkg()+"/tmp/", func(f string) {
fnID := NewToken()
fn:= func(string) string {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Foreground", "file://"+f)
return ""
}
GlobalVars.EventHandlersMapLock.Lock()
GlobalVars.EventHandlersMap[fnID] =fn
GlobalVars.EventHandlersMapLock.Unlock()
GlobalVars.UIs[v.UI].RunUIThread(fnID)
})
return
}
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Foreground", s)
}
func (v *FBaseView) CachedForeground(s string) {
if len(s) > len("https://") && s[:len("http")] == "http" {
go CacheNetFile(s, "/data/data/"+GlobalVars.UIs[v.UI].GetPkg()+"/cacheDir/", func(f string) {
if v.srcCachedForeground=="file://"+f{
return
}
fnID := NewToken()
fn:=func(string) string {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Foreground", "file://"+f)
v.srcCachedForeground="file://"+f
return ""
}
GlobalVars.EventHandlersMapLock.Lock()
GlobalVars.EventHandlersMap[fnID] = fn
GlobalVars.EventHandlersMapLock.Unlock()
GlobalVars.UIs[v.UI].RunUIThread(fnID)
})
return
}
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Foreground", s)
}
func (v *FBaseView) BackgroundColor(s string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "BackgroundColor", s)
}
func (v *FBaseView) Visible() {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Visibility", "VISIBLE")
}
func (v *FBaseView) Invisible() {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Visibility", "INVISIBLE")
}
func (v *FBaseView) Gone() {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Visibility", "GONE")
}
func (v *FBaseView) IsVisible() bool {
return GlobalVars.UIs[v.UI].ViewGetAttr(v.VID, "Visibility") == "VISIBLE"
}
func (v *FBaseView) IsInvisible() bool {
return GlobalVars.UIs[v.UI].ViewGetAttr(v.VID, "Visibility") == "INVISIBLE"
}
func (v *FBaseView) IsGone() bool {
return GlobalVars.UIs[v.UI].ViewGetAttr(v.VID, "Visibility") == "GONE"
}
func (v *FBaseView) Padding(left, top, right, bottom int) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Padding", JsonArray([]int{left, top, right, bottom}))
}
func (v *FBaseView) Margin(left, top, right, bottom int) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Margin", JsonArray([]int{left, top, right, bottom}))
}
func (v *FBaseView) LayoutGravity(gravity int) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "LayoutGravity", SPrintf(gravity))
}
func (v *FBaseView) Elevation(dp float64) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Elevation", SPrintf(dp))
}
func (v *FBaseView) LayoutWeight(f int) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "LayoutWeight", SPrintf(f))
}
func (v *FBaseView) Clickable(b bool) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Clickable", SPrintf(b))
}
func (f *FBaseView) OnClick(ff func()) {
fnID := NewToken()
fn := func(string) string {
ff()
return ""
}
GlobalVars.EventHandlersMapLock.Lock()
GlobalVars.EventHandlersMap[fnID] = fn
GlobalVars.EventHandlersMapLock.Unlock()
GlobalVars.UIs[f.UI].ViewSetAttr(f.VID, "OnClick", fnID)
}
//constraint
var parent = "_Parent_"
func (v *FBaseView) Top2TopOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Top2TopOf", id)
}
func (v *FBaseView) Top2BottomOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Top2BottomOf", id)
}
func (v *FBaseView) Bottom2TopOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Bottom2TopOf", id)
}
func (v *FBaseView) Bottom2BottomOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Bottom2BottomOf", id)
}
func (v *FBaseView) Left2LeftOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Left2LeftOf", id)
}
func (v *FBaseView) Right2RightOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Right2RightOf", id)
}
func (v *FBaseView) Left2RightOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Left2RightOf", id)
}
func (v *FBaseView) Right2LeftOf(id string) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "Right2LeftOf", id)
}
func (v *FBaseView) CenterX() {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "CenterX", "")
}
func (v *FBaseView) CenterY() {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "CenterY", "")
}
func (v *FBaseView) WidthPercent(num float64) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "WidthPercent", SPrintf(num))
}
func (v *FBaseView) HeightPercent(num float64) {
GlobalVars.UIs[v.UI].ViewSetAttr(v.VID, "HeightPercent", SPrintf(num))
}