-
Notifications
You must be signed in to change notification settings - Fork 58
/
main.lua
executable file
·340 lines (298 loc) · 10.3 KB
/
main.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
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
334
335
336
337
338
339
-- Project: Business Sample App
--
-- File name: main.lua
--
-- Author: Corona Labs
--
-- Abstract: Main entry point.
--
--
-- Target devices: simulator, device
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved.
---------------------------------------------------------------------------------------
--[[
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
]]--
---------------------------------------------------------------------------------------
--display.setStatusBar( display.HiddenStatusBar )
--
-- load in composer
--
local composer = require ( "composer" )
local widget = require( "widget" )
local json = require( "json" )
local myApp = require( "classes.myapp" )
if (display.pixelHeight/display.pixelWidth) > 1.5 then
myApp.isTall = true
end
if display.contentWidth > 320 then
myApp.is_iPad = true
end
math.randomseed(os.time())
--
-- Initialize database
--
local db = require( "classes.database" )
local myScheme = {}
myScheme["__tableName"] = "accounts"
myScheme["firstName"] = "text"
myScheme["lastName"] = "text"
myScheme["email"] = "text"
--
-- Create the database
-- store the object handle in our faux global myApp table
--
db.init( "mydatabase.db", myScheme )
-- NOTE: In a real app you should do a one way encryption on the password field and never store it in clear text.
-- It's always best to encrypt it, and compare it to the encryptied value in the database.
-- MD5 hash's are easy encrytption for passwwords, bt most hackers have already gotten MD5 password hashes for most
-- common passwords anyway.
--
-- Load our fonts and define our styles
--
local tabBarBackgroundFile = "images/tabBarBg7.png"
local tabBarLeft = "images/tabBar_tabSelectedLeft7.png"
local tabBarMiddle = "images/tabBar_tabSelectedMiddle7.png"
local tabBarRight = "images/tabBar_tabSelectedRight7.png"
myApp.topBarBg = "images/topBarBg7.png"
local iconInfo = {
width = 40,
height = 40,
numFrames = 20,
sheetContentWidth = 200,
sheetContentHeight = 160
}
myApp.icons = graphics.newImageSheet("images/ios7icons.png", iconInfo)
myApp.font = "fonts/Roboto-Light.ttf"
myApp.fontBold = "fonts/Roboto-Regular.ttf"
myApp.fontItalic = "fonts/Roboto-LightItalic.ttf"
myApp.fontBoldItalic = "fonts/Roboto-Italic.ttf"
myApp.theme = "widget_theme_ios7"
if system.getInfo("platformName") == "Android" then
myApp.topBarBg = "images/topBarBg7.png"
else
local coronaBuild = system.getInfo("build")
if tonumber(coronaBuild:sub(6,12)) < 1206 then
myApp.theme = "widget_theme_ios"
end
end
widget.setTheme(myApp.theme)
--
-- These next functions, showScreen1 - showScreen4 are the functions that are
-- triggered when the user taps the buttons in the bottom tabView
--
--
-- These should be pretty straight forward. You need to provide a local file
-- name to download the feed to (feedName), the URL to fetch from, displayMode
-- can be either "podcaset" or "webpage", which tells the module how to handle
-- the story body.
-- pageTitle is the thing that shows at the top of the list view.
--
--
-- The variable "composer" is just a Lua table that is returned from the
-- require("composer" above. As such, I can freely add members/attributes/entries
-- to the table. By using this technique, I can quickly pass data between
-- composer scenes. It's like making them global without the penalties of
-- making them global. There is one catch... Corona Labs could come along and
-- add theor own "displayMode" member (or any of them) later and trump yours
-- but the risk is minmal.
--
myApp.tabBar = {}
function myApp.showScreen1()
myApp.tabBar:setSelected(1)
composer.removeHidden()
composer.gotoScene("scenes.menu", {time=250, effect="crossFade"})
return true
end
function myApp.showScreen2(event)
myApp.tabBar:setSelected(2)
local options = {
feedName = "corona.rss",
feedURL = "https://www.coronalabs.com/feed",
icons = "fixed",
displayMode = "scenes.webpage",
pageTitle = "Corona Labs"
}
composer.removeHidden()
composer.gotoScene("scenes.feed", {time=250, effect="crossFade", params = options})
return true
end
function myApp.showScreen3()
myApp.tabBar:setSelected(3)
composer.removeHidden()
composer.gotoScene("scenes.photogallery", {time=250, effect="crossFade"})
return true
end
function myApp.showScreen4()
myApp.tabBar:setSelected(4)
local options = {
feedName = "video.rss",
feedURL = "https://www.youtube.com/feeds/videos.xml?user=CoronaLabs",
icons = "fixed",
displayMode = "scenes.videoviewer",
pageTitle = "Corona Videos"
}
composer.removeHidden()
composer.gotoScene("scenes.feed2", {time=250, effect="crossFade", params = options})
return true
end
function myApp.showScreen5()
myApp.tabBar:setSelected(5)
local options = {
pageTitle = "Corona Headquarters"
}
composer.removeHidden()
composer.gotoScene("scenes.mapscene", {time=250, effect="crossFade", params = options})
return true
end
function myApp.showScreen6()
myApp.tabBar:setSelected(6)
local options = {
pageTitle = "Data Table"
}
composer.removeHidden()
composer.gotoScene("scenes.datatable", {time=250, effect="crossFade", params = options})
return true
end
--
-- build the top bar which is a tab bar without buttons
--
--Create a group that contains the screens beneath the tab bar
-- each button has a label which shows on the buttons. You need an up-state
-- graphic (non-selected buttons, a down-state button (the currently selected
-- tab) selected will mark which button starts as active, and the onPress calls
-- the function above to actually show each tab.
local tabButtons = {
{
label = "Menu",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen1,
selected = true,
},
{
label = "Blogs",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen2,
},
{
label = "Pics",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen3,
},
{
label = "Video",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen4,
},
{
label = "Map",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen5,
},
{
label = "Data",
defaultFile = "images/tabbaricon.png",
overFile = "images/tabbaricon-down.png",
labelColor = {
default = { 0.25, 0.25, 0.25 },
over = { 0.768, 0.516, 0.25 }
},
width = 32,
height = 32,
onPress = myApp.showScreen6,
},
}
myApp.tabBar = widget.newTabBar{
top = display.safeActualContentHeight - 50 + display.safeScreenOriginY,
left = 0,
width = display.safeActualContentWidth,
backgroundFile = tabBarBackgroundFile,
tabSelectedLeftFile = tabBarLeft, -- New
tabSelectedRightFile = tabBarRight, -- New
tabSelectedMiddleFile = tabBarMiddle, -- New
tabSelectedFrameWidth = 20, -- New
tabSelectedFrameHeight = 50, -- New
buttons = tabButtons,
height = 50,
--background="images/tabBarBg7.png"
}
local background = display.newRect( 0, 0, display.actualContentWidth, display.actualContentHeight )
background:setFillColor( 1, 1, 1 )
background.x = display.contentCenterX
background.y = display.contentCenterY
local title = display.newText( "Corona Labs", 0, 0, myApp.fontBold, 32 )
title:setFillColor( 0, 0, 0 )
title.x = display.contentCenterX
title.y = 64
local logo = display.newImageRect( "images/CoronaLogo.png", 256, 256 )
logo.x = display.contentCenterX
logo.y = display.contentCenterY
local subTitle = display.newText( "Business App Sample", 0, 0, myApp.fontBold, 28 )
subTitle:setFillColor( 0, 0, 0 )
subTitle.x = display.contentCenterX
subTitle.y = display.contentHeight - 64
--
-- now make the first tab active.align
--
local function closeSplash()
display.remove( title )
title = nil
display.remove( subTitle )
subTitle = nil
display.remove( logo )
logo = nil
display.remove( background )
background = nil
myApp.showScreen1()
end
timer.performWithDelay( 1500, closeSplash )