package b4a.bbb;


import anywheresoftware.b4a.B4AMenuItem;
import android.app.Activity;
import android.os.Bundle;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.B4AActivity;
import anywheresoftware.b4a.ObjectWrapper;
import anywheresoftware.b4a.objects.ActivityWrapper;
import java.lang.reflect.InvocationTargetException;
import anywheresoftware.b4a.B4AUncaughtException;
import anywheresoftware.b4a.debug.*;
import java.lang.ref.WeakReference;

public class main extends Activity implements B4AActivity{
	public static main mostCurrent;
	static boolean afterFirstLayout;
	static boolean isFirst = true;
    private static boolean processGlobalsRun = false;
	BALayout layout;
	public static BA processBA;
	BA activityBA;
    ActivityWrapper _activity;
    java.util.ArrayList<B4AMenuItem> menuItems;
	public static final boolean fullScreen = false;
	public static final boolean includeTitle = false;
    public static WeakReference<Activity> previousOne;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mostCurrent = this;
		if (processBA == null) {
			processBA = new anywheresoftware.b4a.ShellBA(this.getApplicationContext(), null, null, "b4a.bbb", "b4a.bbb.main");
			processBA.loadHtSubs(this.getClass());
	        float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
	        BALayout.setDeviceScale(deviceScale);
            
		}
		else if (previousOne != null) {
			Activity p = previousOne.get();
			if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
				p.finish();
			}
		}
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
		if (!includeTitle) {
        	this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
        	getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
        			android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
		
        processBA.sharedProcessBA.activityBA = null;
		layout = new BALayout(this);
		setContentView(layout);
		afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();
        if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(this, processBA, wl, false))
		    BA.handler.postDelayed(wl, 5);

	}
	static class WaitForLayout implements Runnable {
		public void run() {
			if (afterFirstLayout)
				return;
			if (mostCurrent == null)
				return;
            
			if (mostCurrent.layout.getWidth() == 0) {
				BA.handler.postDelayed(this, 5);
				return;
			}
			mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
			mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
			afterFirstLayout = true;
			mostCurrent.afterFirstLayout();
		}
	}
	private void afterFirstLayout() {
        if (this != mostCurrent)
			return;
		activityBA = new BA(this, layout, processBA, "b4a.bbb", "b4a.bbb.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
			if (isFirst)
				processBA.raiseEvent2(null, true, "SHELL", false);
			processBA.raiseEvent2(null, true, "CREATE", true, "b4a.bbb.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
			_activity.reinitializeForShell(activityBA, "activity");
		}
        initializeProcessGlobals();		
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create, isFirst = " + isFirst + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
		isFirst = false;
		if (this != mostCurrent)
			return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
			try {
				android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	public void addMenuItem(B4AMenuItem item) {
		if (menuItems == null)
			menuItems = new java.util.ArrayList<B4AMenuItem>();
		menuItems.add(item);
	}
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		super.onCreateOptionsMenu(menu);
        try {
            if (processBA.subExists("activity_actionbarhomeclick")) {
                Class.forName("android.app.ActionBar").getMethod("setHomeButtonEnabled", boolean.class).invoke(
                    getClass().getMethod("getActionBar").invoke(this), true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (processBA.runHook("oncreateoptionsmenu", this, new Object[] {menu}))
            return true;
		if (menuItems == null)
			return false;
		for (B4AMenuItem bmi : menuItems) {
			android.view.MenuItem mi = menu.add(bmi.title);
			if (bmi.drawable != null)
				mi.setIcon(bmi.drawable);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
				try {
                    if (bmi.addToBar) {
				        android.view.MenuItem.class.getMethod("setShowAsAction", int.class).invoke(mi, 1);
                    }
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			mi.setOnMenuItemClickListener(new B4AMenuItemsClickListener(bmi.eventName.toLowerCase(BA.cul)));
		}
        
		return true;
	}   
 @Override
 public boolean onOptionsItemSelected(android.view.MenuItem item) {
    if (item.getItemId() == 16908332) {
        processBA.raiseEvent(null, "activity_actionbarhomeclick");
        return true;
    }
    else
        return super.onOptionsItemSelected(item); 
}
@Override
 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    processBA.runHook("onprepareoptionsmenu", this, new Object[] {menu});
    return true;
    
 }
 protected void onStart() {
    super.onStart();
    processBA.runHook("onstart", this, null);
}
 protected void onStop() {
    super.onStop();
    processBA.runHook("onstop", this, null);
}
    public void onWindowFocusChanged(boolean hasFocus) {
       super.onWindowFocusChanged(hasFocus);
       if (processBA.subExists("activity_windowfocuschanged"))
           processBA.raiseEvent2(null, true, "activity_windowfocuschanged", false, hasFocus);
    }
	private class B4AMenuItemsClickListener implements android.view.MenuItem.OnMenuItemClickListener {
		private final String eventName;
		public B4AMenuItemsClickListener(String eventName) {
			this.eventName = eventName;
		}
		public boolean onMenuItemClick(android.view.MenuItem item) {
			processBA.raiseEventFromUI(item.getTitle(), eventName + "_click");
			return true;
		}
	}
    public static Class<?> getObject() {
		return main.class;
	}
    private Boolean onKeySubExist = null;
    private Boolean onKeyUpSubExist = null;
	@Override
	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeydown", this, new Object[] {keyCode, event}))
            return true;
		if (onKeySubExist == null)
			onKeySubExist = processBA.subExists("activity_keypress");
		if (onKeySubExist) {
			if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK &&
					android.os.Build.VERSION.SDK_INT >= 18) {
				HandleKeyDelayed hk = new HandleKeyDelayed();
				hk.kc = keyCode;
				BA.handler.post(hk);
				return true;
			}
			else {
				boolean res = new HandleKeyDelayed().runDirectly(keyCode);
				if (res)
					return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	private class HandleKeyDelayed implements Runnable {
		int kc;
		public void run() {
			runDirectly(kc);
		}
		public boolean runDirectly(int keyCode) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keypress", false, keyCode);
			if (res == null || res == true) {
                return true;
            }
            else if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK) {
				finish();
				return true;
			}
            return false;
		}
		
	}
    @Override
	public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeyup", this, new Object[] {keyCode, event}))
            return true;
		if (onKeyUpSubExist == null)
			onKeyUpSubExist = processBA.subExists("activity_keyup");
		if (onKeyUpSubExist) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keyup", false, keyCode);
			if (res == null || res == true)
				return true;
		}
		return super.onKeyUp(keyCode, event);
	}
	@Override
	public void onNewIntent(android.content.Intent intent) {
        super.onNewIntent(intent);
		this.setIntent(intent);
        processBA.runHook("onnewintent", this, new Object[] {intent});
	}
    @Override 
	public void onPause() {
		super.onPause();
        if (_activity == null)
            return;
        if (this != mostCurrent)
			return;
		anywheresoftware.b4a.Msgbox.dismiss(true);
        BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
        if (mostCurrent != null)
            processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
        processBA.setActivityPaused(true);
        mostCurrent = null;
        if (!activityBA.activity.isFinishing())
			previousOne = new WeakReference<Activity>(this);
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        processBA.runHook("onpause", this, null);
	}

	@Override
	public void onDestroy() {
        super.onDestroy();
		previousOne = null;
        processBA.runHook("ondestroy", this, null);
	}
    @Override 
	public void onResume() {
		super.onResume();
        mostCurrent = this;
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (activityBA != null) { //will be null during activity create (which waits for AfterLayout).
        	ResumeMessage rm = new ResumeMessage(mostCurrent);
        	BA.handler.post(rm);
        }
        processBA.runHook("onresume", this, null);
	}
    private static class ResumeMessage implements Runnable {
    	private final WeakReference<Activity> activity;
    	public ResumeMessage(Activity activity) {
    		this.activity = new WeakReference<Activity>(activity);
    	}
		public void run() {
            main mc = mostCurrent;
			if (mc == null || mc != activity.get())
				return;
			processBA.setActivityPaused(false);
            BA.LogInfo("** Activity (main) Resume **");
            if (mc != mostCurrent)
                return;
		    processBA.raiseEvent(mc._activity, "activity_resume", (Object[])null);
		}
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode,
	      android.content.Intent data) {
		processBA.onActivityResult(requestCode, resultCode, data);
        processBA.runHook("onactivityresult", this, new Object[] {requestCode, resultCode});
	}
	private static void initializeGlobals() {
		processBA.raiseEvent2(null, true, "globals", false, (Object[])null);
	}
    public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
        for (int i = 0;i < permissions.length;i++) {
            Object[] o = new Object[] {permissions[i], grantResults[i] == 0};
            processBA.raiseEventFromDifferentThread(null,null, 0, "activity_permissionresult", true, o);
        }
            
    }



public static void initializeProcessGlobals() {
    
    if (main.processGlobalsRun == false) {
	    main.processGlobalsRun = true;
		try {
		        		
        } catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
}
public static boolean isAnyActivityVisible() {
    boolean vis = false;
vis = vis | (main.mostCurrent != null);
vis = vis | (setup.mostCurrent != null);
vis = vis | (cockpit.mostCurrent != null);
return vis;}

private static BA killProgramHelper(BA ba) {
    if (ba == null)
        return null;
    anywheresoftware.b4a.BA.SharedProcessBA sharedProcessBA = ba.sharedProcessBA;
    if (sharedProcessBA == null || sharedProcessBA.activityBA == null)
        return null;
    return sharedProcessBA.activityBA.get();
}
public static void killProgram() {
     {
            Activity __a = null;
            if (main.previousOne != null) {
				__a = main.previousOne.get();
			}
            else {
                BA ba = killProgramHelper(main.mostCurrent == null ? null : main.mostCurrent.processBA);
                if (ba != null) __a = ba.activity;
            }
            if (__a != null)
				__a.finish();}

BA.applicationContext.stopService(new android.content.Intent(BA.applicationContext, starter.class));
 {
            Activity __a = null;
            if (setup.previousOne != null) {
				__a = setup.previousOne.get();
			}
            else {
                BA ba = killProgramHelper(setup.mostCurrent == null ? null : setup.mostCurrent.processBA);
                if (ba != null) __a = ba.activity;
            }
            if (__a != null)
				__a.finish();}

 {
            Activity __a = null;
            if (cockpit.previousOne != null) {
				__a = cockpit.previousOne.get();
			}
            else {
                BA ba = killProgramHelper(cockpit.mostCurrent == null ? null : cockpit.mostCurrent.processBA);
                if (ba != null) __a = ba.activity;
            }
            if (__a != null)
				__a.finish();}

BA.applicationContext.stopService(new android.content.Intent(BA.applicationContext, collecte_data_sensor.class));
BA.applicationContext.stopService(new android.content.Intent(BA.applicationContext, httputils2service.class));
}
public anywheresoftware.b4a.keywords.Common __c = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnreaddata = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btndisconnect = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnscan = null;
public anywheresoftware.b4a.objects.LabelWrapper _lbldevicestatus = null;
public anywheresoftware.b4a.objects.LabelWrapper _lblstate = null;
public anywheresoftware.b4a.objects.ProgressBarWrapper _pbreaddata = null;
public anywheresoftware.b4a.objects.ProgressBarWrapper _pbscan = null;
public b4a.example3.customlistview _clv = null;
public anywheresoftware.b4a.agraham.byteconverter.ByteConverter _bc = null;
public anywheresoftware.b4a.objects.ButtonWrapper _bntreadservice = null;
public static String _service_battery = "";
public static String _level_battery = "";
public static String _service_temperature = "";
public static String _temperature = "";
public anywheresoftware.b4a.objects.ButtonWrapper _bntlevelbattery = null;
public anywheresoftware.b4a.objects.IME _ime = null;
public anywheresoftware.b4a.objects.LabelWrapper _lbaddsensor = null;
public b4a.bbb.starter _starter = null;
public b4a.bbb.param _param = null;
public b4a.bbb.setup _setup = null;
public b4a.bbb.cockpit _cockpit = null;
public b4a.bbb.collecte_data_sensor _collecte_data_sensor = null;
public b4a.bbb.httputils2service _httputils2service = null;
public static String  _activity_create(boolean _firsttime) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "activity_create", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "activity_create", new Object[] {_firsttime}));}
RDebugUtils.currentLine=131072;
 //BA.debugLineNum = 131072;BA.debugLine="Sub Activity_Create(FirstTime As Boolean)";
RDebugUtils.currentLine=131074;
 //BA.debugLineNum = 131074;BA.debugLine="Activity.LoadLayout(\"1\")";
mostCurrent._activity.LoadLayout("1",mostCurrent.activityBA);
RDebugUtils.currentLine=131077;
 //BA.debugLineNum = 131077;BA.debugLine="StartService(Collecte_data_sensor)";
anywheresoftware.b4a.keywords.Common.StartService(processBA,(Object)(mostCurrent._collecte_data_sensor.getObject()));
RDebugUtils.currentLine=131078;
 //BA.debugLineNum = 131078;BA.debugLine="StartActivity(Cockpit)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(mostCurrent._cockpit.getObject()));
RDebugUtils.currentLine=131080;
 //BA.debugLineNum = 131080;BA.debugLine="End Sub";
return "";
}
public static String  _activity_pause(boolean _userclosed) throws Exception{
RDebugUtils.currentModule="main";
RDebugUtils.currentLine=327680;
 //BA.debugLineNum = 327680;BA.debugLine="Sub Activity_Pause (UserClosed As Boolean)";
RDebugUtils.currentLine=327682;
 //BA.debugLineNum = 327682;BA.debugLine="End Sub";
return "";
}
public static String  _activity_resume() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "activity_resume", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "activity_resume", null));}
RDebugUtils.currentLine=196608;
 //BA.debugLineNum = 196608;BA.debugLine="Sub Activity_Resume";
RDebugUtils.currentLine=196610;
 //BA.debugLineNum = 196610;BA.debugLine="StateChanged";
_statechanged();
RDebugUtils.currentLine=196611;
 //BA.debugLineNum = 196611;BA.debugLine="End Sub";
return "";
}
public static String  _statechanged() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "statechanged", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "statechanged", null));}
RDebugUtils.currentLine=262144;
 //BA.debugLineNum = 262144;BA.debugLine="Public Sub StateChanged";
RDebugUtils.currentLine=262145;
 //BA.debugLineNum = 262145;BA.debugLine="lblState.Text = Starter.currentStateText";
mostCurrent._lblstate.setText(BA.ObjectToCharSequence(mostCurrent._starter._currentstatetext /*String*/ ));
RDebugUtils.currentLine=262146;
 //BA.debugLineNum = 262146;BA.debugLine="If Starter.connected Then";
if (mostCurrent._starter._connected /*boolean*/ ) { 
RDebugUtils.currentLine=262147;
 //BA.debugLineNum = 262147;BA.debugLine="lblDeviceStatus.Text = \"Connected: \" & Starter.C";
mostCurrent._lbldevicestatus.setText(BA.ObjectToCharSequence("Connected: "+mostCurrent._starter._connectedname /*String*/ ));
 }else {
RDebugUtils.currentLine=262149;
 //BA.debugLineNum = 262149;BA.debugLine="lblDeviceStatus.Text = \"Not connected\"";
mostCurrent._lbldevicestatus.setText(BA.ObjectToCharSequence("Not connected"));
 };
RDebugUtils.currentLine=262151;
 //BA.debugLineNum = 262151;BA.debugLine="btnDisconnect.Enabled = Starter.connected";
mostCurrent._btndisconnect.setEnabled(mostCurrent._starter._connected /*boolean*/ );
RDebugUtils.currentLine=262152;
 //BA.debugLineNum = 262152;BA.debugLine="btnScan.Enabled = Not(Starter.connected)";
mostCurrent._btnscan.setEnabled(anywheresoftware.b4a.keywords.Common.Not(mostCurrent._starter._connected /*boolean*/ ));
RDebugUtils.currentLine=262153;
 //BA.debugLineNum = 262153;BA.debugLine="pbReadData.Visible = False";
mostCurrent._pbreaddata.setVisible(anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=262154;
 //BA.debugLineNum = 262154;BA.debugLine="pbScan.Visible = False";
mostCurrent._pbscan.setVisible(anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=262155;
 //BA.debugLineNum = 262155;BA.debugLine="btnReadData.Enabled = Starter.connected";
mostCurrent._btnreaddata.setEnabled(mostCurrent._starter._connected /*boolean*/ );
RDebugUtils.currentLine=262156;
 //BA.debugLineNum = 262156;BA.debugLine="bntReadService.Enabled=Starter.connected";
mostCurrent._bntreadservice.setEnabled(mostCurrent._starter._connected /*boolean*/ );
RDebugUtils.currentLine=262157;
 //BA.debugLineNum = 262157;BA.debugLine="bntlevelBattery.Enabled=Starter.connected";
mostCurrent._bntlevelbattery.setEnabled(mostCurrent._starter._connected /*boolean*/ );
RDebugUtils.currentLine=262158;
 //BA.debugLineNum = 262158;BA.debugLine="btnScan.Enabled = (Starter.currentState = Starter";
mostCurrent._btnscan.setEnabled((mostCurrent._starter._currentstate /*int*/ ==mostCurrent._starter._manager /*anywheresoftware.b4a.objects.BleManager2*/ .STATE_POWERED_ON) && mostCurrent._starter._connected /*boolean*/ ==anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=262159;
 //BA.debugLineNum = 262159;BA.debugLine="End Sub";
return "";
}
public static String  _bntlevelbattery_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "bntlevelbattery_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "bntlevelbattery_click", null));}
RDebugUtils.currentLine=917504;
 //BA.debugLineNum = 917504;BA.debugLine="Sub bntlevelBattery_Click";
RDebugUtils.currentLine=917505;
 //BA.debugLineNum = 917505;BA.debugLine="Starter.manager.ReadData2(service_battery,Level_b";
mostCurrent._starter._manager /*anywheresoftware.b4a.objects.BleManager2*/ .ReadData2(mostCurrent._service_battery,mostCurrent._level_battery);
RDebugUtils.currentLine=917506;
 //BA.debugLineNum = 917506;BA.debugLine="End Sub";
return "";
}
public static String  _bntreadservice_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "bntreadservice_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "bntreadservice_click", null));}
RDebugUtils.currentLine=851968;
 //BA.debugLineNum = 851968;BA.debugLine="Sub bntReadService_Click";
RDebugUtils.currentLine=851969;
 //BA.debugLineNum = 851969;BA.debugLine="pbReadData.Visible = True";
mostCurrent._pbreaddata.setVisible(anywheresoftware.b4a.keywords.Common.True);
RDebugUtils.currentLine=851970;
 //BA.debugLineNum = 851970;BA.debugLine="clv.Clear";
mostCurrent._clv._clear();
RDebugUtils.currentLine=851971;
 //BA.debugLineNum = 851971;BA.debugLine="Starter.manager.SetNotify(service_Temperature,Tem";
mostCurrent._starter._manager /*anywheresoftware.b4a.objects.BleManager2*/ .SetNotify(mostCurrent._service_temperature,mostCurrent._temperature,anywheresoftware.b4a.keywords.Common.True);
RDebugUtils.currentLine=851973;
 //BA.debugLineNum = 851973;BA.debugLine="End Sub";
return "";
}
public static String  _btndisconnect_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btndisconnect_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "btndisconnect_click", null));}
RDebugUtils.currentLine=589824;
 //BA.debugLineNum = 589824;BA.debugLine="Sub btnDisconnect_Click";
RDebugUtils.currentLine=589825;
 //BA.debugLineNum = 589825;BA.debugLine="CallSub(Starter, \"Disconnect\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._starter.getObject()),"Disconnect");
RDebugUtils.currentLine=589826;
 //BA.debugLineNum = 589826;BA.debugLine="End Sub";
return "";
}
public static String  _btnreaddata_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btnreaddata_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "btnreaddata_click", null));}
RDebugUtils.currentLine=655360;
 //BA.debugLineNum = 655360;BA.debugLine="Sub btnReadData_Click";
RDebugUtils.currentLine=655361;
 //BA.debugLineNum = 655361;BA.debugLine="pbReadData.Visible = True";
mostCurrent._pbreaddata.setVisible(anywheresoftware.b4a.keywords.Common.True);
RDebugUtils.currentLine=655362;
 //BA.debugLineNum = 655362;BA.debugLine="clv.Clear";
mostCurrent._clv._clear();
RDebugUtils.currentLine=655363;
 //BA.debugLineNum = 655363;BA.debugLine="CallSub(Starter, \"ReadData\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(mostCurrent._starter.getObject()),"ReadData");
RDebugUtils.currentLine=655365;
 //BA.debugLineNum = 655365;BA.debugLine="End Sub";
return "";
}
public static void  _btnscan_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btnscan_click", false))
	 {Debug.delegate(mostCurrent.activityBA, "btnscan_click", null); return;}
ResumableSub_btnScan_Click rsub = new ResumableSub_btnScan_Click(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_btnScan_Click extends BA.ResumableSub {
public ResumableSub_btnScan_Click(b4a.bbb.main parent) {
this.parent = parent;
}
b4a.bbb.main parent;
String _permission = "";
boolean _result = false;

@Override
public void resume(BA ba, Object[] result) throws Exception{
RDebugUtils.currentModule="main";

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
RDebugUtils.currentLine=393217;
 //BA.debugLineNum = 393217;BA.debugLine="Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_";
parent.mostCurrent._starter._rp /*anywheresoftware.b4a.objects.RuntimePermissions*/ .CheckAndRequest(processBA,parent.mostCurrent._starter._rp /*anywheresoftware.b4a.objects.RuntimePermissions*/ .PERMISSION_ACCESS_COARSE_LOCATION);
RDebugUtils.currentLine=393218;
 //BA.debugLineNum = 393218;BA.debugLine="Wait For Activity_PermissionResult (Permission As";
anywheresoftware.b4a.keywords.Common.WaitFor("activity_permissionresult", processBA, new anywheresoftware.b4a.shell.DebugResumableSub.DelegatableResumableSub(this, "main", "btnscan_click"), null);
this.state = 7;
return;
case 7:
//C
this.state = 1;
_permission = (String) result[0];
_result = (Boolean) result[1];
;
RDebugUtils.currentLine=393219;
 //BA.debugLineNum = 393219;BA.debugLine="If Result = False Then Return";
if (true) break;

case 1:
//if
this.state = 6;
if (_result==anywheresoftware.b4a.keywords.Common.False) { 
this.state = 3;
;}if (true) break;

case 3:
//C
this.state = 6;
if (true) return ;
if (true) break;

case 6:
//C
this.state = -1;
;
RDebugUtils.currentLine=393220;
 //BA.debugLineNum = 393220;BA.debugLine="pbScan.Visible = True";
parent.mostCurrent._pbscan.setVisible(anywheresoftware.b4a.keywords.Common.True);
RDebugUtils.currentLine=393221;
 //BA.debugLineNum = 393221;BA.debugLine="CallSub(Starter, \"StartScan\")";
anywheresoftware.b4a.keywords.Common.CallSubDebug(processBA,(Object)(parent.mostCurrent._starter.getObject()),"StartScan");
RDebugUtils.currentLine=393222;
 //BA.debugLineNum = 393222;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static anywheresoftware.b4a.objects.PanelWrapper  _createcharacteristicitem(String _id,byte[] _data) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "createcharacteristicitem", false))
	 {return ((anywheresoftware.b4a.objects.PanelWrapper) Debug.delegate(mostCurrent.activityBA, "createcharacteristicitem", new Object[] {_id,_data}));}
anywheresoftware.b4a.objects.PanelWrapper _pnl = null;
anywheresoftware.b4a.objects.LabelWrapper _lbl = null;
anywheresoftware.b4a.objects.LabelWrapper _lbl2 = null;
RDebugUtils.currentLine=786432;
 //BA.debugLineNum = 786432;BA.debugLine="Sub CreateCharacteristicItem(Id As String, Data()";
RDebugUtils.currentLine=786433;
 //BA.debugLineNum = 786433;BA.debugLine="Dim pnl As Panel";
_pnl = new anywheresoftware.b4a.objects.PanelWrapper();
RDebugUtils.currentLine=786434;
 //BA.debugLineNum = 786434;BA.debugLine="pnl.Initialize(\"\")";
_pnl.Initialize(mostCurrent.activityBA,"");
RDebugUtils.currentLine=786435;
 //BA.debugLineNum = 786435;BA.debugLine="pnl.SetLayoutAnimated(0, 0, 0, clv.AsView.Width,";
_pnl.SetLayoutAnimated((int) (0),(int) (0),(int) (0),mostCurrent._clv._asview().getWidth(),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (40)));
RDebugUtils.currentLine=786436;
 //BA.debugLineNum = 786436;BA.debugLine="pnl.Color = Colors.White";
_pnl.setColor(anywheresoftware.b4a.keywords.Common.Colors.White);
RDebugUtils.currentLine=786437;
 //BA.debugLineNum = 786437;BA.debugLine="Dim lbl As Label";
_lbl = new anywheresoftware.b4a.objects.LabelWrapper();
RDebugUtils.currentLine=786438;
 //BA.debugLineNum = 786438;BA.debugLine="lbl.Initialize(\"\")";
_lbl.Initialize(mostCurrent.activityBA,"");
RDebugUtils.currentLine=786439;
 //BA.debugLineNum = 786439;BA.debugLine="lbl.Text = Id";
_lbl.setText(BA.ObjectToCharSequence(_id));
RDebugUtils.currentLine=786440;
 //BA.debugLineNum = 786440;BA.debugLine="pnl.AddView(lbl, 0, 0, clv.AsView.Width, 20dip)";
_pnl.AddView((android.view.View)(_lbl.getObject()),(int) (0),(int) (0),mostCurrent._clv._asview().getWidth(),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (20)));
RDebugUtils.currentLine=786441;
 //BA.debugLineNum = 786441;BA.debugLine="Dim lbl2 As Label";
_lbl2 = new anywheresoftware.b4a.objects.LabelWrapper();
RDebugUtils.currentLine=786442;
 //BA.debugLineNum = 786442;BA.debugLine="lbl2.Initialize(\"\")";
_lbl2.Initialize(mostCurrent.activityBA,"");
RDebugUtils.currentLine=786443;
 //BA.debugLineNum = 786443;BA.debugLine="Try";
try {RDebugUtils.currentLine=786444;
 //BA.debugLineNum = 786444;BA.debugLine="If Id=Level_battery Then";
if ((_id).equals(mostCurrent._level_battery)) { 
RDebugUtils.currentLine=786445;
 //BA.debugLineNum = 786445;BA.debugLine="lbl2.Text = \"Level Battery : \" & Data(0) & \"%\"";
_lbl2.setText(BA.ObjectToCharSequence("Level Battery : "+BA.NumberToString(_data[(int) (0)])+"%"));
 }else {
RDebugUtils.currentLine=786447;
 //BA.debugLineNum = 786447;BA.debugLine="lbl2.Text = BytesToString(Data, 0, Data.Length,";
_lbl2.setText(BA.ObjectToCharSequence(anywheresoftware.b4a.keywords.Common.BytesToString(_data,(int) (0),_data.length,"UTF8")));
 };
 } 
       catch (Exception e18) {
			processBA.setLastException(e18);RDebugUtils.currentLine=786451;
 //BA.debugLineNum = 786451;BA.debugLine="Log(LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("6786451",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
RDebugUtils.currentLine=786452;
 //BA.debugLineNum = 786452;BA.debugLine="lbl2.Text = \"Error reading data as string\"";
_lbl2.setText(BA.ObjectToCharSequence("Error reading data as string"));
 };
RDebugUtils.currentLine=786454;
 //BA.debugLineNum = 786454;BA.debugLine="lbl2.TextColor = 0xFF909090";
_lbl2.setTextColor((int) (0xff909090));
RDebugUtils.currentLine=786455;
 //BA.debugLineNum = 786455;BA.debugLine="lbl2.TextSize = 14";
_lbl2.setTextSize((float) (14));
RDebugUtils.currentLine=786456;
 //BA.debugLineNum = 786456;BA.debugLine="pnl.AddView(lbl2, 0, 20dip, clv.AsView.Width, 20d";
_pnl.AddView((android.view.View)(_lbl2.getObject()),(int) (0),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (20)),mostCurrent._clv._asview().getWidth(),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (20)));
RDebugUtils.currentLine=786457;
 //BA.debugLineNum = 786457;BA.debugLine="Return pnl";
if (true) return _pnl;
RDebugUtils.currentLine=786458;
 //BA.debugLineNum = 786458;BA.debugLine="End Sub";
return null;
}
public static anywheresoftware.b4a.objects.PanelWrapper  _createserviceitem(String _service) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "createserviceitem", false))
	 {return ((anywheresoftware.b4a.objects.PanelWrapper) Debug.delegate(mostCurrent.activityBA, "createserviceitem", new Object[] {_service}));}
anywheresoftware.b4a.objects.PanelWrapper _pnl = null;
anywheresoftware.b4a.objects.LabelWrapper _lbl = null;
RDebugUtils.currentLine=720896;
 //BA.debugLineNum = 720896;BA.debugLine="Sub CreateServiceItem (service As String) As Panel";
RDebugUtils.currentLine=720897;
 //BA.debugLineNum = 720897;BA.debugLine="Dim pnl As Panel";
_pnl = new anywheresoftware.b4a.objects.PanelWrapper();
RDebugUtils.currentLine=720898;
 //BA.debugLineNum = 720898;BA.debugLine="pnl.Initialize(\"\")";
_pnl.Initialize(mostCurrent.activityBA,"");
RDebugUtils.currentLine=720899;
 //BA.debugLineNum = 720899;BA.debugLine="pnl.Color = 0xFF808080";
_pnl.setColor((int) (0xff808080));
RDebugUtils.currentLine=720900;
 //BA.debugLineNum = 720900;BA.debugLine="pnl.SetLayoutAnimated(0, 0, 0, clv.AsView.Width,";
_pnl.SetLayoutAnimated((int) (0),(int) (0),(int) (0),mostCurrent._clv._asview().getWidth(),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (30)));
RDebugUtils.currentLine=720901;
 //BA.debugLineNum = 720901;BA.debugLine="Dim lbl As Label";
_lbl = new anywheresoftware.b4a.objects.LabelWrapper();
RDebugUtils.currentLine=720902;
 //BA.debugLineNum = 720902;BA.debugLine="lbl.Initialize(\"\")";
_lbl.Initialize(mostCurrent.activityBA,"");
RDebugUtils.currentLine=720903;
 //BA.debugLineNum = 720903;BA.debugLine="lbl.Text = service";
_lbl.setText(BA.ObjectToCharSequence(_service));
RDebugUtils.currentLine=720904;
 //BA.debugLineNum = 720904;BA.debugLine="lbl.Gravity = Gravity.CENTER";
_lbl.setGravity(anywheresoftware.b4a.keywords.Common.Gravity.CENTER);
RDebugUtils.currentLine=720905;
 //BA.debugLineNum = 720905;BA.debugLine="lbl.Typeface = Typeface.DEFAULT_BOLD";
_lbl.setTypeface(anywheresoftware.b4a.keywords.Common.Typeface.DEFAULT_BOLD);
RDebugUtils.currentLine=720906;
 //BA.debugLineNum = 720906;BA.debugLine="pnl.AddView(lbl, 0, 0, clv.AsView.Width, 30dip)";
_pnl.AddView((android.view.View)(_lbl.getObject()),(int) (0),(int) (0),mostCurrent._clv._asview().getWidth(),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (30)));
RDebugUtils.currentLine=720907;
 //BA.debugLineNum = 720907;BA.debugLine="Return pnl";
if (true) return _pnl;
RDebugUtils.currentLine=720908;
 //BA.debugLineNum = 720908;BA.debugLine="End Sub";
return null;
}
public static String  _dataavailable(String _service,anywheresoftware.b4a.objects.collections.Map _characteristics) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "dataavailable", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "dataavailable", new Object[] {_service,_characteristics}));}
String _id = "";
byte[] _value = null;
String _c = "";
RDebugUtils.currentLine=458752;
 //BA.debugLineNum = 458752;BA.debugLine="Sub DataAvailable (Service As String, Characterist";
RDebugUtils.currentLine=458753;
 //BA.debugLineNum = 458753;BA.debugLine="pbReadData.Visible = False";
mostCurrent._pbreaddata.setVisible(anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=458754;
 //BA.debugLineNum = 458754;BA.debugLine="clv.Add(CreateServiceItem(Service), \"\")";
mostCurrent._clv._add((anywheresoftware.b4a.objects.B4XViewWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.B4XViewWrapper(), (java.lang.Object)(_createserviceitem(_service).getObject())),(Object)(""));
RDebugUtils.currentLine=458755;
 //BA.debugLineNum = 458755;BA.debugLine="For Each id As String In Characteristics.Keys";
{
final anywheresoftware.b4a.BA.IterableList group3 = _characteristics.Keys();
final int groupLen3 = group3.getSize()
;int index3 = 0;
;
for (; index3 < groupLen3;index3++){
_id = BA.ObjectToString(group3.Get(index3));
RDebugUtils.currentLine=458757;
 //BA.debugLineNum = 458757;BA.debugLine="If Service=service_battery Then";
if ((_service).equals(mostCurrent._service_battery)) { 
RDebugUtils.currentLine=458758;
 //BA.debugLineNum = 458758;BA.debugLine="Dim value() As Byte=Characteristics.Get(id)";
_value = (byte[])(_characteristics.Get((Object)(_id)));
RDebugUtils.currentLine=458759;
 //BA.debugLineNum = 458759;BA.debugLine="clv.Add(CreateCharacteristicItem(id, value), \"\"";
mostCurrent._clv._add((anywheresoftware.b4a.objects.B4XViewWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.B4XViewWrapper(), (java.lang.Object)(_createcharacteristicitem(_id,_value).getObject())),(Object)(""));
RDebugUtils.currentLine=458760;
 //BA.debugLineNum = 458760;BA.debugLine="Log(\"Level Battery : \" & value(0) & \"%\")";
anywheresoftware.b4a.keywords.Common.LogImpl("6458760","Level Battery : "+BA.NumberToString(_value[(int) (0)])+"%",0);
 };
RDebugUtils.currentLine=458762;
 //BA.debugLineNum = 458762;BA.debugLine="clv.Add(CreateCharacteristicItem(id, Characteris";
mostCurrent._clv._add((anywheresoftware.b4a.objects.B4XViewWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.B4XViewWrapper(), (java.lang.Object)(_createcharacteristicitem(_id,(byte[])(_characteristics.Get((Object)(_id)))).getObject())),(Object)(""));
RDebugUtils.currentLine=458766;
 //BA.debugLineNum = 458766;BA.debugLine="Log(Service)";
anywheresoftware.b4a.keywords.Common.LogImpl("6458766",_service,0);
RDebugUtils.currentLine=458767;
 //BA.debugLineNum = 458767;BA.debugLine="Log(id & \";\" & Characteristics.Get(id))";
anywheresoftware.b4a.keywords.Common.LogImpl("6458767",_id+";"+BA.ObjectToString(_characteristics.Get((Object)(_id))),0);
 }
};
RDebugUtils.currentLine=458771;
 //BA.debugLineNum = 458771;BA.debugLine="For Each c As String In Characteristics.Keys";
{
final anywheresoftware.b4a.BA.IterableList group13 = _characteristics.Keys();
final int groupLen13 = group13.getSize()
;int index13 = 0;
;
for (; index13 < groupLen13;index13++){
_c = BA.ObjectToString(group13.Get(index13));
RDebugUtils.currentLine=458772;
 //BA.debugLineNum = 458772;BA.debugLine="PrintCharProperties(c, Starter.manager.GetCharac";
_printcharproperties(_c,mostCurrent._starter._manager /*anywheresoftware.b4a.objects.BleManager2*/ .GetCharacteristicProperties(_service,_c));
 }
};
RDebugUtils.currentLine=458774;
 //BA.debugLineNum = 458774;BA.debugLine="End Sub";
return "";
}
public static String  _printcharproperties(String _characteristic,int _properties) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "printcharproperties", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "printcharproperties", new Object[] {_characteristic,_properties}));}
anywheresoftware.b4a.objects.collections.Map _props = null;
int _key = 0;
RDebugUtils.currentLine=524288;
 //BA.debugLineNum = 524288;BA.debugLine="Sub PrintCharProperties(Characteristic As String,";
RDebugUtils.currentLine=524289;
 //BA.debugLineNum = 524289;BA.debugLine="Log($\"${Characteristic} Properties:\"$)";
anywheresoftware.b4a.keywords.Common.LogImpl("6524289",(""+anywheresoftware.b4a.keywords.Common.SmartStringFormatter("",(Object)(_characteristic))+" Properties:"),0);
RDebugUtils.currentLine=524290;
 //BA.debugLineNum = 524290;BA.debugLine="Dim props As Map = CreateMap(1: \"Broadcast\", 2: \"";
_props = new anywheresoftware.b4a.objects.collections.Map();
_props = anywheresoftware.b4a.keywords.Common.createMap(new Object[] {(Object)(1),(Object)("Broadcast"),(Object)(2),(Object)("Read"),(Object)(4),(Object)("WriteWithoutResponse"),(Object)(8),(Object)("Write"),(Object)(0x10),(Object)("Notify")});
RDebugUtils.currentLine=524292;
 //BA.debugLineNum = 524292;BA.debugLine="For Each key As Int In props.Keys";
{
final anywheresoftware.b4a.BA.IterableList group3 = _props.Keys();
final int groupLen3 = group3.getSize()
;int index3 = 0;
;
for (; index3 < groupLen3;index3++){
_key = (int)(BA.ObjectToNumber(group3.Get(index3)));
RDebugUtils.currentLine=524293;
 //BA.debugLineNum = 524293;BA.debugLine="If Bit.And(Properties, key) <> 0 Then Log(props.";
if (anywheresoftware.b4a.keywords.Common.Bit.And(_properties,_key)!=0) { 
anywheresoftware.b4a.keywords.Common.LogImpl("6524293",BA.ObjectToString(_props.Get((Object)(_key))),0);};
 }
};
RDebugUtils.currentLine=524295;
 //BA.debugLineNum = 524295;BA.debugLine="End Sub";
return "";
}
public static String  _lbaddsensor_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "lbaddsensor_click", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "lbaddsensor_click", null));}
RDebugUtils.currentLine=983040;
 //BA.debugLineNum = 983040;BA.debugLine="Sub lbAddSensor_Click";
RDebugUtils.currentLine=983042;
 //BA.debugLineNum = 983042;BA.debugLine="End Sub";
return "";
}
}