#Region  Project Attributes 
	#ApplicationLabel: B4A Example
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: unspecified
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: False
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Type DBResult (Tag As Object, Columns As Map, Rows As List)
	Type DBCommand (Name As String, Parameters() As Object)
	Private const rdcLink As String = "http://192.168.8.109:17178/rdc"
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Private ListViewListTable As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	'Activity.LoadLayout("Layout1")
	Activity.LoadLayout("main")
	
	ListViewListTable.TwoLinesAndBitmap.Label.TextSize = 16
	ListViewListTable.TwoLinesAndBitmap.Label.TextColor = Colors.Black
	ListViewListTable.TwoLinesAndBitmap.Label.Typeface = Typeface.DEFAULT_BOLD
	ListViewListTable.TwoLinesAndBitmap.SecondLabel.TextSize = 14
	ListViewListTable.TwoLinesAndBitmap.SecondLabel.TextColor = Colors.Gray
	ListViewListTable.TwoLinesAndBitmap.ItemHeight = 100dip
	ListViewListTable.TwoLinesAndBitmap.ImageView.Gravity = Gravity.NO_GRAVITY
	ListViewListTable.TwoLinesAndBitmap.ImageView.Height = 60dip
	ListViewListTable.TwoLinesAndBitmap.ImageView.Width = 60dip
	ListViewListTable.TwoLinesAndBitmap.ImageView.Top = (ListViewListTable.TwoLinesAndBitmap.ItemHeight / 2) - ListViewListTable.TwoLinesAndBitmap.ImageView.Height / 2
	ListViewListTable.TwoLinesAndBitmap.Label.Top = (ListViewListTable.TwoLinesAndBitmap.ItemHeight / 2) - (ListViewListTable.TwoLinesAndBitmap.Label.Height)
	ListViewListTable.TwoLinesAndBitmap.Label.Left = 100dip
	ListViewListTable.TwoLinesAndBitmap.SecondLabel.Top = (ListViewListTable.TwoLinesAndBitmap.ItemHeight / 2) - (ListViewListTable.TwoLinesAndBitmap.SecondLabel.Height - 30dip)
	ListViewListTable.TwoLinesAndBitmap.SecondLabel.Left = 100dip
	
	SetDivider(ListViewListTable, Colors.LightGray, 1dip)
	
	GetRecord
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CreateRequest As DBRequestManager
	Dim req As DBRequestManager
	req.Initialize(Me, rdcLink)
	Return req
End Sub

Sub CreateCommand(Name As String, Parameters() As Object) As DBCommand
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = Name
	If Parameters <> Null Then cmd.Parameters = Parameters
	Return cmd
End Sub

Sub GetRecord
	Dim req As DBRequestManager = CreateRequest
	Dim cmd As DBCommand = CreateCommand("selectAllItem", Null)
	Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
	
	If j.Success Then
		req.HandleJobAsync(j, "req")
		Wait For (req) req_Result(res As DBResult)
		'work with result
'		req.PrintTable(res)
		Log(res.Columns)
		ListViewListTable.Clear
		For Each row() As Object In res.Rows
			Dim oBitMap As Bitmap
			Dim buffer() As Byte
			buffer = row(res.Columns.Get("image"))
			oBitMap = req.BytesToImage(buffer)
			ListViewListTable.AddTwoLinesAndBitmap(row(1), "$" & row(2) & "      See more...", oBitMap)
		Next
	Else
		Log("ERROR: " & j.ErrorMessage)
	End If
	
	j.Release
End Sub



Sub SetDivider(lv As ListView, Color As Int, Height As Int)
	Dim r As Reflector
	r.Target = lv
	Dim CD As ColorDrawable
	CD.Initialize(Color, 0)
	r.RunMethod4("setDivider", Array As Object(CD), Array As String("android.graphics.drawable.Drawable"))
	r.RunMethod2("setDividerHeight", Height, "java.lang.int")
End Sub


Sub Button1_Click
	
End Sub

Sub ListViewListTable_ItemLongClick (Position As Int, Value As Object)
	
End Sub

Sub ListViewListTable_ItemClick (Position As Int, Value As Object)
	
End Sub