protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button connectButton = FindViewById <Button> (Resource.Id.connectButton); pressure = FindViewById <TextView> (Resource.Id.pressure); height = FindViewById <TextView> (Resource.Id.height); addTileButton = FindViewById <Button> (Resource.Id.addTileButton); addTileButton.Click += AddTileButton_Click; addTileButton.Enabled = false; connectButton.Click += async delegate { if (Model.Instance.Connected) { try { await barometer.StopReadingsAsync(); await Model.Instance.Client.DisconnectAsync(); Model.Instance.Client = null; pressure.Text = ""; connectButton.Text = "Connect Band!"; addTileButton.Enabled = false; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Disconnect", ex); } } else { try { var bandClientManager = BandClientManager.Instance; // query the service for paired devices var pairedBands = await bandClientManager.GetPairedBandsAsync(); // connect to the first device var bandInfo = pairedBands.FirstOrDefault(); var bandClient = await bandClientManager.ConnectAsync(bandInfo); Model.Instance.Client = bandClient; // get the current set of tiles IEnumerable <BandTile> tiles = await Model.Instance.Client.TileManager.GetTilesAsync(); // get the number of tiles we can add int capacity = await Model.Instance.Client.TileManager.GetRemainingTileCapacityAsync(); foreach (BandTile tile in tiles) { if (tile.Id.Equals(tileId)) { tileFound = true; } } if (tileFound) { addTileButton.Text = RemoveTileString; addTileButton.Enabled = true; } else if (capacity != 0) { addTileButton.Text = AddTileString; addTileButton.Enabled = true; } // get the barometer sensor barometer = bandClient.SensorManager.Barometer; // add a handler barometer.ReadingChanged += OnBarometerChanged; // zero AGL count = 0; await barometer.StartReadingsAsync(BandSensorSampleRate.Ms128); connectButton.Text = "Disconnect Band!"; addTileButton.Enabled = true; altitudeContent.PageId = pageId; altitudeContent.PageLayoutIndex = 1; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Connect", ex); } } }; }