Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Fuse As FusedLocationProvider
Dim count As Int
Dim time As Long
Dim sNotif As Notification
Dim LastSentLoc As Location
Dim LastSentTics As Long
Dim CurrentLoc As Location
Dim DbFileName2 As String : DbFileName2 = "workorderpref.db"
Dim Terminate As Boolean
Dim FirstTime As Boolean
Dim sTim As Int
Dim eTim As Int
Dim dDay As String
End Sub
Sub Service_Create
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("Work Orders","Time Clock...",Main)
sNotif.Sound = False
sNotif.Notify(1)
CurrentLoc.Initialize
LastSentLoc.Initialize
Service.StartForeground(1,sNotif)
Fuse.Initialize("FusedLocation")
ToastMessageShow("Fuse Initialized from Service Create "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now),False)
Log ("Fuse Initialized from Service Create "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
FirstTime=True
End Sub
Sub Service_Start (StartingIntent As Intent)
Fuse.Connect
Log ("Fuse Started "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
ToastMessageShow("Fuse Started "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now),False)
End Sub
Sub Service_Destroy
Fuse.Disconnect
End Sub
Sub FusedLocation_ConnectionFailed(ConnectionResult1 As Int)
ToastMessageShow("FusedLocationProvider1_ConnectionFailed",False)
Log("FusedLocationProvider1_ConnectionFailed")
Select ConnectionResult1
Case Fuse.ConnectionResult.NETWORK_ERROR
' a network error has occurred, this is likely to be a recoverable error
' so try to connect again
Fuse.Connect
Case Else
' TODO handle other errors
End Select
End Sub
Sub FusedLocation_ConnectionSuccess
Log("fuse_ConnectionSuccess")
ToastMessageShow("fuse_ConnectionSuccess",False)
If CurrentLoc.IsInitialized = False Then
CurrentLoc.Initialize
End If
If LastSentLoc.IsInitialized = False Then
LastSentLoc.Initialize
End If
CurrentLoc = Fuse.GetLastKnownLocation
SendLocation(False)
Log("long,lat"&CurrentLoc.Longitude&","&CurrentLoc.Latitude)
Dim LocationRequest1 As LocationRequest
LocationRequest1.Initialize
LocationRequest1.SetInterval(1000) ' 30000 milliseconds (30 seconds)
LocationRequest1.SetPriority(LocationRequest1.Priority.PRIORITY_HIGH_ACCURACY)
LocationRequest1.SetSmallestDisplacement(1) ' 1 meter
Fuse.RequestLocationUpdates(LocationRequest1)
End Sub
Sub FusedLocation_LocationChanged(Location1 As Location)
Log("Location Changed "&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now))
ToastMessageShow("Location Changed "&Location1.Accuracy& " "&Location1.DistanceTo(LastSentLoc),False)
If Location1.Accuracy <=100 Then
CurrentLoc=Location1
Log("Location saved" )
If LastSentLoc.Longitude = 0 Or Location1.DistanceTo(LastSentLoc)>100 Or Terminate Or DateTime.Now-LastSentTics>10000 Then ' Moved over 100 meters, or every 10000 ms (10 seconds) send an update
SendLocation(False)
LastSentTics=DateTime.Now
End If
End If
End Sub