package keymon.lat.medicomed;


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

public class newinst2 extends android.app.Service{
	public static class newinst2_BR extends android.content.BroadcastReceiver {

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

	}
    static newinst2 mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return newinst2.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new anywheresoftware.b4a.ShellBA(this, null, null, "keymon.lat.medicomed", "keymon.lat.medicomed.newinst2");
            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, "keymon.lat.medicomed.newinst2", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!false && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (newinst2) 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 (newinst2) 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 (newinst2) 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 (newinst2) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (newinst2) 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 String _pkg = "";
public static boolean _svcverbose = false;
public static int _logcolor1 = 0;
public b4a.example.dateutils _dateutils = null;
public keymon.lat.medicomed.main _main = null;
public keymon.lat.medicomed.starter _starter = null;
public keymon.lat.medicomed.subs _subs = null;
public keymon.lat.medicomed.appupdater _appupdater = null;
public keymon.lat.medicomed.mapa_rutas _mapa_rutas = null;
public keymon.lat.medicomed.tracker _tracker = null;
public keymon.lat.medicomed.b4xpages _b4xpages = null;
public keymon.lat.medicomed.b4xcollections _b4xcollections = null;
public keymon.lat.medicomed.httputils2service _httputils2service = null;
public keymon.lat.medicomed.xuiviewsutils _xuiviewsutils = null;
public static String  _getpackagename() throws Exception{
RDebugUtils.currentModule="newinst2";
if (Debug.shouldDelegate(processBA, "getpackagename", false))
	 {return ((String) Debug.delegate(processBA, "getpackagename", null));}
anywheresoftware.b4a.agraham.reflection.Reflection _r = null;
RDebugUtils.currentLine=32833536;
 //BA.debugLineNum = 32833536;BA.debugLine="Sub GetPackageName As String";
RDebugUtils.currentLine=32833537;
 //BA.debugLineNum = 32833537;BA.debugLine="Dim r As Reflector";
_r = new anywheresoftware.b4a.agraham.reflection.Reflection();
RDebugUtils.currentLine=32833538;
 //BA.debugLineNum = 32833538;BA.debugLine="Return r.GetStaticField(\"anywheresoftware.b4a.BA\"";
if (true) return BA.ObjectToString(_r.GetStaticField("anywheresoftware.b4a.BA","packageName"));
RDebugUtils.currentLine=32833539;
 //BA.debugLineNum = 32833539;BA.debugLine="End Sub";
return "";
}
public static String  _myappreload() throws Exception{
RDebugUtils.currentModule="newinst2";
if (Debug.shouldDelegate(processBA, "myappreload", false))
	 {return ((String) Debug.delegate(processBA, "myappreload", null));}
RDebugUtils.currentLine=32899072;
 //BA.debugLineNum = 32899072;BA.debugLine="Sub MyAppReload";
RDebugUtils.currentLine=32899073;
 //BA.debugLineNum = 32899073;BA.debugLine="If svcVerbose Then Log(\"-- AppUpdating.NewInst2:";
if (_svcverbose) { 
anywheresoftware.b4a.keywords.Common.LogImpl("332899073","-- AppUpdating.NewInst2: processing MyAppReload",0);};
RDebugUtils.currentLine=32899074;
 //BA.debugLineNum = 32899074;BA.debugLine="If IsPaused(\"main\") Then";
if (anywheresoftware.b4a.keywords.Common.IsPaused(processBA,(Object)("main"))) { 
RDebugUtils.currentLine=32899075;
 //BA.debugLineNum = 32899075;BA.debugLine="StartActivity(\"main\")";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)("main"));
 };
RDebugUtils.currentLine=32899079;
 //BA.debugLineNum = 32899079;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
RDebugUtils.currentModule="newinst2";
if (Debug.shouldDelegate(processBA, "service_create", false))
	 {return ((String) Debug.delegate(processBA, "service_create", null));}
RDebugUtils.currentLine=32636928;
 //BA.debugLineNum = 32636928;BA.debugLine="Sub Service_Create";
RDebugUtils.currentLine=32636929;
 //BA.debugLineNum = 32636929;BA.debugLine="LogColor(\"---- AppUpdating.newinst2: service crea";
anywheresoftware.b4a.keywords.Common.LogImpl("332636929","---- AppUpdating.newinst2: service created",_logcolor1);
RDebugUtils.currentLine=32636930;
 //BA.debugLineNum = 32636930;BA.debugLine="pkg = \"\"";
_pkg = "";
RDebugUtils.currentLine=32636931;
 //BA.debugLineNum = 32636931;BA.debugLine="svcVerbose = False";
_svcverbose = anywheresoftware.b4a.keywords.Common.False;
RDebugUtils.currentLine=32636932;
 //BA.debugLineNum = 32636932;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
RDebugUtils.currentModule="newinst2";
if (Debug.shouldDelegate(processBA, "service_destroy", false))
	 {return ((String) Debug.delegate(processBA, "service_destroy", null));}
RDebugUtils.currentLine=32768000;
 //BA.debugLineNum = 32768000;BA.debugLine="Sub Service_Destroy";
RDebugUtils.currentLine=32768001;
 //BA.debugLineNum = 32768001;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
RDebugUtils.currentModule="newinst2";
if (Debug.shouldDelegate(processBA, "service_start", false))
	 {return ((String) Debug.delegate(processBA, "service_start", new Object[] {_startingintent}));}
RDebugUtils.currentLine=32702464;
 //BA.debugLineNum = 32702464;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
RDebugUtils.currentLine=32702465;
 //BA.debugLineNum = 32702465;BA.debugLine="LogColor(\"---- AppUpdating.newinst2: service_star";
anywheresoftware.b4a.keywords.Common.LogImpl("332702465","---- AppUpdating.newinst2: service_started",_logcolor1);
RDebugUtils.currentLine=32702466;
 //BA.debugLineNum = 32702466;BA.debugLine="If svcVerbose Then";
if (_svcverbose) { 
RDebugUtils.currentLine=32702467;
 //BA.debugLineNum = 32702467;BA.debugLine="Log($\"${TAB}intent: ${StartingIntent}\"$)";
anywheresoftware.b4a.keywords.Common.LogImpl("332702467",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"intent: "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_startingintent.getObject()))+""),0);
RDebugUtils.currentLine=32702468;
 //BA.debugLineNum = 32702468;BA.debugLine="Log($\"${TAB}action: ${StartingIntent.Action}\"$)";
anywheresoftware.b4a.keywords.Common.LogImpl("332702468",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"action: "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_startingintent.getAction()))+""),0);
RDebugUtils.currentLine=32702469;
 //BA.debugLineNum = 32702469;BA.debugLine="Log($\"${TAB}extra: ${StartingIntent.ExtrasToStri";
anywheresoftware.b4a.keywords.Common.LogImpl("332702469",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"extra: "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_startingintent.ExtrasToString()))+""),0);
RDebugUtils.currentLine=32702470;
 //BA.debugLineNum = 32702470;BA.debugLine="Log($\"${TAB}data: ${StartingIntent.GetData}\"$)";
anywheresoftware.b4a.keywords.Common.LogImpl("332702470",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"data: "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_startingintent.GetData()))+""),0);
 };
RDebugUtils.currentLine=32702472;
 //BA.debugLineNum = 32702472;BA.debugLine="If StartingIntent.Action = \"android.intent.action";
if ((_startingintent.getAction()).equals("android.intent.action.MY_PACKAGE_REPLACED")) { 
RDebugUtils.currentLine=32702473;
 //BA.debugLineNum = 32702473;BA.debugLine="If svcVerbose Then Log($\"${TAB}Intent MY_PACKAGE";
if (_svcverbose) { 
anywheresoftware.b4a.keywords.Common.LogImpl("332702473",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"Intent MY_PACKAGE_REPLACED received!"),0);};
RDebugUtils.currentLine=32702474;
 //BA.debugLineNum = 32702474;BA.debugLine="pkg = GetPackageName";
_pkg = _getpackagename();
RDebugUtils.currentLine=32702475;
 //BA.debugLineNum = 32702475;BA.debugLine="If svcVerbose Then Log($\"${TAB}package: ${pkg}\"$";
if (_svcverbose) { 
anywheresoftware.b4a.keywords.Common.LogImpl("332702475",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(anywheresoftware.b4a.keywords.Common.TAB))+"package: "+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_pkg))+""),0);};
RDebugUtils.currentLine=32702476;
 //BA.debugLineNum = 32702476;BA.debugLine="MyAppReload";
_myappreload();
 };
RDebugUtils.currentLine=32702478;
 //BA.debugLineNum = 32702478;BA.debugLine="End Sub";
return "";
}
}