Sub Process_Globals
Dim httpC As HttpClient 'the Connection client
End Sub
Sub Globals
Dim pnlbg As Panel ' background panel
Dim btnsubmit As Button ' Send to DB
Dim btncallDB As Button ' Retrieve from DB
Dim txtinput As EditText ' Text entry field
Dim lvoutput As ListView ' Show the messages from the DB
Dim reader As TextReader ' reading the text from the DB
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
httpC.Initialize("httpC")
'keeps it transparent wehn you scroll to see the text
lvoutput.ScrollingBackgroundColor = Colors.Transparent
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btncallDB_Click
Dim req As HttpRequest ' requesting net data
req.InitializeGet("http://mysqlandroid.webatu.com/Automerk.php?action=getall")
httpC.Execute(req, 1)
ProgressDialogShow("Fetching all data...")
End Sub
Sub httpC_ResponseSuccess (Response As HttpResponse, TaskId As Int)
lvoutput.Clear
'download results
Dim result As String
result = Response.GetString("UTF8")
'strip out the underscores
result = result.Replace("_"," ")
'write it to a file
File.WriteString(File.DirInternalCache, "automerk.txt",result)
'get it back from the file
reader.Initialize(File.OpenInput(File.DirInternalCache, "automerk.txt"))
Dim Merk, Land As String
Merk = reader.ReadLine
Land = reader.ReadLine
Dim i As Int :i = 0
Do While Merk, Land <> Null
i = i+1
Dim linetext As String
linetext = reader.ReadLine
lvoutput.SingleLineLayout.Label.TextSize = 16
lvoutput.SingleLineLayout.ItemHeight = 35
lvoutput.SingleLineLayout.Label.TextColor = Colors.Black
lvoutput.AddSingleLine(i&" "& Merk & Land &" "& linetext)
Merk = reader.ReadLine
Land = reader.ReadLine
Loop
reader.Close
ProgressDialogHide
lvoutput.SetSelection(0)
End Sub
Sub lvoutput_ItemClick(Position As Int, Value As Object)
Msgbox(Value, "Message")
End Sub
Sub httpC_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Msgbox("Error connecting to server"&CRLF&CRLF&Reason,"Error ("&StatusCode&")")
ProgressDialogHide
End Sub
'SUBMIT MESSAGE
Sub btnsubmit_click
Activity.Title = "Submitted"
'Log(deviceID)
Dim inputtext As String
inputtext = txtinput.Text
If inputtext <>"" Then
inputtext = inputtext.Replace(" ", "_")
ProgressDialogShow("Submitting data...")
Dim req As HttpRequest
sendrequest = "http://mysqlandroid.webatu.com/Automerk.php?action=add&Merk&Land="
req.InitializeGet(sendrequest & "" &"&text=" & inputtext)
httpC.Execute(req, 1)
Else
ToastMessageShow("Put a message in first", False)
End If
'clear the text box
txtinput.Text = ""
End Sub