Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
DimSQL1AsSQLCipher
End Sub
Sub Globals
Dimclv1AsCustomListView
End Sub
Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("Main")
'Second list is created programmatically.
'Create 20 items made of a label, button and checkbox.
clv1.Initialize(Me, "clv1")
Activity.AddView(clv1.AsView, 0, 5%x, 100%x, 50%y)
SQL1.Initialize(File.DirRootExternal, "1.db", True, "3u2344k", "")
Dim Cursor1 AsCursor
Cursor1 = SQL1.ExecQuery("SELECT * FROM Areas")' Where PropertyID = '" & Main.PropertyID & "'")
For i = 0To Cursor1.RowCount - 1
Cursor1.Position = i
clv1.Add(CreateListItem(Cursor1.GetString("AreaName"), Cursor1.GetString("AreaID"), clv1.AsView.Width, 9%x), 9%x, "")
Next
Cursor1.Close
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed AsBoolean)
End Sub
Sub clv1_ItemClick(Index AsInt, Value AsObject)
Log(Index & " = " & Value)
End Sub
Sub CreateListItem(Text AsString, Text2 AsString, Width AsInt, Height AsInt) AsPanel
Dim p AsPanel
p.Initialize("")
p.Color = Colors.Black
Dim chk AsCheckBox
chk.Initialize("chk")
chk.Color = Colors.White
SetCBDrawable(chk,Colors.DarkGray,2Dip,Colors.Blue,Chr(10004),Colors.LightGray,60Dip,2dip)
Dim chk2 AsCheckBox
chk2.Initialize("chk2")
chk2.Color = Colors.Yellow
chk2.Enabled = False
SetCBDrawable(chk2,Colors.DarkGray,2Dip,Colors.Blue,Chr(10004),Colors.LightGray,60Dip,2dip)
Dim lbl AsLabel
lbl.Initialize("")
lbl.Gravity = Bit.OR(Gravity.TOP, Gravity.LEFT)
lbl.Text = Text
lbl.TextSize = 1.5%x
lbl.TextColor = Colors.White
p.AddView(lbl, 5dip, 2dip, 70%x, 50dip) 'view #0
p.AddView(chk, 71%x, 2dip, 60dip, 60dip) 'view #2
p.AddView(chk2, 85%x, 2dip, 60dip, 60dip) 'view #3
Return p
End Sub
Sub chk_CheckedChange(Checked AsBoolean)
Dim index AsInt
index = clv1.GetItemFromView(Sender)
Dim pnl AsPanel
pnl = clv1.GetPanel(index)
Dim chk AsCheckBox
chk = pnl.GetView(1)
Msgbox("Item value: " & clv1.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub
Sub chk2_CheckedChange(Checked AsBoolean)
Dim index AsInt
index = clv1.GetItemFromView(Sender)
Dim pnl AsPanel
pnl = clv1.GetPanel(index)
Dim chk2 AsCheckBox
chk2 = pnl.GetView(2)
Msgbox("Item value: " & clv1.GetValue(index) & CRLF & "Check value: " & chk2.Checked, "")
End Sub
Sub SetCBDrawable(CB AsCheckBox,BoxColor AsInt,BoxWidth AsInt,TickColor AsInt,TickChar AsString,DisabledColor AsInt,Size AsInt,Padding AsInt)
Dim SLD AsStateListDrawable
SLD.Initialize
Dim BMEnabled,BMChecked,BMDisabled AsBitmap
BMEnabled.InitializeMutable(Size,Size)
BMChecked.InitializeMutable(Size,Size)
BMDisabled.InitializeMutable(Size,Size)
'Draw Enabled State
Dim CNV AsCanvas
CNV.Initialize2(BMEnabled)
Dim Rect1 AsRect
Rect1.Initialize(Padding ,Padding ,Size - Padding ,Size - Padding)
CNV.DrawRect(Rect1,BoxColor,False,BoxWidth)
Dim Enabled,Checked,Disabled AsBitmapDrawable
Enabled.Initialize(BMEnabled)
'Draw Selected state
Dim CNV1 AsCanvas
CNV1.Initialize2(BMChecked)
If TickChar = "Fill"Then
CNV1.DrawRect(Rect1,TickColor,True,BoxWidth)
CNV1.DrawRect(Rect1,BoxColor,False,BoxWidth)
Else
CNV1.DrawRect(Rect1,BoxColor,False,BoxWidth)
'Start small and find the largest font that allows the tick to fit in the box
Dim FontSize AsInt = 6
DoWhile CNV.MeasureStringHeight(TickChar,Typeface.DEFAULT,FontSize) < Size - (BoxWidth * 2) - (Padding * 2)
FontSize = FontSize + 1
Loop
FontSize = FontSize - 1
'Draw the TickChar centered in the box
CNV1.DrawText(TickChar,Size/2,(Size + CNV.MeasureStringHeight(TickChar,Typeface.DEFAULT,25))/2,Typeface.DEFAULT,FontSize,TickColor,"CENTER")
EndIf
Checked.Initialize(BMChecked)
'Draw disabled State
Dim CNV2 AsCanvas
CNV2.Initialize2(BMDisabled)
CNV2.DrawRect(Rect1,DisabledColor,True,BoxWidth)
CNV2.DrawRect(Rect1,BoxColor,False,BoxWidth)
Disabled.Initialize(BMDisabled)
'Add to the StateList Drawable
SLD.AddState(SLD.State_Disabled,Disabled)
SLD.AddState(SLD.State_Checked,Checked)
SLD.AddState(SLD.State_Enabled,Enabled)
SLD.AddCatchAllState(Enabled)
'Add SLD to the Checkbox
Dim JO AsJavaObject = CB
JO.RunMethod("setButtonDrawable",ArrayAsObject(SLD))
End Sub