Advertisement
Guest User

B4A SCIS AHActionBar

a guest
Apr 15th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. #Region Module Attributes
  2. #FullScreen: False
  3. #IncludeTitle: False
  4. #ApplicationLabel: CookIT
  5. #VersionCode: 1
  6. #VersionName:
  7. #SupportedOrientations: unspecified
  8. #CanInstallToExternalStorage: False
  9. #End Region
  10.  
  11. 'Activity module
  12. Sub Process_Globals
  13. 'These global variables will be declared once when the application starts.
  14. 'These variables can be accessed from all modules.
  15. Dim ShowPanelTimer As Timer 'Timer to control the animation
  16. 'Constants for the actionbar
  17. Dim ID_ACTION_HOME As Int : ID_ACTION_HOME = 0
  18. Dim ID_ACTION_MENU As Int : ID_ACTION_MENU = 1
  19. Dim ID_ACTION_REGISTER As Int : ID_ACTION_REGISTER = 2
  20. End Sub
  21.  
  22. Sub Globals
  23. 'These global variables will be redeclared each time the activity is created.
  24. 'These variables can only be accessed from this module.
  25. Dim IME As IME
  26.  
  27. Dim Dropmenu As AHPopupMenu
  28.  
  29. Dim btnStart As Button
  30. Dim btnMenu As Button
  31.  
  32. Dim btnBoodschappenlijst As Button
  33. Dim btnFavorieten As Button
  34. Dim btnRecepten As Button
  35. Dim btnSociaal As Button
  36.  
  37. Dim AB As AHActionBar
  38. 'Initialize some bitmaps for the actionbar.
  39. Dim ABBackground As BitmapDrawable : ABBackground.Initialize(LoadBitmap(File.DirAssets,"banner.png"))
  40. Dim ABHome As BitmapDrawable : ABHome.Initialize(LoadBitmap(File.DirAssets,"cookitappklein.png"))
  41. Dim ABMenu As BitmapDrawable : ABMenu.Initialize(LoadBitmap(File.DirAssets,"menu.png"))
  42. Dim ABRegister As BitmapDrawable: ABRegister.Initialize(LoadBitmap(File.DirAssets,"register.png"))
  43.  
  44. Dim pnlSearch As Panel
  45.  
  46. Dim Counter As Int 'Will use this to set the TOP position of the panel
  47. Dim blnSearchOpen As Boolean 'Searchbar activated or not.
  48. Dim acetSearch As AutoCompleteEditText
  49.  
  50. Dim imgvLogo As ImageView
  51. End Sub
  52.  
  53. Sub Activity_Create(FirstTime As Boolean)
  54. 'If FirstTime = True Then
  55. ' StartActivity(actLogin)
  56. 'Else
  57. 'Load this particular layout.
  58. Activity.LoadLayout("Screenresol")
  59. 'End If
  60. 'Initialize the popup menu.
  61. Dropmenu.Initialize("AC")
  62. '3 options will be in th popup menu. Increase the last number to have more options.
  63. For i = 1 To 2
  64. Dim ai As AHActionItem
  65. Dim bd As BitmapDrawable
  66. Dim Filename, Text As String
  67. 'Select the id and set the icon (filename) and text for it.
  68. Select i
  69. Case 1
  70. Filename = "browse.png"
  71. Text = "Website"
  72. Case 2
  73. Filename = "help.png"
  74. Text = "Help"
  75. 'Case 3
  76. ' Filename = "sticky.png"
  77. ' Text = "Sticky"
  78. End Select
  79.  
  80. 'Initialize a bitmap drawable (icon of option) and the action item (complete option with id, text and icon).
  81. bd.Initialize(LoadBitmap(File.DirAssets, Filename))
  82. ai.Initialize(i, Text, bd)
  83. ai.Selected = True
  84.  
  85. 'Make the third item sticky so they will not close the popup.
  86. 'If i = 3 Then ai.Sticky = True
  87.  
  88. 'Add the items to the popup menu.
  89. Dropmenu.AddActionItem(ai)
  90. Next
  91.  
  92. 'ANIMATION OF THE SEARCHBOX!!!!
  93. 'ShowPanelTimer.Initialize("ShowPanelTimer", 20) 'Initialize the panel, the shorter the number the faster it will open
  94. 'pnlSearch.Top = pnlSearch.Top + pnlSearch.Height - pnlSearch.Height - 3 'The panel will be hidden regardless the height or position of the "search" panel
  95. 'Counter = pnlSearch.Top 'Set the Counter to that position
  96.  
  97. 'ACTIONBAR
  98. AB.Initialize2("AB",ABBackground) 'Initializes the actionbar and sets the background of the actionbar.
  99. AB.ActionWidth = 42dip 'You can change the width of an action item. 42dip is default.
  100. AB.AddHomeAction(ID_ACTION_HOME,ABHome) 'Adds the home button to the actionbar.
  101. AB.AddAction(ID_ACTION_REGISTER,ABRegister) 'Adds an action button to the actionbar.
  102. AB.AddAction(ID_ACTION_MENU,ABMenu) 'Adds an action button to the actionbar.
  103. AB.TitleColor = Colors.White
  104. Activity.AddView(AB, 0, 0, 100%x, 42dip) 'Adds the actionbar to the activity.
  105. End Sub
  106.  
  107. Sub Activity_Resume
  108.  
  109. End Sub
  110.  
  111. Sub Activity_Pause (UserClosed As Boolean)
  112.  
  113. End Sub
  114.  
  115. Sub Activity_Click
  116. 'Check if the search is open, if yes, close it.
  117. CheckSearchOpen
  118. End Sub
  119. Sub AB_ItemClicked(ItemID As Int)
  120. 'If the refresh action is pressed, show the progress indicator a few seconds.
  121. Select ItemID
  122. Case ID_ACTION_MENU
  123. Dropmenu.Show(AB.GetActionView(ID_ACTION_MENU))
  124. Case ID_ACTION_REGISTER
  125. StartActivity(actRegister)
  126. End Select
  127. End Sub
  128.  
  129. 'Event sub when item is pressed on.
  130. Sub AC_Click (Position As Int, ActionItemID As Int)
  131. Dim Action As AHActionItem
  132.  
  133. Action = Dropmenu.getActionItem(Position)
  134. Select Action.ActionId
  135. Case 1
  136. Dim p As PhoneIntents
  137. StartActivity(p.OpenBrowser("http://www.cookit-app.be"))
  138. Case 2
  139. Msgbox("In development.","Error")
  140. End Select
  141. End Sub
  142. Sub Search_Click()
  143. ShowPanelTimer.Enabled = True 'enable the timer to start "animating" the panel
  144. End Sub
  145. Sub btnBoodschappenlijst_Click
  146. 'open nieuw scherm
  147. Msgbox("Still in development.","Error")
  148. End Sub
  149. Sub btnRecepten_Click
  150. 'open nieuw scherm
  151. StartActivity(actCategories)
  152. End Sub
  153. Sub btnFavorieten_Click
  154. 'open nieuw scherm
  155. Msgbox("Still in development.","Error")
  156. End Sub
  157. Sub btnSociaal_Click
  158. 'open nieuw scherm
  159. Msgbox("Still in development.","Error")
  160. End Sub
  161. 'Takes care of the appearing and dissapearing of the searchbox and it's animation.
  162. Sub ShowPanelTimer_Tick
  163. If blnSearchOpen = False Then
  164. pnlSearch.Visible = True
  165. IME.ShowKeyboard(acetSearch)
  166. pnlSearch.Top = Counter
  167. Counter = Counter + 5dip
  168. If Counter > pnlSearch.top + pnlSearch.Height + 5dip - 3 Then 'When the panel is fully visible, stop
  169. ShowPanelTimer.Enabled = False
  170. blnSearchOpen = True
  171. End If
  172. Else
  173. pnlSearch.Top = Counter
  174.  
  175. Counter = Counter - 5dip
  176.  
  177. If Counter < pnlSearch.Top + pnlSearch.Height - pnlSearch.Height - 3 Then
  178. Counter = pnlSearch.Top + pnlSearch.Height - pnlSearch.Height - 3
  179. ShowPanelTimer.Enabled = False
  180. IME.HideKeyboard
  181. acetSearch.Text = ""
  182. pnlSearch.Visible = False
  183. blnSearchOpen = False
  184. End If
  185. End If
  186. End Sub
  187. Sub CheckSearchOpen
  188. If blnSearchOpen = True Then
  189. ShowPanelTimer.Enabled = True 'enable the timer to start "animating" the panel
  190. pnlSearch.Top = Counter
  191.  
  192. Counter = Counter - 5dip
  193.  
  194. If Counter < pnlSearch.Top + pnlSearch.Height - pnlSearch.Height - 3 Then
  195. Counter = pnlSearch.Top + pnlSearch.Height - pnlSearch.Height - 3
  196. ShowPanelTimer.Enabled = False
  197. blnSearchOpen = False
  198. End If
  199. IME.HideKeyboard
  200. End If
  201. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement