public static ShowExceptionAlert ( Android.App.Activity activity, string operation, |
||
activity | Android.App.Activity | |
operation | string | |
ex | ||
return | void |
async void AddTileButton_Click(object sender, EventArgs e) { if (0 == String.Compare(addTileButton.Text, AddTileString)) { // add tile try { BitmapFactory.Options options = new BitmapFactory.Options(); options.InScaled = false; var tile = new BandTile(tileId) { Icon = BandImage.FromBitmap(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options)), Name = "Altitude", SmallIcon = BandImage.FromBitmap(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options)), IsScreenTimeoutDisabled = true }; // define the page layout var pageLayout = new PageLayout { Root = new FlowPanel { Orientation = FlowPanelOrientation.Vertical, Rect = new PageRect(0, 0, 258, 128), } }; // Page1 line1 var line1 = new FlowPanel { Orientation = FlowPanelOrientation.Horizontal, Rect = new PageRect(0, 0, 258, 30), Elements = { new TextBlock { ElementId = 1, Rect = new PageRect(0, 0, 258, 30), Margins = new Margins(15, 0, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.Small, ColorSource = ElementColorSource.BandHighlight, }, new TextBlock { ElementId = 2, Rect = new PageRect(0, 0, 258, 30), Margins = new Margins(10, 0, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.Small } } }; // Page1 Line2 var line2 = new FlowPanel { Orientation = FlowPanelOrientation.Horizontal, Rect = new PageRect(0, 38, 280, 90), Elements = { new Icon { ElementId = 10, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(15, 35, 0, 0), VerticalAlignment = VerticalAlignment.Top, ColorSource = ElementColorSource.BandBase }, new Icon { ElementId = 11, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Top, Color = new BandColor(0xff, 0, 0) //red }, new Icon { ElementId = 12, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Color = new BandColor(0xff, 0xff, 0) //yellow }, new Icon { ElementId = 13, Rect = new PageRect(0, 0, 24, 24), Margins = new Margins(-24, 35, 0, 0), VerticalAlignment = VerticalAlignment.Bottom, Color = new BandColor(0, 0xff, 0) //green }, new TextBlock { ElementId = 5, Rect = new PageRect(0, 0, 228, 90), Margins = new Margins(10, 0, 0, 15), VerticalAlignment = VerticalAlignment.Bottom, Font = TextBlockFont.ExtraLargeNumbersBold } } }; pageLayout.Root.Elements.Add(line1); pageLayout.Root.Elements.Add(line2); // add the page layout to the tile tile.PageLayouts.Add(pageLayout); // add the tile to the Band await Model.Instance.Client.TileManager.AddTileAsync(tile); addTileButton.Text = RemoveTileString; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Add Tile", ex); } } else { // remove tile try { await Model.Instance.Client.TileManager.RemoveTileAsync(tileId); addTileButton.Text = AddTileString; } catch (Exception ex) { Util.ShowExceptionAlert(this, "Remove Tile", ex); } } }
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); } } }; }