'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim GPS1 As GPS
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.
Dim filefrom As FileDialog
Dim Btn As Button
Dim Btn2 As Button
Dim Btn3 As Button
Dim Btn4 As Button
Dim lblPath As Label
Dim lblFileName As Label
filefrom.FilePath = "/mnt/sdcard/download"
Dim Table1, Table2 As Table
Dim lblLat As Label
Dim lblLng As Label
Dim Map1 As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
GPS1.Initialize("GPS")
End If
Btn.Initialize("btn")
Btn2.Initialize("btn2")
Btn3.Initialize("btn3")
Btn4.Initialize("btn4")
lblPath.Initialize("")
lblFileName.Initialize("")
lblLat.Initialize("")
lblLng.Initialize("")
Table1.Initialize(Me, "Table1", 4)
Table2.Initialize(Me, "Table1", 4)
Activity.AddView(Btn,0,0,150,100)
Activity.AddView(Btn2,160,0,150,100)
Activity.AddView(Btn3,320,0,150,100)
Btn.Text = "Dirs to Log"
Btn2.Text = "FileDLG"
Btn3.Text = "Files on Download"
Btn4.Text = "Import csv file"
Btn4.Enabled = False
Activity.AddView(lblPath, 0, 110, 100%x, 40dip)
Activity.AddView(lblFileName, 0, 160, 100%x, 40dip)
Activity.AddView(lblLat, 0, 190, 100%x, 40dip)
Activity.AddView(lblLng, 0, 220, 100%x, 40dip)
Activity.AddView(Btn4,0,100%y - 100,150,100)
Table1.AddToActivity(Activity, 500, 260, 100%x, 50%y)
Table2.AddToActivity(Activity, 0, 260, 100%x, 50%y)
Table1.SetHeader(Array As String("Row", "Lat", "lng", "Name"))
For i = 0 To 50
Table1.AddRow(Array As String(i, "Col1", "Col2", "Col3"))
Next
Table2.SetHeader(Array As String("Lat", "lng", "Name", "< 5km"))
Table1.SetColumnsWidths(Array As Int(70dip, 60dip, 160dip, 160dip))
Table2.SetColumnsWidths(Array As Int(70dip, 70dip, 110dip, 60dip))
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(0, 0) 'Listen to GPS with no filters.
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub
Sub btn_click
Log("File.DirAssets="&File.DirAssets)
Log("File.DirDefaultExternal="&File.DirDefaultExternal)
Log("File.DirInternal="&File.DirInternal)
Log("File.DirInternalCache="&File.DirInternalCache)
Log("File.DirRootExternal="&File.DirRootExternal)
End Sub
Sub btn2_click
'filefrom.Show("List of csv files", "", "", "", Null)
Dim fd As FileDialog
fd.FastScroll = True
'fd.ShowOnlyFolders = True
'fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string
'fd.ShowOnlyFolders = true
'fd.FileFilter = ".txt" ' for example or ".jpg,.png" for multiple file types
fd.FilePath = "/mnt/sdcard/download"
fd.FileFilter = ".xls" ' ".txt" ' for example or ".jpg,.png" for multiple file types
ret = fd.Show("B4A File Dialog", "Yes", "No", "Maybe", Null)
lblPath.text = fd.FilePath
lblFileName.text = fd.ChosenName
End Sub
Sub btn3_click
filefrom.FilePath = "/mnt/sdcard/download"
'filefrom.FileFilter = ".csv"
filefrom.FileFilter = ".xls"
filefrom.Show("List of csv files", "OK", "Cancel", "", Null)
lblPath.text = filefrom.FilePath
lblFileName.text = filefrom.ChosenName
End Sub
Sub Btn4_click
Table1.LoadTableFromCSV(lblPath.Text, lblFileName.Text, True)
Dim MyLocation As Location
Dim Location1 As Location
Log("a")
Dim myLocationCircle As Circle
MyLocation.Initialize2(lblLat.Text, lblLng.Text)
myLocationCircle.Initialize(MyLocation, 5000)
Log("b")
Log(MyLocation.Latitude)
Log(MyLocation.Longitude)
Dim LocationName As String
Dim i As Int
Try
Log("c")
For r = 0 To 1000
' Log(r)
' Log(Table1.GetValue(0, r))
' Log(Table1.GetValue(1,r))
' Log(Table1.GetValue(2,r))
Location1.Initialize2(Table1.GetValue(1, r), Table1.GetValue(0, r))
' Log(Location1.Latitude)
' Log(Location1.Longitude)
'
' Log(Location1)
LocationName = Table1.GetValue(2,r)
Log("myLoc: " & myLocationCircle.Contains(Location1))
If myLocationCircle.Contains(Location1) Then
Log("adding: " & r)
Table2.AddRow(Array As String(Location1.Latitude, Location1.Longitude, LocationName, True))
End If
Next
Catch
Log(LastException.Message)
End Try
' Table2.visible = True
' Table1.visible = False
Table2.AddRow(Array As String("Done", "", "", ""))
End Sub
Sub Table1_CellClick (Col As Int, Row As Int)
Log("CellClick: " & Col & " , " & Row)
Activity.Title = Table1.GetValue(Col, Row)
End Sub
Sub Table1_HeaderClick (Col As Int)
Log("HeaderClick: " & Col)
End Sub
Sub GPS_LocationChanged (Location1 As Location)
Dim dt As String
Dim now As Long
DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
now = DateTime.now
dt = DateTime.Date(now)
' lblLat.Text = "Lat = " & Location1.Latitude
' lblLng.Text = "Lon = " & Location1.Longitude
lblLat.Text = Location1.Latitude
lblLng.Text = Location1.Longitude
If Btn4.Enabled = False Then
Btn4.Enabled = True
End If
GPS1.Stop
End Sub
Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub