package reparto_intmex.keymon.lat;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.objects.ServiceHelper;
import anywheresoftware.b4a.debug.*;

public class tracker extends android.app.Service{
	public static class tracker_BR extends android.content.BroadcastReceiver {

		@Override
		public void onReceive(android.content.Context context, android.content.Intent intent) {
            BA.LogInfo("** Receiver (tracker) OnReceive **");
			android.content.Intent in = new android.content.Intent(context, tracker.class);
			if (intent != null)
				in.putExtra("b4a_internal_intent", intent);
            ServiceHelper.StarterHelper.startServiceFromReceiver (context, in, false, BA.class);
		}

	}
    static tracker mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return tracker.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new BA(this, null, null, "reparto_intmex.keymon.lat", "reparto_intmex.keymon.lat.tracker");
            if (BA.isShellModeRuntimeCheck(processBA)) {
                processBA.raiseEvent2(null, true, "SHELL", false);
		    }
            try {
                Class.forName(BA.applicationContext.getPackageName() + ".main").getMethod("initializeProcessGlobals").invoke(null, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            processBA.loadHtSubs(this.getClass());
            ServiceHelper.init();
        }
        _service = new ServiceHelper(this);
        processBA.service = this;
        
        if (BA.isShellModeRuntimeCheck(processBA)) {
			processBA.raiseEvent2(null, true, "CREATE", true, "reparto_intmex.keymon.lat.tracker", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!false && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (tracker) Create ***");
            processBA.raiseEvent(null, "service_create");
        }
        processBA.runHook("oncreate", this, null);
        if (false) {
			if (ServiceHelper.StarterHelper.runWaitForLayouts() == false) {
                BA.LogInfo("stopping spontaneous created service");
                stopSelf();
            }
		}
    }
		@Override
	public void onStart(android.content.Intent intent, int startId) {
		onStartCommand(intent, 0, 0);
    }
    @Override
    public int onStartCommand(final android.content.Intent intent, int flags, int startId) {
    	if (ServiceHelper.StarterHelper.onStartCommand(processBA, new Runnable() {
            public void run() {
                handleStart(intent);
            }}))
			;
		else {
			ServiceHelper.StarterHelper.addWaitForLayout (new Runnable() {
				public void run() {
                    processBA.setActivityPaused(false);
                    BA.LogInfo("** Service (tracker) Create **");
                    processBA.raiseEvent(null, "service_create");
					handleStart(intent);
                    ServiceHelper.StarterHelper.removeWaitForLayout();
				}
			});
		}
        processBA.runHook("onstartcommand", this, new Object[] {intent, flags, startId});
		return android.app.Service.START_NOT_STICKY;
    }
    public void onTaskRemoved(android.content.Intent rootIntent) {
        super.onTaskRemoved(rootIntent);
        if (false)
            processBA.raiseEvent(null, "service_taskremoved");
            
    }
    private void handleStart(android.content.Intent intent) {
    	BA.LogInfo("** Service (tracker) Start **");
    	java.lang.reflect.Method startEvent = processBA.htSubs.get("service_start");
    	if (startEvent != null) {
    		if (startEvent.getParameterTypes().length > 0) {
    			anywheresoftware.b4a.objects.IntentWrapper iw = ServiceHelper.StarterHelper.handleStartIntent(intent, _service, processBA);
    			processBA.raiseEvent(null, "service_start", iw);
    		}
    		else {
    			processBA.raiseEvent(null, "service_start");
    		}
    	}
    }
	
	@Override
	public void onDestroy() {
        super.onDestroy();
        if (false) {
            BA.LogInfo("** Service (tracker) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (tracker) Destroy **");
		    processBA.raiseEvent(null, "service_destroy");
            processBA.service = null;
		    mostCurrent = null;
		    processBA.setActivityPaused(true);
            processBA.runHook("ondestroy", this, null);
        }
	}

@Override
	public android.os.IBinder onBind(android.content.Intent intent) {
		return null;
	}public anywheresoftware.b4a.keywords.Common __c = null;
public static int _nid = 0;
public static boolean _tracking = false;
public static anywheresoftware.b4a.phone.Phone.PhoneWakeState _lock = null;
public static uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper _flp = null;
public static uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest _actuallr = null;
public static boolean _flpstarted = false;
public static String _locrequest = "";
public static anywheresoftware.b4a.gps.LocationWrapper _uugcoords = null;
public static String _trackeractividad = "";
public static String _pushserviceactividad = "";
public b4a.example.dateutils _dateutils = null;
public reparto_intmex.keymon.lat.main _main = null;
public reparto_intmex.keymon.lat.appupdater _appupdater = null;
public reparto_intmex.keymon.lat.starter _starter = null;
public reparto_intmex.keymon.lat.foto _foto = null;
public reparto_intmex.keymon.lat.mapa_cliente _mapa_cliente = null;
public reparto_intmex.keymon.lat.mapa_rutas _mapa_rutas = null;
public reparto_intmex.keymon.lat.subs _subs = null;
public reparto_intmex.keymon.lat.newinst2 _newinst2 = null;
public reparto_intmex.keymon.lat.b4xpages _b4xpages = null;
public reparto_intmex.keymon.lat.b4xcollections _b4xcollections = null;
public reparto_intmex.keymon.lat.httputils2service _httputils2service = null;
public reparto_intmex.keymon.lat.xuiviewsutils _xuiviewsutils = null;
public static uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest  _createlocationrequest() throws Exception{
uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest _lr = null;
 //BA.debugLineNum = 119;BA.debugLine="Private Sub CreateLocationRequest As LocationReque";
 //BA.debugLineNum = 120;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"CreateLocat";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("871958529","CreateLocationRequest",0);};
 //BA.debugLineNum = 121;BA.debugLine="Dim lr As LocationRequest";
_lr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 122;BA.debugLine="lr.Initialize";
_lr.Initialize();
 //BA.debugLineNum = 123;BA.debugLine="lr.SetInterval(10000) 'Intervalo deseado para act";
_lr.SetInterval((long) (10000));
 //BA.debugLineNum = 124;BA.debugLine="lr.SetFastestInterval(lr.GetInterval / 2) 'Interv";
_lr.SetFastestInterval((long) (_lr.GetInterval()/(double)2));
 //BA.debugLineNum = 125;BA.debugLine="lr.SetSmallestDisplacement(75) 'Solo registra cam";
_lr.SetSmallestDisplacement((float) (75));
 //BA.debugLineNum = 126;BA.debugLine="lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY";
_lr.SetPriority(_lr.Priority.PRIORITY_HIGH_ACCURACY);
 //BA.debugLineNum = 127;BA.debugLine="actualLR=lr";
_actuallr = _lr;
 //BA.debugLineNum = 128;BA.debugLine="Return lr";
if (true) return _lr;
 //BA.debugLineNum = 129;BA.debugLine="End Sub";
return null;
}
public static uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest  _createlocationrequest2times() throws Exception{
uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest _lr = null;
 //BA.debugLineNum = 131;BA.debugLine="Private Sub CreateLocationRequest2times As Locatio";
 //BA.debugLineNum = 132;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Iniciamos C";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872024065","Iniciamos CreateLocationRequest2times",0);};
 //BA.debugLineNum = 133;BA.debugLine="Dim lr As LocationRequest";
_lr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 134;BA.debugLine="lr.Initialize";
_lr.Initialize();
 //BA.debugLineNum = 135;BA.debugLine="lr.SetInterval(2000) 'Intervalo deseado para actu";
_lr.SetInterval((long) (2000));
 //BA.debugLineNum = 136;BA.debugLine="lr.SetFastestInterval(lr.GetInterval / 2) 'Interv";
_lr.SetFastestInterval((long) (_lr.GetInterval()/(double)2));
 //BA.debugLineNum = 137;BA.debugLine="lr.setNumUpdates(2) 'Solicitamos solo 2 actualiza";
_lr.SetNumUpdates((int) (2));
 //BA.debugLineNum = 138;BA.debugLine="lr.SetSmallestDisplacement(10) 'Solo registra cam";
_lr.SetSmallestDisplacement((float) (10));
 //BA.debugLineNum = 139;BA.debugLine="lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY";
_lr.SetPriority(_lr.Priority.PRIORITY_HIGH_ACCURACY);
 //BA.debugLineNum = 140;BA.debugLine="actualLR=lr";
_actuallr = _lr;
 //BA.debugLineNum = 141;BA.debugLine="Return lr";
if (true) return _lr;
 //BA.debugLineNum = 142;BA.debugLine="End Sub";
return null;
}
public static anywheresoftware.b4a.objects.NotificationWrapper  _createnotification(String _body) throws Exception{
anywheresoftware.b4a.objects.NotificationWrapper _notification = null;
 //BA.debugLineNum = 206;BA.debugLine="Sub CreateNotification (Body As String) As Notific";
 //BA.debugLineNum = 207;BA.debugLine="Dim notification As Notification";
_notification = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 208;BA.debugLine="notification.Initialize2(notification.IMPORTANCE_";
_notification.Initialize2(_notification.IMPORTANCE_LOW);
 //BA.debugLineNum = 209;BA.debugLine="notification.Icon = \"icon\"";
_notification.setIcon("icon");
 //BA.debugLineNum = 210;BA.debugLine="notification.SetInfo(\"INTMEX REPARTO\", Body, Main";
_notification.SetInfoNew(processBA,BA.ObjectToCharSequence("INTMEX REPARTO"),BA.ObjectToCharSequence(_body),(Object)(mostCurrent._main.getObject()));
 //BA.debugLineNum = 211;BA.debugLine="Return notification";
if (true) return _notification;
 //BA.debugLineNum = 212;BA.debugLine="End Sub";
return null;
}
public static String  _dameultimaubicacionconocida() throws Exception{
String _coords = "";
 //BA.debugLineNum = 144;BA.debugLine="Sub dameUltimaUbicacionConocida";
 //BA.debugLineNum = 145;BA.debugLine="If FLP.GetLastKnownLocation.IsInitialized Then 'M";
if (_flp.GetLastKnownLocation().IsInitialized()) { 
 //BA.debugLineNum = 147;BA.debugLine="If B4XPages.MainPage.Logger Then LogColor($\"Mand";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872089603",("Mandamos UUC \""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(mostCurrent._subs._fechakmt /*String*/ (processBA,BA.NumberToString(_flp.GetLastKnownLocation().getTime()))))+"|Acc:"+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("0.2",(Object)(_flp.GetLastKnownLocation().getAccuracy()))+"|"+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("0.8",(Object)(_flp.GetLastKnownLocation().getLatitude()))+"|"+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("0.8",(Object)(_flp.GetLastKnownLocation().getLongitude()))+"|Spd:"+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("0.2",(Object)(_flp.GetLastKnownLocation().getSpeed()))+"|"),anywheresoftware.b4a.keywords.Common.Colors.RGB((int) (255),(int) (112),(int) (35)));};
 //BA.debugLineNum = 148;BA.debugLine="Dim coords As String = FLP.GetLastKnownLocation.";
_coords = BA.NumberToString(_flp.GetLastKnownLocation().getLatitude())+","+BA.NumberToString(_flp.GetLastKnownLocation().getLongitude())+","+_formatofecha(BA.NumberToString(_flp.GetLastKnownLocation().getTime()));
 //BA.debugLineNum = 150;BA.debugLine="Subs.mandamosLoc(coords)";
mostCurrent._subs._mandamosloc /*String*/ (processBA,_coords);
 };
 //BA.debugLineNum = 152;BA.debugLine="End Sub";
return "";
}
public static String  _flp_connectionfailed(int _connectionresult1) throws Exception{
 //BA.debugLineNum = 59;BA.debugLine="Sub flp_ConnectionFailed(ConnectionResult1 As Int)";
 //BA.debugLineNum = 60;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Failed to c";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("871565313","Failed to connect to location provider",0);};
 //BA.debugLineNum = 61;BA.debugLine="End Sub";
return "";
}
public static String  _flp_connectionsuccess() throws Exception{
 //BA.debugLineNum = 54;BA.debugLine="Sub flp_ConnectionSuccess";
 //BA.debugLineNum = 57;BA.debugLine="End Sub";
return "";
}
public static String  _flp_connectionsuspended(int _connectionresult1) throws Exception{
 //BA.debugLineNum = 63;BA.debugLine="Sub flp_ConnectionSuspended(ConnectionResult1 As I";
 //BA.debugLineNum = 64;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"FLP conecti";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("871630849","FLP conection suspended",0);};
 //BA.debugLineNum = 65;BA.debugLine="StartFLP";
_startflp();
 //BA.debugLineNum = 66;BA.debugLine="End Sub";
return "";
}
public static String  _flp_locationchanged(anywheresoftware.b4a.gps.LocationWrapper _location1) throws Exception{
String _sdate = "";
String _stime = "";
String _coords = "";
String _origformat = "";
int _minsdif = 0;
 //BA.debugLineNum = 162;BA.debugLine="Sub flp_LocationChanged (Location1 As Location)";
 //BA.debugLineNum = 163;BA.debugLine="Starter.trackerActividad = Subs.fechaKMT(DateTime";
mostCurrent._starter._trackeractividad /*String*/  = mostCurrent._subs._fechakmt /*String*/ (processBA,BA.NumberToString(anywheresoftware.b4a.keywords.Common.DateTime.getNow()));
 //BA.debugLineNum = 164;BA.debugLine="UUGCoords = Location1";
_uugcoords = _location1;
 //BA.debugLineNum = 166;BA.debugLine="CallSub2(Starter, \"GPS_LocationChanged\", Location";
anywheresoftware.b4a.keywords.Common.CallSubNew2(processBA,(Object)(mostCurrent._starter.getObject()),"GPS_LocationChanged",(Object)(_location1));
 //BA.debugLineNum = 169;BA.debugLine="B4XPages.MainPage.lat_gps = Location1.Latitude";
mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._lat_gps /*String*/  = BA.NumberToString(_location1.getLatitude());
 //BA.debugLineNum = 170;BA.debugLine="B4XPages.MainPage.lon_gps = Location1.Longitude";
mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._lon_gps /*String*/  = BA.NumberToString(_location1.getLongitude());
 //BA.debugLineNum = 172;BA.debugLine="Dim sDate,sTime As String";
_sdate = "";
_stime = "";
 //BA.debugLineNum = 173;BA.debugLine="DateTime.DateFormat = \"MM/dd/yyyy\"";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat("MM/dd/yyyy");
 //BA.debugLineNum = 174;BA.debugLine="sDate=DateTime.Date(DateTime.Now)";
_sdate = anywheresoftware.b4a.keywords.Common.DateTime.Date(anywheresoftware.b4a.keywords.Common.DateTime.getNow());
 //BA.debugLineNum = 175;BA.debugLine="sTime=DateTime.Time(DateTime.Now)";
_stime = anywheresoftware.b4a.keywords.Common.DateTime.Time(anywheresoftware.b4a.keywords.Common.DateTime.getNow());
 //BA.debugLineNum = 176;BA.debugLine="Try";
try { //BA.debugLineNum = 177;BA.debugLine="Starter.skmt.ExecNonQuery(\"DELETE FROM HIST_GPS\"";
mostCurrent._starter._skmt /*anywheresoftware.b4a.sql.SQL*/ .ExecNonQuery("DELETE FROM HIST_GPS");
 //BA.debugLineNum = 178;BA.debugLine="Starter.skmt.ExecNonQuery2(\"INSERT INTO HIST_GPS";
mostCurrent._starter._skmt /*anywheresoftware.b4a.sql.SQL*/ .ExecNonQuery2("INSERT INTO HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ",anywheresoftware.b4a.keywords.Common.ArrayToList(new Object[]{(Object)(_sdate+_stime),(Object)(mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._lat_gps /*String*/ ),(Object)(mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._lon_gps /*String*/ )}));
 } 
       catch (Exception e14) {
			processBA.setLastException(e14); //BA.debugLineNum = 180;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Error al b";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872220690","Error al borrar o insertar nuevas coordendas en HIST_GPS",0);};
 };
 //BA.debugLineNum = 183;BA.debugLine="Dim coords As String = Location1.Latitude&\",\"&Loc";
_coords = BA.NumberToString(_location1.getLatitude())+","+BA.NumberToString(_location1.getLongitude())+","+_formatofecha(BA.NumberToString(_location1.getTime()));
 //BA.debugLineNum = 184;BA.debugLine="Log(\"Loc changed : \"&Location1.Latitude&\",\"&Locat";
anywheresoftware.b4a.keywords.Common.LogImpl("872220694","Loc changed : "+BA.NumberToString(_location1.getLatitude())+","+BA.NumberToString(_location1.getLongitude()),0);
 //BA.debugLineNum = 185;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Mandamos Ub";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872220695","Mandamos Ubicacion",0);};
 //BA.debugLineNum = 186;BA.debugLine="If B4XPages.MainPage.logger Then Log(locRequest)";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872220696",_locrequest,0);};
 //BA.debugLineNum = 188;BA.debugLine="If Location1.Accuracy < 100 Then";
if (_location1.getAccuracy()<100) { 
 //BA.debugLineNum = 189;BA.debugLine="Subs.guardaInfoEnBD(coords)'Escribimos coordenad";
mostCurrent._subs._guardainfoenbd /*String*/ (processBA,_coords);
 //BA.debugLineNum = 191;BA.debugLine="Subs.mandamosLoc(coords)";
mostCurrent._subs._mandamosloc /*String*/ (processBA,_coords);
 };
 //BA.debugLineNum = 193;BA.debugLine="Dim origFormat As String = DateTime.TimeFormat 'G";
_origformat = anywheresoftware.b4a.keywords.Common.DateTime.getTimeFormat();
 //BA.debugLineNum = 194;BA.debugLine="DateTime.TimeFormat = \"HHmmss\" ' Modificamos form";
anywheresoftware.b4a.keywords.Common.DateTime.setTimeFormat("HHmmss");
 //BA.debugLineNum = 195;BA.debugLine="Dim minsDif As Int = DateTime.Time(DateTime.Now)";
_minsdif = (int) ((double)(Double.parseDouble(anywheresoftware.b4a.keywords.Common.DateTime.Time(anywheresoftware.b4a.keywords.Common.DateTime.getNow())))-(double)(Double.parseDouble(mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._ultimaactualizaciongps /*String*/ )));
 //BA.debugLineNum = 197;BA.debugLine="If Location1.Accuracy < 100 And minsDif > 240 The";
if (_location1.getAccuracy()<100 && _minsdif>240) { 
 //BA.debugLineNum = 198;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"actualizam";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("872220708","actualizamos Ubicacion Web",0);};
 //BA.debugLineNum = 199;BA.debugLine="CallSubDelayed(Starter, \"ENVIA_ULTIMA_GPS\")";
anywheresoftware.b4a.keywords.Common.CallSubDelayed(processBA,(Object)(mostCurrent._starter.getObject()),"ENVIA_ULTIMA_GPS");
 };
 //BA.debugLineNum = 201;BA.debugLine="DateTime.TimeFormat = origFormat 'Regresamos form";
anywheresoftware.b4a.keywords.Common.DateTime.setTimeFormat(_origformat);
 //BA.debugLineNum = 203;BA.debugLine="Subs.monitor";
mostCurrent._subs._monitor /*String*/ (processBA);
 //BA.debugLineNum = 204;BA.debugLine="End Sub";
return "";
}
public static String  _formatofecha(String _fecha) throws Exception{
String _origformat = "";
String _lastupdate = "";
 //BA.debugLineNum = 222;BA.debugLine="Sub formatoFecha(fecha As String) As String 'Convi";
 //BA.debugLineNum = 224;BA.debugLine="Dim OrigFormat As String = DateTime.DateFormat  '";
_origformat = anywheresoftware.b4a.keywords.Common.DateTime.getDateFormat();
 //BA.debugLineNum = 225;BA.debugLine="DateTime.DateFormat=\"yyMMddHHmmss\"";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat("yyMMddHHmmss");
 //BA.debugLineNum = 226;BA.debugLine="Dim lastUpdate As String=DateTime.Date(fecha)";
_lastupdate = anywheresoftware.b4a.keywords.Common.DateTime.Date((long)(Double.parseDouble(_fecha)));
 //BA.debugLineNum = 227;BA.debugLine="DateTime.DateFormat=OrigFormat  'return to orig d";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat(_origformat);
 //BA.debugLineNum = 229;BA.debugLine="Return lastUpdate";
if (true) return _lastupdate;
 //BA.debugLineNum = 230;BA.debugLine="End Sub";
return "";
}
public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 29;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 30;BA.debugLine="Private nid As Int = 1";
_nid = (int) (1);
 //BA.debugLineNum = 31;BA.debugLine="dim Tracking As Boolean";
_tracking = false;
 //BA.debugLineNum = 32;BA.debugLine="Private lock As PhoneWakeState";
_lock = new anywheresoftware.b4a.phone.Phone.PhoneWakeState();
 //BA.debugLineNum = 34;BA.debugLine="Public FLP As FusedLocationProvider";
_flp = new uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper();
 //BA.debugLineNum = 35;BA.debugLine="Dim actualLR As LocationRequest";
_actuallr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 36;BA.debugLine="Private flpStarted As Boolean";
_flpstarted = false;
 //BA.debugLineNum = 37;BA.debugLine="Dim locRequest As String";
_locrequest = "";
 //BA.debugLineNum = 38;BA.debugLine="Dim UUGCoords As Location 'Ultima Ubicacion Guard";
_uugcoords = new anywheresoftware.b4a.gps.LocationWrapper();
 //BA.debugLineNum = 39;BA.debugLine="Dim trackerActividad, pushServiceActividad As Str";
_trackeractividad = "";
_pushserviceactividad = "";
 //BA.debugLineNum = 40;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
 //BA.debugLineNum = 42;BA.debugLine="Sub Service_Create";
 //BA.debugLineNum = 43;BA.debugLine="Service.AutomaticForegroundMode = Service.AUTOMAT";
mostCurrent._service.AutomaticForegroundMode = mostCurrent._service.AUTOMATIC_FOREGROUND_NEVER;
 //BA.debugLineNum = 44;BA.debugLine="UUGCoords.Initialize";
_uugcoords.Initialize();
 //BA.debugLineNum = 45;BA.debugLine="UUGCoords.Latitude = 0";
_uugcoords.setLatitude(0);
 //BA.debugLineNum = 46;BA.debugLine="UUGCoords.Longitude = 0";
_uugcoords.setLongitude(0);
 //BA.debugLineNum = 48;BA.debugLine="FLP.Initialize(\"flp\")";
_flp.Initialize(processBA,"flp");
 //BA.debugLineNum = 49;BA.debugLine="FLP.Connect";
_flp.Connect();
 //BA.debugLineNum = 50;BA.debugLine="lock.PartialLock";
_lock.PartialLock(processBA);
 //BA.debugLineNum = 51;BA.debugLine="StartFLP";
_startflp();
 //BA.debugLineNum = 52;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 214;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 215;BA.debugLine="If Tracking Then";
if (_tracking) { 
 //BA.debugLineNum = 216;BA.debugLine="StopFLP";
_stopflp();
 };
 //BA.debugLineNum = 218;BA.debugLine="Tracking = False";
_tracking = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 219;BA.debugLine="lock.ReleasePartialLock";
_lock.ReleasePartialLock();
 //BA.debugLineNum = 220;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 68;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 69;BA.debugLine="LogColor(\"Iniciando Tracker ...\", Colors.Green)";
anywheresoftware.b4a.keywords.Common.LogImpl("871696385","Iniciando Tracker ...",anywheresoftware.b4a.keywords.Common.Colors.Green);
 //BA.debugLineNum = 70;BA.debugLine="Service.StopAutomaticForeground";
mostCurrent._service.StopAutomaticForeground();
 //BA.debugLineNum = 72;BA.debugLine="StartServiceAt(Me, DateTime.Now + 10 * DateTime.T";
anywheresoftware.b4a.keywords.Common.StartServiceAt(processBA,tracker.getObject(),(long) (anywheresoftware.b4a.keywords.Common.DateTime.getNow()+10*anywheresoftware.b4a.keywords.Common.DateTime.TicksPerMinute),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 73;BA.debugLine="Track";
_track();
 //BA.debugLineNum = 74;BA.debugLine="Starter.trackerActividad = Subs.fechaKMT(DateTime";
mostCurrent._starter._trackeractividad /*String*/  = mostCurrent._subs._fechakmt /*String*/ (processBA,BA.NumberToString(anywheresoftware.b4a.keywords.Common.DateTime.getNow()));
 //BA.debugLineNum = 76;BA.debugLine="End Sub";
return "";
}
public static void  _startflp() throws Exception{
ResumableSub_StartFLP rsub = new ResumableSub_StartFLP(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_StartFLP extends BA.ResumableSub {
public ResumableSub_StartFLP(reparto_intmex.keymon.lat.tracker parent) {
this.parent = parent;
}
reparto_intmex.keymon.lat.tracker parent;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 94;BA.debugLine="Do While FLP.IsConnected = False";
if (true) break;

case 1:
//do while
this.state = 4;
while (parent._flp.IsConnected()==anywheresoftware.b4a.keywords.Common.False) {
this.state = 3;
if (true) break;
}
if (true) break;

case 3:
//C
this.state = 1;
 //BA.debugLineNum = 95;BA.debugLine="Sleep(500)";
anywheresoftware.b4a.keywords.Common.Sleep(processBA,this,(int) (500));
this.state = 5;
return;
case 5:
//C
this.state = 1;
;
 if (true) break;

case 4:
//C
this.state = -1;
;
 //BA.debugLineNum = 100;BA.debugLine="FLP.RequestLocationUpdates(CreateLocationRequest";
parent._flp.RequestLocationUpdates((com.google.android.gms.location.LocationRequest)(_createlocationrequest().getObject()));
 //BA.debugLineNum = 103;BA.debugLine="flpStarted = True";
parent._flpstarted = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 105;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static void  _startflp2reqs() throws Exception{
ResumableSub_StartFLP2Reqs rsub = new ResumableSub_StartFLP2Reqs(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_StartFLP2Reqs extends BA.ResumableSub {
public ResumableSub_StartFLP2Reqs(reparto_intmex.keymon.lat.tracker parent) {
this.parent = parent;
}
reparto_intmex.keymon.lat.tracker parent;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 108;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"StartFLP -";
if (true) break;

case 1:
//if
this.state = 6;
if (parent.mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
this.state = 3;
;}if (true) break;

case 3:
//C
this.state = 6;
anywheresoftware.b4a.keywords.Common.LogImpl("871892993","StartFLP - flpStarted="+BA.ObjectToString(parent._flpstarted),0);
if (true) break;

case 6:
//C
this.state = 7;
;
 //BA.debugLineNum = 109;BA.debugLine="Do While FLP.IsConnected = False";
if (true) break;

case 7:
//do while
this.state = 16;
while (parent._flp.IsConnected()==anywheresoftware.b4a.keywords.Common.False) {
this.state = 9;
if (true) break;
}
if (true) break;

case 9:
//C
this.state = 10;
 //BA.debugLineNum = 110;BA.debugLine="Sleep(500)";
anywheresoftware.b4a.keywords.Common.Sleep(processBA,this,(int) (500));
this.state = 29;
return;
case 29:
//C
this.state = 10;
;
 //BA.debugLineNum = 111;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"sleeping G";
if (true) break;

case 10:
//if
this.state = 15;
if (parent.mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
this.state = 12;
;}if (true) break;

case 12:
//C
this.state = 15;
anywheresoftware.b4a.keywords.Common.LogImpl("871892996","sleeping GR",0);
if (true) break;

case 15:
//C
this.state = 7;
;
 if (true) break;

case 16:
//C
this.state = 17;
;
 //BA.debugLineNum = 113;BA.debugLine="dameUltimaUbicacionConocida 'Regresamos ultima ub";
_dameultimaubicacionconocida();
 //BA.debugLineNum = 114;BA.debugLine="FLP.RequestLocationUpdates(CreateLocationRequest2";
parent._flp.RequestLocationUpdates((com.google.android.gms.location.LocationRequest)(_createlocationrequest2times().getObject()));
 //BA.debugLineNum = 115;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Buscamos ub";
if (true) break;

case 17:
//if
this.state = 22;
if (parent.mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
this.state = 19;
;}if (true) break;

case 19:
//C
this.state = 22;
anywheresoftware.b4a.keywords.Common.LogImpl("871893000","Buscamos ubicacion 2 peticiones",0);
if (true) break;

case 22:
//C
this.state = 23;
;
 //BA.debugLineNum = 116;BA.debugLine="If B4XPages.MainPage.logger Then Log(actualLR.Get";
if (true) break;

case 23:
//if
this.state = 28;
if (parent.mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
this.state = 25;
;}if (true) break;

case 25:
//C
this.state = 28;
anywheresoftware.b4a.keywords.Common.LogImpl("871893001",BA.NumberToString(parent._actuallr.GetSmallestDisplacement()),0);
if (true) break;

case 28:
//C
this.state = -1;
;
 //BA.debugLineNum = 117;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static String  _stopflp() throws Exception{
 //BA.debugLineNum = 154;BA.debugLine="Public Sub StopFLP";
 //BA.debugLineNum = 156;BA.debugLine="If flpStarted Then";
if (_flpstarted) { 
 //BA.debugLineNum = 157;BA.debugLine="FLP.RemoveLocationUpdates  'Eliminamos todas las";
_flp.RemoveLocationUpdates();
 //BA.debugLineNum = 158;BA.debugLine="flpStarted = False";
_flpstarted = anywheresoftware.b4a.keywords.Common.False;
 };
 //BA.debugLineNum = 160;BA.debugLine="End Sub";
return "";
}
public static String  _track() throws Exception{
 //BA.debugLineNum = 78;BA.debugLine="Public Sub Track";
 //BA.debugLineNum = 79;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"Inicia Trac";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("871761921","Inicia Track - Tracking : "+BA.ObjectToString(_tracking),0);};
 //BA.debugLineNum = 80;BA.debugLine="If Tracking Then";
if (_tracking) { 
 //BA.debugLineNum = 82;BA.debugLine="Return 'Si ya estamos \"rastreando\" no hacemos na";
if (true) return "";
 };
 //BA.debugLineNum = 84;BA.debugLine="If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_";
if (mostCurrent._starter._rp /*anywheresoftware.b4a.objects.RuntimePermissions*/ .Check(mostCurrent._starter._rp /*anywheresoftware.b4a.objects.RuntimePermissions*/ .PERMISSION_ACCESS_FINE_LOCATION)==anywheresoftware.b4a.keywords.Common.False) { 
 //BA.debugLineNum = 85;BA.debugLine="If B4XPages.MainPage.logger Then Log(\"No permiss";
if (mostCurrent._b4xpages._mainpage /*reparto_intmex.keymon.lat.b4xmainpage*/ (processBA)._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("871761927","No permission",0);};
 //BA.debugLineNum = 86;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 88;BA.debugLine="StartFLP 'Iniciamos FusedLocationProvider";
_startflp();
 //BA.debugLineNum = 89;BA.debugLine="Tracking = True";
_tracking = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 90;BA.debugLine="End Sub";
return "";
}
}
