forked from coronalabs/framework-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
picker.lua
executable file
·165 lines (132 loc) · 3.62 KB
/
picker.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
-- Copyright (C) 2013 Corona Inc. All Rights Reserved.
-- File: newPickerWheel unit test.
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 xAnchor, yAnchor
if not isGraphicsV1 then
xAnchor = display.contentCenterX
yAnchor = display.contentCenterY
else
xAnchor = 0
yAnchor = 0
end
function scene:createScene( event )
local group = self.view
-- Test android theme
if USE_ANDROID_THEME then
widget.setTheme( "widget_theme_android" )
end
--Display an iOS style background
local background
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 )
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 )
topMask:setFillColor( 235, 235, 235, 255 )
group:insert( topMask )
end
local backButtonPosition = 5
local backButtonSize = 52
if USE_IOS7_THEME then
backButtonPosition = 0
backButtonSize = 40
end
-- Button to return to unit test listing
local returnToListing = widget.newButton{
id = "returnToListing",
left = 60,
top = backButtonPosition,
label = "Exit",
width = 200, height = 40,
onRelease = function() storyboard.gotoScene( "unitTestListing" ) end;
}
returnToListing.x = display.contentCenterX
group:insert( returnToListing )
----------------------------------------------------------------------------------------------------------------
-- START OF UNIT TEST
----------------------------------------------------------------------------------------------------------------
local days = {}
local years = {}
for i = 1, 31 do
days[i] = i
end
for i = 1, 44 do
years[i] = 1969 + i
end
-- Set up the Picker Wheel's columns
local columnData =
{
{
align = "right",
width = 150,
startIndex = 1,
labels =
{
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
},
},
{
align = "center",
width = 60,
startIndex = 18,
labels = days,
},
{
align = "right",
width = 80,
startIndex = 10,
labels = years,
},
}
-- Create a new Picker Wheel
local pickerWheel = widget.newPickerWheel
{
top = display.contentHeight - 222,
columns = columnData,
}
group:insert( pickerWheel )
-- Scroll the second column to it's 8'th row
--pickerWheel:scrollToIndex( 2, 8, 0 )
local function showValues( event )
local values = pickerWheel:getValues()
--print( values )
---[[
for i = 1, #values do
print( "Column", i, "value is:", values[i].value )
--print( "Column", i, "index is:", values[i].index )
end
--]]
return true
end
local getValuesButton = widget.newButton{
id = "getValues",
left = display.contentWidth * 0.5 - 50,
top = 60,
label = "Values",
width = 100, height = 52,
onRelease = showValues;
}
returnToListing.x = display.contentCenterX
group:insert( getValuesButton )
end
function scene:didExitScene( event )
--Cancel test timer if active
if testTimer ~= nil then
timer.cancel( testTimer )
testTimer = nil
end
storyboard.removeAll()
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "didExitScene", scene )
return scene