'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim TabCount, CurrentTab As Int
Type aTab (aTabBody As Panel , Title As Label, Icon As ImageView, Value As Object)
Type Tabs (Container As Panel, ActivityName As String, SelectBackground As String, NonSelectBackground As String, TextSize As Int, TextFont As Typeface)
End Sub
Sub AddTab (TabsObj As Tabs, Title As String, Icon As String)
Dim a As aTab, aTabWidth As Int, SelectedPic, UnSelectedPic As BitmapDrawable, sld As StateListDrawable
aTabWidth = TabsObj.Container.Width/(TabCount + 1)
Dim v0 As Object, v1 As Panel
For i=0 To TabsObj.Container.NumberOfViews - 1
v0 = TabsObj.Container.GetView(i)
If v0 Is Panel Then
v1 = v0
CenterTab(v1, aTabWidth)
v1.Left = v1.Width * v1.Tag
End If
Next
a.Initialize
a.aTabBody.Initialize("AllTabs"):a.aTabBody.Tag = TabCount
a.Icon.Initialize("AllTabs"):a.Icon.Tag = TabCount
a.Title.Initialize("AllTabs"): a.Title.Tag = TabCount
TabsObj.Container.AddView(a.aTabBody, TabCount * aTabWidth,0, aTabWidth, TabsObj.Container.Height)
a.aTabBody.AddView(a.Icon, 0, 0, 1, 1)
a.aTabBody.AddView(a.Title, 0, 0, 1, 1)
a.aTabBody.Width = aTabWidth 'tab width
a.aTabBody.Left = TabCount * a.aTabBody.Width
CenterTab(a.aTabBody, aTabWidth)
If Icon <> "" Then
a.Icon.Bitmap = LoadBitmap(File.DirAssets, Icon)
a.Title.Top = a.aTabBody.Height/2 'label top & height
a.Title.Height = a.aTabBody.Height/2
Else 'no icon
a.Title.Top = a.aTabBody.Height/4
a.Title.Height = a.aTabBody.Height * 0.7
End If
a.Title.Gravity = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
a.Title.Text = Title
a.Title.TextSize = TabsObj.TextSize
a.Title.BringToFront
a.Title.TextColor = Colors.Black
a.Title.Color = Colors.Transparent
If TabsObj.TextFont <> Null Then
a.Title.Typeface = TabsObj.TextFont
End If
If TabsObj.SelectBackground <> "" AND TabsObj.NonSelectBackground <> "" Then
a.aTabBody.SetBackgroundImage (LoadBitmap(File.DirAssets, TabsObj.NonSelectBackground))
End If
TabCount = TabCount + 1
End Sub
Sub CenterTab (Pnl As Panel, aTabWidth As Int)
Dim v0 As Object, v2 As ImageView, v3 As Label
Pnl.Width = aTabWidth
For i=0 To Pnl.NumberOfViews - 1
v0 = Pnl.GetView(i)
If v0 Is ImageView Then
v2 = v0
v2.Width = aTabWidth/3
v2.Height = v2.Width
v2.Left = (Pnl.Width - v2.Width)/2
Else If v0 Is Label Then
v3 = v0
v3.Width = Pnl.Width * 0.7
v3.Left = (Pnl.Width - v3.Width)/2
End If
Next
End Sub
Sub Initialize (Activity As Activity, ViewTop As Int, ViewLeft As Int, ViewWidth As Int, ViewHeight As Int, SelectBackground As String, NonSelectBackground As String, TextSize As Int, TextFont As Typeface) As Tabs
Dim T As Tabs, tc As Panel
tc.Initialize("")
T.Container = tc
Activity.AddView(T.Container,ViewLeft,ViewTop,ViewWidth,ViewHeight)
T.ActivityName = Activity
T.NonSelectBackground = NonSelectBackground
T.SelectBackground = SelectBackground
If TextFont <> Null Then
T.TextFont = TextFont
Else
T.TextFont = Typeface.DEFAULT
End If
T.TextSize = TextSize
T.IsInitialized = True
Return T
End Sub
Sub Selection (TabsObj As Tabs, CurTab As String)
Dim v1 As Object, v2 As Panel, s As String
For i=0 To TabsObj.Container.NumberOfViews - 1
v1 = TabsObj.Container.GetView(i)
If v1 Is Panel Then
v2 = v1
s = v2.Tag
If s <> CurTab Then
v2.SetBackgroundImage(LoadBitmap(File.DirAssets, TabsObj.NonSelectBackground))
Else
v2.SetBackgroundImage(LoadBitmap(File.DirAssets, TabsObj.SelectBackground))
End If
End If
Next
End Sub