示例#1
0
        private void limparAlertado(double Latitude, double Longitude, double distanciaRadar)
        {
            /*
             * int radarAtivo = 0;
             * int radarTodo = 0;
             * foreach (KeyValuePair<string, bool> alerta in _radares) {
             *  radarTodo++;
             *  if (alerta.Value)
             *      radarAtivo++;
             * }
             */
            List <string> desativado = new List <string>();

            foreach (KeyValuePair <string, bool> alerta in _radares)
            {
                string str           = alerta.Key.Substring(0, alerta.Key.IndexOf('|'));
                double latitudeRadar = Convert.ToDouble(str);
                str = alerta.Key.Substring(alerta.Key.IndexOf('|') + 1);
                double longitudeRadar = Convert.ToDouble(str);
                double distancia      = Math.Floor(GPSUtils.calcularDistancia(Latitude, Longitude, latitudeRadar, longitudeRadar));
                if (distancia > distanciaRadar && _radares.ContainsKey(alerta.Key))
                {
                    //_radares[alerta.Key] = false;
                    desativado.Add(alerta.Key);
                }
            }
            foreach (string posicao in desativado)
            {
                _radares[posicao] = false;
            }
        }
示例#2
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (intent.Action == Intent.ActionBootCompleted)
     {
         Intent pushIntent = new Intent(context, typeof(GPSAndroid));
         context.StartService(pushIntent);
         InvokeAbortBroadcast();
     }
     else if (intent.Action == PercursoBLL.ACAO_PARAR_SIMULACAO)
     {
         GPSUtils.pararSimulacao();
         MensagemUtils.pararNotificaoPermanente(PercursoBLL.NOTIFICACAO_SIMULACAO_PERCURSO_ID);
         InvokeAbortBroadcast();
     }
     else if (intent.Action == PercursoBLL.ACAO_PARAR_GRAVACAO)
     {
         PercursoBLL regraPercurso = PercursoFactory.create();
         regraPercurso.pararGravacao();
         //MensagemUtils.pararNotificaoPermanente(PercursoBLL.NOTIFICACAO_GRAVAR_PERCURSO_ID);
         InvokeAbortBroadcast();
     }
     else if (intent.Action == "Fechar")
     {
         NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService);
         notificationManager.Cancel(1);
         System.Environment.Exit(0);
         Process.KillProcess(Process.MyPid());
     }
 }
示例#3
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            if (Device.OS == TargetPlatform.iOS)
            {
                GPSUtils.inicializar();
            }
            if (Device.OS == TargetPlatform.Android)
            {
                GPSUtils.verificarFuncionamentoGPS();
            }
        }
示例#4
0
        private void inicializarMenu()
        {
            var excluiPercurso = new MenuItem
            {
                Text = "Excluir"
            };

            excluiPercurso.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            excluiPercurso.Clicked += (sender, e) =>
            {
                PercursoInfo percurso      = (PercursoInfo)((MenuItem)sender).BindingContext;
                PercursoBLL  regraPercurso = PercursoFactory.create();
                regraPercurso.excluir(percurso.Id);

                ListView percursoListView = this.Parent as ListView;

                percursoListView.SetBinding(ListView.ItemsSourceProperty, new Binding("."));

                var percursos = regraPercurso.listar();
                percursoListView.BindingContext = percursos;
                percursoListView.ItemTemplate   = new DataTemplate(typeof(PercursoPageCell));
            };

            var simulaPercurso = new MenuItem
            {
                Text = "Simular"
            };

            simulaPercurso.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            simulaPercurso.Clicked += (sender, e) =>
            {
                PercursoInfo percurso = (PercursoInfo)((MenuItem)sender).BindingContext;
                if (percurso != null)
                {
                    GPSUtils.simularPercurso(percurso.Id);
                }
                OnAppearing();
            };

            ContextActions.Add(simulaPercurso);
            ContextActions.Add(excluiPercurso);
        }
示例#5
0
        private void processarPonto(LocalizacaoInfo local, RadarInfo radar = null)
        {
            var  distancia = GPSUtils.calcularDistancia(local.Latitude, local.Longitude, PercursoUtils.Latitude, PercursoUtils.Longitude);
            bool alterado  = false;

            if (distancia >= DISTANCIA_MINIMA_PROCESSAMENTO)
            {
                var ponto = gerarPonto(local, radar);
                gravarPonto(ponto);
                PercursoUtils.PercursoAtual.Pontos.Add(ponto);

                PercursoUtils.Latitude  = (float)local.Latitude;
                PercursoUtils.Longitude = (float)local.Longitude;
                alterado = true;
            }
            if (PercursoUtils.PaginaAtual != null)
            {
                PercursoUtils.PaginaAtual.atualizarGravacao(local, alterado);
            }
        }
示例#6
0
        public GPSiOS()
        {
            this.locMgr = new CLLocationManager();
            this.locMgr.PausesLocationUpdatesAutomatically = false;

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locMgr.RequestAlwaysAuthorization(); // works in background
                                                     //locMgr.RequestWhenInUseAuthorization (); // only in foreground
            }
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                locMgr.AllowsBackgroundLocationUpdates = true;
            }

            LocationUpdated += (sender, e) => {
                CLLocation      location = e.Location;
                LocalizacaoInfo local    = new LocalizacaoInfo();
                local.Latitude  = location.Coordinate.Latitude;
                local.Longitude = location.Coordinate.Longitude;
                local.Precisao  = (float)((location.HorizontalAccuracy + location.VerticalAccuracy) / 2);
                if (location.Course == -1)
                {
                    local.Sentido = _sentidoAntigo;
                }
                else
                {
                    local.Sentido  = (float)location.Course;
                    _sentidoAntigo = local.Sentido;
                }

                local.Tempo      = NSDateToDateTime(location.Timestamp);
                local.Velocidade = location.Speed * 3.6;

                GPSUtils.atualizarPosicao(local);
            };
        }
示例#7
0
        public PercursoPageCell()
        {
            var excluiPercurso = new MenuItem
            {
                Text = "Excluir"
            };

            excluiPercurso.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            excluiPercurso.Clicked += (sender, e) =>
            {
                PercursoInfo percurso      = (PercursoInfo)((MenuItem)sender).BindingContext;
                PercursoBLL  regraPercurso = PercursoFactory.create();
                regraPercurso.excluir(percurso.Id);

                ListView percursoListView = this.Parent as ListView;

                percursoListView.SetBinding(ListView.ItemsSourceProperty, new Binding("."));

                var percursos = regraPercurso.listar();
                percursoListView.BindingContext = percursos;
                percursoListView.ItemTemplate   = new DataTemplate(typeof(PercursoPageCell));
            };

            var simulaPercurso = new MenuItem
            {
                Text = "Simular"
            };

            simulaPercurso.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
            simulaPercurso.Clicked += (sender, e) =>
            {
                PercursoInfo percurso = (PercursoInfo)((MenuItem)sender).BindingContext;
                if (percurso != null)
                {
                    GPSUtils.simularPercurso(percurso.Id);
                }
                OnAppearing();
            };

            ContextActions.Add(simulaPercurso);
            ContextActions.Add(excluiPercurso);

            desc.HorizontalOptions = LayoutOptions.Fill;
            desc.VerticalOptions   = LayoutOptions.CenterAndExpand;
            desc.Spacing           = 1;

            tempoCorrendo.HorizontalOptions    = LayoutOptions.Start;
            tempoParado.HorizontalOptions      = LayoutOptions.Start;
            paradas.HorizontalOptions          = LayoutOptions.Start;
            paradas.VerticalOptions            = LayoutOptions.Center;
            velocidadeMaxima.HorizontalOptions = LayoutOptions.Start;
            velocidadeMedia.HorizontalOptions  = LayoutOptions.Start;
            radares.HorizontalOptions          = LayoutOptions.Start;

            relogioIco.Source      = ImageSource.FromFile("relogio_20x20_preto.png");
            paradoIco.Source       = ImageSource.FromFile("mao_20x20_preto.png");
            ampulhetaIco.Source    = ImageSource.FromFile("ampulheta_20x20_preto.png");
            velocimetroIco.Source  = ImageSource.FromFile("velocimetro_20x20_preto.png");
            velocimetroIco2.Source = ImageSource.FromFile("velocimetro_20x20_preto.png");
            radarIco.Source        = ImageSource.FromFile("radar_20x20_preto.png");

            tempoCorrendo.SetBinding(Label.TextProperty, new Binding("TempoGravacaoStr", stringFormat: "Tempo: {0}"));
            tempoCorrendo.FontSize = 14;
            tempoParado.SetBinding(Label.TextProperty, new Binding("TempoParadoStr", stringFormat: "Parado: {0}"));
            tempoParado.FontSize = 14;

            paradas.SetBinding(Label.TextProperty, new Binding("QuantidadeParadaStr", stringFormat: "Paradas: {0}"));
            paradas.FontSize = 14;
            velocidadeMedia.SetBinding(Label.TextProperty, new Binding("VelocidadeMediaStr", stringFormat: "V Méd: {0}"));
            velocidadeMedia.FontSize = 14;
            velocidadeMaxima.SetBinding(Label.TextProperty, new Binding("VelocidadeMaximaStr", stringFormat: "V Max: {0}"));
            velocidadeMaxima.FontSize = 14;
            radares.SetBinding(Label.TextProperty, new Binding("QuantidadeRadarStr", stringFormat: "Radares: {0}"));
            radares.FontSize = 14;

            desc.Children.Add(relogioIco);
            desc.Children.Add(tempoCorrendo);
            desc.Children.Add(ampulhetaIco);
            desc.Children.Add(tempoParado);
            desc.Children.Add(paradoIco);
            desc.Children.Add(paradas);
            desc.Children.Add(velocimetroIco);
            desc.Children.Add(velocidadeMedia);
            desc.Children.Add(velocimetroIco2);
            desc.Children.Add(velocidadeMaxima);
            desc.Children.Add(radarIco);
            desc.Children.Add(radares);

            Frame cardLeft = new Frame()
            {
                HorizontalOptions = LayoutOptions.Center,
                Margin            = new Thickness(0, 0, 0, 90),
                WidthRequest      = TelaUtils.LarguraSemPixel * 0.2
            };

            StackLayout cardLeftStack = new StackLayout()
            {
                Orientation       = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill
            };

            Image percursoIco = new Image()
            {
                Source            = ImageSource.FromFile("percursos.png"),
                WidthRequest      = cardLeft.WidthRequest * 0.3,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Start
            };

            BoxView linha = new BoxView()
            {
                HeightRequest     = 1,
                BackgroundColor   = Color.FromHex(TemaInfo.DividerColor),
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Start
            };

            Label distanciaText = new Label()
            {
                FontSize          = 14,
                TextColor         = Color.FromHex(TemaInfo.PrimaryColor),
                FontFamily        = "Roboto-Condensed",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Start
            };

            distanciaText.SetBinding(Label.TextProperty, new Binding("DistanciaTotalStr"));

            cardLeftStack.Children.Add(percursoIco);
            cardLeftStack.Children.Add(distanciaText);
            cardLeft.Content = cardLeftStack;

            Frame cardRigth = new Frame()
            {
                HorizontalOptions = LayoutOptions.Start,
                WidthRequest      = TelaUtils.LarguraSemPixel * 0.7
            };

            if (TelaUtils.Orientacao == "Landscape")
            {
                cardLeft.Margin        = new Thickness(0, 0, 0, 70);
                cardLeft.WidthRequest  = TelaUtils.LarguraSemPixel * 0.15;
                cardRigth.WidthRequest = TelaUtils.LarguraSemPixel * 0.5;
            }
            if (TelaUtils.Orientacao == "LandscapeLeft" || TelaUtils.Orientacao == "LandscapeRight")
            {
                cardLeft.Margin        = new Thickness(0, 0, 0, 70);
                cardLeft.WidthRequest  = TelaUtils.LarguraSemPixel * 0.15;
                cardRigth.WidthRequest = TelaUtils.LarguraSemPixel * 0.5;
            }
            StackLayout cardRigthStackVer = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Spacing     = 1
            };


            Label titulo = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                FontSize          = 26,
                FontFamily        = "Roboto-Condensed",
                TextColor         = Color.FromHex(TemaInfo.PrimaryColor)
            };

            titulo.SetBinding(Label.TextProperty, new Binding("Titulo"));

            Label endereco = new Label()
            {
                //Text = "Rua H-149, 1-73 Cidade Vera Cruz/ Aparecida de Goiânia",
                WidthRequest      = TelaUtils.LarguraSemPixel * 0.7,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                FontSize          = 16,
                FontFamily        = "Roboto-Condensed",
                //HorizontalTextAlignment = TextAlignment.Start
            };

            endereco.SetBinding(Label.TextProperty, new Binding("Endereco"));


            cardRigthStackVer.Children.Add(titulo);
            cardRigthStackVer.Children.Add(linha);
            cardRigthStackVer.Children.Add(endereco);
            cardRigthStackVer.Children.Add(desc);

            cardRigth.Content = cardRigthStackVer;

            View = new StackLayout()
            {
                Margin            = new Thickness(5, 0, 5, 0),
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Fill,
                WidthRequest      = TelaUtils.LarguraSemPixel,
                Children          =
                {
                    cardLeft,
                    cardRigth
                }
            };
        }
示例#8
0
        public void OnLocationChanged(Location location)
        {
            if (desativando)
            {
                return;
            }
            LocalizacaoInfo local = converterLocalizacao(location);

            /*
             * local.Velocidade = 20;
             * local.Latitude = -16.620743;
             * local.Longitude = -49.356621;
             * local.Sentido = 324;
             */
            if (Situacao == GPSSituacaoEnum.Ativo)
            {
                if (Xamarin.Forms.Forms.IsInitialized)
                {
                    local = GPSUtils.atualizarPosicao(local);
                    RadarInfo radar = RadarBLL.RadarAtual;
                    if (radar != null)
                    {
                        //var velocidadeImagem = mRootLayout.FindViewById<ImageView>(Resource.Id.velocidadeImagem);
                        atualizarVelocidadeRadar(radar.Velocidade);
                        var distanciaRadar = mRootLayout.FindViewById <TextView>(Resource.Id.distanciaRadar);
                        int distancia      = Convert.ToInt32(Math.Floor(local.Distancia));
                        //velocidadeImagem.SetImageResource(Resource.Drawable.radar_20);
                        //velocidadeRadar.Text = radar.VelocidadeStr;
                        distanciaRadar.Text = distancia.ToString() + " m";
                        if (mRootLayout.Visibility != ViewStates.Visible)
                        {
                            mRootLayout.Visibility = ViewStates.Visible;
                        }
                    }
                    else
                    {
                        if (mRootLayout.Visibility == ViewStates.Visible)
                        {
                            mRootLayout.Visibility = ViewStates.Invisible;
                        }
                    }
                }
            }
            else if (Situacao == GPSSituacaoEnum.Espera)
            {
                var regraPreferencia = new PreferenciaBLL();
                if (regraPreferencia.pegar("ligarDesligar", "") == "1" && local.Precisao <= 30)
                {
                    if (local.Velocidade >= 15)
                    {
                        Situacao = GPSSituacaoEnum.Ativo;
                        if (!Xamarin.Forms.Forms.IsInitialized)
                        {
                            Intent intent = new Intent(this, typeof(MainActivity));
                            intent.AddFlags(ActivityFlags.NewTask);
                            StartActivity(intent);
                        }
                        else if (MainActivity.Situacao != JanelaSituacaoEnum.Aberta)
                        {
                            Intent intent = new Intent(this, typeof(MainActivity));
                            intent.AddFlags(ActivityFlags.NewTask);
                            StartActivity(intent);
                        }
                    }
                    else
                    {
                        desativarGPS();
                        new Handler().PostDelayed(() => { ativarGPS(); }, 30000);
                    }
                }
            }
        }
示例#9
0
        public IList <PercursoResumoInfo> listarResumo(int idPercuso)
        {
            var regraRadar = RadarFactory.create();

            var percurso = pegar(idPercuso);
            var pontos   = percurso.Pontos.ToList();

            var resumos = new List <PercursoResumoInfo>();

            var inicio  = pontos[0];
            var chegada = pontos[pontos.Count - 1];

            pontos.Remove(inicio);
            pontos.Remove(chegada);

            resumos.Add(new PercursoResumoInfo {
                Icone     = "partida.png",
                Descricao = "Saída",
                Data      = inicio.Data,
                Distancia = 0,
                Latitude  = (float)inicio.Latitude,
                Longitude = (float)inicio.Longitude,
                Tempo     = TimeSpan.Zero
            });

            var      idRadarOld         = inicio.IdRadar;
            var      dataOld            = inicio.Data;
            var      latitudeOld        = (float)inicio.Latitude;
            var      longitudeOld       = (float)inicio.Longitude;
            double   distanciaAcumulada = 0;
            TimeSpan tempoAcumulado     = TimeSpan.Zero;

            double   distancia = 0;
            TimeSpan tempo     = TimeSpan.Zero;

            foreach (var ponto in percurso.Pontos)
            {
                distancia = GPSUtils.calcularDistancia(latitudeOld, longitudeOld, ponto.Latitude, ponto.Longitude);
                tempo     = ponto.Data.Subtract(dataOld);
                if (distancia > DISTANCIA_MINIMA_RESUMO)
                {
                    distanciaAcumulada += distancia;
                    tempoAcumulado      = tempoAcumulado.Add(tempo);
                    if (tempo.TotalSeconds > TEMPO_MINIMO_PARADO)
                    {
                        resumos.Add(new PercursoParadoInfo
                        {
                            Icone     = "para.png",
                            Descricao = "Parada",
                            Data      = ponto.Data,
                            Tempo     = tempoAcumulado,
                            Distancia = distanciaAcumulada,
                            Latitude  = (float)ponto.Latitude,
                            Longitude = (float)ponto.Longitude,
                        });
                        distanciaAcumulada = 0;
                        tempoAcumulado     = TimeSpan.Zero;
                    }
                    if (idRadarOld != ponto.IdRadar && ponto.IdRadar > 0)
                    {
                        var ultimoPonto = (
                            from p in percurso.Pontos
                            where p.IdRadar == ponto.IdRadar
                            orderby p.Data descending
                            select p
                            ).FirstOrDefault <PercursoPontoInfo>();
                        var radar = regraRadar.pegar(ponto.IdRadar);
                        if (radar != null)
                        {
                            distancia           = GPSUtils.calcularDistancia(latitudeOld, longitudeOld, ultimoPonto.Latitude, ultimoPonto.Longitude);
                            distanciaAcumulada += distancia;
                            resumos.Add(new PercursoRadarInfo
                            {
                                Icone           = radar.Imagem,
                                Descricao       = radar.Titulo,
                                Data            = ultimoPonto.Data,
                                Distancia       = distanciaAcumulada,
                                Latitude        = (float)ultimoPonto.Latitude,
                                Longitude       = (float)ultimoPonto.Longitude,
                                Tempo           = tempoAcumulado,
                                MinhaVelocidade = ultimoPonto.Velocidade,
                                Velocidade      = radar.Velocidade,
                                Tipo            = radar.Tipo
                            });
                        }
                        idRadarOld         = ponto.IdRadar;
                        distanciaAcumulada = 0;
                        tempoAcumulado     = TimeSpan.Zero;
                    }

                    dataOld      = ponto.Data;
                    latitudeOld  = (float)ponto.Latitude;
                    longitudeOld = (float)ponto.Longitude;
                }
            }

            distancia           = GPSUtils.calcularDistancia(latitudeOld, longitudeOld, chegada.Latitude, chegada.Longitude);
            tempo               = chegada.Data.Subtract(dataOld);
            distanciaAcumulada += distancia;
            tempoAcumulado      = tempoAcumulado.Add(tempo);
            resumos.Add(new PercursoResumoInfo
            {
                Icone     = "chegada.png",
                Descricao = "Chegada",
                Data      = chegada.Data,
                Tempo     = tempoAcumulado,
                Distancia = distanciaAcumulada,
                Latitude  = (float)chegada.Latitude,
                Longitude = (float)chegada.Longitude,
            });

            var regraGasto = GastoFactory.create();
            var gastos     = regraGasto.listar(idPercuso);

            foreach (var gasto in gastos)
            {
                resumos.Add(new PercursoGastoInfo
                {
                    Icone      = "ic_monetization_on_black_24dp.png",
                    Descricao  = gasto.Observacao,
                    Data       = gasto.DataInclusao,
                    Tempo      = TimeSpan.Zero,
                    Distancia  = 0,
                    Latitude   = (float)gasto.Latitude,
                    Longitude  = (float)gasto.Longitude,
                    FotoBase64 = gasto.FotoBase64
                });
            }

            var retorno = (
                from r in resumos
                orderby r.Data
                select r
                ).ToList();

            return(retorno);
        }