forked from coronalabs/framework-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunitTestListing.lua
More file actions
executable file
·333 lines (283 loc) · 7.49 KB
/
unitTestListing.lua
File metadata and controls
executable file
·333 lines (283 loc) · 7.49 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
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
-- Copyright (C) 2013 Corona Inc. All Rights Reserved.
local widget = require( "widget" )
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local USE_ANDROID_THEME = false
local USE_IOS7_THEME = true
local isGraphicsV1 = ( 1 == display.getDefault( "graphicsCompatibility" ) )
local topGrayColor = { 0.92, 0.92, 0.92, 1 }
local separatorColor = { 0.77, 0.77, 0.77, 1 }
local headerTextColor = { 0, 0, 0, 1 }
local scrollViewBg = { 1, 0, 0, 1 }
local scrollView
if isGraphicsV1 then
widget._convertColorToV1( topGrayColor )
widget._convertColorToV1( separatorColor )
widget._convertColorToV1( headerTextColor )
widget._convertColorToV1( scrollViewBg )
end
function scene:createScene( event )
local group = self.view
-- Set theme
if USE_ANDROID_THEME then
widget.setTheme( "widget_theme_android" )
end
if USE_IOS7_THEME then
--widget.setTheme( "widget_theme_ios7" )
end
--Display an iOS style background
local background
local xAnchor, yAnchor
if not isGraphicsV1 then
xAnchor = display.contentCenterX
yAnchor = display.contentCenterY
else
xAnchor = 0
yAnchor = 0
end
if USE_IOS7_THEME then
background = display.newRect( xAnchor, yAnchor, display.contentWidth, display.contentHeight )
else
background = display.newImage( "unitTestAssets/background.png" )
background.x, background.y = xAnchor, yAnchor
end
group:insert( background )
scrollView = widget.newScrollView
{
left = 0,
top = 40,
x = 160,
y = 260,
width = display.contentWidth,
height = display.contentHeight - 40,
horizontalScrollDisabled = true,
hideScrollBar = false,
hideBackground = true,
backgroundColor = scrollViewBg
}
group:insert( scrollView )
if USE_IOS7_THEME then
-- create a white background, 40px tall, to mask / hide the scrollView
local topMask = display.newRect( 0, 0, display.contentWidth, 40 )
if not isGraphicsV1 then
topMask.x = topMask.x + topMask.contentWidth * 0.5
topMask.y = topMask.y + topMask.contentHeight * 0.5
end
topMask:setFillColor( unpack( topGrayColor ) )
topMask.alpha = 0
group:insert( topMask )
end
--Create a title to make the menu visibly clear
-- create some skinning variables
local fontUsed = native.systemFont
local headerTextSize = 20
local separatorColor = { unpack( separatorColor ) }
if USE_IOS7_THEME then
fontUsed = "HelveticaNeue-Medium"
headerTextSize = 17
end
local title = display.newEmbossedText( group, "Select a unit test to view", 0, 0, fontUsed, headerTextSize )
title:setFillColor( unpack( headerTextColor ) )
title.x, title.y = display.contentCenterX, 20
group:insert( title )
if USE_IOS7_THEME then
local separator = display.newRect( group, 0, title.contentHeight + title.y, display.contentWidth, 0.5 )
separator:setFillColor( unpack ( separatorColor ) )
end
--Go to selected unit test
local function gotoSelection( event )
local phase = event.phase
if "moved" == phase then
local dy = math.abs( event.y - event.yStart )
if dy > 15 then
scrollView:takeFocus( event )
end
elseif "ended" == phase then
local targetScene = event.target.id
storyboard.gotoScene( targetScene )
end
return true
end
local buttonX = 0
if isGraphicsV1 then
buttonX = 160
end
local function yCoord( coord )
if isGraphicsV1 then
coord = coord + scrollView.contentHeight * 0.5
end
return coord
end
-- spinner unit test
local spinnerButton = widget.newButton
{
id = "spinner",
left = -100,
top = - 230,
x = buttonX,
y = yCoord( -190 ),
label = "Spinner",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( spinnerButton )
-- switch unit test
local switchButton = widget.newButton
{
id = "switch",
x = buttonX,
y = spinnerButton.y + 50,
label = "Switch",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( switchButton )
-- Stepper unit test
local stepperButton = widget.newButton
{
id = "stepper",
left = -100,
top = switchButton.y + 50,
x = buttonX,
y = switchButton.y + 50,
label = "Stepper",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( stepperButton )
-- Search field unit test
local searchFieldButton = widget.newButton
{
id = "searchField",
left = -100,
top = stepperButton.y + 50,
x = buttonX,
y = stepperButton.y + 50,
label = "Search Field",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( searchFieldButton )
-- progressView unit test
local progressViewButton = widget.newButton
{
id = "progressView",
left = -100,
top = searchFieldButton.y + 50,
x = buttonX,
y = searchFieldButton.y + 50,
label = "Progress View",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( progressViewButton )
-- segmentedControl unit test
local segmentedControlButton = widget.newButton
{
id = "segmentedControl",
left = -100,
top = progressViewButton.y + 50,
x = buttonX,
y = progressViewButton.y + 50,
label = "Segmented Control",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( segmentedControlButton )
-- button unit test
local buttonButton = widget.newButton
{
id = "button",
left = -100,
top = segmentedControlButton.y + 50,
x = buttonX,
y = segmentedControlButton.y + 50,
label = "Button",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( buttonButton )
-- tabBar unit test
local tabBarButton = widget.newButton
{
id = "tabBar",
left = -100,
top = buttonButton.y + 50,
x = buttonX,
y = buttonButton.y + 50,
label = "TabBar",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( tabBarButton )
-- slider unit test
local sliderButton = widget.newButton
{
id = "slider",
left = -100,
top = tabBarButton.y + 50,
x = buttonX,
y = tabBarButton.y + 50,
label = "Slider",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( sliderButton )
-- picker unit test
local pickerButton = widget.newButton
{
id = "picker",
left = -100,
top = sliderButton.y + 50,
x = buttonX,
y = sliderButton.y + 50,
label = "Picker",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( pickerButton )
-- tableView unit test
local tableViewButton = widget.newButton
{
id = "tableView",
left = -100,
top = pickerButton.y + 50,
x = buttonX,
y = pickerButton.y + 50,
label = "TableView",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( tableViewButton )
-- scrollView unit test
local scrollViewButton = widget.newButton
{
id = "scrollView",
left = -100,
top = tableViewButton.y + 50,
x = buttonX,
y = tableViewButton.y + 50,
label = "ScrollView",
width = 200, height = 52,
cornerRadius = 8,
onEvent = gotoSelection
}
scrollView:insert( scrollViewButton )
end
function scene:didExitScene( event )
storyboard.removeAll()
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "didExitScene", scene )
return scene