Пример #1
0
 private void CreateBoolPoll()
 {
     TextBlock nameTextBlock = new TextBlock() { Color = Colors.Blue.ToBandColor(), ElementId = 1, Rect = new PageRect(0, 0, 200, 30) };
     WrappedTextBlock questionBlock = new WrappedTextBlock() { ElementId = 2, Rect = new PageRect(0, 25, 200, 60) };
     TextButton button1 = new TextButton() { ElementId = 3, Rect = new PageRect(0, 0, 100, 100), PressedColor = new BandColor(0xFF, 0x00, 0x00) };
     TextButton button2 = new TextButton() { ElementId = 4, Rect = new PageRect(0, 0, 100, 100), PressedColor = new BandColor(0xFF, 0x00, 0x00) };
     FlowPanel panel1 = new FlowPanel(nameTextBlock, questionBlock)
     {
         Orientation = FlowPanelOrientation.Vertical,
         Rect = new PageRect(0, 0, 200, 102)
     };
     FlowPanel panel2 = new FlowPanel(button1, button2)
     {
         Orientation = FlowPanelOrientation.Horizontal,
         Rect = new PageRect(0, 0, 200, 102)
     };
     ScrollFlowPanel panelBool = new ScrollFlowPanel(panel1, panel2)
     {
         Orientation = FlowPanelOrientation.Horizontal,
         Rect = new PageRect(0, 0, 200, 102),
         ScrollBarColorSource = ElementColorSource.BandBase
     };
     PageLayout pageLayout = new PageLayout(panelBool);
     PageLayouts.Add(pageLayout);
 }
        private static PageLayout CreateMessageWithButtonLayout()
        {
            var customMessageWrappedTextBlock = new WrappedTextBlock()
            {
                ElementId = PageElementKind.CustomMessageText2,
                Rect = new PageRect(0, 0, 258, 102),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top
            };

            var customMessageButton = new TextButton()
            {
                ElementId = PageElementKind.CustomMessageButton,
                Margins = new Margins(25, 10, 25, 10),
                Rect = new PageRect(0, 0, 170, 45),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            var customMessageWithAckButtonPanel = new ScrollFlowPanel(customMessageWrappedTextBlock, customMessageButton)
            {
                Orientation = FlowPanelOrientation.Vertical,
                Rect = new PageRect(0, 0, 258, 102),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
            };

            var customMessageWithAckButtonLayout = new PageLayout(customMessageWithAckButtonPanel);
            return customMessageWithAckButtonLayout;
        }
        private static PageLayout CreateMessageLayout()
        {
            var messageWrappedTextBlock = new WrappedTextBlock()
            {
                ElementId = PageElementKind.CustomMessageText,
                Rect = new PageRect(0, 0, 258, 102),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top
            };

            var messageWithoutAckButtonPanel = new ScrollFlowPanel(messageWrappedTextBlock)
            {
                Orientation = FlowPanelOrientation.Vertical,
                Rect = new PageRect(0, 0, 258, 102),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
            };

            var messageWithoutAckButtonLayout = new PageLayout(messageWithoutAckButtonPanel);
            return messageWithoutAckButtonLayout;
        }
Пример #4
0
        private void CreateLayout(BandTile tile)
        {
            ScrollFlowPanel panel = new ScrollFlowPanel()
            {
                Rect = new PageRect(0, 0, 245, 102),
                Orientation = FlowPanelOrientation.Vertical
            };

            Icon icon = new Icon()
            {
                ElementId = 3,
                Rect = new PageRect(0, 0, 245, 102),
                Margins = new Margins(15, 0, 15, 0),
                VerticalAlignment = VerticalAlignment.Top,
            };

            var nombre = new WrappedTextBlock
            {
                ElementId = 1,
                Rect = new PageRect(0, 0, 245, 102),
                Margins = new Margins(15, 0, 15, 0),
                Color = new BandColor(0xFF, 0xFF, 0xFF),
                Font = WrappedTextBlockFont.Small,
                VerticalAlignment = VerticalAlignment.Top
            };

            var motto = new WrappedTextBlock
            {
                ElementId = 2,
                Rect = new PageRect(0, 0, 245, 102),
                Margins = new Margins(15, 0, 15, 0),
                Color = new BandColor(0xFF, 0xFF, 0xFF),
                Font = WrappedTextBlockFont.Small,
                VerticalAlignment = VerticalAlignment.Top
            };

            panel.Elements.Add(icon); 
            panel.Elements.Add(nombre);
            panel.Elements.Add(motto);

            PageLayout layout = new PageLayout(panel);
            tile.PageLayouts.Add(layout);
        }
Пример #5
0
        async private void Click_AddTile(object sender, RoutedEventArgs e)
        {
            AppBarButton_Pin.IsEnabled = false;
            try
            {
                // determine the number of available tile slots on the Band
                int tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();
                if (tileCapacity < 1)
                {
                    return;
                }
            }
            catch (BandException ex)
            {
                // handle a Band connection exception }
            }
            
            // Create the small and tile icons from writable bitmaps.
            // Small icons are 24x24 pixels.
            BandIcon smallIcon;
            StorageFile imageFile_small = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Band_SmallIcon.png"));
            using (IRandomAccessStream fileStream = await imageFile_small.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap bitmap = new WriteableBitmap(24, 24);
                await bitmap.SetSourceAsync(fileStream);
                smallIcon = bitmap.ToBandIcon();
            }

            // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels
            // for Microsoft Band 2.
            BandIcon tileIcon;
            StorageFile imageFile_large = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Band_LargeIcon.png"));
            using (IRandomAccessStream fileStream = await imageFile_large.OpenAsync(FileAccessMode.Read))
            {
                WriteableBitmap bitmap = new WriteableBitmap(48, 48);
                await bitmap.SetSourceAsync(fileStream);
                tileIcon = bitmap.ToBandIcon();
            }

            // create a new Guid for the tile
            Guid newGuid = Guid.NewGuid();
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            localSettings.Values["BOLGuid"] = tileGuid = newGuid;
            // create a new tile with a new Guid
            tile = new BandTile(tileGuid)
            {
                // enable badging (the count of unread messages)
                IsBadgingEnabled = true,
                // set the name
                Name = "Band of Love",
                // set the icons
                SmallIcon = smallIcon,
                TileIcon = tileIcon
            };

            // Create a scrollable vertical panel that will hold 2 text messages.
            ScrollFlowPanel panel = new ScrollFlowPanel
            {
                Rect = new PageRect(0, 0, 245, 102),
                Orientation = FlowPanelOrientation.Vertical,
                ScrollBarColorSource = ElementColorSource.BandBase
            };

            // add the text block to contain the first message
            panel.Elements.Add(
                new WrappedTextBlock
                {
                    ElementId = (short)TileMessagesLayoutElementId.Message1,
                    Rect = new PageRect(0, 0, 245, 102),
                    // left, top, right, bottom margins
                    Margins = new Margins(15, 0, 15, 0),
                    Color = new BandColor(0xFF, 0xFF, 0xFF),
                    Font = WrappedTextBlockFont.Small
                }
            );

            // add the text block to contain the second message
            panel.Elements.Add(
                new WrappedTextBlock
                {
                    ElementId = (short)TileMessagesLayoutElementId.Message2,
                    Rect = new PageRect(0, 0, 245, 102),
                    // left, top, right, bottom margins
                    Margins = new Margins(15, 0, 15, 0),
                    Color = new BandColor(0xFF, 0xFF, 0xFF),
                    Font = WrappedTextBlockFont.Small
                }
            );
            // create the page layout
            PageLayout layout = new PageLayout(panel);

            try
            {     // add the layout to the tile
                tile.PageLayouts.Add(layout);
            }
            catch (BandException ex)
            {
                // handle an error adding the layout
            }

            try
            {
                // add the tile to the Band
                if (await bandClient.TileManager.AddTileAsync(tile))
                {
                    // tile was successfully added
                    AppBarButton_Pin.Visibility = Visibility.Collapsed;
                    AppBarButton_UnPin.Visibility = Visibility.Visible;
                    AppBarButton_UnPin.IsEnabled = true;

                    // can proceed to set tile content with SetPagesAsync
                }
                else
                {
                    // tile failed to be added, handle error
                }
            }
            catch (BandException ex)
            {
                // handle a Band connection exception }
            }

            // create a new Guid for the messages page
            Guid messagesPageGuid = Guid.NewGuid();
            // create the object that contains the page content to be set
            PageData pageContent = new PageData(
                messagesPageGuid,
                // specify which layout to use for this page
                (int)TileLayoutIndex.MessagesLayout,
                new WrappedTextBlockData(
                    (Int16)TileMessagesLayoutElementId.Message1,
                    "This is the text of the first message"
                ),
                new WrappedTextBlockData(
                    (Int16)TileMessagesLayoutElementId.Message2,
                    "This is the text of the second message"
                )
            );
            try
            {
                // set the page content on the Band
                if (await bandClient.TileManager.SetPagesAsync(tileGuid, pageContent))
                {
                    // page content successfully set on Band
                }
                else
                {
                    // unable to set content to the Band
                }
            }
            catch (BandException ex)
            {
                // handle a Band connection exception
            }
        }
Пример #6
0
 private void Message()
 {
     TextBlock nameTextBlock = new TextBlock() { Color = Colors.Blue.ToBandColor(), ElementId = 1, Rect = new PageRect(0, 0, 200, 30) };
     WrappedTextBlock questionBlock = new WrappedTextBlock() { ElementId = 2, Rect = new PageRect(0, 0, 200, 60) };
     ScrollFlowPanel panelRate = new ScrollFlowPanel(nameTextBlock, questionBlock)
     {
         Orientation = FlowPanelOrientation.Vertical,
         Rect = new PageRect(0, 0, 200, 102),
         ScrollBarColorSource = ElementColorSource.BandBase
     };
     PageLayout pageLayout = new PageLayout(panelRate);
     PageLayouts.Add(pageLayout);
 }
Пример #7
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            this.viewModel.StatusMessage = "Running ...";

            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
                if (pairedBands.Length < 1)
                {
                    this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }


                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    // Create a Tile with a TextButton on it.

                    IEnumerable<BandTile> tileslist = await
                       bandClient.TileManager.GetTilesAsync();

                    foreach (var t in tileslist)
                    {

                        if (t.Name == "Fan Control")
                        {
                            a = t.Name;
                        }
                    }

                    if (a != "Fan Control")
                    {
                        Guid myTileId = new Guid("12408A60-13EB-46C2-9D24-F14BF6A033C6");
                        Guid pageId = Guid.NewGuid();

                        BandTile myTile = new BandTile(myTileId)
                        {
                            Name = "Fan Control",
                            TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                            SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                        };

                        TextButton button = new TextButton() { ElementId = 1, Rect = new PageRect(0, 0, 50, 120) };
                        TextButton button1 = new TextButton() { ElementId = 2, Rect = new PageRect(50, 0, 50, 120) };
                        TextButton button2 = new TextButton() { ElementId = 3, Rect = new PageRect(100, 0, 50, 120) };
                        TextButton button3 = new TextButton() { ElementId = 4, Rect = new PageRect(150,0, 50, 120) };
                        TextButton button4= new TextButton() { ElementId = 5, Rect = new PageRect(200, 0, 50, 120) };
                        TextButton button5 = new TextButton() { ElementId = 6, Rect = new PageRect(250, 0, 50, 120) };

                        ScrollFlowPanel panel = new ScrollFlowPanel(button, button1, button2, button3, button4, button5) { 
                            Orientation = FlowPanelOrientation.Horizontal,
                            Rect = new PageRect(0, 0, 320, 120), 
                            };
                        myTile.PageLayouts.Add(new PageLayout(panel));


                        //FilledPanel panel1 = new FilledPanel(button1) { Rect = new PageRect(0, 0, 220, 150) };
                        //myTile.PageLayouts.Add(new PageLayout(panel1));

                        // 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(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 0, new TextButtonData(1, "1"), new TextButtonData(2, "2"), new TextButtonData(3, "3"), new TextButtonData(4, "4"), new TextButtonData(5, "5"), new TextButtonData(6, "6")));
                        //await bandClient.TileManager.SetPagesAsync(myTileId, new PageData(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 1, new TextButtonData(2, "Click here2")));

                        // Subscribe to Tile events.
                        int buttonPressedCount = 0;

                        
                    }
                   
                        bandClient.TileManager.TileButtonPressed += TileManager_TileButtonPressed;
                    
                    TaskCompletionSource<bool> closePressed = new TaskCompletionSource<bool>();

                    bandClient.TileManager.TileClosed += (s, args) =>
                    {
                        closePressed.TrySetResult(true);
                    };

                    await bandClient.TileManager.StartReadingsAsync();

                    // Receive events until the Tile is closed.
                    this.viewModel.StatusMessage = "Check the Tile on your Band (it's the last Tile). Waiting for events ...";

                    await closePressed.Task;

                    // Stop listening for Tile events.
                  //  await bandClient.TileManager.StopReadingsAsync();

                    //this.viewModel.StatusMessage = "Done.";
                }
            }
            catch (Exception ex)
            {
                this.viewModel.StatusMessage = ex.ToString();
            }
        }