Exemple #1
0
        public async Task<bool> RegisterTile() {
            var pairedBands = await BandClientManager.Instance.GetBandsAsync();

            using (var bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])) {
                var tiles = await bandClient.TileManager.GetTilesAsync();

                var tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();

                var tileIconBitmap = new WriteableBitmap(46, 46);
                
                var tileIcon = tileIconBitmap.ToBandIcon();

                var tileGuid = Guid.NewGuid();

                var tile = new BandTile(tileGuid) { 
                    IsBadgingEnabled = true,   
                    Name = "jcMSBWN",     
                    TileIcon = tileIcon
                };

                await bandClient.TileManager.AddTileAsync(tile);
                
                _setting.WriteSetting(SETTINGS.TILE_ID, tile.TileId);
            }

            return true;
        }
        private static async Task<BandIcon> LoadIcon(string uri)
        {
            var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

            using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
            {
                var bitmap = new WriteableBitmap(1, 1);
                bitmap.SetSource(fileStream);
                return bitmap.ToBandIcon();
            }
        }
        public async void TileManager_SetNewTile()
        {
            var bandClient = await TestUtils.GetBandClientAsync();

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

            // Create the small and tile icons from writable bitmaps. 
            // Small icons are 24x24 pixels. 
            WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
            BandIcon smallIcon = smallIconBitmap.ToBandIcon();

            // Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels  
            // for Microsoft Band 2. 
            WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
            BandIcon tileIcon = tileIconBitmap.ToBandIcon();   
            
            // create a new tile 
            BandTile tile = new BandTile(tileGuid)
            {
                // set the name     
                Name = "MyTile",
                
                // set the icons     
                SmallIcon = smallIcon,
                TileIcon = tileIcon
            }; 

            // get the current set of tiles 
            try
            {
                // add the tile to the Band     
                if (await bandClient.TileManager.AddTileAsync(tile))
                {
                    // tile was successfully added          
                    // can proceed to set tile content with SetPagesAsync     
                }
                else
                {
                    // tile failed to be added, handle error     
                }
            }
            catch (BandException ex)
            {     
                // handle a Band connection exception } 

            }
        }
Exemple #4
0
        private async Task<BandIcon> GetBandIcon(string icon)
        {
            using (var imageFile = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("CTime2.Core.Services.Band.Icons." + icon))
            {
                WriteableBitmap bitmap = new WriteableBitmap(1, 1);
                await bitmap.SetSourceAsync(imageFile.AsRandomAccessStream());

                return bitmap.ToBandIcon();
            }
        }
Exemple #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
            }
        }
Exemple #6
0
        private async void SetBandTile()
        {
            var bandManager = BandClientManager.Instance;
            // query the service for paired devices
            var pairedBands = await bandManager.GetBandsAsync();
            // connect to the first device
            var bandInfo = pairedBands.FirstOrDefault();

            var bandClient = await bandManager.ConnectAsync(bandInfo);

            //RETRIEVING THE BAND VERSION INFORMATION
            string fwVersion;//"2.0.3923.0"
            string hwVersion;//"26"
            try
            {
                fwVersion = await bandClient.GetFirmwareVersionAsync();
                hwVersion = await bandClient.GetHardwareVersionAsync();
                // do work with firmware & hardware versions
            }
            catch (BandException ex)
            {
                // handle any BandExceptions
            }
            ///////////////////////////////////////





            //just vibration because of reasons - no message
            //await bandClient.NotificationManager.VibrateAsync(Microsoft.Band.Notifications.VibrationType.NotificationAlarm);
            //    bandClient.TileManager.TileButtonPressed += TileManager_TileButtonPressed;
            //await bandClient.TileManager.StartReadingsAsync();

            var smallIconFile = await StorageFile.GetFileFromApplicationUriAsync(
                                    new Uri("ms-appx:///Assets/logo_small.png"));


            using (var smallStream = await smallIconFile.OpenReadAsync())
            {
                var largeBitmap = new WriteableBitmap(48, 48);
                largeBitmap.SetSource(smallStream);
                var largeIcon = largeBitmap.ToBandIcon();

                var guid = Guid.NewGuid();//{be8a038f-2532-4be7-ac5e-aacf1771c788}

                var added = await bandClient.TileManager.AddTileAsync(
                  new BandTile(guid)
                  {
                      Name = "MarvelCrimeCenterUnit",
                      TileIcon = largeIcon,
                      SmallIcon = largeIcon
                  }
                );
                if (added)
                {
                    // NB: This call will return back to us *before* t
                    // user has acknowledged the dialog on their device -
                    // we don't get to know their answer here.
                    //await bandClient.NotificationManager.ShowDialogAsync(guid, "Test", "Hello Mario");

                    //PageData pageContent = new PageData(guid,
                    //    0, // index of our (only) layout 
                    //    new TextButtonData((short)1, "CALL SUPERHEROES!"));

                    //await bandClient.TileManager.SetPagesAsync(guid, pageContent);

                }

            }

            bandClient.TileManager.TileOpened += TileManager_TileOpened;

            await bandClient.TileManager.StartReadingsAsync();

        }