Beispiel #1
0
        public async Task AddTile()
        {
            // Tile Definition
            var myTile = new BandTile(TileId)
            {
                Name      = "El Bruno Tile Simple",
                TileIcon  = await ImageHelper.LoadIcon("ms-appx:///Assets/RugbyBall46.png"),
                SmallIcon = await ImageHelper.LoadIcon("ms-appx:///Assets/RugbyBall24.png")
            };

            // Page UI
            var button = new TextButton
            {
                ElementId = 1,
                Rect      = new PageRect(10, 10, 200, 90)
            };
            var panel = new FilledPanel(button)
            {
                Rect = new PageRect(0, 0, 220, 150)
            };

            myTile.PageLayouts.Add(new PageLayout(panel));

            await BandHub.Instance.BandClient.TileManager.RemoveTileAsync(TileId);

            await BandHub.Instance.BandClient.TileManager.AddTileAsync(myTile);

            // Page Data
            var pageId      = new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200");
            var textButtonA = new TextButtonData(1, "El Button");
            var page        = new PageData(pageId, 0, textButtonA);
            await BandHub.Instance.BandClient.TileManager.SetPagesAsync(TileId, page);
        }
Beispiel #2
0
        async partial void AddButtonPageClick(UIButton sender)
        {
            if (client != null && client.IsConnected)
            {
                Output("Creating tile...");

                // remove an old tile
                try {
                    var tiles = await client.TileManager.GetTilesTaskAsync();

                    if (tiles.Any(x => x.TileId.AsString() == tileId.AsString()))
                    {
                        // a tile exists, so remove it
                        await client.TileManager.RemoveTileTaskAsync(tileId);

                        Output("Removed tile!");
                    }
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }

                // create the tile
                NSError operationError;
                var     tileName  = "iOS Sample";
                var     tileIcon  = BandIcon.FromUIImage(UIImage.FromBundle("tile.png"), out operationError);
                var     smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("badge.png"), out operationError);
                var     tile      = BandTile.Create(tileId, tileName, tileIcon, smallIcon, out operationError);
                tile.BadgingEnabled = true;

                // create the button page
                var textBlock = new TextBlock(PageRect.Create(0, 0, 200, 40), TextBlockFont.Small);
                textBlock.ElementId           = 10;
                textBlock.Baseline            = 25;
                textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                textBlock.BaselineAlignment   = TextBlockBaselineAlignment.Relative;
                textBlock.AutoWidth           = false;
                textBlock.Color   = BandColor.FromUIColor(UIColor.Red, out operationError);
                textBlock.Margins = Margins.Create(5, 2, 5, 2);

                var button = new TextButton(PageRect.Create(0, 0, 200, 40));
                button.ElementId           = 11;
                button.HorizontalAlignment = HorizontalAlignment.Center;
                button.PressedColor        = BandColor.FromUIColor(UIColor.Purple, out operationError);
                button.Margins             = Margins.Create(5, 2, 5, 2);

                var flowPanel = new FlowPanel(PageRect.Create(15, 0, 260, 105));
                flowPanel.AddElement(textBlock);
                flowPanel.AddElement(button);

                var pageLayout = new PageLayout();
                pageLayout.Root = flowPanel;
                tile.PageLayouts.Add(pageLayout);

                // add the tile to the band
                try {
                    Output("Adding tile...");
                    await client.TileManager.AddTileTaskAsync(tile);
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }

                // set the page data
                try {
                    Output("Creating page data...");
                    var pageValues = new PageElementData [] {
                        TextBlockData.Create(textBlock.ElementId, "TextButton sample", out operationError),
                        TextButtonData.Create(button.ElementId, "Press Me", out operationError)
                    };
                    var page = PageData.Create(barcodePageId, 0, pageValues);

                    await client.TileManager.SetPagesTaskAsync(new[] { page }, tileId);

                    Output("Completed custom page!");
                } catch (BandException ex) {
                    Output("Error: " + ex.Message);
                }
            }
            else
            {
                Output("Band is not connected. Please wait....");
            }
        }
Beispiel #3
0
        private async void CreateTileWithButton_Click(object sender, EventArgs e)
        {
            // add the layout to the tile
            if (BandHelper.Instance.BandClient == null)
            {
                await BandHelper.Instance.Connect();
            }

            var tile = await BandHelper.CreateTile("Step 7 Tile");

            // create a filled rectangle to provide the background for a button
            var panel = new FilledPanel
            {
                Rect = new PageRect(0, 0, 245, 102),
                BackgroundColorSource = ElementColorSource.BandBase
            };

            // add a button to our layout
            panel.Elements.Add(
                new TextButton
            {
                ElementId    = (short)TilePageElementId.Button_PushMe,
                Rect         = new PageRect(60, 25, 100, 50),
                PressedColor = new Microsoft.Band.Portable.BandColor(0xFF, 0x00, 0x00),
            });

            // create the page layout
            var layout = new PageLayout(panel);

            // add the layout to the tile, and add the tile to the Band
            try
            {
                tile.PageLayouts.Add(layout);
                if (await BandHelper.Instance.BandClient.TileManager.AddTileAsync(tile))
                {
                    // layout and tile added successfully
                }
                else
                {
                    // tile failed to be added, handle error
                }
            }
            catch (Exception ex)
            {
                // handle an error adding the layout
            }

            var pageGuid = Guid.NewGuid();

            // create the content to assign to the page
            var textButtonData = new TextButtonData
            {
                ElementId = (int)TilePageElementId.Button_PushMe,
                Text      = "Push Me!"
            };

            var pageContent = new PageData
            {
                PageId          = pageGuid,
                PageLayoutIndex = 0,
                Data            =
                {
                    textButtonData
                }
            };


            // set the page content to the Band
            try
            {
                await BandHelper.Instance.BandClient.TileManager
                .SetTilePageDataAsync(tile.Id, pageContent);
            }
            catch (Exception ex)
            {
                // handle a Band connection exception
            }
        }