protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); ClipboardInterface.GetInstance().SetClipboardManager((ClipboardManager)GetSystemService(Context.ClipboardService)); commManager = CommunicationManger.GetInstance(); txtState = FindViewById <TextView>(Resource.Id.txtState); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar1); var searchBtn = FindViewById <Button>(Resource.Id.searchBtn); txtState.Text = "Searching for server"; txtState.Visibility = ViewStates.Gone; progressBar.Visibility = ViewStates.Gone; searchBtn.Click += (sender, args) => SearchServer(30); onSearchEnd += SearchEnded; if (!commManager.IsBluetoothExists()) { Console.WriteLine("finished"); Toast.MakeText(this, "No bluetooth adapter found", ToastLength.Long); Finish(); return; } if (!commManager.IsBluetoothOn()) { Intent enableIntent = new Intent(BluetoothAdapter.ActionRequestEnable); StartActivityForResult(enableIntent, 2); } Console.WriteLine("finished setup"); }
private void SearchServer(double sec) { if (!commManager.IsBluetoothOn()) { Intent enableIntent = new Intent(BluetoothAdapter.ActionRequestEnable); StartActivityForResult(enableIntent, 2); } if (commManager.Searching) { return; } txtState.Text = "Searching for server"; txtState.Visibility = ViewStates.Visible; progressBar.Visibility = ViewStates.Visible; new Thread(() => { bool res = commManager.TryConnect(sec); onSearchEnd.Invoke(this, new SearchEventArgs(res)); }).Start(); }