'Activity module
Sub Process_Globals
Dim HttpClient1 As HttpClient
Dim Parser As SaxParser
End Sub
Sub Globals
Dim Label1 As Label
Dim wm As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
HttpClient1.Initialize("HttpClient1")
Parser.Initialize
End If
Activity.LoadLayout("layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Label1_Click
wm = ""
Dim request As HttpRequest
request.InitializeGet("http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=-26,132")
request.Timeout = 10000 'set timeout to 10 seconds
If HttpClient1.Execute(request, 1) = False Then Return 'Will be false if there is already a running task (with the same id).
ProgressDialogShow("Calling address server...")
request.InitializeGet("http://ws.geonames.org/findNearByWeatherXML?lat=-26&lng=132")
request.Timeout = 10000 'set timeout to 10 seconds
If HttpClient1.Execute(request, 2) = False Then Return 'Will be false if there is already a running task (with the same id).
ProgressDialogShow("Calling weather server...")
End Sub
Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
ProgressDialogHide
Dim result As InputStream
result = Response.GetInputStream 'GetString("UTF8") 'Convert the response to a string
Parser.Parse(result, "Parser")
result.Close
Label1.Text = wm
End Sub
Sub HttpClient1_ResponseError (Reason As String, StatusCode As Int, TaskId As Int)
ProgressDialogHide
If StatusCode = -1 Then msg = "The phone is offline"
'If reason <> Null Then msg = msg & CRLF & Reason
ToastMessageShow (Reason, True)
End Sub
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
End Sub
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If Parser.Parents.IndexOf("Placemark") > -1 Then
If Name = "address" Then
If wm.Length > 0 Then Return
wm = "Address: " & Text.ToString & CRLF
End If
End If
If Parser.Parents.IndexOf("geonames") > -1 Then
If Name = "temperature" Then
wm = wm & "Temperature: " & Text.ToString & Chr(176) & "C" & CRLF
temp = Text.ToString & Chr(176) & "C" & CRLF
Else If Name = "humidity" Then
wm = wm & "Humidity: " & Text.ToString & "%RH" & CRLF
temp = temp & Text.ToString & "%RH"
Else If Name = "seaLevelPressure" Then
wm = wm & "Pressure: " & Text.ToString & "mb" & CRLF
Else If Name = "windDirection" Then
wm = wm & "Wind direction: " & Text.ToString & Chr(176) & CRLF
Else If Name = "windSpeed" Then
wm = wm & "Wind speed: " & Text.ToString & "km/h" & CRLF
Else If Name = "clouds" Then
a = Text.ToString
a = a.ToUpperCase.CharAt(0) & a.SubString(1)
wm = wm & a & CRLF
End If
End If
End Sub