Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.49 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------
  2. --
  3. -- main.lua
  4. --
  5. -----------------------------------------------------------------------------------------
  6.  
  7. -- background image properties
  8.  
  9. local background = display.newImage("Background.jpg")
  10. background.anchorX = 0
  11. background.anchorY = 0
  12. background:scale(0.45, 0.58)
  13.  
  14. local widget = require( "widget" )
  15. local sqlite3 = require( "sqlite3" )
  16. local path = system.pathForFile( "data.db", system.ResourceDirectory )
  17. local db = sqlite3.open( path )
  18.  
  19. -- Handle the "applicationExit" event to close the database
  20. local function onSystemEvent( event )
  21. if ( event.type == "applicationExit" ) then
  22. db:close()
  23. end
  24. end
  25.  
  26. -- Configure tab buttons
  27. local tabButtons = {
  28. {
  29. width = 40,
  30. height = 50,
  31. defaultFile = "baseline_menu_white_18dp.png",
  32. overFile = "baseline_menu_white_18dp.png",
  33. id = "tab1",
  34. labelXOffset = -20,
  35. onPress = handleInput
  36. },
  37. {
  38. width = 180,
  39. height = 70,
  40. --label = "App Name",
  41. defaultFile = "app_name_28.png",
  42. overFile = "app_name_28.png",
  43. id = "tab2",
  44. onPress = handleInput
  45. }
  46. }
  47.  
  48. -- Create the widget
  49. local tabBar = widget.newTabBar(
  50. {
  51. backgroundFile = "tab_bar_background.png",
  52. tabSelectedLeftFile = "transparent_image.png",
  53. tabSelectedRightFile = "transparent_image.png",
  54. tabSelectedMiddleFile = "transparent_image.png",
  55. tabSelectedFrameWidth = 1,
  56. tabSelectedFrameHeight = 1,
  57. top = -53,
  58. top = display.screenOriginY - 10,
  59. height = 52,
  60. width = display.contentWidth,
  61. --label = "App Name",
  62. buttons = tabButtons
  63. }
  64. )
  65.  
  66. -- end top menu section
  67.  
  68. -- array of Widgets to show the buttons
  69. local buttons
  70. local buttonFillColor = { default={0, 0.8, 0.8, 1 }, over={0, 0.8, 0.8, 1} }
  71. local buttonStrokeFillColor = { default={0,0.8,0.8}, over={0.8,0.8,1,1} }
  72.  
  73. -- handle button press
  74. local function handleInput( event )
  75. id = event.target.id
  76. print("button push " .. id)
  77. if id == 2 then
  78. hideButtons(currentButtons)
  79. showButtons(mainMenuButtons)
  80. showButtons(menuBarButtons)
  81. elseif id == 4 then
  82. hideButtons(currentButtons)
  83. populateLawyerList()
  84. showButtons(localLawyerButtons)
  85. showButtons(menuBarButtons)
  86. elseif id == 5 then
  87. hideButtons(mainMenuButtons)
  88. showButtons(phraseButtons)
  89. showButtons(menuBarButtons)
  90. elseif id == 10 then
  91. if loginAccepted() then
  92. hideButtons(loginButtons)
  93. showButtons(mainMenuButtons)
  94. showButtons(menuBarButtons)
  95. end
  96. end
  97. end
  98.  
  99. -- handle scrolling
  100. local function scrollListener( event )
  101. local phase = event.phase
  102. if ( phase == "began" ) then print( "Scroll view was touched" )
  103. elseif ( phase == "moved" ) then print( "Scroll view was moved" )
  104. elseif ( phase == "ended" ) then print( "Scroll view was released" )
  105. end
  106.  
  107. -- In the event a scroll limit is reached...
  108. if ( event.limitReached ) then
  109. if ( event.direction == "up" ) then print( "Reached bottom limit" )
  110. elseif ( event.direction == "down" ) then print( "Reached top limit" )
  111. end
  112. end
  113.  
  114. return true
  115. end
  116.  
  117. -- handle searching
  118. local function searchListener( event )
  119. if ( event.phase == "ended" or event.phase == "submitted" ) then
  120. lawyerScroll:removeSelf()
  121. lawyerScroll = getLawyerScroll()
  122. table.insert(currentButtons, lawyerScroll)
  123. populateLawyerList(lawyerSearch.text)
  124. end
  125. end
  126.  
  127. function loginAccepted()
  128. query = [[SELECT * FROM user WHERE username="]] .. txtUsername.text .. [["]]
  129. for row in db:nrows(query) do
  130. return row.password == txtPassword.text
  131. end
  132. end
  133.  
  134. -- utility to make buttons
  135. local function addButton( ID, x, y, width, height, isIcon, isPanic, label )
  136. if isIcon then
  137. button = widget.newButton(
  138. {
  139. id = ID,
  140. default = label,
  141. onRelease = handleInput,
  142. emboss = false,
  143. width = width,
  144. height = height,
  145. x = x,
  146. y = y
  147. }
  148. )
  149.  
  150. elseif isPanic then
  151. button = widget.newButton(
  152. {
  153. id = ID,
  154. label = label,
  155. shape = "roundedRect",
  156. cornerRadius = 8,
  157. fillColor = { default = { 255, 0, 0,}, over = { 255, 0, 0.5,} },
  158. strokeColor = { default = { 255, 0, 0 }, over = { 255, 0, 0} },
  159. labelColor = { default = { 255, 255, 0 }, over = { 255, 255, 0} },
  160. strokeWidth = 1,
  161. onRelease = handleInput,
  162. emboss = false,
  163. width = 130,
  164. height = 38,
  165. x = x,
  166. y = y
  167.  
  168. }
  169.  
  170. )
  171. else
  172. button = widget.newButton(
  173. {
  174. id = ID,
  175. label = label,
  176. shape = "roundedRect",
  177. cornerRadius = 10,
  178. fillColor = buttonFillColor,
  179. strokeColor = buttonStrokeFillColor,
  180. labelColor = { default = { 163, 25, 12 }, over = { 163, 25, 12} },
  181. strokeWidth = 2,
  182. onRelease = handleInput,
  183. emboss = false,
  184. width = width,
  185. height = height,
  186. x = x,
  187. y = y
  188.  
  189. }
  190.  
  191. )
  192. end
  193. return button
  194. end
  195.  
  196.  
  197. homeButton = display.newImage("home_white_192x192.png")
  198. homeButton:scale(0.22, 0.22)
  199. homeButton.y = display.contentHeight + 10
  200. homeButton.x = 9.3*display.contentWidth/10
  201.  
  202. panicSettingsButton = display.newImage("User-Profile.png")
  203. panicSettingsButton:scale(0.12, 0.12)
  204. panicSettingsButton.y = display.contentHeight + 10
  205. panicSettingsButton.x = 7.75*display.contentWidth/10
  206.  
  207.  
  208.  
  209. -- login feature which is enabled by default --
  210.  
  211. -- username capture
  212.  
  213. txtUsername = native.newTextField(0,0,200,30)
  214. labelUsername = display.newText( "Username", 265, 85, 0, 0, native.systemFont, 18 )
  215. labelUsername:setFillColor ( black )
  216. txtUsername.anchorX = 0
  217. txtUsername.anchorY = 0
  218. txtUsername.x = 10
  219. txtUsername.y = 70
  220. txtUsername:setTextColor(0,0,0)
  221. --set input type
  222. txtUsername.inputType = "default"
  223. --define the placeholder
  224. txtUsername.placeholder = "-- insert username --"
  225. --set font
  226. txtUsername.font = native.newFont(native.systemFont, 12)
  227. native.setKeyboardFocus(txtUsername)
  228.  
  229. -- password capture
  230. txtPassword = native.newTextField(0,0,200,30)
  231. labelPassword = display.newText( "Password", 265, 135, 0, 0, native.systemFont, 18 )
  232. labelPassword:setFillColor ( black )
  233. txtPassword.anchorX = 0
  234. txtPassword.anchorY = 0
  235. txtPassword.x = 10
  236. txtPassword.y = 120
  237. txtPassword:setTextColor(0,0,0)
  238. txtPassword.isSecure = true
  239. --set input type
  240. txtPassword.inputType = "default"
  241. --define the placeholder
  242. txtPassword.placeholder = "-- insert password --"
  243. --set font
  244. txtPassword.font = native.newFont(native.systemFont, 12)
  245.  
  246. -- scroll pane for local lawyer list
  247.  
  248. function getLawyerScroll()
  249. scroll = widget.newScrollView(
  250. {
  251. id = "lawyer",
  252. top = 100,
  253. left = 0,
  254. width = display.contentWidth,
  255. height = 350,
  256. scrollWidth = display.contentWidth,
  257. scrollHeight = 1600,
  258. hideBackground = true,
  259. horizontalScrollDisabled = true,
  260. listener = scrollListener
  261. }
  262. )
  263. return scroll
  264. end
  265.  
  266. lawyerScroll = getLawyerScroll()
  267. lawyerSearch = native.newTextField(display.contentWidth/2,display.contentHeight/12,0.9*display.contentWidth,50)
  268. lawyerSearch.placeholder = "Search Lawyers"
  269. lawyerSearch.id = "lawyer"
  270. lawyerSearch:addEventListener("userInput", searchListener)
  271.  
  272. function addButtonToScroll(scroll, row, num)
  273. button = widget.newButton(
  274. {
  275. id = scroll.id .. row.id,
  276. label = row.name,
  277. shape = "roundedRect",
  278. cornerRadius = 0,
  279. fillColor = buttonFillColor,
  280. strokeColor = buttonStrokeFillColor,
  281. strokeWidth = 0,
  282. height = display.contentHeight/9,
  283. width = 300,
  284. x = display.contentWidth/2,
  285. y = (num * 75) + 30,
  286. onRelease = handleInput
  287. }
  288. )
  289. scroll:insert(button)
  290. end
  291.  
  292. function populateLawyerList( search )
  293. if search == nil then
  294. query = [[SELECT * FROM lawyer]]
  295. else
  296. query = [[SELECT * FROM lawyer WHERE UPPER(name) LIKE "%]] .. search:upper() .. [[%"]]
  297. print("Searched on " .. search .. " query " .. query)
  298. end
  299. i = 0
  300. for row in db:nrows(query) do
  301. addButtonToScroll(lawyerScroll, row, i)
  302. i = i + 1
  303. end
  304. end
  305.  
  306. currentButtons = {}
  307.  
  308. countrySelectButton = addButton( 99, display.contentWidth/2, display.contentHeight/15, display.contentWidth, display.contentHeight/15, false, false, 'Current Country: Australia')
  309.  
  310. menuBarButtons = {
  311. addButton( 1, display.contentWidth/2, display.contentHeight + 10, display.contentWidth/3, display.contentHeight/12, false, true, 'Panic Button'),
  312. addButton( 2, homeButton.x, homeButton.y, homeButton.width*0.22, homeButton.height*0.22, true, false, homeButton ),
  313. addButton( 3, panicSettingsButton.x, panicSettingsButton.y, panicSettingsButton.width*0.12, panicSettingsButton.height*0.12, true, false, panicSettingsButton ),
  314. homeButton,
  315. panicSettingsButton
  316. }
  317.  
  318. mainMenuButtons = {
  319. countrySelectButton,
  320.  
  321. addButton( 4, display.contentWidth/2, 2*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Local Lawyers'),
  322. addButton( 5, display.contentWidth/2, 3.5*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Phrase Translation'),
  323. addButton( 6, display.contentWidth/2, 5*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Useful Contacts'),
  324. =======
  325. addButton( 4, display.contentWidth/2, 2*display.contentHeight/8, display.contentWidth, display.contentHeight/10, false, 'Local Lawyers'),
  326. addButton( 5, display.contentWidth/2, 3.5*display.contentHeight/8, display.contentWidth, display.contentHeight/10, false, 'Phrase Translation'),
  327. addButton( 6, display.contentWidth/2, 5*display.contentHeight/8, display.contentWidth, display.contentHeight/10, false, 'Useful Contacts')
  328. >>>>>>> 5e3a5d2d7575ce032121831a0d4c181169673d43
  329. }
  330.  
  331. phraseButtons = {
  332. countrySelectButton,
  333. addButton( 7, display.contentWidth/2, 2*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Useful Phrases'),
  334. addButton( 8, display.contentWidth/2, 3.5*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Legal Phrases'),
  335. addButton( 9, display.contentWidth/2, 5*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Set Favourite Phrases'),
  336. }
  337.  
  338. loginButtons = {
  339. addButton( 10, display.contentWidth/2, 6*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Login'),
  340. addButton( 11, display.contentWidth/2, 7*display.contentHeight/8, display.contentWidth, display.contentHeight/11.5, false, false, 'Register'),
  341. txtPassword,
  342. txtUsername,
  343. labelPassword,
  344. labelUsername
  345. }
  346.  
  347. localLawyerButtons = {
  348. lawyerScroll,
  349. lawyerSearch
  350. }
  351.  
  352. function showButtons(buttons)
  353. for _, button in pairs(buttons) do
  354. button.isVisible = true
  355. table.insert(currentButtons, button)
  356. end
  357. end
  358.  
  359. function hideButtons(buttons)
  360. for _, button in pairs(buttons) do
  361. button.isVisible = false
  362. end
  363. currentButtons = {}
  364. end
  365.  
  366. populateLawyerList()
  367. hideButtons(phraseButtons)
  368. hideButtons(menuBarButtons)
  369. hideButtons(localLawyerButtons)
  370. hideButtons(loginButtons)
  371. showButtons(mainMenuButtons)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement