diff --git a/Files/infowindow.bal b/Files/infowindow.bal index af0f94f..3c191d0 100644 Binary files a/Files/infowindow.bal and b/Files/infowindow.bal differ diff --git a/FirebaseMessaging.bas b/FirebaseMessaging.bas index 046e9ad..8b40095 100644 --- a/FirebaseMessaging.bas +++ b/FirebaseMessaging.bas @@ -32,49 +32,74 @@ Sub Service_Start (StartingIntent As Intent) End Sub Sub fm_MessageArrived (Message As RemoteMessage) - Log("Mensaje recibido") - Log($"Message data: ${Message.GetData}"$) + Log($"Pusher - Mensaje recibido: ${Message.GetData}"$) +' Log($"Message data: ${Message.GetData}"$) 'Si recibimos Pong, lo agregamos a la lista de dispositivos activos If Message.GetData.ContainsKey("t") And Message.GetData.Get("t") = "pong" Then - Log("Recibimos pong "&Message.GetData.Get("d")) + Log("Pusher - Recibimos pong "&Message.GetData.Get("d")) If Main.dispositivos.ContainsKey(Message.GetData.Get("d")) Then Dim dMap As Map = Main.dispositivos.Get(Message.GetData.Get("d")) Dim dispData As Map = dMap Else Dim dispData As Map = CreateMap("coords": "0,0", "d": Message.GetData.Get("d"),"v": Message.GetData.Get("v"), "w": Message.GetData.Get("w")) End If - Log("** "&dispData) +' Log("** "&dispData) Main.dispositivos.Put(Message.GetData.Get("d"), dispData) End If 'Si el mensaje es de ubicacion recibida If Message.GetData.ContainsKey("t") And (Message.GetData.Get("t") = "u" Or Message.GetData.Get("t") = "au") Then - Log("Recibimos ubicacion") + Log("Pusher - Recibimos ubicacion") Private ubi As Location - Log("Llamamos UbicacionRecibida") - If Message.GetData.Get("t") = "au" Then +' Log("Llamamos UbicacionRecibida") + If Message.GetData.Get("t") = "au" Or Message.GetData.Get("t") = "u" Then ' ToastMessageShow("Ubicacion recibida:"&Message.GetData.Get("body"),False) Private coords() As String = Regex.split(",", Message.GetData.Get("body")) ubi.Initialize - ubi.Latitude = coords(0) - ubi.Longitude = coords(1) + If Message.GetData.Get("body") <> "" Then + ubi.Latitude = coords(0) + ubi.Longitude = coords(1) + Else + ubi.Latitude = 0 + ubi.Longitude = 0 + End If +' ubi.Longitude = coords(1) Private c As Cursor = db.ExecQuery("select * from geocercas") 'Traemos las geocercas Private estaGC As Location + Private enGoecerca As Boolean = False + Private nuevoEnGoecerca As Boolean = False If c.RowCount > 0 Then For i = 0 To c.RowCount - 1 c.Position = i estaGC.Initialize estaGC.Latitude = c.GetString("lat") estaGC.Longitude = c.GetString("lon") - Log(ubi & "|" & estaGC) - Log(ubi.DistanceTo(estaGC)) +' Log(ubi & "|" & estaGC) +' Log(ubi.DistanceTo(estaGC)) If ubi.DistanceTo(estaGC) < 300 Then 'Revisamos si la ubicaccion recibida esta dentro de alguna geocerca. ' ToastMessageShow($"Dentro de ${c.GetString("nombre")}"$, False) - Subs.notiHigh("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") + enGoecerca = True + If Not(Starter.dentroDeGeocerca.ContainsKey(Message.GetData.Get("d"))) Then + Starter.dentroDeGeocerca.Put(Message.GetData.Get("d"), c.GetString("nombre")) + nuevoEnGoecerca = True + End If +' Log(nuevoEnGoecerca) +' notiBigText("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") End If Next End If + If Not(enGoecerca) Then + Starter.dentroDeGeocerca.Remove(Message.GetData.Get("d")) +' Log(Starter.dentroDeGeocerca) + End If + Private textoNoti As String = "" + For Each key As String In Starter.dentroDeGeocerca.Keys +' Log(Starter.dentroDeGeocerca.Get(key)) + textoNoti = $"${textoNoti}${CRLF}${key} - ${Starter.dentroDeGeocerca.Get(key)} "$ + Next + If nuevoEnGoecerca Then notiBigText("Geocercas", $"${textoNoti}"$, 777, "Main") +' LogColor("****** " & Starter.dentroDeGeocerca, Colors.blue) ' Subs.notiHigh("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") End If CallSub2(Main, "ubicacionRecibida", Message.GetData) @@ -99,6 +124,17 @@ Sub Service_Destroy End Sub +Sub notiBigText(title2 As String, body2 As String, id2 As String, act As Object) + Dim smiley As Bitmap = LoadBitmapResize(File.DirAssets, "logo_keymon.png", 24dip, 24dip, False) + Dim n As NB6 + n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley) +' Dim cs As CSBuilder + n.BigTextStyle("Geocercas", "", "") + n.OnGoing(True) +' n.SetDefaults(true, True, True) + n.Build(title2, body2, "tag", act).Notify(id2) +End Sub + Sub descomprimeRuta Dim su As StringUtils Dim decompressedbytes() As Byte = su.DecodeBase64(Main.base64) diff --git a/Pusher.b4a b/Pusher.b4a index 588edd3..416391e 100644 --- a/Pusher.b4a +++ b/Pusher.b4a @@ -1,15 +1,17 @@ Build1=Default,pusher.chv.com File1=96761371-car-icon-white-icon-with-shadow-on-transparent-background.jpg -File10=marker-rojo-0.png -File11=marker-rojo-coche.png -File12=waze.png -File13=waze-moving.png -File14=waze-moving-2.png -File15=waze-moving-small.png -File16=waze-sleeping.png -File17=waze-sleeping-small.png -File18=zzz.png +File10=logo_keymon.png +File11=marker-rojo-0.png +File12=marker-rojo-coche.png +File13=smiley.png +File14=waze.png +File15=waze-moving.png +File16=waze-moving-2.png +File17=waze-moving-small.png +File18=waze-sleeping.png +File19=waze-sleeping-small.png File2=ballon280.png +File20=zzz.png File3=ballon50.png File4=balloon_overlay_close.png File5=datetimelayout.bal @@ -27,7 +29,9 @@ FileGroup15=Default Group FileGroup16=Default Group FileGroup17=Default Group FileGroup18=Default Group +FileGroup19=Default Group FileGroup2=Default Group +FileGroup20=Default Group FileGroup3=Default Group FileGroup4=Default Group FileGroup5=Default Group @@ -48,9 +52,10 @@ Library17=randomaccessfile Library18=reflection Library19=runtimepermissions Library2=byteconverter -Library20=xcustomlistview -Library21=xui -Library22=sql +Library20=sql +Library21=xcustomlistview +Library22=xui +Library23=nb6 Library3=compressstrings Library4=core Library5=dateutils @@ -65,15 +70,15 @@ Module3=Mods Module4=MyPopup Module5=Starter Module6=Subs -NumberOfFiles=18 -NumberOfLibraries=22 +NumberOfFiles=20 +NumberOfLibraries=23 NumberOfModules=6 Version=12.5 @EndOfDesignText@ #Region Project Attributes #ApplicationLabel: Pusher 2.0 #VersionCode: 1 - #VersionName: 3.09.27 + #VersionName: 3.09.29 'Ver. 3.09.18 - Se agregó la posibilidad de mostrar puntos internedios en la ruta y muestra icono diferente si esta en movimiento o parado. 'SupportedOrientations possible values: unspecified, landscape or portrait. #SupportedOrientations: portrait @@ -126,12 +131,12 @@ Sub Process_Globals Private hInicio, hFinal As String Private distanciaRecorrida As String = "0" Private usuario As String - dim punto as LatLng + Dim punto As LatLng End Sub Sub Globals 'These global variables will be redeclared each time the activity is created. - Private gmap As GoogleMap + Private gmap, gmap2 As GoogleMap Dim MapFragment1 As MapFragment Dim latmarker As String Dim longmarker As String @@ -326,6 +331,7 @@ Sub JobDone(Job As HttpJob) End If Private d As String = records(result.Columns.Get("DATOS")) & "," & records(result.Columns.Get("FECHA")) Private l As List = Regex.Split(",", d) +' Log(rutaSeleccionada) estasCoords.Initialize estasCoords.Latitude = l.Get(0) estasCoords.Longitude = l.Get(1) @@ -349,6 +355,7 @@ Sub JobDone(Job As HttpJob) fechaFinRutaGPS = DateTime.Date(fechaFinRutaGPS) & ", " & DateTime.Time(fechaFinRutaGPS) Next Private estaGC As Location + Private enGeocerca As Boolean = False If c.RowCount > 0 Then For i = 0 To c.RowCount - 1 c.Position = i @@ -356,17 +363,32 @@ Sub JobDone(Job As HttpJob) estaGC.Latitude = c.GetString("lat") estaGC.Longitude = c.GetString("lon") ' Log(estasCoords & "|" & thisGC) - Log(estasCoords.DistanceTo(estaGC)) +' Log(estasCoords.DistanceTo(estaGC)) If estasCoords.DistanceTo(estaGC) < 300 Then ToastMessageShow($"Dentro de ${c.GetString("nombre")}"$, False) -' Subs.notiHigh("Dentro de Geocerca", $"${usuario} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") + Starter.dentroDeGeocerca.Put(usuario, c.GetString("nombre")) +' Log("+*************** " & Starter.dentroDeGeocerca) +' Subs.notiHigh($"Geocerca"$, $"${usuario} esta dentro de ${c.GetString("nombre")}"$, 777, "Main") + enGeocerca = True End If Next End If + If Not(enGeocerca) Then + Starter.dentroDeGeocerca.Remove(usuario) + Log(Starter.dentroDeGeocerca) +' Subs.notiHigh("Geocercas", $"${usuario} salió de geocerca."$, 777, "Main") + End If + Private textoNoti As String = "" + For Each key As String In Starter.dentroDeGeocerca.Keys +' Log(Starter.dentroDeGeocerca.Get(key)) + textoNoti = $"${textoNoti}${CRLF}${key} - ${Starter.dentroDeGeocerca.Get(key)} "$ + Next +' Log(textoNoti) + notiBigText("Geocercas", $"${textoNoti}"$, 777, "Main") c.Close ToastMessageShow("Recibimos ruta con " & reqManager.HandleJob(Job).Rows.Size & " puntos.", False) ' Log(rutaGPS) - LogColor($"Distancia recorrida: $1.1{distanciaRecorrida/1000} kms."$, Colors.Magenta) +' LogColor($"Distancia recorrida: $1.1{distanciaRecorrida/1000} kms."$, Colors.Magenta) l_distanciaRecorrida.Text = $"Dist. recorrida: $1.1{distanciaRecorrida/1000} kms."$ muestraRuta End If @@ -377,7 +399,7 @@ Sub JobDone(Job As HttpJob) s_rutas.Add("Selecciona") For Each records() As Object In result.Rows For Each k As String In result.Columns.Keys - Log(result.Tag & ": " & k & ": " & records(result.Columns.Get(k))) +' Log(result.Tag & ": " & k & ": " & records(result.Columns.Get(k))) s_rutas.Add(records(result.Columns.Get(k))) Next Next @@ -387,6 +409,17 @@ Sub JobDone(Job As HttpJob) Job.Release End Sub +Sub notiBigText(title2 As String, body2 As String, id2 As String, act As Object) + Dim smiley As Bitmap = LoadBitmapResize(File.DirAssets, "logo_keymon.png", 24dip, 24dip, False) + Dim n As NB6 + n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley) +' Dim cs As CSBuilder + n.BigTextStyle("Geocercas", "", "") + n.OnGoing(True) +' n.SetDefaults(true, True, True) + n.Build(title2, body2, "tag", act).Notify(id2) +End Sub + public Sub ubicacionRecibida(message As Map) 'Aqui mostramos la ubicacion recibida en el mapa Dim coords As List = Regex.Split(",",message.Get("body")) @@ -415,7 +448,7 @@ public Sub ubicacionRecibida(message As Map) Dim dispData As Map = CreateMap("coords" : coords.Get(0)&","&coords.Get(1), "tm" : timemarker, "d" : message.Get("d"), "b" : batt, "w" : wifi, "mt" : montoTotal, "v" : v) dispositivos.Put(message.Get("d"), dispData) ' Log("dispositvos="&dispositivos) - Log(DateTime.Time(timemarker)) +' Log(DateTime.Time(timemarker)) MapFragment1_Ready Log("Dispositivos : "&dispositivos.Size) End Sub @@ -449,7 +482,7 @@ Sub agregaAListview Next cuantos.Text = "Rutas"&CRLF&ListView1.Size ubicados.Text = "Ubicados"&CRLF&dUbicados - Log("dUbicados="&dUbicados) +' Log("dUbicados="&dUbicados) End Sub Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int) @@ -520,7 +553,6 @@ Sub MapFragment1_Ready '/////////////////////////////////////////// Dim GoogleMapsExtras1 As GoogleMapsExtras Dim InfoWindowAdapter1 As InfoWindowAdapter - InfoWindowAdapter1.Initialize("InfoWindowAdapter1") GoogleMapsExtras1.SetInfoWindowAdapter(gmap, InfoWindowAdapter1) InfoWindowPanel.Initialize("") @@ -557,6 +589,21 @@ Sub MapFragment1_Ready ' Subs.mueveCamaraMapa(MapFragment1, latmarker, longmarker) End Sub +Sub MapFragment2_Ready + gmap2 = MapFragment2.GetMap + '/////////////////////////////////////////// + Dim GoogleMapsExtras2 As GoogleMapsExtras + Dim InfoWindowAdapter2 As InfoWindowAdapter + InfoWindowAdapter2.Initialize("InfoWindowAdapter1") + GoogleMapsExtras2.SetInfoWindowAdapter(gmap2, InfoWindowAdapter2) + InfoWindowPanel.Initialize("") + InfoWindowPanel.LoadLayout("InfoWindow") + ' a hack(ish) way to set InfoWindowPanel width and height! + MapPanel.AddView(InfoWindowPanel, 0, 0, 190dip, 80dip) + InfoWindowPanel.RemoveView + '///////////////////////////////////////////// +End Sub + Sub MapFragment2_LongClick(Point As LatLng) Log("LONG: " & Point) p_addGeofence.BringToFront @@ -575,22 +622,33 @@ Sub InfoWindowAdapter1_GetInfoContents(Marker1 As Marker) As View Return InfoWindowPanel End Sub +Sub InfoWindowAdapter2_GetInfoContents(Marker1 As Marker) As View + ' the default InfoContent will be used if this event Sub is not defined or if it returns Null + ' Log("InfoWindowAdapter1_GetInfoContents") + TitleLabel.Text=Marker1.Title + SnippetLabel.Text=Marker1.Snippet + ' ThumbImage.Bitmap=? how will you store the file path/file name of the image to display? + ' it's a shame that the Marker object has no Tag property which could be used to store such info + Return InfoWindowPanel +End Sub + Sub muestraRuta -' Log("iniciamos MuestraRuta") + Log("-------- = iniciamos MuestraRuta") + MapFragment2_Ready Private estasCoords, coordsAnt As Location coordsAnt.Initialize estasCoords.Initialize ' If lineAnt.IsInitialized Then lineAnt.Visible = False 'Ocultamos ruta anterior If mapaDestino = 1 Then - gmap = MapFragment1.GetMap + gmap2 = MapFragment1.GetMap Else - gmap = MapFragment2.GetMap + gmap2 = MapFragment2.GetMap End If Dim points As List Dim point As LatLng Dim lat1, lon1, latIn, lonIn, latOut, lonOut As Double - line=gmap.AddPolyline - line.Width=10 + line = gmap2.AddPolyline + line.Width = 10 ' Log("Color ruta") 'Cambiamos el color de la ruta cada vez que se solicite una nueva If colorAnt = 1 Then line.color=Colors.RGB(255, 54, 54) ' Rojo @@ -614,7 +672,7 @@ Sub muestraRuta listtemp = Regex.Split(CRLF, rutaGPS) ' Log(listtemp.Size) For i = 1 To listtemp.Size-1 - Dim coords() As String = Regex.Split(",",listtemp.Get(i)) + Dim coords() As String = Regex.Split(",", listtemp.Get(i)) If i = 1 Then latIn = coords(0) lonIn = coords(1) @@ -634,11 +692,11 @@ Sub muestraRuta DateTime.timeformat = "HH:mm" hora = DateTime.Time(hora) If speedOut > 0.5 Then - Marker0 = gmap.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-moving-small.png")) + Marker0 = gmap2.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-moving-small.png")) Else - Marker0 = gmap.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-sleeping-small.png")) + Marker0 = gmap2.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-sleeping-small.png")) End If - Marker0.Snippet = "Hora: " & hora & ", Vel.: " & NumberFormat2((speedOut * 3.6), 1, 2, 2, True) & " km/h" + Marker0.Snippet = "Hora: " & hora & CRLF &"Velocidad: " & NumberFormat2((speedOut * 3.6), 1, 2, 2, True) & " km/h" End If lat1 = coords(0) lon1 = coords(1) @@ -652,7 +710,7 @@ Sub muestraRuta Dim data As Map = CreateMap("ruta" : line) rutasGPS.Put(rRuta, data) ' Log(rutasGPS) - Log("Puntos : "&listtemp.Size) +' Log("Puntos : "&listtemp.Size) ' ToastMessageShow("Recibimos ruta con "&listtemp.Size&" puntos", True) rutaAnt = rRuta ' Ponemos en rutaAnt la ruta actual 'Mueve el mapa a las ultmas coordenadas de la ruta @@ -661,17 +719,17 @@ Sub muestraRuta Else 'Los puntos de la ruta de la base de datos se traen en orden ascendente (los mas viejos primero) Subs.mueveCamaraMapa(MapFragment2, latOut, lonOut) Dim Marker1 As Marker -' Marker1 = gmap.AddMarker(latOut, lonOut, "Fin " & usuario) +' Marker1 = gmap2.AddMarker(latOut, lonOut, "Fin " & usuario) If speedOut > 1 Then - Marker1 = gmap.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-moving.png")) + Marker1 = gmap2.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-moving.png")) Else - Marker1 = gmap.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-sleeping.png")) + Marker1 = gmap2.AddMarker3(latOut, lonOut, "Fin " & usuario, LoadBitmap(File.DirAssets, "waze-sleeping.png")) End If ' Marker1.Title = "Fin " & usuario - Marker1.Snippet = "Fecha: " & fechaFinRutaGPS & ", Vel.: " & NumberFormat2((speedOut * 3.6), 1, 2, 2, True) & " km/h" + Marker1.Snippet = "Fecha: " & fechaFinRutaGPS & CRLF & "Velocidad: " & NumberFormat2((speedOut * 3.6), 1, 2, 2, True) & " km/h" Dim Marker0 As Marker - Marker0 = gmap.AddMarker2(latIn, lonIn, "Inicio " & usuario, gmap.HUE_GREEN) + Marker0 = gmap2.AddMarker2(latIn, lonIn, "Inicio " & usuario, gmap2.HUE_GREEN) ' Marker0.Title = "Inicio " & usuario Marker0.Snippet = $"Fecha: ${fechaInicioRutaGPS}"$ End If diff --git a/Starter.bas b/Starter.bas index 8517406..a7b7f2e 100644 --- a/Starter.bas +++ b/Starter.bas @@ -12,10 +12,12 @@ Version=9.9 Sub Process_Globals Public rp As RuntimePermissions Public FLP As FusedLocationProvider + Dim dentroDeGeocerca As Map End Sub Sub Service_Create CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") + dentroDeGeocerca.Initialize End Sub Sub Service_Start (StartingIntent As Intent) diff --git a/subs.bas b/subs.bas index c09e490..e8780dd 100644 --- a/subs.bas +++ b/subs.bas @@ -153,6 +153,7 @@ Sub notiHigh(title As String, body As String, id As String, activity As Object) activity = Main Private notif As Notification notif.Initialize2(notif.IMPORTANCE_HIGH) + notif.OnGoingEvent = True notif.Icon = "icon" notif.Vibrate = False notif.Sound = False @@ -163,6 +164,11 @@ Sub notiHigh(title As String, body As String, id As String, activity As Object) notif.Notify(id) End Sub +Sub cancelNoti(id) 'ignore + Private notif As Notification 'ignore + notif.Cancel(id) +End Sub + 'Geo-Zone Determination (Point in Polygon) 'Use this to determine If a vehicle is within a defined zone made of 5 or more lat/lon coordinates. 'Point 1 Is also Point 5 (first point And last point are same value).