/// <summary> /// Update the application's tile with the most recent quote /// </summary> /// <param name="quote">The quote's content to update the tile with</param> public void UpdateTile(BackgroundQuote quote) { XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideText09); XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text"); tileTextAttributes[0].InnerText = quote.Author; tileTextAttributes[1].InnerText = quote.Content; // Square tile XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text02); XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text"); //squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode("Hello World! My very own tile notification")); squareTileTextAttributes[0].InnerText = quote.Author; squareTileTextAttributes[1].InnerText = quote.Content; // Integration of the two tile templates IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true); tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node); // Tile Notification TileNotification tileNotification = new TileNotification(tileXml); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
/// <summary> /// Delete HTML tags from the quote props and checks values /// </summary> /// <param name="quote"></param> /// <returns></returns> public BackgroundQuote Normalize(BackgroundQuote quote) { quote.Author = DeleteHTMLTags(quote.Author); quote.Content = DeleteHTMLTags(quote.Content); quote.Reference = DeleteHTMLTags(quote.Reference); if (quote.Reference.Contains("Vos avis")) { int index = quote.Reference.IndexOf("Vos avis"); quote.Reference = quote.Reference.Substring(0, index); } return(quote); }
public void SaveDailyQuote(BackgroundQuote dailyQuote) { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; ApplicationDataCompositeValue compositeQuote = new ApplicationDataCompositeValue(); compositeQuote[DAILY_QUOTE_CONTENT] = dailyQuote.Content; compositeQuote[DAILY_QUOTE_AUTHOR] = dailyQuote.Author; compositeQuote[DAILY_QUOTE_AUTHOR_LINK] = dailyQuote.AuthorLink; compositeQuote[DAILY_QUOTE_REFERENCE] = dailyQuote.Reference; compositeQuote[DAILY_QUOTE_LINK] = dailyQuote.Link; localSettings.Values[DAILY_QUOTE] = compositeQuote; }
public BackgroundQuote RetrieveDailyQuote() { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; ApplicationDataCompositeValue compositeQuote = (ApplicationDataCompositeValue)localSettings.Values[DAILY_QUOTE]; BackgroundQuote quote = new BackgroundQuote( (string)compositeQuote[DAILY_QUOTE_CONTENT], (string)compositeQuote[DAILY_QUOTE_AUTHOR], (string)compositeQuote[DAILY_QUOTE_AUTHOR_LINK], null, (string)compositeQuote[DAILY_QUOTE_REFERENCE], (string)compositeQuote[DAILY_QUOTE_LINK]); return(quote); }
private async Task <StorageFile> TakeScreenshot(string url, string name, BackgroundQuote quote) { var bold = new FontWeight(); bold.Weight = 700; TextBlock txtLine1 = new TextBlock() { Text = "totooooooo", Foreground = new SolidColorBrush(Windows.UI.Colors.White), Opacity = 0.6, FontSize = 32, FontWeight = bold, TextAlignment = TextAlignment.Left, Margin = new Thickness(48, 400, 12, 0), TextWrapping = TextWrapping.Wrap }; StackPanel sp = new StackPanel() { Background = new SolidColorBrush(Windows.UI.Colors.Brown), Width = 720, Height = 1280, Orientation = Orientation.Vertical }; var bitmap = new BitmapImage(new System.Uri(url)); var brush = new ImageBrush(); brush.ImageSource = bitmap; brush.Opacity = 0.5; sp.Background = brush; //TextBlock txtLine2 = new TextBlock { // Text = "Text Line 2", // Foreground = new SolidColorBrush(Windows.UI.Colors.White), // Width = 200, // Height = 30, // FontSize = 32, // TextAlignment = TextAlignment.Left, // Margin = new Thickness(9, 3, 0, 3) //}; sp.Children.Add(txtLine1); //sp.Children.Add(txtLine2); sp.UpdateLayout(); //sp.Measure(new Size(200, 200)); //sp.Arrange(new Rect(0, 0, 200, 200)); //sp.UpdateLayout(); //now lets render this stackpanel on image try { RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); await renderTargetBitmap.RenderAsync(sp, 520, 1080); var pixelBuffer = await renderTargetBitmap.GetPixelsAsync(); StorageFolder storageFolder = ApplicationData.Current.LocalFolder; var tileFile = await storageFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting); // Encode the image to the selected file on disk using (var fileStream = await tileFile.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBuffer.ToArray()); await encoder.FlushAsync(); } return(tileFile); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); //new MessageDialog(ex.Message, "Error").ShowAsync(); return(null); } }