package medicomed.keymon.com.mx;


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, "medicomed.keymon.com.mx", "medicomed.keymon.com.mx.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, "medicomed.keymon.com.mx.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");
    		}
    	}
    }

	public void onTimeout(int startId) {
        BA.LogInfo("** Service (tracker) Timeout **");
        anywheresoftware.b4a.objects.collections.Map params = new anywheresoftware.b4a.objects.collections.Map();
        params.Initialize();
        params.Put("StartId", startId);
        processBA.raiseEvent(null, "service_timeout", params);
            
    }
	@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 anywheresoftware.b4a.gps.LocationWrapper _uugcoords = null;
public b4a.example.dateutils _dateutils = null;
public medicomed.keymon.com.mx.main _main = null;
public medicomed.keymon.com.mx.starter _starter = null;
public medicomed.keymon.com.mx.appupdater _appupdater = null;
public medicomed.keymon.com.mx.mapa_rutas _mapa_rutas = null;
public medicomed.keymon.com.mx.mapa_cliente _mapa_cliente = null;
public medicomed.keymon.com.mx.subs _subs = null;
public medicomed.keymon.com.mx.notificationservice _notificationservice = null;
public medicomed.keymon.com.mx.pendientes _pendientes = null;
public medicomed.keymon.com.mx.newinst2 _newinst2 = null;
public medicomed.keymon.com.mx.b4xpages _b4xpages = null;
public medicomed.keymon.com.mx.b4xcollections _b4xcollections = null;
public medicomed.keymon.com.mx.httputils2service _httputils2service = null;
public medicomed.keymon.com.mx.xuiviewsutils _xuiviewsutils = null;
public static uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest  _createlocationrequest() throws Exception{
uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest _lr = null;
 //BA.debugLineNum = 112;BA.debugLine="Private Sub CreateLocationRequest As LocationReque";
 //BA.debugLineNum = 114;BA.debugLine="Dim lr As LocationRequest";
_lr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 115;BA.debugLine="lr.Initialize";
_lr.Initialize();
 //BA.debugLineNum = 116;BA.debugLine="lr.SetInterval(1) 'Intervalo deseado para actuali";
_lr.SetInterval((long) (1));
 //BA.debugLineNum = 117;BA.debugLine="lr.SetFastestInterval(lr.GetInterval / 2) 'Interv";
_lr.SetFastestInterval((long) (_lr.GetInterval()/(double)2));
 //BA.debugLineNum = 118;BA.debugLine="lr.SetSmallestDisplacement(0) 'Solo registra camb";
_lr.SetSmallestDisplacement((float) (0));
 //BA.debugLineNum = 119;BA.debugLine="lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY";
_lr.SetPriority(_lr.Priority.PRIORITY_HIGH_ACCURACY);
 //BA.debugLineNum = 120;BA.debugLine="actualLR=lr";
_actuallr = _lr;
 //BA.debugLineNum = 121;BA.debugLine="Return lr";
if (true) return _lr;
 //BA.debugLineNum = 122;BA.debugLine="End Sub";
return null;
}
public static uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest  _createlocationrequestsmalld() throws Exception{
uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest _lr = null;
 //BA.debugLineNum = 124;BA.debugLine="Private Sub CreateLocationRequestSmallD As Locatio";
 //BA.debugLineNum = 126;BA.debugLine="Dim lr As LocationRequest";
_lr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 127;BA.debugLine="lr.Initialize";
_lr.Initialize();
 //BA.debugLineNum = 128;BA.debugLine="lr.SetInterval(2000) 'Intervalo deseado para actu";
_lr.SetInterval((long) (2000));
 //BA.debugLineNum = 129;BA.debugLine="lr.SetFastestInterval(lr.GetInterval / 2) 'Interv";
_lr.SetFastestInterval((long) (_lr.GetInterval()/(double)2));
 //BA.debugLineNum = 130;BA.debugLine="lr.setNumUpdates(2) 'Solicitamos solo 2 actualiza";
_lr.SetNumUpdates((int) (2));
 //BA.debugLineNum = 131;BA.debugLine="lr.SetSmallestDisplacement(1) 'Solo registra camb";
_lr.SetSmallestDisplacement((float) (1));
 //BA.debugLineNum = 132;BA.debugLine="lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY";
_lr.SetPriority(_lr.Priority.PRIORITY_HIGH_ACCURACY);
 //BA.debugLineNum = 133;BA.debugLine="actualLR=lr";
_actuallr = _lr;
 //BA.debugLineNum = 134;BA.debugLine="Return lr";
if (true) return _lr;
 //BA.debugLineNum = 135;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 = 198;BA.debugLine="Sub CreateNotification (Body As String) As Notific";
 //BA.debugLineNum = 199;BA.debugLine="Dim notification As Notification";
_notification = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 200;BA.debugLine="notification.Initialize2(notification.IMPORTANCE_";
_notification.Initialize2(_notification.IMPORTANCE_LOW);
 //BA.debugLineNum = 201;BA.debugLine="notification.Icon = \"icon\"";
_notification.setIcon("icon");
 //BA.debugLineNum = 202;BA.debugLine="notification.SetInfo(\"ADM\", Body, Main)";
_notification.SetInfoNew(processBA,BA.ObjectToCharSequence("ADM"),BA.ObjectToCharSequence(_body),(Object)(mostCurrent._main.getObject()));
 //BA.debugLineNum = 203;BA.debugLine="Return notification";
if (true) return _notification;
 //BA.debugLineNum = 204;BA.debugLine="End Sub";
return null;
}
public static String  _dameultimaubicacionconocida() throws Exception{
String _coords = "";
 //BA.debugLineNum = 137;BA.debugLine="Sub dameUltimaUbicacionConocida";
 //BA.debugLineNum = 138;BA.debugLine="If FLP.GetLastKnownLocation.IsInitialized Then 'M";
if (_flp.GetLastKnownLocation().IsInitialized()) { 
 //BA.debugLineNum = 140;BA.debugLine="If Starter.Logger Then LogColor($\"Mandamos UUC \"";
if (mostCurrent._starter._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("777725699",("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 = 141;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 = 145;BA.debugLine="End Sub";
return "";
}
public static String  _flp_connectionfailed(int _connectionresult1) throws Exception{
 //BA.debugLineNum = 56;BA.debugLine="Sub flp_ConnectionFailed(ConnectionResult1 As Int)";
 //BA.debugLineNum = 57;BA.debugLine="Log(\"Failed to connect to location provider\")";
anywheresoftware.b4a.keywords.Common.LogImpl("777266945","Failed to connect to location provider",0);
 //BA.debugLineNum = 58;BA.debugLine="End Sub";
return "";
}
public static String  _flp_connectionsuccess() throws Exception{
 //BA.debugLineNum = 51;BA.debugLine="Sub flp_ConnectionSuccess";
 //BA.debugLineNum = 54;BA.debugLine="End Sub";
return "";
}
public static String  _flp_locationchanged(anywheresoftware.b4a.gps.LocationWrapper _location1) throws Exception{
String _sdate = "";
String _stime = "";
String _coords = "";
 //BA.debugLineNum = 155;BA.debugLine="Sub flp_LocationChanged (Location1 As Location)";
 //BA.debugLineNum = 158;BA.debugLine="B4XPages.MainPage.lat_gps = Location1.Latitude";
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._lat_gps /*String*/  = BA.NumberToString(_location1.getLatitude());
 //BA.debugLineNum = 159;BA.debugLine="B4XPages.MainPage.lon_gps = Location1.Longitude";
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._lon_gps /*String*/  = BA.NumberToString(_location1.getLongitude());
 //BA.debugLineNum = 160;BA.debugLine="UUGCoords = Location1";
_uugcoords = _location1;
 //BA.debugLineNum = 168;BA.debugLine="Dim sDate,sTime As String";
_sdate = "";
_stime = "";
 //BA.debugLineNum = 169;BA.debugLine="DateTime.DateFormat = \"MM/dd/yyyy\"";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat("MM/dd/yyyy");
 //BA.debugLineNum = 170;BA.debugLine="sDate=DateTime.Date(DateTime.Now)";
_sdate = anywheresoftware.b4a.keywords.Common.DateTime.Date(anywheresoftware.b4a.keywords.Common.DateTime.getNow());
 //BA.debugLineNum = 171;BA.debugLine="sTime=DateTime.Time(DateTime.Now)";
_stime = anywheresoftware.b4a.keywords.Common.DateTime.Time(anywheresoftware.b4a.keywords.Common.DateTime.getNow());
 //BA.debugLineNum = 172;BA.debugLine="If Not(B4XPages.MainPage.skmt.IsInitialized) Then";
if (anywheresoftware.b4a.keywords.Common.Not(mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._skmt /*anywheresoftware.b4a.sql.SQL*/ .IsInitialized())) { 
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._skmt /*anywheresoftware.b4a.sql.SQL*/ .Initialize(mostCurrent._starter._ruta /*String*/ ,"kmt.db",anywheresoftware.b4a.keywords.Common.True);};
 //BA.debugLineNum = 173;BA.debugLine="Try";
try { //BA.debugLineNum = 174;BA.debugLine="B4XPages.MainPage.skmt.ExecNonQuery2(\"INSERT INT";
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._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 /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._lat_gps /*String*/ ),(Object)(mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._lon_gps /*String*/ )}));
 //BA.debugLineNum = 175;BA.debugLine="B4XPages.MainPage.skmt.ExecNonQuery(\"DELETE FROM";
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._skmt /*anywheresoftware.b4a.sql.SQL*/ .ExecNonQuery("DELETE FROM HIST_GPS");
 } 
       catch (Exception e13) {
			processBA.setLastException(e13); //BA.debugLineNum = 177;BA.debugLine="LogColor(LastException, Colors.Red)";
anywheresoftware.b4a.keywords.Common.LogImpl("777856790",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 //BA.debugLineNum = 180;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 = 185;BA.debugLine="If Location1.Accuracy < 100 Then";
if (_location1.getAccuracy()<100) { 
 };
 //BA.debugLineNum = 189;BA.debugLine="CallSub2(Starter, \"GPS_LocationChanged\", Location";
anywheresoftware.b4a.keywords.Common.CallSubNew2(processBA,(Object)(mostCurrent._starter.getObject()),"GPS_LocationChanged",(Object)(_location1));
 //BA.debugLineNum = 192;BA.debugLine="If B4XPages.MainPage.cliente.IsInitialized Then";
if (mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._cliente /*medicomed.keymon.com.mx.c_cliente*/ .IsInitialized /*boolean*/ ()) { 
 //BA.debugLineNum = 193;BA.debugLine="CallSub2(B4XPages.GetPage(\"Cliente\"), \"GPS_Locat";
anywheresoftware.b4a.keywords.Common.CallSubNew2(processBA,mostCurrent._b4xpages._getpage /*Object*/ (processBA,"Cliente"),"GPS_LocationChanged",(Object)(_location1));
 };
 //BA.debugLineNum = 196;BA.debugLine="End Sub";
return "";
}
public static String  _formatofecha(String _fecha) throws Exception{
String _origformat = "";
String _lastupdate = "";
 //BA.debugLineNum = 214;BA.debugLine="Sub formatoFecha(fecha As String) As String 'Convi";
 //BA.debugLineNum = 216;BA.debugLine="Dim OrigFormat As String = DateTime.DateFormat  '";
_origformat = anywheresoftware.b4a.keywords.Common.DateTime.getDateFormat();
 //BA.debugLineNum = 217;BA.debugLine="DateTime.DateFormat=\"yyMMddHHmmss\"";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat("yyMMddHHmmss");
 //BA.debugLineNum = 218;BA.debugLine="Dim lastUpdate As String=DateTime.Date(fecha)";
_lastupdate = anywheresoftware.b4a.keywords.Common.DateTime.Date((long)(Double.parseDouble(_fecha)));
 //BA.debugLineNum = 219;BA.debugLine="DateTime.DateFormat=OrigFormat  'return to orig d";
anywheresoftware.b4a.keywords.Common.DateTime.setDateFormat(_origformat);
 //BA.debugLineNum = 221;BA.debugLine="Return lastUpdate";
if (true) return _lastupdate;
 //BA.debugLineNum = 222;BA.debugLine="End Sub";
return "";
}
public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 30;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 31;BA.debugLine="Private nid As Int = 51042";
_nid = (int) (51042);
 //BA.debugLineNum = 32;BA.debugLine="Private Tracking As Boolean";
_tracking = false;
 //BA.debugLineNum = 33;BA.debugLine="Private lock As PhoneWakeState";
_lock = new anywheresoftware.b4a.phone.Phone.PhoneWakeState();
 //BA.debugLineNum = 35;BA.debugLine="Public FLP As FusedLocationProvider";
_flp = new uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper();
 //BA.debugLineNum = 36;BA.debugLine="Dim actualLR As LocationRequest";
_actuallr = new uk.co.martinpearman.b4a.fusedlocationprovider.LocationRequest();
 //BA.debugLineNum = 37;BA.debugLine="Private flpStarted As Boolean";
_flpstarted = false;
 //BA.debugLineNum = 39;BA.debugLine="Dim UUGCoords As Location 'Ultima Ubicacion Guard";
_uugcoords = new anywheresoftware.b4a.gps.LocationWrapper();
 //BA.debugLineNum = 40;BA.debugLine="End Sub";
return "";
}
public static String  _revisaflp() throws Exception{
boolean _todobienflp = false;
 //BA.debugLineNum = 225;BA.debugLine="Sub revisaFLP 'ignore";
 //BA.debugLineNum = 226;BA.debugLine="LogColor(\"**** **** Revisamos FLP **** ****\", Col";
anywheresoftware.b4a.keywords.Common.LogImpl("778118913","**** **** Revisamos FLP **** ****",anywheresoftware.b4a.keywords.Common.Colors.RGB((int) (78),(int) (0),(int) (227)));
 //BA.debugLineNum = 227;BA.debugLine="Private todoBienFLP As Boolean = True";
_todobienflp = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 228;BA.debugLine="Try";
try { //BA.debugLineNum = 229;BA.debugLine="If Not(FLP.IsInitialized) Then";
if (anywheresoftware.b4a.keywords.Common.Not(_flp.IsInitialized())) { 
 //BA.debugLineNum = 230;BA.debugLine="Subs.log2DB(\"revisaFLP: No esta inicializado ..";
mostCurrent._subs._log2db /*String*/ (processBA,"revisaFLP: No esta inicializado ... 'Reinicializando FLP'");
 //BA.debugLineNum = 231;BA.debugLine="FLP.Initialize(\"flp\")";
_flp.Initialize(processBA,"flp");
 //BA.debugLineNum = 232;BA.debugLine="todoBienFLP = False";
_todobienflp = anywheresoftware.b4a.keywords.Common.False;
 };
 } 
       catch (Exception e10) {
			processBA.setLastException(e10); //BA.debugLineNum = 235;BA.debugLine="LogColor(\"If Not(Tracker.FLP.IsInitialized) -->";
anywheresoftware.b4a.keywords.Common.LogImpl("778118922","If Not(Tracker.FLP.IsInitialized) --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 //BA.debugLineNum = 237;BA.debugLine="Try";
try { //BA.debugLineNum = 238;BA.debugLine="If FLP.IsInitialized Then";
if (_flp.IsInitialized()) { 
 //BA.debugLineNum = 239;BA.debugLine="Try";
try { //BA.debugLineNum = 240;BA.debugLine="If Not(FLP.IsConnected) Then";
if (anywheresoftware.b4a.keywords.Common.Not(_flp.IsConnected())) { 
 //BA.debugLineNum = 241;BA.debugLine="Subs.log2DB(\"revisaFLP: No esta conectado ...";
mostCurrent._subs._log2db /*String*/ (processBA,"revisaFLP: No esta conectado ... 'Reconectando FLP'");
 //BA.debugLineNum = 243;BA.debugLine="StartFLP";
_startflp();
 //BA.debugLineNum = 244;BA.debugLine="todoBienFLP = False";
_todobienflp = anywheresoftware.b4a.keywords.Common.False;
 };
 } 
       catch (Exception e21) {
			processBA.setLastException(e21); //BA.debugLineNum = 247;BA.debugLine="LogColor(\"If Not(Tracker.FLP.IsConnected) -->";
anywheresoftware.b4a.keywords.Common.LogImpl("778118934","If Not(Tracker.FLP.IsConnected) --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 //BA.debugLineNum = 249;BA.debugLine="Try";
try { //BA.debugLineNum = 250;BA.debugLine="If FLP.IsConnected And _ 					FLP.GetLastKnown";
if (_flp.IsConnected() && _flp.GetLastKnownLocation().IsInitialized() && _flp.GetLastKnownLocation().DistanceTo((android.location.Location)(_uugcoords.getObject()))>500) { 
 //BA.debugLineNum = 253;BA.debugLine="Subs.log2DB(\"revisaFLP: 'No se esta actualiza";
mostCurrent._subs._log2db /*String*/ (processBA,"revisaFLP: 'No se esta actualizando, lo reiniciamos ...'");
 //BA.debugLineNum = 254;BA.debugLine="StartService(Me)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,tracker.getObject());
 //BA.debugLineNum = 255;BA.debugLine="todoBienFLP = False";
_todobienflp = anywheresoftware.b4a.keywords.Common.False;
 };
 } 
       catch (Exception e30) {
			processBA.setLastException(e30); //BA.debugLineNum = 258;BA.debugLine="LogColor(\"If FLP.IsConnectctd and FLP.getLKL.I";
anywheresoftware.b4a.keywords.Common.LogImpl("778118945","If FLP.IsConnectctd and FLP.getLKL.IsInitialized --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 };
 //BA.debugLineNum = 261;BA.debugLine="If todoBienFLP Then LogColor(\" +++ +++ Sin error";
if (_todobienflp) { 
anywheresoftware.b4a.keywords.Common.LogImpl("778118948"," +++ +++ Sin errores en FLP",anywheresoftware.b4a.keywords.Common.Colors.Green);};
 } 
       catch (Exception e35) {
			processBA.setLastException(e35); //BA.debugLineNum = 263;BA.debugLine="LogColor(\"If Tracker.FLP.IsInitialized --> \"&Las";
anywheresoftware.b4a.keywords.Common.LogImpl("778118950","If Tracker.FLP.IsInitialized --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 //BA.debugLineNum = 266;BA.debugLine="End Sub";
return "";
}
public static String  _revisauug() throws Exception{
int _daa = 0;
 //BA.debugLineNum = 270;BA.debugLine="Sub revisaUUG 'ignore";
 //BA.debugLineNum = 271;BA.debugLine="Try";
try { //BA.debugLineNum = 273;BA.debugLine="If FLP.IsInitialized And FLP.IsConnected Then";
if (_flp.IsInitialized() && _flp.IsConnected()) { 
 //BA.debugLineNum = 274;BA.debugLine="Try";
try { //BA.debugLineNum = 275;BA.debugLine="If FLP.GetLastKnownLocation.IsInitialized Then";
if (_flp.GetLastKnownLocation().IsInitialized()) { 
 //BA.debugLineNum = 277;BA.debugLine="Dim daa As Int = UUGCoords.DistanceTo(FLP.Get";
_daa = (int) (_uugcoords.DistanceTo((android.location.Location)(_flp.GetLastKnownLocation().getObject())));
 //BA.debugLineNum = 278;BA.debugLine="If Starter.Logger Then LogColor($\"**** UUC \"$";
if (mostCurrent._starter._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("778184456",("**** UUC \""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(mostCurrent._subs._fechakmt /*String*/ (processBA,BA.NumberToString(_flp.GetLastKnownLocation().getTime()))))+"|"+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()))+"|"+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 = 279;BA.debugLine="If daa > 40 And FLP.GetLastKnownLocation.Accu";
if (_daa>40 && _flp.GetLastKnownLocation().getAccuracy()<35) { 
 //BA.debugLineNum = 280;BA.debugLine="B4XPages.MainPage.skmt.ExecNonQuery2(\"INSERT";
mostCurrent._b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (processBA)._skmt /*anywheresoftware.b4a.sql.SQL*/ .ExecNonQuery2("INSERT INTO RUTA_GPS(fecha, lat, lon) VALUES (?,?,?)",anywheresoftware.b4a.keywords.Common.ArrayToList(new Object[]{(Object)(mostCurrent._subs._fechakmt /*String*/ (processBA,BA.NumberToString(_flp.GetLastKnownLocation().getTime()))),(Object)(_flp.GetLastKnownLocation().getLatitude()),(Object)(_flp.GetLastKnownLocation().getLongitude())}));
 //BA.debugLineNum = 281;BA.debugLine="If Starter.Logger Then Log(\"++++ Distancia a";
if (mostCurrent._starter._logger /*boolean*/ ) { 
anywheresoftware.b4a.keywords.Common.LogImpl("778184459","++++ Distancia a anterior="+BA.NumberToString(_daa)+"|"+"Precision="+BA.NumberToString(_flp.GetLastKnownLocation().getAccuracy()),0);};
 };
 //BA.debugLineNum = 283;BA.debugLine="UUGCoords = FLP.GetLastKnownLocation";
_uugcoords = _flp.GetLastKnownLocation();
 };
 } 
       catch (Exception e14) {
			processBA.setLastException(e14); //BA.debugLineNum = 286;BA.debugLine="LogColor(\"FLP.GetLastKnownLocation.IsInitializ";
anywheresoftware.b4a.keywords.Common.LogImpl("778184464","FLP.GetLastKnownLocation.IsInitialized --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 }else {
 //BA.debugLineNum = 289;BA.debugLine="Log(\"StartFLP\")";
anywheresoftware.b4a.keywords.Common.LogImpl("778184467","StartFLP",0);
 //BA.debugLineNum = 290;BA.debugLine="StartFLP";
_startflp();
 };
 } 
       catch (Exception e21) {
			processBA.setLastException(e21); //BA.debugLineNum = 293;BA.debugLine="LogColor(\"If FLP.IsInitialized --> \"&LastExcepti";
anywheresoftware.b4a.keywords.Common.LogImpl("778184471","If FLP.IsInitialized --> "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(processBA)),anywheresoftware.b4a.keywords.Common.Colors.Red);
 };
 //BA.debugLineNum = 295;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 = 45;BA.debugLine="FLP.Initialize(\"flp\")";
_flp.Initialize(processBA,"flp");
 //BA.debugLineNum = 46;BA.debugLine="FLP.Connect";
_flp.Connect();
 //BA.debugLineNum = 47;BA.debugLine="lock.PartialLock";
_lock.PartialLock(processBA);
 //BA.debugLineNum = 48;BA.debugLine="StartFLP";
_startflp();
 //BA.debugLineNum = 49;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 206;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 207;BA.debugLine="If Tracking Then";
if (_tracking) { 
 //BA.debugLineNum = 208;BA.debugLine="StopFLP";
_stopflp();
 };
 //BA.debugLineNum = 210;BA.debugLine="Tracking = False";
_tracking = anywheresoftware.b4a.keywords.Common.False;
 //BA.debugLineNum = 211;BA.debugLine="lock.ReleasePartialLock";
_lock.ReleasePartialLock();
 //BA.debugLineNum = 212;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 60;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 62;BA.debugLine="Service.StopAutomaticForeground";
mostCurrent._service.StopAutomaticForeground();
 //BA.debugLineNum = 63;BA.debugLine="Service.StartForeground(nid, CreateNotification(\"";
mostCurrent._service.StartForeground(_nid,(android.app.Notification)(_createnotification("...").getObject()));
 //BA.debugLineNum = 64;BA.debugLine="Track";
_track();
 //BA.debugLineNum = 65;BA.debugLine="StartServiceAt(Me, DateTime.Now + 5 * DateTime.Ti";
anywheresoftware.b4a.keywords.Common.StartServiceAt(processBA,tracker.getObject(),(long) (anywheresoftware.b4a.keywords.Common.DateTime.getNow()+5*anywheresoftware.b4a.keywords.Common.DateTime.TicksPerMinute),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 66;BA.debugLine="FLP.GetLastKnownLocation.Initialize";
_flp.GetLastKnownLocation().Initialize();
 //BA.debugLineNum = 67;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(medicomed.keymon.com.mx.tracker parent) {
this.parent = parent;
}
medicomed.keymon.com.mx.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 = 87;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 = 88;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 = 93;BA.debugLine="FLP.RequestLocationUpdates(CreateLocationRequest)";
parent._flp.RequestLocationUpdates((com.google.android.gms.location.LocationRequest)(_createlocationrequest().getObject()));
 //BA.debugLineNum = 96;BA.debugLine="flpStarted = True";
parent._flpstarted = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 98;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static void  _startflpsmall() throws Exception{
ResumableSub_StartFLPSmall rsub = new ResumableSub_StartFLPSmall(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_StartFLPSmall extends BA.ResumableSub {
public ResumableSub_StartFLPSmall(medicomed.keymon.com.mx.tracker parent) {
this.parent = parent;
}
medicomed.keymon.com.mx.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 = 102;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 = 103;BA.debugLine="Sleep(500)";
anywheresoftware.b4a.keywords.Common.Sleep(processBA,this,(int) (500));
this.state = 5;
return;
case 5:
//C
this.state = 1;
;
 //BA.debugLineNum = 104;BA.debugLine="Log(\"sleeping\")";
anywheresoftware.b4a.keywords.Common.LogImpl("777529092","sleeping",0);
 if (true) break;

case 4:
//C
this.state = -1;
;
 //BA.debugLineNum = 106;BA.debugLine="dameUltimaUbicacionConocida 'Regresamos ultima ub";
_dameultimaubicacionconocida();
 //BA.debugLineNum = 107;BA.debugLine="FLP.RequestLocationUpdates(CreateLocationRequestS";
parent._flp.RequestLocationUpdates((com.google.android.gms.location.LocationRequest)(_createlocationrequestsmalld().getObject()));
 //BA.debugLineNum = 110;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static String  _stopflp() throws Exception{
 //BA.debugLineNum = 147;BA.debugLine="Public Sub StopFLP";
 //BA.debugLineNum = 149;BA.debugLine="If flpStarted Then";
if (_flpstarted) { 
 //BA.debugLineNum = 150;BA.debugLine="FLP.RemoveLocationUpdates  'Eliminamos todas las";
_flp.RemoveLocationUpdates();
 //BA.debugLineNum = 151;BA.debugLine="flpStarted = False";
_flpstarted = anywheresoftware.b4a.keywords.Common.False;
 };
 //BA.debugLineNum = 153;BA.debugLine="End Sub";
return "";
}
public static String  _track() throws Exception{
 //BA.debugLineNum = 69;BA.debugLine="Public Sub Track";
 //BA.debugLineNum = 71;BA.debugLine="If Not(FLP.IsInitialized) Then FLP.Initialize(\"fl";
if (anywheresoftware.b4a.keywords.Common.Not(_flp.IsInitialized())) { 
_flp.Initialize(processBA,"flp");};
 //BA.debugLineNum = 72;BA.debugLine="If Not(FLP.IsConnected) Then FLP.Connect";
if (anywheresoftware.b4a.keywords.Common.Not(_flp.IsConnected())) { 
_flp.Connect();};
 //BA.debugLineNum = 73;BA.debugLine="If Tracking And actualLR.IsInitialized Then";
if (_tracking && _actuallr.IsInitialized()) { 
 //BA.debugLineNum = 75;BA.debugLine="Return 'Si ya estamos \"rastreando\" no hacemos na";
if (true) return "";
 };
 //BA.debugLineNum = 77;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 = 78;BA.debugLine="Log(\"No permission\")";
anywheresoftware.b4a.keywords.Common.LogImpl("777398025","No permission",0);
 //BA.debugLineNum = 79;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 81;BA.debugLine="StartFLP 'Iniciamos FusedLocationProvider";
_startflp();
 //BA.debugLineNum = 82;BA.debugLine="Tracking = True";
_tracking = anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 83;BA.debugLine="End Sub";
return "";
}
}
