package b4a.HC05DataLogger;


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 = true;
    public static WeakReference<Activity> previousOne;
    public static boolean dontPause;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mostCurrent = this;
		if (processBA == null) {
			processBA = new anywheresoftware.b4a.ShellBA(this.getApplicationContext(), null, null, "b4a.HC05DataLogger", "b4a.HC05DataLogger.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.HC05DataLogger", "b4a.HC05DataLogger.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.HC05DataLogger.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
			_activity.reinitializeForShell(activityBA, "activity");
		}
        initializeProcessGlobals();		
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create " + (isFirst ? "(first time)" : "") + " **");
        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);
        if (!dontPause)
            BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
        else
            BA.LogInfo("** Activity (main) Pause event (activity is not paused). **");
        if (mostCurrent != null)
            processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
        if (!dontPause) {
            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);
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));
}
public anywheresoftware.b4a.keywords.Common __c = null;
public static anywheresoftware.b4a.objects.RuntimePermissions _rp = null;
public b4a.HC05DataLogger.bluetoothasynchstream _bta = null;
public anywheresoftware.b4a.objects.CompoundButtonWrapper.ToggleButtonWrapper _tbtled = null;
public anywheresoftware.b4a.objects.LabelWrapper _lblstatus = null;
public anywheresoftware.b4a.objects.ProgressBarWrapper _progressbar1 = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnconnect = null;
public anywheresoftware.b4a.objects.LabelWrapper _lblmessage = null;
public anywheresoftware.b4a.objects.PanelWrapper _pnldisplay = null;
public anywheresoftware.b4a.objects.drawable.CanvasWrapper _cvsdisplay = null;
public static double _value = 0;
public static int _counter = 0;
public static int _xstep = 0;
public static double _scale = 0;
public static int _x0 = 0;
public static int _y0 = 0;
public static int _x1 = 0;
public static int _y1 = 0;
public anywheresoftware.b4a.objects.drawable.CanvasWrapper.RectWrapper _rectdisplay = null;
public anywheresoftware.b4a.objects.drawable.CanvasWrapper.RectWrapper _rectval = null;
public static String _devicename = "";
public static boolean _connected = false;
public b4a.HC05DataLogger.starter _starter = 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=131073;
 //BA.debugLineNum = 131073;BA.debugLine="Activity.LoadLayout(\"Main\")";
mostCurrent._activity.LoadLayout("Main",mostCurrent.activityBA);
RDebugUtils.currentLine=131076;
 //BA.debugLineNum = 131076;BA.debugLine="BTA.Initialize(Me, \"BTA\", lblStatus, ProgressBar1";
mostCurrent._bta._initialize /*String*/ (null,mostCurrent.activityBA,main.getObject(),"BTA",mostCurrent._lblstatus,mostCurrent._progressbar1);
RDebugUtils.currentLine=131078;
 //BA.debugLineNum = 131078;BA.debugLine="cvsDisplay.Initialize(pnlDisplay)";
mostCurrent._cvsdisplay.Initialize((android.view.View)(mostCurrent._pnldisplay.getObject()));
RDebugUtils.currentLine=131079;
 //BA.debugLineNum = 131079;BA.debugLine="rectDisplay.Initialize(0, 0, pnlDisplay.Width, pn";
mostCurrent._rectdisplay.Initialize((int) (0),(int) (0),mostCurrent._pnldisplay.getWidth(),mostCurrent._pnldisplay.getHeight());
RDebugUtils.currentLine=131080;
 //BA.debugLineNum = 131080;BA.debugLine="DrawInit	'initializes the drawing";
_drawinit();
RDebugUtils.currentLine=131081;
 //BA.debugLineNum = 131081;BA.debugLine="End Sub";
return "";
}
public static String  _drawinit() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "drawinit", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "drawinit", null));}
RDebugUtils.currentLine=589824;
 //BA.debugLineNum = 589824;BA.debugLine="Private Sub DrawInit";
RDebugUtils.currentLine=589825;
 //BA.debugLineNum = 589825;BA.debugLine="Scale = pnlDisplay.Height / 5";
_scale = mostCurrent._pnldisplay.getHeight()/(double)5;
RDebugUtils.currentLine=589826;
 //BA.debugLineNum = 589826;BA.debugLine="End Sub";
return "";
}
public static String  _activity_pause(boolean _userclosed) throws Exception{
RDebugUtils.currentModule="main";
RDebugUtils.currentLine=262144;
 //BA.debugLineNum = 262144;BA.debugLine="Sub Activity_Pause (UserClosed As Boolean)";
RDebugUtils.currentLine=262145;
 //BA.debugLineNum = 262145;BA.debugLine="If UserClosed = True And Connected = True Then";
if (_userclosed==anywheresoftware.b4a.keywords.Common.True && _connected==anywheresoftware.b4a.keywords.Common.True) { 
RDebugUtils.currentLine=262146;
 //BA.debugLineNum = 262146;BA.debugLine="BTA.SendBytes(Array As Byte(0))";
mostCurrent._bta._sendbytes /*String*/ (null,new byte[]{(byte) (0)});
RDebugUtils.currentLine=262147;
 //BA.debugLineNum = 262147;BA.debugLine="BTA.Disconnect";
mostCurrent._bta._disconnect /*String*/ (null);
 };
RDebugUtils.currentLine=262149;
 //BA.debugLineNum = 262149;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="End Sub";
return "";
}
public static String  _bta_connected(boolean _success) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "bta_connected", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "bta_connected", new Object[] {_success}));}
RDebugUtils.currentLine=524288;
 //BA.debugLineNum = 524288;BA.debugLine="Private Sub BTA_Connected (Success As Boolean)";
RDebugUtils.currentLine=524289;
 //BA.debugLineNum = 524289;BA.debugLine="If Success = True Then";
if (_success==anywheresoftware.b4a.keywords.Common.True) { 
RDebugUtils.currentLine=524290;
 //BA.debugLineNum = 524290;BA.debugLine="Connected = Success";
_connected = _success;
RDebugUtils.currentLine=524291;
 //BA.debugLineNum = 524291;BA.debugLine="btnConnect.Enabled = False";
mostCurrent._btnconnect.setEnabled(anywheresoftware.b4a.keywords.Common.False);
RDebugUtils.currentLine=524292;
 //BA.debugLineNum = 524292;BA.debugLine="tbtLED.Enabled = True";
mostCurrent._tbtled.setEnabled(anywheresoftware.b4a.keywords.Common.True);
 };
RDebugUtils.currentLine=524294;
 //BA.debugLineNum = 524294;BA.debugLine="End Sub";
return "";
}
public static String  _bta_newtext(String _msg) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "bta_newtext", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "bta_newtext", new Object[] {_msg}));}
double _val = 0;
RDebugUtils.currentLine=327680;
 //BA.debugLineNum = 327680;BA.debugLine="Public Sub BTA_NewText(msg As String)";
RDebugUtils.currentLine=327681;
 //BA.debugLineNum = 327681;BA.debugLine="If lblMessage.Text <> \"No data\"	Then";
if ((mostCurrent._lblmessage.getText()).equals("No data") == false) { 
RDebugUtils.currentLine=327682;
 //BA.debugLineNum = 327682;BA.debugLine="Private Val As Double";
_val = 0;
RDebugUtils.currentLine=327683;
 //BA.debugLineNum = 327683;BA.debugLine="Val = msg";
_val = (double)(Double.parseDouble(_msg));
RDebugUtils.currentLine=327684;
 //BA.debugLineNum = 327684;BA.debugLine="Value = 5 * Val / 1024";
_value = 5*_val/(double)1024;
RDebugUtils.currentLine=327685;
 //BA.debugLineNum = 327685;BA.debugLine="lblMessage.Text = NumberFormat(Value, 0, 2)";
mostCurrent._lblmessage.setText(BA.ObjectToCharSequence(anywheresoftware.b4a.keywords.Common.NumberFormat(_value,(int) (0),(int) (2))));
RDebugUtils.currentLine=327687;
 //BA.debugLineNum = 327687;BA.debugLine="DrawValue";
_drawvalue();
 };
RDebugUtils.currentLine=327689;
 //BA.debugLineNum = 327689;BA.debugLine="End Sub";
return "";
}
public static String  _drawvalue() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "drawvalue", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "drawvalue", null));}
RDebugUtils.currentLine=655360;
 //BA.debugLineNum = 655360;BA.debugLine="Private Sub DrawValue";
RDebugUtils.currentLine=655361;
 //BA.debugLineNum = 655361;BA.debugLine="Counter = Counter + XStep";
_counter = (int) (_counter+_xstep);
RDebugUtils.currentLine=655362;
 //BA.debugLineNum = 655362;BA.debugLine="x1 = Counter";
_x1 = _counter;
RDebugUtils.currentLine=655363;
 //BA.debugLineNum = 655363;BA.debugLine="y1 = pnlDisplay.Height - Value * Scale";
_y1 = (int) (mostCurrent._pnldisplay.getHeight()-_value*_scale);
RDebugUtils.currentLine=655364;
 //BA.debugLineNum = 655364;BA.debugLine="rectVal.Initialize(x0, 0, x1, pnlDisplay.Height)";
mostCurrent._rectval.Initialize(_x0,(int) (0),_x1,mostCurrent._pnldisplay.getHeight());
RDebugUtils.currentLine=655365;
 //BA.debugLineNum = 655365;BA.debugLine="cvsDisplay.DrawLine(x0, y0, x1, y1, Colors.Red, 1";
mostCurrent._cvsdisplay.DrawLine((float) (_x0),(float) (_y0),(float) (_x1),(float) (_y1),anywheresoftware.b4a.keywords.Common.Colors.Red,(float) (anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (1))));
RDebugUtils.currentLine=655366;
 //BA.debugLineNum = 655366;BA.debugLine="pnlDisplay.Invalidate2(rectVal)";
mostCurrent._pnldisplay.Invalidate2((android.graphics.Rect)(mostCurrent._rectval.getObject()));
RDebugUtils.currentLine=655367;
 //BA.debugLineNum = 655367;BA.debugLine="x0 =x1";
_x0 = _x1;
RDebugUtils.currentLine=655368;
 //BA.debugLineNum = 655368;BA.debugLine="y0 = y1";
_y0 = _y1;
RDebugUtils.currentLine=655370;
 //BA.debugLineNum = 655370;BA.debugLine="If Counter >= pnlDisplay.Width Then";
if (_counter>=mostCurrent._pnldisplay.getWidth()) { 
RDebugUtils.currentLine=655371;
 //BA.debugLineNum = 655371;BA.debugLine="x0 = 0";
_x0 = (int) (0);
RDebugUtils.currentLine=655372;
 //BA.debugLineNum = 655372;BA.debugLine="Counter = 0";
_counter = (int) (0);
RDebugUtils.currentLine=655373;
 //BA.debugLineNum = 655373;BA.debugLine="cvsDisplay.DrawRect(rectDisplay, Colors.White, T";
mostCurrent._cvsdisplay.DrawRect((android.graphics.Rect)(mostCurrent._rectdisplay.getObject()),anywheresoftware.b4a.keywords.Common.Colors.White,anywheresoftware.b4a.keywords.Common.True,(float) (1));
RDebugUtils.currentLine=655374;
 //BA.debugLineNum = 655374;BA.debugLine="pnlDisplay.Invalidate";
mostCurrent._pnldisplay.Invalidate();
 };
RDebugUtils.currentLine=655376;
 //BA.debugLineNum = 655376;BA.debugLine="End Sub";
return "";
}
public static void  _btnconnect_click() throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "btnconnect_click", false))
	 {Debug.delegate(mostCurrent.activityBA, "btnconnect_click", null); return;}
ResumableSub_btnConnect_Click rsub = new ResumableSub_btnConnect_Click(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_btnConnect_Click extends BA.ResumableSub {
public ResumableSub_btnConnect_Click(b4a.HC05DataLogger.main parent) {
this.parent = parent;
}
b4a.HC05DataLogger.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=458753;
 //BA.debugLineNum = 458753;BA.debugLine="rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCA";
parent._rp.CheckAndRequest(processBA,parent._rp.PERMISSION_ACCESS_FINE_LOCATION);
RDebugUtils.currentLine=458754;
 //BA.debugLineNum = 458754;BA.debugLine="Wait For Activity_PermissionResult (Permission As";
anywheresoftware.b4a.keywords.Common.WaitFor("activity_permissionresult", processBA, new anywheresoftware.b4a.shell.DebugResumableSub.DelegatableResumableSub(this, "main", "btnconnect_click"), null);
this.state = 7;
return;
case 7:
//C
this.state = 1;
_permission = (String) result[0];
_result = (Boolean) result[1];
;
RDebugUtils.currentLine=458755;
 //BA.debugLineNum = 458755;BA.debugLine="If Result = False Then";
if (true) break;

case 1:
//if
this.state = 6;
if (_result==anywheresoftware.b4a.keywords.Common.False) { 
this.state = 3;
}else {
this.state = 5;
}if (true) break;

case 3:
//C
this.state = 6;
RDebugUtils.currentLine=458756;
 //BA.debugLineNum = 458756;BA.debugLine="lblStatus.Text = \"No permission...\"";
parent.mostCurrent._lblstatus.setText(BA.ObjectToCharSequence("No permission..."));
 if (true) break;

case 5:
//C
this.state = 6;
RDebugUtils.currentLine=458758;
 //BA.debugLineNum = 458758;BA.debugLine="BTA.Connect(DeviceName)";
parent.mostCurrent._bta._connect /*String*/ (null,parent.mostCurrent._devicename);
 if (true) break;

case 6:
//C
this.state = -1;
;
RDebugUtils.currentLine=458760;
 //BA.debugLineNum = 458760;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static String  _tbtled_checkedchange(boolean _checked) throws Exception{
RDebugUtils.currentModule="main";
if (Debug.shouldDelegate(mostCurrent.activityBA, "tbtled_checkedchange", false))
	 {return ((String) Debug.delegate(mostCurrent.activityBA, "tbtled_checkedchange", new Object[] {_checked}));}
byte _b = (byte)0;
RDebugUtils.currentLine=393216;
 //BA.debugLineNum = 393216;BA.debugLine="Sub tbtLED_CheckedChange(Checked As Boolean)";
RDebugUtils.currentLine=393217;
 //BA.debugLineNum = 393217;BA.debugLine="Dim b As Byte";
_b = (byte)0;
RDebugUtils.currentLine=393218;
 //BA.debugLineNum = 393218;BA.debugLine="If Checked = True Then";
if (_checked==anywheresoftware.b4a.keywords.Common.True) { 
RDebugUtils.currentLine=393219;
 //BA.debugLineNum = 393219;BA.debugLine="b = 1";
_b = (byte) (1);
RDebugUtils.currentLine=393220;
 //BA.debugLineNum = 393220;BA.debugLine="lblMessage.Text = \"\"";
mostCurrent._lblmessage.setText(BA.ObjectToCharSequence(""));
 }else {
RDebugUtils.currentLine=393222;
 //BA.debugLineNum = 393222;BA.debugLine="b = 0";
_b = (byte) (0);
RDebugUtils.currentLine=393223;
 //BA.debugLineNum = 393223;BA.debugLine="lblMessage.Text = \"No data\"";
mostCurrent._lblmessage.setText(BA.ObjectToCharSequence("No data"));
 };
RDebugUtils.currentLine=393225;
 //BA.debugLineNum = 393225;BA.debugLine="BTA.SendBytes(Array As Byte(b))";
mostCurrent._bta._sendbytes /*String*/ (null,new byte[]{_b});
RDebugUtils.currentLine=393226;
 //BA.debugLineNum = 393226;BA.debugLine="End Sub";
return "";
}
}