Sub Process_Globals
Dim mSQL As SQL
Dim mCursor As Cursor
End Sub
Sub Globals
Dim Panel1, Panel2, Panel3, Panel4, Panel6, Panel7, Panel10, Panel11 As Panel
Dim BtnArts, BtnContact, BtnCrafts, BtnEvents, BtnFamily As Button
Dim BtnGardens, BtnPlaces, BtnPosh, BtnPub, BtnShopping As Button
Dim BtnTea, BtnTrains, BtnZoo As Button
Dim UpdateSuccessFlag, UpdateOrNotFlag, UpdatingFlag As Boolean
Dim NamesList As ListView
Dim ImgPicture As ImageView
Dim ScvDescription, ScvChoose As ScrollView
Dim LblDescription, LblNameandTown, LblPlace, LblWaiting As Label
Dim WebAddress, Latitude, Longitude, Datasrc, Datafile As String
Dim WebView1, MapWebView As WebView
Dim ScaleLat, ScaleLong, CurrentLat, CurrentLong As Float
Dim lm As LocationManager
Dim Local, SeenBefore, ChooseLocal As Boolean
Dim Mess As PhoneSms
Dim p As PhoneCalls
Dim BtnPhone As Button
Dim BtnSMS As Button
Dim EdtSMS As EditText
Dim ProgressBar1 As ProgressBar
Dim pfilepath As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim txt, Info, Dlfilename As String
Dim FullDate As Long
Dim Year, Month, ThisYear, ThisMonth As Int
If File.ExternalWritable = True Then
pfilepath = File.DirDefaultExternal
Else
pfilepath = File.DirInternal
End If
lm.Initialize("Location")
lm.requestLocation
ChooseLocal = False
UpdateSuccessFlag = True
UpdateOrNotFlag=False
Info = DateTime.Date(File.LastModified(pfilepath, "places.db"))
FullDate = DateTime.DateParse(Info)
Month = DateTime.GetMonth(FullDate)
Year = DateTime.GetYear(FullDate)
Info = DateTime.Now
ThisMonth = DateTime.GetMonth(Info)
ThisYear = DateTime.GetYear(Info)
mSQL.Initialize(pfilepath, "places.db", True)
Activity.LoadLayout("Main")
ScvDescription.Panel.LoadLayout("Detail")
ScvChoose.Panel.LoadLayout("Choose")
MapWebView.Initialize("")
Activity.AddView(MapWebView,0,0,100%x,100%y)
MapWebView.Visible = False
If ThisYear <> Year OR ThisMonth <> Month Then
UpdateOrNot
End If
If UpdateOrNotFlag=True Then
Datasrc = "http://caron-promotions.co.uk/"
Datafile = "update.db"
Dlfilename = Datasrc & Datafile
ToastMessageShow("Downloading Data Update - Please wait. . .",True)
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("Job1", Dlfilename)
End If
If File.Exists(pfilepath, "places.db") = False Then
File.Copy(File.DirAssets, "places.db", pfilepath, "places.db")
End If
If File.Exists(pfilepath, "places.bak") = True Then
UpdatingFlag=True
Checkpix
File.Delete(pfilepath, "places.bak")
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
lm.stopListening
End Sub
Sub LocalOrNot
Dim txt, Answ As String
If ChooseLocal = False Then
ChooseLocal = True
txt = "Results within 30 miles only?"
Answ = Msgbox2(txt, "", "Yes", "", "No", Null)
If Answ = DialogResponse.NEGATIVE Then
Local = False
Return True
Else
Local = True
Return False
End If
End If
End Sub
Sub UpdateOrNot
Dim txt, Answ As String
txt = "Download data update?"
Answ = Msgbox2(txt, "", "Yes", "", "No", Null)
If Answ = DialogResponse.NEGATIVE Then
UpdateOrNotFlag = False
Return True
Else
UpdateOrNotFlag = True
Return False
End If
End Sub
Sub BtnZoo_Click
LocalOrNot
PopulateList(12)
End Sub
Sub BtnTrains_Click
LocalOrNot
PopulateList(8)
End Sub
Sub BtnTea_Click
LocalOrNot
PopulateList(5)
End Sub
Sub BtnShopping_Click
LocalOrNot
PopulateList(10)
End Sub
Sub BtnPub_Click
LocalOrNot
PopulateList(3)
End Sub
Sub BtnPosh_Click
LocalOrNot
PopulateList(4)
End Sub
Sub BtnPlaces_Click
LocalOrNot
PopulateList(7)
End Sub
Sub BtnGardens_Click
LocalOrNot
PopulateList(9)
End Sub
Sub BtnFamily_Click
LocalOrNot
PopulateList(1)
End Sub
Sub BtnEvents_Click
LocalOrNot
PopulateList(2)
End Sub
Sub BtnCrafts_Click
LocalOrNot
PopulateList(11)
End Sub
Sub BtnContact_Click
Panel1.Visible = False
If EdtSMS.Text = "" Then
EdtSMS.Visible = False
BtnSMS.Text = "Create Text Message"
Else
EdtSMS.Visible = True
BtnSMS.Text = "Send Text Message"
End If
Panel6.Visible = True
End Sub
Sub BtnSMS_Click
Dim SMSText As String
If BtnSMS.Text = "Create Text Message" Then
EdtSMS.Visible = True
Else
If EdtSMS.Text<>"" Then
SMSText=EdtSMS.Text
Mess.Send("07974535783",SMSText)
ToastMessageShow("Message sent!", False)
EdtSMS.Text=""
EdtSMS.Visible = False
BtnSMS.Text = "Create Text Message"
End If
End If
End Sub
Sub BtnPhone_Click
StartActivity(p.Call("01974299039"))
End Sub
Sub Checkpix
Dim Counter As Int
Dim Picture, Dlfilename As String
mCursor = mSQL.ExecQuery("SELECT * FROM places")
For I = 0 To mCursor.RowCount - 1
Counter = 0
mCursor.Position = I
Picture = mCursor.GetString("Picture")
If File.Exists(pfilepath, Picture) = False AND File.Exists(File.DirAssets, Picture) = False Then
Datasrc = "http://caron-promotions.co.uk/"
Datafile = Picture
Dlfilename = Datasrc & Datafile
ToastMessageShow("Almost done...",True)
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.Download("Job2", Dlfilename)
End If
Counter = Counter + 1
Next
End Sub
Sub JobDone (Job As String)
Dim updatestatus, Dlfilename As String
Dim In As InputStream, Out As OutputStream
Dlfilename = Datasrc & Datafile
UpdatingFlag=True
If HttpUtils.IsSuccess(Dlfilename) Then
Select Job
Case "Job1"
If HttpUtils.IsSuccess(Dlfilename) Then
In = HttpUtils.GetInputStream(Dlfilename)
Out = File.OpenOutput(pfilepath, Datafile, False)
File.copy2(In,Out )
Out.Flush
Out.Close
File.copy(pfilepath,"places.db",pfilepath,"places.bak")
File.copy(pfilepath,"update.db",pfilepath,"places.db")
File.Delete(pfilepath, "update.db")
Else
ToastMessageShow("Problem downloading data, will retry later!", False)
UpdateSuccessFlag = False
UpdatingFlag=False
End If
UpdatingFlag=False
Case "Job2"
If HttpUtils.IsSuccess(Dlfilename) Then
In = HttpUtils.GetInputStream(Dlfilename)
Out = File.OpenOutput(pfilepath, Datafile, False)
File.copy2(In,Out )
Out.Flush
Out.Close
ToastMessageShow("Data downloaded OK!", False)
Else
ToastMessageShow("Problem Downloading Data!", False)
End If
UpdatingFlag=False
End Select
Else
ToastMessageShow("Can't Connect to Server: Check Internet Connection or Try Later!",True)
End If
SeenBefore = True
Activity_Create(True)
UpdatingFlag=False
End Sub
Sub BtnArts_Click
LocalOrNot
PopulateList(6)
End Sub
Sub BntBack_Click
End Sub
Sub PopulateList(a As Int)
Dim m, LatMost, LatLeast, LongMost, LongLeast As Float
Dim Found As Boolean
Dim Counter As Int
Dim Name, Town, Description, Picture, Web, txt, Answ As String
Found = False
NamesList.Clear
m=0.5
If Local = False Then
mCursor = mSQL.ExecQuery("SELECT * FROM places where Type = '" & a & "' order by Name")
Else
LatMost = CurrentLat+m
LatLeast = CurrentLat-m
LongMost = CurrentLong+m
LongLeast = CurrentLong-m
mCursor = mSQL.ExecQuery("SELECT * FROM places where Type = '" & a & "' and Latitude < '" & LatMost & "' and Latitude > '" & LatLeast & "' and Longitude < '" & LatLeast & "' and Longitude > '" & LongMost & "' order by Name")
End If
For I = 0 To mCursor.RowCount - 1
Counter = 0
mCursor.Position = I
Name = mCursor.GetString("Name")
Town = mCursor.GetString("Town")
Description = mCursor.GetString("Description")
Picture = mCursor.GetString("Picture")
Web = mCursor.GetString("Web")
NamesList.AddSingleLine(Name)
Found = True
Counter = Counter + 1
Next
If Found = False AND Local = False Then
ToastMessageShow("Sorry - we didn't find any matches!",False)
LblDescription.Text = ""
End If
If Found = False AND Local = True Then
txt = "No match; widen search?"
Answ = Msgbox2(txt, "", "Yes", "", "No", Null)
If Answ = DialogResponse.POSITIVE Then
Local = False
End If
End If
If Found = True Then
Panel2.Visible= True
Else
Panel1.Visible = True
End If
mCursor.Close
End Sub
Sub NamesList_ItemClick (Position As Int, Value As Object)
Dim Name, Town, Description, Picture, Web, txt, Answ As String
Panel3.Visible = True
WebView1.Visible = True
ScvDescription.ScrollPosition = 0
Panel2.Visible = False
mCursor = mSQL.ExecQuery("SELECT * FROM places WHERE Name = '" & Value & "'")
mCursor.Position = 0
Name = mCursor.GetString("Name")
Town = mCursor.GetString("Town")
Picture = mCursor.GetString("Picture")
Description = mCursor.GetString("Description")
WebAddress = mCursor.GetString("Web")
Latitude = mCursor.GetString("Latitude")
Longitude = mCursor.GetString("Longitude")
LblDescription.Text = Description
LblNameandTown.Text = Name & ", " & Town
ToastMessageShow("Tap name for website or picture for map." ,False)
If File.exists(File.DirAssets, Picture)= True Then
ImgPicture.SetBackgroundImage(LoadBitmap(File.DirAssets, Picture))
Else
If File.exists(pfilepath, Picture)= True Then
ImgPicture.SetBackgroundImage(LoadBitmap(pfilepath, Picture))
Else
ImgPicture.SetBackgroundImage(LoadBitmap(File.DirAssets, "default.jpg"))
End If
End If
WebView1.LoadHtml("<html><body>Loading Page - please wait...</body></html>")
End Sub
Sub LblNameandTown_Click
Panel4.Visible = True
End Sub
Sub ImgPicture_Click
ToastMessageShow("Fetching new map - this may take a few moments. . .",True)
ShowMap(Latitude, Longitude, 15, True, True, True, "TOP_LEFT", True)
End Sub
Sub WebView1_PageFinished (Url As String)
If Url = "file:///" Then
WebView1.LoadUrl(WebAddress)
End If
End Sub
Sub ShowMap(CenterLat As Float, CenterLong As Float, Zoom As Int, MapTypeControl As Boolean, DispZoomControl As Boolean, DispScaleControl As Boolean, ScaleControlPosition As String, DispMarkerCenter As Boolean)
Dim HtmlCode As String
Dim i, j As Int
MapWebView.Visible = True
HtmlCode = "<!DOCTYPE html><html><head><meta name=
If DispMarkerCenter = True Then
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({ position: new google.maps.LatLng(" & CenterLat & "," & CenterLong & "),map: map, title:
End If
HtmlCode = HtmlCode & "; }</script></head><body onload=
MapWebView.LoadHtml(HtmlCode)
End Sub
Sub Location_LocationChanged (Longi As Double, Lati As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long)
CurrentLat = Lati
CurrentLong = Longi
End Sub
Sub Location_ProviderDisabled (Provider As String)
Msgbox("Provider","Provider Disabled")
End Sub
Sub Location_ProviderEnabled (Provider As String)
Msgbox("Provider","Provider Enabled")
End Sub
Sub Location_StatusChanged (Provider As String, Status As Int)
Msgbox("Provider: " & Provider & CRLF & "Status: " & Status,"Status Changed")
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
If MapWebView.Visible = True Then
MapWebView.Visible = False
Else If Panel6.Visible = True Then
Panel6.Visible = False
Panel1.Visible = True
Else If Panel4.Visible = True Then
Panel4.Visible = False
Else If Panel3.Visible = True Then
LblDescription.Text = ""
Panel3.Visible=False
Panel2.Visible = True
Else If Panel2.Visible = True Then
Panel2.Visible = False
ScvChoose.ScrollPosition = 0
Panel1.Visible = True
Else If Panel1.Visible = True AND UpdatingFlag = False Then
Activity.finish
End If
Return True
End If
End Sub
Sub EdtSMS_TextChanged (Old As String, New As String)
BtnSMS.Text = "Send Text Message"
End Sub