private IEnumerable<PageLayout> BuildTileUi()
    {
      var bandUi = new List<PageLayout>();
      var page1Elements = new List<PageElement>
      {
        new Icon {ElementId = BandUiDefinitions.IconId, Rect = new PageRect(60,10,24,24)},
        new TextBlock  {ElementId = BandUiDefinitions.TextTemperatureId, Rect = new PageRect(90, 10, 50, 40)},
        new TextButton {ElementId = BandUiDefinitions.ButtonToggleFanId, Rect = new PageRect(10, 50, 220, 40), HorizontalAlignment = HorizontalAlignment.Center}
      };
      var firstPanel = new FilledPanel(page1Elements) { Rect = new PageRect(0, 0, 240, 150) };

      var page2Elements = new List<PageElement>
      {
        new TextBlock {ElementId = BandUiDefinitions.TextTimeId, Rect = new PageRect(10, 10, 220, 40)},
        new TextBlock {ElementId = BandUiDefinitions.TextDateId, Rect = new PageRect(10, 58, 220, 40)}
      };
      var secondPanel = new FilledPanel(page2Elements) { Rect = new PageRect(0, 0, 240, 150) };

      bandUi.Add(new PageLayout(firstPanel));
      bandUi.Add(new PageLayout(secondPanel));

      return bandUi;
    }
Beispiel #2
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.
                    Guid myTileId = new Guid("12408A60-13EB-46C2-9D24-F14BF6A033C6");
                    BandTile myTile = new BandTile(myTileId)
                    {
                        Name = "My Tile",
                        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(10, 10, 200, 90) };
                    FilledPanel panel = new FilledPanel(button) { Rect = new PageRect(0, 0, 220, 150) };
                    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(new Guid("5F5FD06E-BD37-4B71-B36C-3ED9D721F200"), 0, new TextButtonData(1, "Click here")));

                    // Subscribe to Tile events.
                    int buttonPressedCount = 0;
                    TaskCompletionSource<bool> closePressed = new TaskCompletionSource<bool>();

                    bandClient.TileManager.TileButtonPressed += (s, args) => 
                    {
                        var a = Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal,
                            () =>
                            {
                                buttonPressedCount++;
                                this.viewModel.StatusMessage = string.Format("TileButtonPressed = {0}", buttonPressedCount);
                            }
                        );
                    };
                    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();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Called when the "Install Tile" button is pressed in the UI.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void InstallTileButton_Click(object sender, RoutedEventArgs e)
        {
            App.Current.StatusMessage = "Installing...\n";
            try
            {
                // Get the list of Microsoft Bands paired to the phone.
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
                if (pairedBands.Length < 1)
                {
                    App.Current.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 and WrappedTextBlock on it.
                    BandTile myTile = new BandTile(TileConstants.TileGuid)
                    {
                        Name = "My Tile",
                        TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"),
                        SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png")
                    };
                    TextButton button = new TextButton() { ElementId = TileConstants.Button1ElementId, Rect = new PageRect(10, 5, 200, 30) };
                    WrappedTextBlock textblock = new WrappedTextBlock() { ElementId = TileConstants.TextElementId, Rect = new PageRect(10, 40, 200, 88) };
                    PageElement[] elements = new PageElement[] { button, textblock };
                    FilledPanel panel = new FilledPanel(elements) { Rect = new PageRect(0, 0, 220, 128) };
                    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(TileConstants.TileGuid);

                    // Create the Tile on the Band.
                    await bandClient.TileManager.AddTileAsync(myTile);
                    PageElementData[] pagedata = new PageElementData[] 
                    {
                        new TextButtonData(TileConstants.Button1ElementId, TileConstants.ButtonLabel),
                        new WrappedTextBlockData(TileConstants.TextElementId, "...")
                    };
                    await bandClient.TileManager.SetPagesAsync(TileConstants.TileGuid, new PageData(TileConstants.Page1Guid, 0, pagedata));

                    // Subscribe to background tile events
                    await bandClient.SubscribeToBackgroundTileEventsAsync(TileConstants.TileGuid);

                    App.Current.StatusMessage = "Installed Tile";
                }
            }
            catch (Exception ex)
            {
                App.Current.StatusMessage = ex.ToString();
            }
        }
Beispiel #4
0
        private async Task CreateJukeboxTileAsync()
        {
            // create the small and tile icons from writable bitmaps.
            // Small icons are 24x24 pixels.
            var writeableSmallBmp = BitmapFactory.New(24, 24);
            using (writeableSmallBmp.GetBitmapContext())
            {
                // Load an image from the calling Assembly's resources via the relative path
                writeableSmallBmp = await BitmapFactory.New(1, 1).FromContent(new Uri("ms-appx:///Assets/Sensor24x24.png"));
            }
            var smallIcon = writeableSmallBmp.ToBandIcon();

            // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels for Microsoft 
            // Band 2.
            var writeableBmp = BitmapFactory.New(46, 46);
            using (writeableBmp.GetBitmapContext())
            {
                // Load an image from the calling Assembly's resources via the relative path
                writeableBmp = await BitmapFactory.New(1, 1).FromContent(new Uri("ms-appx:///Assets/Sensor46x46.png"));
            }
            var tileIcon = writeableBmp.ToBandIcon();

            // create a new Guid for the tile
            var tileGuid = Guid.NewGuid();

            // create a new tile with a new Guid
            var tile = new BandTile(tileGuid)
            {
                IsBadgingEnabled = true,
                Name = "Sensor Manager",
                SmallIcon = smallIcon,
                TileIcon = tileIcon
            };

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

            // add buttons to our layout 
            panel.Elements.Add(new TextButton
            {
                ElementId = (short)TilePageElementId.Jukebox_PlayRandom,
                Rect = new PageRect(20, 0, 70, 102),
                PressedColor = Colors.Blue.ToBandColor()
            });

            panel.Elements.Add(new TextButton
            {
                ElementId = (short)TilePageElementId.Jukebox_Pause,
                Rect = new PageRect(120, 0, 100, 45),
                PressedColor = Colors.Blue.ToBandColor()
            });

            panel.Elements.Add(new TextButton
            {
                ElementId = (short)TilePageElementId.Jukebox_Stop,
                Rect = new PageRect(120, 55, 100, 45),
                PressedColor = Colors.Blue.ToBandColor()
            });

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

            // add the tile to the Band
            tile.PageLayouts.Add(layout);
            if (await bandClient.TileManager.AddTileAsync(tile))
            {
                // create the content to assign to the page 
                var pageContent = new PageData(Guid.NewGuid(),
                    0, // index of our (only) layout                 
                    new TextButtonData((short)TilePageElementId.Jukebox_PlayRandom, "Play"),
                    new TextButtonData((short)TilePageElementId.Jukebox_Pause, "Pause"),
                    new TextButtonData((short)TilePageElementId.Jukebox_Stop, "Stop"));

                await bandClient.TileManager.SetPagesAsync(tileGuid, pageContent);
            }
        }