internal void PopulateElement(Element_TileBinding binding, TileSize size) { // Assign properties binding.TextStacking = TextStacking; // Add the background image if there's one if (BackgroundImage != null) { // We pull up the overlay value from there binding.Overlay = BackgroundImage.Overlay; // And add it as a child binding.Children.Add(BackgroundImage.ConvertToElement()); } // Add the peek image if there's one if (PeekImage != null) { var el = PeekImage.ConvertToElement(); // If peek overlay needs to be specified if (ShouldSpecifyPeekOverlay(binding, PeekImage)) { el.Overlay = PeekImage.Overlay; } binding.Children.Add(el); } // And then add all the children foreach (var child in Children) { binding.Children.Add(ConvertToBindingChildElement(child)); } }
internal void PopulateElement(Element_TileBinding binding, TileSize size) { binding.Presentation = TilePresentation.People; foreach (var img in Images) binding.Children.Add(img.ConvertToElement()); }
private static bool ShouldSpecifyPeekOverlay(Element_TileBinding binding, TilePeekImage peekImage) { if (binding.Overlay == null) { // Peek defaults to 0 anyways, so no need to specify if (peekImage.Overlay == 0) { return(false); } else { return(true); } } else { // Main matches, no need to specify if (binding.Overlay.Value == peekImage.Overlay) { return(false); } else { return(true); } } }
internal void PopulateElement(Element_TileBinding binding, TileSize size) { // Assign properties binding.TextStacking = TextStacking; // Add the background image if there's one if (BackgroundImage != null) { // We pull up the overlay value from there binding.Overlay = BackgroundImage.Overlay; // And add it as a child binding.Children.Add(BackgroundImage.ConvertToElement()); } // Add the peek image if there's one if (PeekImage != null) { var el = PeekImage.ConvertToElement(); // If peek overlay needs to be specified if (ShouldSpecifyPeekOverlay(binding, PeekImage)) el.Overlay = PeekImage.Overlay; binding.Children.Add(el); } // And then add all the children foreach (var child in Children) { binding.Children.Add(ConvertToBindingChildElement(child)); } }
internal void PopulateElement(Element_TileBinding binding, TileSize size) { // Assign properties binding.TextStacking = TextStacking; // Add the background image if there's one if (BackgroundImage != null) { // We pull up the overlay value from there binding.Overlay = BackgroundImage.Overlay; // And add it as a child binding.Children.Add(BackgroundImage.ConvertToElement()); } // Add the peek image if there's one if (PeekImage != null) { binding.Children.Add(PeekImage.ConvertToElement()); } // And then add all the children foreach (var child in Children) { binding.Children.Add(ConvertToBindingChildElement(child)); } }
internal void PopulateElement(Element_TileBinding binding, TileSize size) { binding.Presentation = TilePresentation.Photos; foreach (var img in Images) { binding.Children.Add(img.ConvertToElement()); } }
internal void PopulateElement(Element_TileBinding binding, TileSize size) { if (Icon != null) { var element = Icon.ConvertToElement(); element.Id = 1; binding.Children.Add(element); } }
internal Element_TileBinding ConvertToElement(TileSize size) { TileTemplateNameV3 templateName = GetTemplateName(Content, size); Element_TileBinding binding = new Element_TileBinding(templateName) { Language = Language, BaseUri = BaseUri, Branding = Branding, AddImageQuery = AddImageQuery, DisplayName = DisplayName, ContentId = ContentId, Arguments = Arguments // LockDetailedStatus gets populated by TileVisual }; PopulateElement(Content, binding, size); return(binding); }
internal Element_TileBinding ConvertToElement(TileSize size) { TileTemplateNameV3 templateName = GetTemplateName(Content, size); Element_TileBinding binding = new Element_TileBinding(templateName) { Language = Language, BaseUri = BaseUri, Branding = Branding, AddImageQuery = AddImageQuery, DisplayName = DisplayName, ContentId = ContentId // LockDetailedStatus gets populated by TileVisual }; PopulateElement(Content, binding, size); return binding; }
private static bool ShouldSpecifyPeekOverlay(Element_TileBinding binding, TilePeekImage peekImage) { if (binding.Overlay == null) { // Peek defaults to 0 anyways, so no need to specify if (peekImage.Overlay == 0) return false; else return true; } else { // Main matches, no need to specify if (binding.Overlay.Value == peekImage.Overlay) return false; else return true; } }
private static void PopulateElement(ITileBindingContent bindingContent, Element_TileBinding binding, TileSize size) { if (bindingContent == null) return; if (bindingContent is TileBindingContentAdaptive) (bindingContent as TileBindingContentAdaptive).PopulateElement(binding, size); else if (bindingContent is TileBindingContentContact) (bindingContent as TileBindingContentContact).PopulateElement(binding, size); else if (bindingContent is TileBindingContentIconic) (bindingContent as TileBindingContentIconic).PopulateElement(binding, size); else if (bindingContent is TileBindingContentPeople) (bindingContent as TileBindingContentPeople).PopulateElement(binding, size); else if (bindingContent is TileBindingContentPhotos) (bindingContent as TileBindingContentPhotos).PopulateElement(binding, size); else throw new NotImplementedException("Unknown binding content type: " + bindingContent.GetType()); }
private static void PopulateElement(ITileBindingContent bindingContent, Element_TileBinding binding, TileSize size) { if (bindingContent == null) { return; } if (bindingContent is TileBindingContentAdaptive) { (bindingContent as TileBindingContentAdaptive).PopulateElement(binding, size); } else if (bindingContent is TileBindingContentContact) { (bindingContent as TileBindingContentContact).PopulateElement(binding, size); } else if (bindingContent is TileBindingContentIconic) { (bindingContent as TileBindingContentIconic).PopulateElement(binding, size); } else if (bindingContent is TileBindingContentPeople) { (bindingContent as TileBindingContentPeople).PopulateElement(binding, size); } else if (bindingContent is TileBindingContentPhotos) { (bindingContent as TileBindingContentPhotos).PopulateElement(binding, size); } else { throw new NotImplementedException("Unknown binding content type: " + bindingContent.GetType()); } }
/// <summary> /// Attempts to find and re-use an existing text element inside the binding. Returns true if it could. Otherwise returns false, and the caller will have to specify the detailed status using the lock hint attribute. /// </summary> /// <param name="lineNumber"></param> /// <param name="lockText"></param> /// <param name="binding"></param> /// <returns></returns> private static bool TryReuseTextElementForLockDetailedText(int lineNumber, string lockText, Element_TileBinding binding) { if (lockText == null) { throw new ArgumentNullException("lockText cannot be null"); } if (binding == null) { throw new ArgumentNullException("binding cannot be null"); } // If a text element already has an id with the line number (only look at immediate children, since the lockscreen will ignore things under groups/subgroups) Element_TileText matchingIdTextElement = binding.Children.OfType <Element_TileText>().FirstOrDefault(i => i.Id != null && i.Id.Equals(lineNumber.ToString())); if (matchingIdTextElement != null) { // If the text in the element matches the lock text, then we're good, don't need to assign anything else! if (matchingIdTextElement.Text != null && matchingIdTextElement.Text.Equals(lockText)) { return(true); } // Otherwise, we need to specify the lock text in the hint attribute, so we return false return(false); } // Otherwise no text elements use that ID, so we could assign one if we find a text element that doesn't have an ID assigned and matches the lock text Element_TileText matchingTextTextElement = binding.Children.OfType <Element_TileText>().FirstOrDefault(i => i.Id == null && i.Text != null && i.Text.Equals(lockText)); // If we found text that matched, we'll assign the id so it gets re-used for lock! if (matchingTextTextElement != null) { matchingTextTextElement.Id = lineNumber; return(true); } // Otherwise we'll need to specify lock text in hint attribute, so return false return(false); }
internal Element_TileVisual ConvertToElement() { var visual = new Element_TileVisual() { Version = Version, Language = Language, BaseUri = BaseUri, Branding = Branding, AddImageQuery = AddImageQuery, ContentId = ContentId, DisplayName = DisplayName }; if (TileSmall != null) { visual.Bindings.Add(TileSmall.ConvertToElement(TileSize.Small)); } if (TileMedium != null) { visual.Bindings.Add(TileMedium.ConvertToElement(TileSize.Medium)); } if (TileWide != null) { Element_TileBinding wideBindingElement = TileWide.ConvertToElement(TileSize.Wide); // If lock detailed status was specified, add them if (LockDetailedStatus1 != null) { // If we can't reuse existing text element, we'll have to use the hints if (!TryReuseTextElementForLockDetailedText(1, LockDetailedStatus1, wideBindingElement)) { wideBindingElement.LockDetailedStatus1 = LockDetailedStatus1; } } if (LockDetailedStatus2 != null) { if (!TryReuseTextElementForLockDetailedText(2, LockDetailedStatus2, wideBindingElement)) { wideBindingElement.LockDetailedStatus2 = LockDetailedStatus2; } } if (LockDetailedStatus3 != null) { if (!TryReuseTextElementForLockDetailedText(3, LockDetailedStatus3, wideBindingElement)) { wideBindingElement.LockDetailedStatus3 = LockDetailedStatus3; } } visual.Bindings.Add(wideBindingElement); } // Otherwise if they specified lock values, throw an exception since lock values require wide else if (HasLockDetailedStatusValues()) { throw new Exception("To provide lock detailed status text strings, you must also provide a TileWide binding. Either provide a TileWide binding, or leave the detailed status values null."); } if (TileLarge != null) { visual.Bindings.Add(TileLarge.ConvertToElement(TileSize.Large)); } // TODO: If a BaseUri wasn't provided, we can potentially optimize the payload size by calculating the best BaseUri return(visual); }
/// <summary> /// Attempts to find and re-use an existing text element inside the binding. Returns true if it could. Otherwise returns false, and the caller will have to specify the detailed status using the lock hint attribute. /// </summary> /// <param name="lineNumber"></param> /// <param name="lockText"></param> /// <param name="binding"></param> /// <returns></returns> private static bool TryReuseTextElementForLockDetailedText(int lineNumber, string lockText, Element_TileBinding binding) { if (lockText == null) throw new ArgumentNullException("lockText cannot be null"); if (binding == null) throw new ArgumentNullException("binding cannot be null"); // If a text element already has an id with the line number (only look at immediate children, since the lockscreen will ignore things under groups/subgroups) Element_TileText matchingIdTextElement = binding.Children.OfType<Element_TileText>().FirstOrDefault(i => i.Id != null && i.Id.Equals(lineNumber.ToString())); if (matchingIdTextElement != null) { // If the text in the element matches the lock text, then we're good, don't need to assign anything else! if (matchingIdTextElement.Text != null && matchingIdTextElement.Text.Equals(lockText)) return true; // Otherwise, we need to specify the lock text in the hint attribute, so we return false return false; } // Otherwise no text elements use that ID, so we could assign one if we find a text element that doesn't have an ID assigned and matches the lock text Element_TileText matchingTextTextElement = binding.Children.OfType<Element_TileText>().FirstOrDefault(i => i.Id == null && i.Text != null && i.Text.Equals(lockText)); // If we found text that matched, we'll assign the id so it gets re-used for lock! if (matchingTextTextElement != null) { matchingTextTextElement.Id = lineNumber; return true; } // Otherwise we'll need to specify lock text in hint attribute, so return false return false; }