package b9x.simple;


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

public class starter extends android.app.Service{
	public static class starter_BR extends android.content.BroadcastReceiver {

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

	}
    static starter mostCurrent;
	public static BA processBA;
    private ServiceHelper _service;
    public static Class<?> getObject() {
		return starter.class;
	}
	@Override
	public void onCreate() {
        super.onCreate();
        mostCurrent = this;
        if (processBA == null) {
		    processBA = new BA(this, null, null, "b9x.simple", "b9x.simple.starter");
            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, "b9x.simple.starter", processBA, _service, anywheresoftware.b4a.keywords.Common.Density);
		}
        if (!true && ServiceHelper.StarterHelper.startFromServiceCreate(processBA, false) == false) {
				
		}
		else {
            processBA.setActivityPaused(false);
            BA.LogInfo("*** Service (starter) Create ***");
            processBA.raiseEvent(null, "service_create");
        }
        processBA.runHook("oncreate", this, null);
        if (true) {
			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 (starter) 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 (true)
            processBA.raiseEvent(null, "service_taskremoved");
            
    }
    private void handleStart(android.content.Intent intent) {
    	BA.LogInfo("** Service (starter) 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 (starter) 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 (true) {
            BA.LogInfo("** Service (starter) Destroy (ignored)**");
        }
        else {
            BA.LogInfo("** Service (starter) 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 b4a.example.modvoice _v7 = null;
public static anywheresoftware.b4a.objects.RuntimePermissions _v5 = null;
public static anywheresoftware.b4a.phone.Phone.PhoneWakeState _vv4 = null;
public b9x.simple.main _vv3 = null;
public static boolean  _application_error(anywheresoftware.b4a.objects.B4AException _error,String _stacktrace) throws Exception{
 //BA.debugLineNum = 40;BA.debugLine="Sub Application_Error (Error As Exception, StackTr";
 //BA.debugLineNum = 41;BA.debugLine="Return True";
if (true) return anywheresoftware.b4a.keywords.Common.True;
 //BA.debugLineNum = 42;BA.debugLine="End Sub";
return false;
}
public static String  _broadcast(String _msg) throws Exception{
 //BA.debugLineNum = 76;BA.debugLine="Sub broadCast(msg As String)";
 //BA.debugLineNum = 77;BA.debugLine="voip.vBroadcast(msg) ' broadcast text message to";
_v7._vvvv5(_msg);
 //BA.debugLineNum = 78;BA.debugLine="End Sub";
return "";
}
public static String  _close() throws Exception{
 //BA.debugLineNum = 72;BA.debugLine="Sub close";
 //BA.debugLineNum = 73;BA.debugLine="voip.vClose(\"adminPassword\")' default admin passw";
_v7._vvvv7("adminPassword");
 //BA.debugLineNum = 74;BA.debugLine="End Sub";
return "";
}
public static String  _connect() throws Exception{
 //BA.debugLineNum = 68;BA.debugLine="Sub connect";
 //BA.debugLineNum = 69;BA.debugLine="Service.StartForeground(1, CreateNotification(\"Ba";
mostCurrent._service.StartForeground((int) (1),(android.app.Notification)(_v6("Background Audio").getObject()));
 //BA.debugLineNum = 70;BA.debugLine="voip.vConnect(\"adminPassword\") ' default admin pa";
_v7._vvvv0("adminPassword");
 //BA.debugLineNum = 71;BA.debugLine="End Sub";
return "";
}
public static anywheresoftware.b4a.objects.NotificationWrapper  _v6(String _body) throws Exception{
anywheresoftware.b4a.objects.NotificationWrapper _notification = null;
 //BA.debugLineNum = 47;BA.debugLine="Sub CreateNotification (Body As String) As Notific";
 //BA.debugLineNum = 48;BA.debugLine="Dim notification As Notification";
_notification = new anywheresoftware.b4a.objects.NotificationWrapper();
 //BA.debugLineNum = 49;BA.debugLine="notification.Initialize2(notification.IMPORTANCE_";
_notification.Initialize2(_notification.IMPORTANCE_LOW);
 //BA.debugLineNum = 50;BA.debugLine="notification.Icon = \"Icon\"";
_notification.setIcon("Icon");
 //BA.debugLineNum = 51;BA.debugLine="notification.SetInfo(\"Audio\", Body, Main)";
_notification.SetInfoNew(processBA,BA.ObjectToCharSequence("Audio"),BA.ObjectToCharSequence(_body),(Object)(mostCurrent._vv3.getObject()));
 //BA.debugLineNum = 52;BA.debugLine="Return notification";
if (true) return _notification;
 //BA.debugLineNum = 53;BA.debugLine="End Sub";
return null;
}
public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 6;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 9;BA.debugLine="Private voip As modVoice";
_v7 = new b4a.example.modvoice();
 //BA.debugLineNum = 10;BA.debugLine="Public rp As RuntimePermissions";
_v5 = new anywheresoftware.b4a.objects.RuntimePermissions();
 //BA.debugLineNum = 11;BA.debugLine="Private lock As PhoneWakeState";
_vv4 = new anywheresoftware.b4a.phone.Phone.PhoneWakeState();
 //BA.debugLineNum = 13;BA.debugLine="End Sub";
return "";
}
public static String  _service_create() throws Exception{
 //BA.debugLineNum = 15;BA.debugLine="Sub Service_Create";
 //BA.debugLineNum = 18;BA.debugLine="lock.PartialLock";
_vv4.PartialLock(processBA);
 //BA.debugLineNum = 19;BA.debugLine="If rp.Check(\"android.permission.RECORD_AUDIO\")=Tr";
if (_v5.Check("android.permission.RECORD_AUDIO")==anywheresoftware.b4a.keywords.Common.True) { 
 //BA.debugLineNum = 20;BA.debugLine="voip.Initialize(Me, \"vx\") ' initialize the libra";
_v7._initialize(processBA,starter.getObject(),"vx");
 //BA.debugLineNum = 21;BA.debugLine="voip.vSetlistenport(0) ' can be any 0 for a rand";
_v7._vvvvv5((int) (0));
 //BA.debugLineNum = 22;BA.debugLine="voip.vSetVOXTrigger(0) 'turn off vox, a value of";
_v7._vvvvv7((int) (0));
 //BA.debugLineNum = 23;BA.debugLine="voip.vSetkey(\"JZ624RAS127878AF901C423910763350\")";
_v7._vvvvv4("JZ624RAS127878AF901C423910763350");
 //BA.debugLineNum = 24;BA.debugLine="voip.vStartListening() ' listen for any received";
_v7._vvvvv0();
 }else {
 //BA.debugLineNum = 26;BA.debugLine="ToastMessageShow(\"Be sure to enable Microphone P";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Be sure to enable Microphone Permission before running app."),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 27;BA.debugLine="ExitApplication";
anywheresoftware.b4a.keywords.Common.ExitApplication();
 };
 //BA.debugLineNum = 29;BA.debugLine="End Sub";
return "";
}
public static String  _service_destroy() throws Exception{
 //BA.debugLineNum = 44;BA.debugLine="Sub Service_Destroy";
 //BA.debugLineNum = 45;BA.debugLine="lock.ReleasePartialLock";
_vv4.ReleasePartialLock();
 //BA.debugLineNum = 46;BA.debugLine="End Sub";
return "";
}
public static String  _service_start(anywheresoftware.b4a.objects.IntentWrapper _startingintent) throws Exception{
 //BA.debugLineNum = 31;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
 //BA.debugLineNum = 32;BA.debugLine="Service.StopAutomaticForeground 'Starter service";
mostCurrent._service.StopAutomaticForeground();
 //BA.debugLineNum = 33;BA.debugLine="End Sub";
return "";
}
public static String  _service_taskremoved() throws Exception{
 //BA.debugLineNum = 35;BA.debugLine="Sub Service_TaskRemoved";
 //BA.debugLineNum = 37;BA.debugLine="End Sub";
return "";
}
public static String  _sethostport(String _hst,String _port) throws Exception{
 //BA.debugLineNum = 55;BA.debugLine="Sub setHostPort(hst As String, port As String)";
 //BA.debugLineNum = 56;BA.debugLine="voip.vSetHost(hst) 'ip or hostname where B9X Serv";
_v7._vvvvv3(_hst);
 //BA.debugLineNum = 57;BA.debugLine="voip.vSetPort(port) ' default port of B9X Server";
_v7._vvvvv6((int)(Double.parseDouble(_port)));
 //BA.debugLineNum = 58;BA.debugLine="End Sub";
return "";
}
public static String  _startsending() throws Exception{
 //BA.debugLineNum = 62;BA.debugLine="Sub startSending";
 //BA.debugLineNum = 63;BA.debugLine="voip.vStartSending ' send audio to all who are co";
_v7._vvvvvv1();
 //BA.debugLineNum = 64;BA.debugLine="End Sub";
return "";
}
public static String  _stopsending() throws Exception{
 //BA.debugLineNum = 65;BA.debugLine="Sub stopSending";
 //BA.debugLineNum = 66;BA.debugLine="voip.vStopSending ' stop sending audio";
_v7._vvvvvv3();
 //BA.debugLineNum = 67;BA.debugLine="End Sub";
return "";
}
public static String  _voxoff() throws Exception{
 //BA.debugLineNum = 82;BA.debugLine="Sub voxOff";
 //BA.debugLineNum = 83;BA.debugLine="voip.vSetVOXTrigger(0) ' turn vox off";
_v7._vvvvv7((int) (0));
 //BA.debugLineNum = 84;BA.debugLine="End Sub";
return "";
}
public static String  _voxon() throws Exception{
 //BA.debugLineNum = 79;BA.debugLine="Sub voxOn";
 //BA.debugLineNum = 80;BA.debugLine="voip.vSetVOXTrigger(3000) ' turn vox on with sens";
_v7._vvvvv7((int) (3000));
 //BA.debugLineNum = 81;BA.debugLine="End Sub";
return "";
}
public static String  _vx_messagereceived(String _msg) throws Exception{
 //BA.debugLineNum = 59;BA.debugLine="Sub vx_messageReceived(msg As String)";
 //BA.debugLineNum = 60;BA.debugLine="CallSubDelayed2(Main, \"voipMessage\",msg) ' status";
anywheresoftware.b4a.keywords.Common.CallSubDelayed2(processBA,(Object)(mostCurrent._vv3.getObject()),"voipMessage",(Object)(_msg));
 //BA.debugLineNum = 61;BA.debugLine="End Sub";
return "";
}
}
