/// <summary> /// Generates the data for page two of the band tile. /// </summary> /// <param name="applicationUpdate">True if being updated by the application.</param> /// <returns>The page data.</returns> private static PageData GenerateInfoPageData(bool applicationUpdate = false) { var description = string.Format("{0} Updated\n{1}", (applicationUpdate ? "Application" : "Background"), DateTime.Now.ToString(Common.DateFormat)); var updated = new WrappedTextBlockData(Common.UpdateId, description); return(new PageData(Guid.NewGuid(), 1, updated)); }
public async Task TestPutTileBand2() { //Step 1: Connect to Band if need to. Message = "Connecting to Band..."; if (currentBandClient == null) { //Connect To Band. bool isConnected = await InitializeBandConnection(); //check if connection successful. if (isConnected == false) { //Something is wrong. Message = "Can't connect to Band. Try Again!"; return; } } Message = "Band Connected! Creating Tiles..."; //Step 2: Create the Tile's Page layout. //Would look like this: // +--------------------+ // | Note #1 | <=== Header Textblock // | Angel is the best | <=== Wrapperd TextBlock for the Note // | girl. Ever <3 | // +--------------------+ //Step 2.1: Create a TextBlock for the Header Microsoft.Band.Tiles.Pages.TextBlock myHeaderTextBlock = new TextBlock(); //Fill The Required Data for the TextBlock (ElementID and Rect): //ElementID is the Unique ID of the control (within the layout/page). NOTE: 0 is not a valid ID. Everything has to be positive. myHeaderTextBlock.ElementId = 1; //Rect: Remember the Rectangle dashed-line in Photoshop when creating a new textbox? That's it. Pretty much the boundary of the control. //We will be wrapping this around a ScrollFlowPanel. X,Y of the PageRect will stay 0 (page 39 SDK) //Band 1 Workable Width: 245px; //Band 2 Workable Width: 258px; myHeaderTextBlock.Rect = new Microsoft.Band.Tiles.Pages.PageRect(0, 0, 200, 25); //For the Header , let follow the Band Color.? <Does it just stay this way?> //myHeaderTextBlock.Color = (await currentBandClient.PersonalizationManager.GetThemeAsync()).Base; <= Not necessarily ? Will be dynamic? Line Blow. Page 40 SDK myHeaderTextBlock.ColorSource = ElementColorSource.BandBase; //Step 2.2: Create the WrappedTextBlock below for the note. Microsoft.Band.Tiles.Pages.WrappedTextBlock myNoteWrappedTextBlock = new WrappedTextBlock(); //Fill in the required data for the wrapped text block (again, elementID and Rect) myNoteWrappedTextBlock.ElementId = 2; myNoteWrappedTextBlock.Rect = new PageRect(0, 0, 250, 100); //<=== Band 2 Height: 128px ; Band 1 Height: 106px; Wrapped TextBlock should allow displaying a long text with ScrollFlowPanel //Actually, the wrapped Textblock seem to not care about the Width? //Color should be default of WrappedTextBlock (White) //Step 3: Create a Controllers' container. Or the basic layout of the page. Think of it as Grid over the entire window in WPF //we use ScrollFlowPanel Microsoft.Band.Tiles.Pages.ScrollFlowPanel myPageScrollFlowPanel = new ScrollFlowPanel(myHeaderTextBlock, myNoteWrappedTextBlock); //Set the flow of the content to be vertically myPageScrollFlowPanel.Orientation = FlowPanelOrientation.Vertical; //Set the color of the scroll bar to match the color of the theme that we are using myPageScrollFlowPanel.ScrollBarColorSource = ElementColorSource.BandBase; //Yet, Rect again. This one should be the entire page.? myPageScrollFlowPanel.Rect = new PageRect(0, 0, 250, 128); // Band 2 only //Step 4: Create the actual Tile. //Step 4.1: Create a Global Unique Identifier for the Tile. Guid myGuid = new Guid("D781F673-6D05-4D69-BCFF-EA7E706C3418"); //Step 4.2 Create the band tile. Microsoft.Band.Tiles.BandTile myTile = new BandTile(myGuid); //Step 4.3 Setup the properties of the tile. (name, icon, and pageLayout) //Name: myTile.Name = "My Custom Note Tile"; //Small and Large Icon. //Set the icon following the sample icon that we have from the SDK. myTile.TileIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconLarge.png"); myTile.SmallIcon = await LoadIcon("ms-appx:///Assets/SampleTileIconSmall.png"); //Create a page layout object from the ScrollFlowPanel that we have. Microsoft.Band.Tiles.Pages.PageLayout myPageLayout = new PageLayout(myPageScrollFlowPanel); //Add that as the first page (can add up to 8) myTile.PageLayouts.Add(myPageLayout); myTile.PageLayouts.Add(myPageLayout); Message = "Done Creating Tile. Syncing..."; //Step 5: Sync over to the phone. //Step 5.0: Remove old-previous pinned tile. //do this to make sure we start fresh everytime. await currentBandClient.TileManager.RemoveTileAsync(myTile.TileId); //Step 5.1: Sync it over to the phone. await currentBandClient.TileManager.AddTileAsync(myTile); //Step 6 (EXTRA): We add in a custom data to the page. //First one. TextBlockData headerText = new TextBlockData(1, "Note #1"); WrappedTextBlockData noteText = new WrappedTextBlockData(2, "Angel is the best girl ever! She is sweet, she is beautiful, she is smart. And after all, she loves me and she is my whole world <3"); PageData myNotePageData = new PageData(Guid.NewGuid(), 0, headerText, noteText); //2nd one TextBlockData headerText2 = new TextBlockData(1, "Note #2"); WrappedTextBlockData noteText2 = new WrappedTextBlockData(2, "Microsoft Band 2 rocks. This tile was created by Visual Studio 2015, written in C# and Microsoft Band SDK 1.3.20217 on Feb 24th 2016 by Scotty"); PageData myNotePageData2 = new PageData(Guid.NewGuid(), 1, headerText2, noteText2); await currentBandClient.TileManager.SetPagesAsync(myTile.TileId, myNotePageData, myNotePageData2); Message = "Done"; }
private async void CreateLayout1Button_Click(object sender, EventArgs e) { // Create a scrollable vertical panel that will hold 2 text messages. var 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 Microsoft.Band.Portable.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 Microsoft.Band.Portable.BandColor(0xFF, 0xFF, 0xFF), Font = WrappedTextBlockFont.Small } ); // create the page layout PageLayout layout = new PageLayout(panel); try { // add the layout to the tile if (BandHelper.Instance.BandClient == null) { await BandHelper.Instance.Connect(); } var tile = await BandHelper.CreateTile("Step5 Tile - Layout 1"); // get the current set of tiles tile.PageLayouts.Add(layout); try { // add the tile to the Band if (await BandHelper.Instance.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 (Exception ex) { // handle a Band connection exception } // specify which layout to use for this page var tbd1 = new WrappedTextBlockData { ElementId = (Int16)TileMessagesLayoutElementId.Message1, Text = "This is the text of the first message" }; var tbd2 = new WrappedTextBlockData { ElementId = (Int16)TileMessagesLayoutElementId.Message2, Text = "This is the text of the second message" }; // create a new Guid for the messages page var messagesPageGuid = Guid.NewGuid(); // create the object that contains the page content to be set var pageContent = new PageData { PageId = messagesPageGuid, PageLayoutIndex = (int)TileLayoutIndex.MessagesLayout, Data = { tbd1, tbd2 } }; try { // set the page content on the Band await BandHelper.Instance.BandClient.TileManager .SetTilePageDataAsync(tile.Id, pageContent); } catch (Exception ex) { // handle a Band connection exception } } catch (Exception ex) { // handle an error adding the layout } } }