Beispiel #1
0
        private async Task BuildLayout(BandTile myTile)
        {
            FilledPanel panel = new FilledPanel()
            {
                Rect = new PageRect(0, 0, 220, 150)
            };

            PageElement buttonElement = null;

            switch (buttonKind)
            {
            case ButtonKind.Text:
                buttonElement = new TextButton();
                break;

            case ButtonKind.Filled:
                buttonElement = new FilledButton()
                {
                    BackgroundColor = new BandColor(0, 128, 0)
                };
                break;

            case ButtonKind.Icon:
                buttonElement = new IconButton();
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/Smile.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/SmileUpsideDown.png"));
                break;

            default:
                throw new NotImplementedException();
            }

            buttonElement.ElementId = 1;
            buttonElement.Rect      = new PageRect(10, 10, 200, 90);

            panel.Elements.Add(buttonElement);

            myTile.PageLayouts.Add(new PageLayout(panel));
        }
Beispiel #2
0
        private async void OnAddButtonTileClick(object sender, EventArgs e)
        {
            try
            {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.InScaled = false;
                BandIcon tileIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.tile, options));

                BandIcon badgeIcon = BandIcon.ToBandIcon(BitmapFactory.DecodeResource(Resources, Resource.Raw.badge, options));

                FilledButton button = new FilledButton(0, 5, 210, 45);
                button.BackgroundColor = Color.Red;
                button.Margins         = new Margins(0, 5, 0, 0);
                button.ElementId       = 12;

                TextButton button2 = new TextButton(0, 0, 210, 45);
                button2.PressedColor = Color.Blue;
                button2.Margins      = new Margins(0, 5, 0, 0);
                button2.ElementId    = 21;

                FlowPanel flowPanel = new FlowPanel(15, 0, 260, 105, FlowPanelOrientation.Vertical);
                flowPanel.AddElements(button);
                flowPanel.AddElements(button2);

                PageLayout pageLayout = new PageLayout(flowPanel);

                BandTile.Builder builder = new BandTile.Builder(Java.Util.UUID.RandomUUID(), mEditTileName.Text, tileIcon);
                if (mCheckboxBadging.Checked)
                {
                    builder.SetTileSmallIcon(badgeIcon);
                }
                if (mCheckboxCustomTheme.Checked)
                {
                    builder.SetTheme(mThemeView.Theme);
                }
                builder.SetPageLayouts(pageLayout);
                BandTile tile = builder.Build();

                try
                {
                    var result = await Model.Instance.Client.TileManager.AddTileTaskAsync(Activity, tile);

                    if (result)
                    {
                        Toast.MakeText(Activity, "Tile added", ToastLength.Short).Show();
                    }
                    else
                    {
                        Toast.MakeText(Activity, "Unable to add tile", ToastLength.Short).Show();
                    }
                }
                catch (Exception ex)
                {
                    Util.ShowExceptionAlert(Activity, "Add tile", ex);
                }

                PageData pageData = new PageData(Java.Util.UUID.RandomUUID(), 0);
                pageData.Update(new FilledButtonData(12, Color.Yellow));
                pageData.Update(new TextButtonData(21, "Text Button"));
                await Model.Instance.Client.TileManager.SetPagesTaskAsync(tile.TileId, pageData);

                Toast.MakeText(Activity, "Page updated", ToastLength.Short).Show();

                // Refresh our tile list and count
                await RefreshData();

                RefreshControls();
            }
            catch (Exception ex)
            {
                Util.ShowExceptionAlert(Activity, "Add tile", ex);
            }
        }
        internal async void Initialize()
        {
            var bandManager = BandClientManager.Instance;
            var pairedBands = await bandManager.GetBandsAsync();

            try
            {
                if (pairedBands.Length < 1)
                {
                    info.Text = "Could not connect";
                    return;
                }

                bandClient = await bandManager.ConnectAsync(pairedBands[0]);

                info.Text = "Connected to Band";
                lastMove  = DateTime.Now;

                // Create a Tile with a TextButton on it.
                BandTile myTile = new BandTile(myTileId)
                {
                    Name      = "My Teletouch",
                    TileIcon  = await LoadIcon("ms-appx:///Assets/BandTileIconLarge.png"),
                    SmallIcon = await LoadIcon("ms-appx:///Assets/BandTileIconSmall.png")
                };
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/left.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/center.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/right.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/switch.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/switch1.png"));
                myTile.AdditionalIcons.Add(await LoadIcon("ms-appx:///Assets/switch2.png"));

                // get the current theme from the Band
                BandTheme theme = await bandClient.PersonalizationManager.GetThemeAsync();

                BandColor colorButton        = theme.Base;
                BandColor colorButtonPressed = new BandColor(0xFF, 0xFF, 0xFF);
                PageRect  rect1 = new PageRect(5, 0, 60, 110);
                PageRect  rect2 = new PageRect(70, 0, 60, 110);
                PageRect  rect3 = new PageRect(135, 0, 60, 110);
                PageRect  rect4 = new PageRect(200, 0, 40, 35);
                PageRect  rect5 = new PageRect(200, 37, 40, 35);
                PageRect  rect6 = new PageRect(200, 75, 40, 35);

                FilledButton buttonLeft = new FilledButton()
                {
                    ElementId = 1, Rect = rect1, BackgroundColor = colorButton
                };
                FilledButton buttonCenter = new FilledButton()
                {
                    ElementId = 2, Rect = rect2, BackgroundColor = colorButton
                };
                FilledButton buttonRight = new FilledButton()
                {
                    ElementId = 3, Rect = rect3, BackgroundColor = colorButton
                };
                FilledButton buttonSwitch = new FilledButton()
                {
                    ElementId = 4, Rect = rect4, BackgroundColor = colorButton
                };
                FilledButton buttonLock = new FilledButton()
                {
                    ElementId = 5, Rect = rect5, BackgroundColor = colorButton
                };
                FilledButton buttonOnOff = new FilledButton()
                {
                    ElementId = 6, Rect = rect6, BackgroundColor = colorButton
                };
                Icon iconLeft = new Icon()
                {
                    ElementId = 7, Rect = rect1, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };
                Icon iconCenter = new Icon()
                {
                    ElementId = 8, Rect = rect2, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };
                Icon iconRight = new Icon()
                {
                    ElementId = 9, Rect = rect3, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };
                Icon iconSwitch = new Icon()
                {
                    ElementId = 10, Rect = rect4, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };
                Icon iconLock = new Icon()
                {
                    ElementId = 11, Rect = rect5, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };
                Icon iconOnOff = new Icon()
                {
                    ElementId = 12, Rect = rect6, Color = colorButtonPressed, HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center, VerticalAlignment = Microsoft.Band.Tiles.Pages.VerticalAlignment.Center
                };

                FilledPanel panel = new FilledPanel(iconLeft, iconCenter, iconRight, iconSwitch, iconLock, iconOnOff,
                                                    buttonLeft, buttonCenter, buttonRight, buttonSwitch, buttonLock, buttonOnOff)
                {
                    Rect = new PageRect(0, 0, 240, 110),
                    HorizontalAlignment = Microsoft.Band.Tiles.Pages.HorizontalAlignment.Center
                };
                myTile.PageLayouts.Add(new PageLayout(panel));

                // Remove the Tile from the Band, if present. An application won't need to do this everytime it runs.
                // But in case you modify this sample code and run it again, let's make sure to start fresh.
                //await bandClient.TileManager.RemoveTileAsync(myTileId);

                // Create the Tile on the Band.
                await bandClient.TileManager.AddTileAsync(myTile);

                await bandClient.TileManager.SetPagesAsync(myTileId, new PageData(pageId, 0,
                                                                                  new FilledButtonData(1, colorButtonPressed),
                                                                                  new FilledButtonData(2, colorButtonPressed),
                                                                                  new FilledButtonData(3, colorButtonPressed),
                                                                                  new FilledButtonData(4, colorButtonPressed),
                                                                                  new FilledButtonData(5, colorButtonPressed),
                                                                                  new FilledButtonData(6, colorButtonPressed),
                                                                                  new IconData(7, 2),
                                                                                  new IconData(8, 3),
                                                                                  new IconData(9, 4),
                                                                                  new IconData(10, 5),
                                                                                  new IconData(11, 6),
                                                                                  new IconData(12, 7)));

                // Subscribe to events
                bandClient.TileManager.TileOpened                 += EventHandler_TileOpened;
                bandClient.TileManager.TileClosed                 += EventHandler_TileClosed;
                bandClient.TileManager.TileButtonPressed          += EventHandler_TileButtonPressed;
                bandClient.SensorManager.Gyroscope.ReadingChanged += Gyroscope_ReadingChanged;

                // Start listening for events
                await bandClient.TileManager.StartReadingsAsync();
            }
            catch (BandException bandException)
            {
                Debug.WriteLine(bandException.Message);
                info.Text = "Could not connect";
            }
        }
Beispiel #4
0
        public TransactionTileLayout()
        {
            LoadIconMethod  = LoadIcon;
            AdjustUriMethod = (uri) => uri;

            panel                     = new FlowPanel();
            panel.Orientation         = FlowPanelOrientation.Vertical;
            panel.Rect                = new PageRect(0, 0, 258, 128);
            panel.ElementId           = 1;
            panel.Margins             = new Margins(0, 0, 0, 0);
            panel.HorizontalAlignment = HorizontalAlignment.Left;
            panel.VerticalAlignment   = VerticalAlignment.Top;

            textBlock                     = new TextBlock();
            textBlock.Font                = TextBlockFont.Small;
            textBlock.Baseline            = 0;
            textBlock.BaselineAlignment   = TextBlockBaselineAlignment.Automatic;
            textBlock.AutoWidth           = true;
            textBlock.ColorSource         = ElementColorSource.BandBase;
            textBlock.Rect                = new PageRect(0, 0, 32, 32);
            textBlock.ElementId           = 2;
            textBlock.Margins             = new Margins(12, 8, 0, 0);
            textBlock.HorizontalAlignment = HorizontalAlignment.Left;
            textBlock.VerticalAlignment   = VerticalAlignment.Top;

            panel.Elements.Add(textBlock);

            AmountDecimalButton = new TextButton();
            AmountDecimalButton.PressedColor        = new BandColor(32, 32, 32);
            AmountDecimalButton.Rect                = new PageRect(0, 0, 80, 44);
            AmountDecimalButton.ElementId           = 3;
            AmountDecimalButton.Margins             = new Margins(12, 20, 0, 0);
            AmountDecimalButton.HorizontalAlignment = HorizontalAlignment.Right;
            AmountDecimalButton.VerticalAlignment   = VerticalAlignment.Top;

            panel.Elements.Add(AmountDecimalButton);

            icon                     = new Icon();
            icon.ColorSource         = ElementColorSource.Custom;
            icon.Color               = new BandColor(255, 21, 28);
            icon.Rect                = new PageRect(0, 0, 32, 32);
            icon.ElementId           = 5;
            icon.Margins             = new Margins(190, -38, 0, 0);
            icon.HorizontalAlignment = HorizontalAlignment.Center;
            icon.VerticalAlignment   = VerticalAlignment.Center;

            panel.Elements.Add(icon);

            CategoryButton = new FilledButton();
            CategoryButton.BackgroundColor     = new BandColor(53, 53, 53);
            CategoryButton.Rect                = new PageRect(0, 0, 44, 44);
            CategoryButton.ElementId           = 4;
            CategoryButton.Margins             = new Margins(184, -40, 0, 0);
            CategoryButton.HorizontalAlignment = HorizontalAlignment.Center;
            CategoryButton.VerticalAlignment   = VerticalAlignment.Center;

            panel.Elements.Add(CategoryButton);

            AmountSingleButton = new TextButton();
            AmountSingleButton.PressedColor        = new BandColor(32, 32, 32);
            AmountSingleButton.Rect                = new PageRect(0, 0, 80, 44);
            AmountSingleButton.ElementId           = 6;
            AmountSingleButton.Margins             = new Margins(92, -44, 0, 0);
            AmountSingleButton.HorizontalAlignment = HorizontalAlignment.Left;
            AmountSingleButton.VerticalAlignment   = VerticalAlignment.Top;

            panel.Elements.Add(AmountSingleButton);
            pageLayout = new PageLayout(panel);

            PageElementData[] pageElementDataArray = new PageElementData[5];
            pageElementDataArray[0] = textBlockData;
            pageElementDataArray[1] = AmountDecimalButtonData;
            pageElementDataArray[2] = iconData;
            pageElementDataArray[3] = CategoryButtonData;
            pageElementDataArray[4] = AmountSingleButtonData;

            pageLayoutData = new PageLayoutData(pageElementDataArray);
        }