com.automaster.autoview.client.Info.java Source code

Java tutorial

Introduction

Here is the source code for com.automaster.autoview.client.Info.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.automaster.autoview.client;

import com.automaster.autoview.client.servicos.DbService;
import com.automaster.autoview.client.servicos.DbServiceAsync;
import com.automaster.autoview.client.ui.paineis.PainelPrincipal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.TreeMap;

/**
 *
 * @author Adriano
 */
public abstract class Info {

    public static boolean teste = true;
    /**************************/
    public static Timer avisoAguarde;
    public static HLayout janelaCarregando;
    public static VLayout janela;
    public static ArrayList<HLayout> arrayHlayout = new ArrayList();
    public static Label mensagem;
    public static ArrayList<Timer> arrayTimer = new ArrayList();
    /***************************/
    public static Timer atualizaLogUsuario;
    public static Timer relogio;
    public static Timer atualizaVeiculosTodos;
    public static Timer atualizaVeiculosNovasPosicoes;
    //public static Timer atualizaGridPosicoesInicio;
    public static TreeMap<String, String> enderecosResolvidos;
    public static Timer atualizaPosicoesSemEndereco;
    public static Timer atualizaPosicoesSemEnderecoHistorico;

    public static ListGridRecord[] listaSeleciona;
    public static int codEstadoUnidade = 0;
    public static int codCidadeUnidade = 0;
    public static PainelPrincipal painelPrincipal = new PainelPrincipal();
    public static DbServiceAsync dbService = GWT.create(DbService.class);
    //TreeMap que ir armazenar o valor do Usurio Logado    
    public static TreeMap<String, String> usuarioLogado = new TreeMap<>();
    // TreeMap para armazenar os valores dos ttulos
    public static TreeMap<String, String> titulosMsg = new TreeMap<>();

    public static native void enderecoGoogleInicio(String latLon, String lat, String lon, String placa,
            Record record)/*-{
                              
                          $wnd.console.log('linha 01 INICIO');
                          //$wnd.header('Access-Control-Allow-Origin: *');
                          $wnd.console.log('linha 02 INICIO');
                          var xmlhttp = new XMLHttpRequest();
                              
                          var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+latLon+"&language=pt-BR&sensor=true";
                          function call(callback) {
                              
                          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                          $wnd.console.log('linha 05');
                          try {
                          var myArr = JSON.parse(xmlhttp.responseText);
                          $wnd.console.log('linha 06'+myArr.results[0].formatted_address);
                          callback(myArr.results[0].formatted_address);
                          } catch(err) {
                          $wnd.console.log('ERRO GOOGLE:'+err);
                          }
                          //myFunction(myArr);
                          //$wnd.console.log('linha 07');
                          } else {
                          callback(null);
                          }
                          };
                          function tratar_resposta(resposta) {
                          //$wnd.console.log("Placa: "+resposta);            
                          @com.automaster.autoview.client.ui.paineis.tabs.monitoramento.TabInicio::enderecoGoogle(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/smartgwt/client/data/Record;)(resposta, lat, lon, placa, record);            
                          }            
                          xmlhttp.onreadystatechange = $wnd.setTimeout(function() {  call(tratar_resposta); }, 1000);
                          if ("withCredentials" in xmlhttp) {
                          // XHR for Chrome/Firefox/Opera/Safari.  
                          $wnd.console.log('linha 01 INICIO');
                          xmlhttp.open("GET", url, true);
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
                          $wnd.console.log('linha 02 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
                          $wnd.console.log('linha 03 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
                              
                          } else if (typeof XDomainRequest != "undefined") {
                          // XDomainRequest for IE.
                          $wnd.console.log('linha 02 INICIO');
                          xmlhttp = new XDomainRequest();
                          xmlhttp.open("GET", url);
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
                          $wnd.console.log('linha 02 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
                          $wnd.console.log('linha 03 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
                          }
                              
                          //xmlhttp.open("GET", url, true);
                          xmlhttp.send();
                              
                          }-*/;

    public static native void enderecoGoogleHistorico(String latLon, String lat, String lon, String placa,
            Record record)/*-{
                              
                          $wnd.console.log('linha 01 HISTORICO');
                          //$wnd.header('Access-Control-Allow-Origin: *');
                          $wnd.console.log('linha 02 HISTORICO');
                          var xmlhttp = new XMLHttpRequest();
                              
                          $wnd.console.log('linha 04 HISTORICO');            
                          var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng="+latLon+"&language=pt-BR&sensor=true";
                          //$wnd.console.log('linha 03 HISTORICO');
                          function call(callback) {
                              
                          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                          //$wnd.console.log('linha 05 HISTORICO');
                          try {
                          var myArr = JSON.parse(xmlhttp.responseText);
                          //$wnd.console.log('linha 06'+myArr.results[0].formatted_address);                        
                          callback(myArr.results[0].formatted_address);
                          } catch(err) {
                          $wnd.console.log('ERRO GOOGLE:'+err);
                          }
                          //myFunction(myArr);
                          //$wnd.console.log('linha 07 HISTORICO');
                          } else {
                          callback(null);
                          }
                          };
                          function tratar_resposta(resposta) {
                          //$wnd.console.log("Placa: "+resposta);
                              
                          @com.automaster.autoview.client.ui.paineis.tabs.monitoramento.TabHistorico::enderecoGoogle(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/smartgwt/client/data/Record;)(resposta, lat, lon, placa, record);
                              
                          }            
                          xmlhttp.onreadystatechange = $wnd.setTimeout(function() {  call(tratar_resposta); }, 1000);
                          if ("withCredentials" in xmlhttp) {
                          // XHR for Chrome/Firefox/Opera/Safari.
                          xmlhttp.open("GET", url, true);
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
                          $wnd.console.log('linha 02 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
                          $wnd.console.log('linha 03 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
                          } else if (typeof XDomainRequest != "undefined") {
                          // XDomainRequest for IE.
                          xmlhttp = new XDomainRequest();
                          xmlhttp.open("GET", url);
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
                          $wnd.console.log('linha 02 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE, OPTIONS');
                          $wnd.console.log('linha 03 HISTORICO');
                          //xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
                          }
                          //xmlhttp.open("GET", url, true);
                          xmlhttp.send();
                              
                          }-*/;

    public static void abrirJanelaCarregando() {

        Info.janelaCarregando = new HLayout();
        Info.janelaCarregando.setWidth100();
        Info.janelaCarregando.setHeight100();
        Info.janelaCarregando.setShowEdges(false);
        Info.janelaCarregando.setLayoutAlign(Alignment.CENTER);
        Info.janelaCarregando.setAlign(Alignment.CENTER);
        arrayHlayout.add(janelaCarregando);

        Info.janela = new VLayout();
        Info.janela.setBackgroundColor("#1BAEAE");
        Info.janela.setWidth(200);
        Info.janela.setHeight(45);
        Info.janela.setShowEdges(false);

        Info.janela.setLayoutAlign(Alignment.CENTER);
        Info.janelaCarregando.addMember(janela);
        //        if (Info.startTread) {
        //            Info.startTread = false;
        Info.avisoAguarde = new Timer() {

            @Override
            public void run() {
                Info.mensagem = new Label(
                        "<center style=\"font-family: Roboto; font-size: 32px; color: #fff;\">Aguarde...</center>");
                Info.mensagem.setLayoutAlign(Alignment.CENTER);
                Info.mensagem.setHeight(35);
                Info.janela.setMembers(Info.mensagem);
                Info.janelaCarregando.setAnimateTime(800);
                Info.janelaCarregando.animateShow(AnimationEffect.FADE);
            }
        };
        Info.avisoAguarde.scheduleRepeating(1000);
        //        } 
        GWT.log("CRIANDO A TIMER!");
        arrayTimer.add(avisoAguarde);
    }

    public static void fecharJanelaCarrgando() {

        Info.janelaCarregando.setAnimateTime(800);
        Info.janelaCarregando.animateHide(AnimationEffect.FADE);
        for (Timer t : arrayTimer) {
            t.cancel();
            GWT.log("CANCELANDO A TIMER!");
        }
        arrayTimer.clear();
        for (HLayout hl : arrayHlayout) {
            hl.destroy();
            GWT.log("CANCELANDO A HLAYOUT!");
        }
        arrayHlayout.clear();
        //        Info.startTread = true;

    }

    /*public static void carregado () {
    String cssMapa = "#" + Info.mapa.getHTMLMapa().getElement().getParentElement().getParentElement().getId() + " {width:100%;height:100%;}";
    GWT.log("CSSMapa"+cssMapa);
    StyleInjector.injectAtEnd(cssMapa);
    }*/
    public static native void telaCheia(String idElement)/*-{
                                                         $wnd.console.log("FullScreen 1");
                                                         if($doc.getElementById(idElement).requestFullscreen) {
                                                         $doc.getElementById(idElement).requestFullscreen();
                                                         } else if($doc.getElementById(idElement).mozRequestFullScreen) {
                                                         $doc.getElementById(idElement).mozRequestFullScreen();
                                                         } else if($doc.getElementById(idElement).webkitRequestFullscreen) {
                                                         $doc.getElementById(idElement).webkitRequestFullscreen();
                                                         } else if($doc.getElementById(idElement).msRequestFullscreen) {
                                                         $doc.getElementById(idElement).msRequestFullscreen();
                                                         }
                                                         $wnd.console.log("FullScreen 2");
                                                         }-*/;

    public static native String timeZoneClient()/*-{
                                                    
                                                var offset = new Date().getTimezoneOffset();
                                                return offset;
                                                    
                                                }-*/;

    public native void fecharDiv() /*-{
                                   $doc.getElementById('origin-input').style.display='none';
                                   }-*/;

    public static native boolean validaCPF(String strCPF) /*-{
                                                              
                                                          var Soma; 
                                                          var Resto; 
                                                          Soma = 0; 
                                                          if (strCPF == "00000000000" ||
                                                          strCPF == "11111111111" || 
                                                          strCPF == "22222222222" || 
                                                          strCPF == "33333333333" || 
                                                          strCPF == "44444444444" || 
                                                          strCPF == "55555555555" || 
                                                          strCPF == "66666666666" || 
                                                          strCPF == "77777777777" || 
                                                          strCPF == "88888888888" || 
                                                          strCPF == "99999999999") 
                                                          return false; 
                                                          for (i=1; i<=9; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (11 - i); 
                                                          Resto = (Soma * 10) % 11; if ((Resto == 10) || (Resto == 11)) Resto = 0; 
                                                          if (Resto != parseInt(strCPF.substring(9, 10)) ) return false; 
                                                          Soma = 0; 
                                                          for (i = 1; i <= 10; i++) Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (12 - i); 
                                                          Resto = (Soma * 10) % 11; 
                                                          if ((Resto == 10) || (Resto == 11)) Resto = 0; 
                                                          if (Resto != parseInt(strCPF.substring(10, 11) ) ) return false; 
                                                          return true; 
                                                              
                                                          }-*/;

    public static native boolean validaCNPJ(String cnpj) /*-{
                                                         cnpj = cnpj.replace(/[^\d]+/g,'');
                                                             
                                                         if(cnpj == '') return false;
                                                             
                                                         if (cnpj.length != 14)
                                                         return false; 
                                                         // Elimina CNPJs invalidos conhecidos
                                                         if (cnpj == "00000000000000" || 
                                                         cnpj == "11111111111111" || 
                                                         cnpj == "22222222222222" || 
                                                         cnpj == "33333333333333" || 
                                                         cnpj == "44444444444444" || 
                                                         cnpj == "55555555555555" || 
                                                         cnpj == "66666666666666" || 
                                                         cnpj == "77777777777777" || 
                                                         cnpj == "88888888888888" || 
                                                         cnpj == "99999999999999")
                                                         return false;
                                                             
                                                         // Valida DVs
                                                         tamanho = cnpj.length - 2
                                                         numeros = cnpj.substring(0,tamanho);
                                                         digitos = cnpj.substring(tamanho);
                                                         soma = 0;
                                                         pos = tamanho - 7;
                                                         for (i = tamanho; i >= 1; i--) {
                                                         soma += numeros.charAt(tamanho - i) * pos--;
                                                         if (pos < 2)
                                                         pos = 9;
                                                         }
                                                         resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                                                         if (resultado != digitos.charAt(0))
                                                         return false;
                                                             
                                                         tamanho = tamanho + 1;
                                                         numeros = cnpj.substring(0,tamanho);
                                                         soma = 0;
                                                         pos = tamanho - 7;
                                                         for (i = tamanho; i >= 1; i--) {
                                                         soma += numeros.charAt(tamanho - i) * pos--;
                                                         if (pos < 2)
                                                         pos = 9;
                                                         }
                                                         resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                                                         if (resultado != digitos.charAt(1))
                                                         return false;
                                                             
                                                         return true;
                                                             
                                                         }-*/;

    public static native String FormataMoeda(String campo, String separador_milhar, String separador_decimal,
            String tecla) /*-{
                          var sep = 0;
                          var key = '';
                          var i = j = 0;
                          var len = len2 = 0;
                          var strCheck = '0123456789';
                          var aux = aux2 = '';
                          //var whichCode = (window.Event) ? tecla.which : tecla.keyCode;
                              
                          //if (whichCode == 13) return true; // Tecla Enter
                          //if (whichCode == 8) return true; // Tecla Delete
                          key = tecla; // Pegando o valor digitado
                          if (strCheck.indexOf(key) == -1) return false; // Valor invlido (no inteiro)
                          len = campo.length;
                          for(i = 0; i < len; i++)
                          if ((campo.charAt(i) != '0') && (campo.charAt(i) != separador_decimal)) break;
                          aux = '';
                          for(; i < len; i++)
                          if (strCheck.indexOf(campo.charAt(i))!=-1) aux += campo.charAt(i);
                          aux += key;
                          len = aux.length;
                          if (len == 0) campo = '';
                          if (len == 1) campo = '0'+ separador_decimal + '0' + aux;
                          if (len == 2) campo = '0'+ separador_decimal + aux;
                              
                          if (len > 2) {
                          aux2 = '';
                              
                          for (j = 0, i = len - 3; i >= 0; i--) {
                          if (j == 3) {
                          aux2 += separador_milhar;
                          j = 0;
                          }
                          aux2 += aux.charAt(i);
                          j++;
                          }
                              
                          campo = '';
                          len2 = aux2.length;
                          for (i = len2 - 1; i >= 0; i--)
                          campo += aux2.charAt(i);
                          campo += separador_decimal + aux.substr(len - 2, len);
                          }
                              
                          return campo;   
                          }-*/;

    public static native int larguraTela()/*-{             
                                              
                                          //pega a largura da resoluo da tela
                                          var width = screen.width;
                                          //pega a altura da resoluo da tela
                                          //var height = screen.height;
                                          return parseInt(width);
                                              
                                          }-*/;

    public static native boolean identificaNavegador()/*-{
                                                      //$wnd.console.log('$wnd.$.browser: '+$wnd.navigator.appName);
                                                      var ie9 = 'Microsoft Internet Explorer';
                                                      var edge = 'Netscape';
                                                      var versao9 = ie9.localeCompare($wnd.navigator.appName);
                                                      var versaoEdge = edge.localeCompare($wnd.navigator.appName);
                                                      //$wnd.console.log('versaoEdge: '+versaoEdge);
                                                      if (versao9 == 0){
                                                      $wnd.console.log('versao9: '+versao9);
                                                      //$wnd.console.log('versaoEdge: '+versaoEdge);
                                                      return true;
                                                      }
                                                      return false;
                                                      }-*/;

    public static native int alturaTela()/*-{             
                                             
                                         //pega a largura da resoluo da tela
                                         //var width = screen.width;
                                         //pega a altura da resoluo da tela
                                         var height = screen.height;
                                         return parseInt(height);
                                             
                                         }-*/;

    public static String formataUsuarioNovo(String nomeCl) {
        String nome = nomeCl.trim();
        if (nome.contains(" ")) {
            String nomeCliente = nome.toLowerCase().substring(0, nome.indexOf(" ")) + "."
                    + nome.toLowerCase().substring(nome.lastIndexOf(" ") + 1, nome.length());
            String usuarioFormatado = nomeCliente.replaceAll("", "a").replaceAll("", "a").replaceAll("", "a")
                    .replaceAll("", "a").replaceAll("", "e").replaceAll("", "e").replaceAll("", "e")
                    .replaceAll("", "i").replaceAll("", "i").replaceAll("", "o").replaceAll("", "o")
                    .replaceAll("", "c").replaceAll("", "o").replaceAll("", "o").replaceAll("", "c")
                    .replaceAll("", "u").replaceAll("", "u");
            return usuarioFormatado;
        }
        return (nome.replaceAll("", "a").replaceAll("", "a").replaceAll("", "a").replaceAll("", "e")
                .replaceAll("", "e").replaceAll("", "i").replaceAll("", "o").replaceAll("", "o")
                .replaceAll("", "c").replaceAll("", "o").replaceAll("", "u").replaceAll("", "u"))
                        .toLowerCase();
    }

    public static double formataDecimal(double valor) {

        BigDecimal decimalFormatado = new BigDecimal(valor).setScale(2, RoundingMode.HALF_EVEN);
        return decimalFormatado.doubleValue();
    }

    public static double formataLatLng(String valor) {
        int indexLat = valor.indexOf(".");
        //GWT.log("LINHA 04");
        int tamanhoLat = valor.length();
        //GWT.log("LINHA 03");
        int decimaisLat = tamanhoLat - (indexLat + 1);
        //GWT.log("LINHA 02");
        String decimalFormatada = valor.substring(0, (decimaisLat < 5) ? indexLat + decimaisLat : indexLat + 5);
        //GWT.log("LINHA 01");
        return Double.parseDouble(decimalFormatada);
    }

    public static double caculaDistanciaEntreDoisPontos(double lat1, double lon1, double lat2, double lon2) {

        //Transforma cordenadas em radianos
        /*String lat1Reduzida = String.valueOf(lat1);
        int index = lat1Reduzida.indexOf(".");
        String latFinal1 = lat1Reduzida.substring(0, index+5);
            
        String lon1Reduzida = String.valueOf(lon1);
        String lonFinal1 = lon1Reduzida.substring(0, index+5);
            
        String lat2Reduzida = String.valueOf(lat2);
        String latFinal2 = lat2Reduzida.substring(0, index+5);
            
        String lon2Reduzida = String.valueOf(lon2);
        String lonFinal2 = lon2Reduzida.substring(0, index+5);*/

        double lat01 = Math.toRadians(lat1);
        double lon01 = Math.toRadians(lon1);
        double lat02 = Math.toRadians(lat2);
        double lon02 = Math.toRadians(lon2);
        //calcula a distncia em KM atravs da frmula
        double dist = (6371 * Math.acos(
                Math.cos(lat01) * Math.cos(lat02) * Math.cos(lon02 - lon01) + Math.sin(lat01) * Math.sin(lat02)));
        //formata o resultado
        if (dist > 0) {
            BigDecimal decimalFormatado = new BigDecimal(dist).setScale(2, RoundingMode.HALF_EVEN);
            return decimalFormatado.doubleValue();
        }
        return 0;
        //retorna a distncia

        //return dist;

    }

    public static String formataReaisFloat(String valor) {
        String valorString = valor;
        int indexPonto = valorString.indexOf(",");
        if (indexPonto == -1) {
            return valorString + ".00";
        } else {
            String restante = valorString.substring(indexPonto + 1, valorString.length());
            if (restante.length() == 1) {
                return valorString.replace(",", ".") + "0";
            } else if (restante.length() > 2) {
                return valorString.replace(",", ".").substring(0, indexPonto + 3);
            } else {
                return valorString.replace(",", ".");
            }
        }

    }

    public static String formataFloat(String valor) {
        String valorString = valor;
        int indexPonto = valorString.indexOf(".");
        if (indexPonto == -1) {
            if (valorString.length() == 1) {
                return "0" + valorString + ".00";
            } else {
                return valorString + ".00";
            }
        } else {
            String restante = valorString.substring(indexPonto + 1, valorString.length());
            if (restante.length() == 1) {
                return valorString + "0";
            } else if (restante.length() > 2) {
                return valorString.substring(0, indexPonto + 3);
            } else {
                return valorString;
            }
        }

    }

    public static String formataValor(float valor) {
        String valorString = String.valueOf(valor);
        int indexPonto = valorString.indexOf(".");
        if (indexPonto == -1) {
            return valorString + ",00";
        } else {
            String restante = valorString.substring(indexPonto + 1, valorString.length());
            if (restante.length() == 1) {
                return valorString.replace(".", ",") + "0";
            } else if (restante.length() > 2) {
                return valorString.replace(".", ",").substring(0, indexPonto + 3);
            } else {
                return valorString.replace(".", ",");
            }
        }

    }

    public static String formataSaldo(double valor) {
        String valorString = String.valueOf(valor);
        int indexPonto = valorString.indexOf(".");
        if (indexPonto == -1) {
            if (Double.parseDouble(valorString) > 1000 && Double.parseDouble(valorString) < 9999) {
                String temp = valorString.substring(0, 1) + "." + valorString.substring(1, valorString.length())
                        + ",00";
                valorString = temp;
                return valorString;
            } else if (Double.parseDouble(valorString) > 9999) {
                String temp = valorString.substring(0, 2) + "." + valorString.substring(2, valorString.length())
                        + ",00";
                valorString = temp;
                return valorString;
            }
            return valorString + ",00";
        } else {
            String restante = valorString.substring(indexPonto + 1, valorString.length());
            if (restante.length() == 1) {
                //                if (Double.parseDouble(valorString) >= 1000) {
                //                    String temp = valorString.substring(0, 1) + "." + valorString.substring(1, valorString.length()).replace(".", ",") + "0";
                //                    valorString = temp;
                //                    return valorString;
                //                }
                if (Double.parseDouble(valorString) >= 1000 && Double.parseDouble(valorString) <= 9999) {
                    String temp = valorString.substring(0, 1) + "."
                            + valorString.substring(1, valorString.length()).replace(".", ",") + "0";
                    valorString = temp;
                    return valorString;
                } else if (Double.parseDouble(valorString) > 9999) {
                    String temp = valorString.substring(0, 2) + "."
                            + valorString.substring(2, valorString.length()).replace(".", ",") + "0";
                    valorString = temp;
                    return valorString;
                }
                return valorString.replace(".", ",") + "0";
            } else if (restante.length() > 2) {
                //                if (Double.parseDouble(valorString) >= 1000) {
                //                    String temp = valorString.substring(0, 1) + "." + valorString.substring(1, indexPonto + 3).replace(".", ",");
                //                    valorString = temp;
                //                    return valorString;
                //                }
                if (Double.parseDouble(valorString) >= 1000 && Double.parseDouble(valorString) <= 9999) {
                    String temp = valorString.substring(0, 1) + "."
                            + valorString.substring(1, indexPonto + 3).replace(".", ",");
                    valorString = temp;
                    return valorString;
                } else if (Double.parseDouble(valorString) > 9999) {
                    String temp = valorString.substring(0, 2) + "."
                            + valorString.substring(2, indexPonto + 3).replace(".", ",");
                    valorString = temp;
                    return valorString;
                }
                return valorString.replace(".", ",").substring(0, indexPonto + 3);
            } else {
                //                if (Double.parseDouble(valorString) >= 1000) {
                //                    String temp = valorString.substring(0, 1) + "." + valorString.substring(1, valorString.length()).replace(".", ",");
                //                    valorString = temp;
                //                    return valorString;
                //                }
                if (Double.parseDouble(valorString) >= 1000 && Double.parseDouble(valorString) <= 9999) {
                    String temp = valorString.substring(0, 1) + "."
                            + valorString.substring(1, valorString.length()).replace(".", ",");
                    valorString = temp;
                    return valorString;
                } else if (Double.parseDouble(valorString) > 9999) {
                    String temp = valorString.substring(0, 2) + "."
                            + valorString.substring(2, valorString.length()).replace(".", ",");
                    valorString = temp;
                    return valorString;
                }
                return valorString.replace(".", ",");
            }
        }

    }

    public static String formataCPF(String cpf) {
        String cpfFormatado = cpf.substring(0, 3) + "." + cpf.substring(3, 6) + "." + cpf.substring(6, 9) + "-"
                + cpf.substring(9, 11);
        return cpfFormatado;
    }

    public static String formataCNPJ(String cnpj) {
        String cnpjFormatado = cnpj.substring(0, 2) + "." + cnpj.substring(2, 5) + "." + cnpj.substring(5, 8) + "/"
                + cnpj.substring(8, 12) + "-" + cnpj.substring(12, 14);
        return cnpjFormatado;
    }

    public static String formataTelefone(String telefone) {
        String cnpjFormatado = "(" + telefone.substring(0, 2) + ")" + telefone.substring(2, 7) + "-"
                + telefone.substring(7, 11);
        return cnpjFormatado;
    }

    public static String formataCEP(String cep) {
        String cepFormatado = cep.substring(0, 5) + "-" + cep.substring(5, cep.length());
        return cepFormatado;
    }

    public static native boolean validaConexao() /*-{
                                                     
                                                 if (navigator.onLine) {
                                                 // est online
                                                 return true;
                                                 } else {
                                                 // est offline
                                                 return false;
                                                 }
                                                 //            var google = "https://www.google.com/images/errors/logo_sm.gif"; 
                                                 //
                                                 //            var ImageObject = new Image();
                                                 //            ImageObject.src = google;
                                                 //
                                                 //            if( ImageObject.height>0 ) {
                                                 //                return true;
                                                 //            } else {
                                                 //            return false;
                                                 //            }
                                                     
                                                     
                                                     
                                                 }-*/;

    public static void registrarLog(int codUsuario, int codOperacao, Timestamp dataEhorAtual, String parametro) {
        TreeMap<String, String> logDoSis = new TreeMap<String, String>();
        logDoSis.put("codOperacao", String.valueOf(codOperacao));
        logDoSis.put("codUsuario", String.valueOf(codUsuario));
        logDoSis.put("parametro", parametro);

        Info.dbService.cadastrarLogDoSis(logDoSis, dataEhorAtual, new AsyncCallback<Boolean>() {

            @Override
            public void onFailure(Throwable caught) {
                throw new UnsupportedOperationException("Not supported yet. Erro ao cadastrar logDoSistema"); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void onSuccess(Boolean result) {
                /*if(result) {
                GWT.log("Log registrado");
                } else {
                GWT.log("ERRO no log");
                }*/

            }
        });
    }

    public static String calculaDatas(long dataFinal, long dataInicial) {

        String tempoDecorrido = "";
        try {
            //GWT.log("datas : "+ dataFinal+ " "+dataInicial);
            //int diferenca = (int) ((int) dataFinal - dataInicial);
            //int diferenca = Integer.parseInt(String.valueOf(dataFinal - dataInicial));
            long diferenca = dataFinal - dataInicial;
            //GWT.log("diferenca : "+ diferenca);
            //int dia = 24*60*60*1000;
            long dia = 0;
            long hora = 0;
            long minuto = 0;
            long segundo = 0;
            //GWT.log("diferenca : "+ diferenca);
            // um dia equivale a 86400000 ms
            // uma hora equivale a 3600000 ms;
            // um minuto equivale a 60000 ms;
            // um minuto equivale a 1000 ms;
            if (diferenca > 0) {
                while (diferenca > 0) {
                    if (diferenca >= 86400000) {
                        //System.out.println("LINHA 01 calculaDatas");
                        dia = diferenca / 86400000;
                        tempoDecorrido = tempoDecorrido + " " + dia + " dia(s), ";
                        diferenca = diferenca % 86400000;
                    } else if (diferenca < 86400000 && diferenca >= 3600000) {
                        //System.out.println("LINHA 02 calculaDatas");
                        hora = diferenca / 3600000;
                        tempoDecorrido = tempoDecorrido + "" + hora + " hora(s), ";
                        diferenca = diferenca % 3600000;

                    } else if (diferenca < 3600000 && diferenca >= 60000) {
                        //System.out.println("LINHA 03 calculaDatas");
                        minuto = diferenca / 60000;
                        tempoDecorrido = tempoDecorrido + "" + minuto + " minuto(s), ";
                        diferenca = diferenca % 60000;

                    } else if (diferenca < 60000) {
                        //System.out.println("LINHA 04 calculaDatas");
                        segundo = diferenca / 1000;
                        tempoDecorrido = tempoDecorrido + "" + segundo + " segundo(s).";
                        diferenca = diferenca % 1000;

                    }
                }
            } else {
                tempoDecorrido = " 0.";
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return tempoDecorrido;
    }

}