private static void AssertAdaptiveChild(string expectedAdaptiveChildXml, IAdaptiveChild child) { AssertAdaptiveChildInToast(expectedAdaptiveChildXml, child); AssertAdaptiveChildInTile(expectedAdaptiveChildXml, child); // Also assert them within group/subgroup if possible! if (child is IAdaptiveSubgroupChild) { AdaptiveGroup group = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { child as IAdaptiveSubgroupChild } } } }; string expectedGroupXml = "<group><subgroup>" + expectedAdaptiveChildXml + "</subgroup></group>"; AssertAdaptiveChildInToast(expectedGroupXml, group); AssertAdaptiveChildInTile(expectedGroupXml, group); } }
private TileContent BuildLiveTile(List <ResponsiveNotificationText> messages) { var results = messages.ElementAt(0); var fixtures = messages.ElementAt(1); if (!results.Matches.Any() && !fixtures.Matches.Any()) { return(null); } TileVisual root = new TileVisual(); TileBinding wideBinding = new TileBinding(); TileBindingContentAdaptive wideBindingContent = new TileBindingContentAdaptive(); wideBinding.Content = wideBindingContent; TileBinding largeBinding = new TileBinding(); TileBindingContentAdaptive largeBindingContent = new TileBindingContentAdaptive(); largeBinding.Content = largeBindingContent; foreach (var notificationGroup in messages) { if (notificationGroup.Matches.Any()) { var group = new AdaptiveGroup(); var subgroup = new AdaptiveSubgroup() { HintTextStacking = AdaptiveSubgroupTextStacking.Center }; subgroup.Children.Add(new AdaptiveText() { Text = notificationGroup.MatchType, HintStyle = AdaptiveTextStyle.Body }); foreach (var match in notificationGroup.Matches) { subgroup.Children.Add(new AdaptiveText() { Text = match, HintStyle = AdaptiveTextStyle.Caption }); } group.Children.Add(subgroup); wideBindingContent.Children.Add(group); largeBindingContent.Children.Add(group); } } root.TileLarge = largeBinding; root.TileWide = wideBinding; return(new TileContent() { Visual = root }); }
private static void AssertAdaptiveSubgroup(string expectedSubgroupXml, AdaptiveSubgroup subgroup) { AdaptiveGroup group = new AdaptiveGroup() { Children = { subgroup } }; AssertAdaptiveChild("<group>" + expectedSubgroupXml + "</group>", group); }
public void AddVisualChildTest_WithCustomVisual_ReturnSelfWithCustomVisualAdded() { // Arrange // Taken from : https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts#adaptive-content AdaptiveGroup group = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = "52 attendees", HintStyle = AdaptiveTextStyle.Base }, new AdaptiveText() { Text = "23 minute drive", HintStyle = AdaptiveTextStyle.CaptionSubtle } } }, new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = "1 Microsoft Way", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Right }, new AdaptiveText() { Text = "Bellevue, WA 98008", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Right } } } } }; ToastContentBuilder builder = new ToastContentBuilder(); // Act ToastContentBuilder anotherReference = builder.AddVisualChild(group); // Assert Assert.AreSame(builder, anotherReference); Assert.IsInstanceOfType(builder.Content.Visual.BindingGeneric.Children.First(), typeof(AdaptiveGroup)); }
private TileBinding CreateTileBinding(TileSize size, string title, int readingTime, string imageSource) { var binding = new TileBinding() { Branding = TileBranding.Logo, Content = new TileBindingContentAdaptive() }; // Create the XML in code var group = new AdaptiveGroup(); var subgroup = new AdaptiveSubgroup(); // Add the title to the tile var tileTitle = new AdaptiveText() { Text = title, HintMaxLines = size == TileSize.Large ? 3 : 2, HintWrap = true, HintStyle = size == TileSize.Medium ? AdaptiveTextStyle.Caption : AdaptiveTextStyle.Body }; subgroup.Children.Add(tileTitle); // Add the reading time string resourceName = size == TileSize.Medium ? "LiveTileReadingTimeShort" : "LiveTileReadingTime"; subgroup.Children.Add(new AdaptiveText() { Text = string.Format(_device.GetLocalizedResource(resourceName), readingTime), HintStyle = AdaptiveTextStyle.CaptionSubtle }); // Finally add the subgroup to the tile group.Children.Add(subgroup); // Add the background image if neccessary if (!string.IsNullOrEmpty(imageSource)) { (binding.Content as TileBindingContentAdaptive).BackgroundImage = new TileBackgroundImage() { Source = imageSource, HintOverlay = 60 }; } // Add the group to the tile (binding.Content as TileBindingContentAdaptive).Children.Add(group); return(binding); }
private ToastContent BuildNotification(List <ResponsiveNotificationText> messages) { ToastVisual root = new ToastVisual(); ToastBindingGeneric binding = new ToastBindingGeneric(); root.BindingGeneric = binding; var results = messages.ElementAt(0); var fixtures = messages.ElementAt(1); if (!fixtures.Matches.Any() && !results.Matches.Any()) { return(null); } foreach (var notificationGroup in messages) { if (notificationGroup.Matches.Any()) { var group = new AdaptiveGroup(); var subgroup = new AdaptiveSubgroup() { HintTextStacking = AdaptiveSubgroupTextStacking.Center }; subgroup.Children.Add(new AdaptiveText() { Text = notificationGroup.MatchType, HintStyle = AdaptiveTextStyle.Subtitle }); foreach (var match in notificationGroup.Matches) { subgroup.Children.Add(new AdaptiveText() { Text = match, HintStyle = AdaptiveTextStyle.BaseSubtle }); } group.Children.Add(subgroup); binding.Children.Add(group); } } return(new ToastContent() { Visual = root }); }
private static TileBindingContentAdaptive CreateTileContent(string prefix, string leftTitle, string leftValue, string rightTitle, string rightValuevalue, string dateTitle, string dateContent) { //Create a TileContent var tileContent = new TileBindingContentAdaptive(); tileContent.TextStacking = TileTextStacking.Center; //Create a groups and subgroups var tileGroup = new AdaptiveGroup(); AdaptiveSubgroup columnGroupLeft = CreateAdaptiveGroupColumn(prefix + " " + leftTitle, leftValue, dateTitle); AdaptiveSubgroup CoulumnGroupRight = CreateAdaptiveGroupColumn(prefix + " " + rightTitle, rightValuevalue, dateContent); tileGroup.Children.Add(columnGroupLeft); tileGroup.Children.Add(CoulumnGroupRight); tileContent.Children.Add(tileGroup); return(tileContent); }
private static TileBindingContentAdaptive GenerateTileNotificationWideContent(IEnumerable <ViewItemSchedule> schedules) { TileBindingContentAdaptive content = new TileBindingContentAdaptive(); if (schedules.Any()) { // Create and add the first large content content.Children.Add(GenerateTileNotificationWideAndLargeGroupContent(schedules.ElementAt(0))); if (schedules.Count() > 1) { // Add the image spacer content.Children.Add(new AdaptiveImage() { Source = "Assets/Tiles/Padding/4px.png", HintAlign = AdaptiveImageAlign.Left, HintRemoveMargin = true }); const int MAX_ADDITIONAL = 4; for (int i = 1; i < schedules.Count() && i < MAX_ADDITIONAL; i++) { ViewItemSchedule schedule = schedules.ElementAt(i); var group = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 20, Children = { new AdaptiveText() { Text = GetTimeString(schedule.StartTime), HintStyle = AdaptiveTextStyle.CaptionSubtle } } }, new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = TrimString(schedule.Class.Name, 22), HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; if (!string.IsNullOrWhiteSpace(schedule.Room)) { group.Children.Last().HintWeight = 30; group.Children.Add(new AdaptiveSubgroup() { // Don't need to assign weight since it gets the remaining from 100, // which saves spaces in the XML! Children = { new AdaptiveText() { Text = TrimString(schedule.Room, 32), HintStyle = AdaptiveTextStyle.CaptionSubtle } } }); } content.Children.Add(group); } } } return(content); }
public ToastNotification CreateCallNotification(IEnumerable <Call> currentCalls) { List <Call> calls = currentCalls.Where(x => x.State != CallState.Disconnected && x.State != CallState.Indeterminate).OrderBy(x => x.State).ToList(); ToastBindingGeneric content = new ToastBindingGeneric(); ToastActionsCustom actions = new ToastActionsCustom(); switch (calls.Count) { case 0: return(null); case 1: Call singleCall = calls.First(); foreach (IToastBindingGenericChild child in CreateVisualForCall(singleCall)) { content.Children.Add(child); } foreach (IToastButton button in CreateButtonsForCall(singleCall)) { actions.Buttons.Add(button); } break; default: content.Children.Add(new AdaptiveText() { Text = "Dialer - Active calls" }); for (int i0 = 0; i0 < calls.Count / 2; i0++) { AdaptiveGroup group = new AdaptiveGroup(); for (int i1 = i0 * 2; i1 < i0 * 2 + 2 && i1 < calls.Count; i1++) { AdaptiveSubgroup subgroup = new AdaptiveSubgroup(); foreach (IAdaptiveSubgroupChild child in CreateVisualForCall(calls[i1])) { subgroup.Children.Add(child); } group.Children.Add(subgroup); } content.Children.Add(group); } foreach (IToastButton button in MergeButtons(calls.Select(x => CreateButtonsForCall(x)).SelectMany(x => x))) { actions.Buttons.Add(button); } break; } Call incomingCall = calls.FirstOrDefault(x => x.State == CallState.Incoming); bool hasRingTone = !string.IsNullOrEmpty(incomingCall?.Contact?.RingToneToken); ToastContent toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = content }, Actions = actions, Audio = new ToastAudio() { Silent = calls.Any(x => x.State != CallState.Incoming), Loop = true, Src = hasRingTone ? new Uri(incomingCall.Contact.RingToneToken) : null }, Launch = $"{ACTION}={SHOW_CALL_UI}", Scenario = ToastScenario.IncomingCall }; ToastNotification notification = new ToastNotification(toastContent.GetXml()) { Tag = CALL_NOTIFICATION_UI, ExpiresOnReboot = true, Priority = ToastNotificationPriority.High, Data = new NotificationData() { Values = { { USED_CALLS, calls.Aggregate(new StringBuilder(), (x, y) => x.Append(y.ID).Append(';'), x => x.ToString()) }, { USED_CALLS_STATES, calls.Aggregate(new StringBuilder(), (x, y) => x.Append((uint)y.State).Append(';'), x => x.ToString()) } } } }; return(notification); }
private static TileBindingContentAdaptive GenerateCondition(Weather weather, ForecastTileType forecastTileType) { var userlang = GlobalizationPreferences.Languages[0]; var culture = new CultureInfo(userlang); var content = new TileBindingContentAdaptive { // Background URI BackgroundImage = new TileBackgroundImage() { Source = wm.GetBackgroundURI(weather) } }; if (forecastTileType == ForecastTileType.Small) { content.Children.Add(new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = weather.update_time.ToString("ddd", culture), HintStyle = AdaptiveTextStyle.Base, HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º", HintStyle = AdaptiveTextStyle.Body, HintAlign = AdaptiveTextAlign.Center } } } } }); } else if (forecastTileType == ForecastTileType.Medium) { content.Children.Add(new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = null } } }, new AdaptiveSubgroup() { HintWeight = 3, HintTextStacking = AdaptiveSubgroupTextStacking.Center, Children = { new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(weather.condition.icon) }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º", HintStyle = AdaptiveTextStyle.Body, HintAlign = AdaptiveTextAlign.Center, } } }, new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = null } } } } }); } else if (forecastTileType == ForecastTileType.Wide) { // Current Condition (Extended) var forecastGroup = new AdaptiveGroup(); var condition = new AdaptiveSubgroup() { HintWeight = 25, Children = { new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(weather.condition.icon) } }, HintTextStacking = AdaptiveSubgroupTextStacking.Center }; var details = new AdaptiveSubgroup() { HintWeight = 75, Children = { new AdaptiveText() { Text = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather, HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"), HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"), HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"), Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"), HintStyle = AdaptiveTextStyle.CaptionSubtle } } }; forecastGroup.Children.Add(condition); forecastGroup.Children.Add(details); content.Children.Add(forecastGroup); } else if (forecastTileType == ForecastTileType.Large) { // Condition + 5-day forecast var forecastGroup = new AdaptiveGroup(); var condition = weather.condition; int forecastLength = LARGE_FORECAST_LENGTH; if (weather.forecast.Length < forecastLength) { forecastLength = weather.forecast.Length; } var conditionGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 25, HintTextStacking = AdaptiveSubgroupTextStacking.Center, Children = { new AdaptiveImage() { Source = wm.GetWeatherIconURI(weather.condition.icon) } } }, new AdaptiveSubgroup() { HintWeight = 75, Children = { new AdaptiveText() { Text = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather, HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"), HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"), HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"), Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"), HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; var text = new AdaptiveText() { Text = "" }; for (int i = 0; i < forecastLength; i++) { var forecast = weather.forecast[i]; var subgroup = new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = forecast.date.ToString("ddd", culture), HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(forecast.icon) }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(double.Parse(forecast.high_f)).ToString() : Math.Round(double.Parse(forecast.high_c)).ToString()) + "º", HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(double.Parse(forecast.low_f)).ToString() : Math.Round(double.Parse(forecast.low_c)).ToString()) + "º", HintStyle = AdaptiveTextStyle.CaptionSubtle, HintAlign = AdaptiveTextAlign.Center } } }; forecastGroup.Children.Add(subgroup); } content.Children.Add(conditionGroup); content.Children.Add(text); content.Children.Add(forecastGroup); } return(content); }
private static TileBindingContentAdaptive GenerateHrForecast(Weather weather, ForecastTileType forecastTileType) { var userlang = GlobalizationPreferences.Languages[0]; var culture = new CultureInfo(userlang); var content = new TileBindingContentAdaptive { // Background URI BackgroundImage = new TileBackgroundImage() { Source = wm.GetBackgroundURI(weather) } }; if (forecastTileType == ForecastTileType.Small) { content.Children.Add(new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = weather.update_time.ToString("ddd", culture), HintStyle = AdaptiveTextStyle.Base, HintAlign = AdaptiveTextAlign.Center }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º", HintStyle = AdaptiveTextStyle.Body, HintAlign = AdaptiveTextAlign.Center } } } } }); } else if (forecastTileType == ForecastTileType.Medium) { var dateGroup = new AdaptiveGroup(); var forecastGroup = new AdaptiveGroup(); var tempGroup = new AdaptiveGroup(); string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ? "HH" : "ht"; int forecastLength = MEDIUM_FORECAST_LENGTH; if (weather.hr_forecast.Length < forecastLength) { forecastLength = weather.hr_forecast.Length; } // 3hr forecast for (int i = 0; i < forecastLength; i++) { var hrforecast = weather.hr_forecast[i]; var dateSubgroup = new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = hrforecast.date.ToString(timeformat, culture).ToLower(), HintAlign = AdaptiveTextAlign.Center }, } }; var iconSubgroup = new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(hrforecast.icon) }, } }; var tempSubgroup = new AdaptiveSubgroup() { HintWeight = 1, HintTextStacking = AdaptiveSubgroupTextStacking.Bottom, Children = { new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º", HintStyle = AdaptiveTextStyle.Caption, HintAlign = AdaptiveTextAlign.Center } } }; dateGroup.Children.Add(dateSubgroup); forecastGroup.Children.Add(iconSubgroup); tempGroup.Children.Add(tempSubgroup); } content.Children.Add(dateGroup); content.Children.Add(forecastGroup); content.Children.Add(tempGroup); } else if (forecastTileType == ForecastTileType.Wide) { // 5-hr forecast var forecastGroup = new AdaptiveGroup(); string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ? "HH" : "ht"; int forecastLength = LARGE_FORECAST_LENGTH; if (weather.hr_forecast.Length < forecastLength) { forecastLength = weather.hr_forecast.Length; } for (int i = 0; i < forecastLength; i++) { var hrforecast = weather.hr_forecast[i]; var subgroup = new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = hrforecast.date.ToString(timeformat, culture).ToLower(), HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(hrforecast.icon) }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º", HintAlign = AdaptiveTextAlign.Center }, } }; forecastGroup.Children.Add(subgroup); } content.Children.Add(forecastGroup); } else if (forecastTileType == ForecastTileType.Large) { // Condition + 5-hr forecast var forecastGroup = new AdaptiveGroup(); string timeformat = culture.DateTimeFormat.ShortTimePattern.Contains("H") ? "HH" : "ht"; string poplabel = (weather.source.Equals(WeatherAPI.OpenWeatherMap) || weather.source.Equals(WeatherAPI.MetNo)) ? App.ResLoader.GetString("Cloudiness_Label") : App.ResLoader.GetString("Precipitation_Label"); // Cloudiness or Precipitation int forecastLength = LARGE_FORECAST_LENGTH; if (weather.hr_forecast.Length < forecastLength) { forecastLength = weather.hr_forecast.Length; } var conditionGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { HintWeight = 25, HintTextStacking = AdaptiveSubgroupTextStacking.Center, Children = { new AdaptiveImage() { Source = wm.GetWeatherIconURI(weather.condition.icon) } } }, new AdaptiveSubgroup() { HintWeight = 75, Children = { new AdaptiveText() { Text = (String.IsNullOrWhiteSpace(weather.condition.weather)) ? "---" : weather.condition.weather, HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Temp_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.temp_f) : Math.Round(weather.condition.temp_c)) + "º"), HintStyle = AdaptiveTextStyle.Caption }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("FeelsLike_Label"), (Settings.IsFahrenheit ? Math.Round(weather.condition.feelslike_f) : Math.Round(weather.condition.feelslike_c)) + "º"), HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = string.Format("{0}: {1}", App.ResLoader.GetString("Wind_Label"), Settings.IsFahrenheit ? Math.Round(weather.condition.wind_mph) + " mph" : Math.Round(weather.condition.wind_kph) + " kph"), HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { Text = weather.precipitation != null ? string.Format("{0}: {1}", poplabel, weather.precipitation.pop + "%") : "", HintStyle = AdaptiveTextStyle.CaptionSubtle } } } } }; var text = new AdaptiveText() { Text = "" }; for (int i = 0; i < forecastLength; i++) { var hrforecast = weather.hr_forecast[i]; var subgroup = new AdaptiveSubgroup() { HintWeight = 1, Children = { new AdaptiveText() { Text = hrforecast.date.ToString(timeformat, culture).ToLower(), HintAlign = AdaptiveTextAlign.Center }, new AdaptiveImage() { HintRemoveMargin = true, Source = wm.GetWeatherIconURI(hrforecast.icon) }, new AdaptiveText() { Text = (Settings.IsFahrenheit ? Math.Round(double.Parse(hrforecast.high_f)).ToString() : Math.Round(double.Parse(hrforecast.high_c)).ToString()) + "º", HintAlign = AdaptiveTextAlign.Center }, } }; forecastGroup.Children.Add(subgroup); } content.Children.Add(conditionGroup); content.Children.Add(text); content.Children.Add(forecastGroup); } return(content); }
public static async Task UpdateTile(Model.Schedule schedule) { TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication(); if (schedule == null) { updater.Clear(); return; } //Windows.Foundation.Diagnostics.LoggingChannel lc = new Windows.Foundation.Diagnostics.LoggingChannel("UCQU_BackgroundTaskPayload", null, new Guid("4bd2826e-54a1-4ba9-bf63-92b73ea1ac4a")); //lc.LogMessage("Entered Payload Method."); //lc.LogMessage("Tile Updated Created."); string id = "", pwdHash = ""; if (Login.LoadCredentials(out id, out pwdHash) == false) { //lc.LogMessage("Credential Load Failed. Clearing tile and exiting..."); updater.Clear(); return; } TileContent content = null; //lc.LogMessage("Obtaining Schedule."); //lc.LogMessage("Getting Schedule of Today."); List <Model.ScheduleEntry> entries = schedule.GetDaySchedule((DateTime.Today /*CommonResources.TestDate*/ - RuntimeData.StartDate).Days).ToList(); entries.RemoveAll(x => { (_, var endTime) = SessionTimeConverter.ConvertShort(x.SessionSpan, CampusSelector.IsCampusD(x.Room)); return(endTime.GetDateTime() < DateTime.Now); }); entries.Sort((x, y) => x.StartSlot - y.StartSlot); //lc.LogMessage("Constructing Tile Content."); TileBindingContentAdaptive midTileContent = new TileBindingContentAdaptive(); TileBindingContentAdaptive wideTileContent = new TileBindingContentAdaptive(); TileBindingContentAdaptive largeTileContent = new TileBindingContentAdaptive(); if (entries.Count > 0) { if (!IsToastScheduled) { try { ScheduleToast(entries); } catch (Exception ex) { } IsToastScheduled = true; } //lc.LogMessage("Course Detected. Creating daily schedule tile."); foreach (Model.ScheduleEntry e in entries) { (var start, var end) = SessionTimeConverter.ConvertShort(e.SessionSpan, CampusSelector.IsCampusD(e.Room)); AdaptiveGroup midGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Caption, HintWrap = true }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } } }; AdaptiveGroup wideGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Caption, }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, } } } }; AdaptiveGroup largeGroup = new AdaptiveGroup() { Children = { new AdaptiveSubgroup() { Children = { new AdaptiveText() { Text = e.Name, HintStyle = AdaptiveTextStyle.Base, HintWrap = true }, new AdaptiveText() { Text = $"{start}-{end} {e.Room}", HintStyle = AdaptiveTextStyle.CaptionSubtle }, new AdaptiveText() { HintStyle = AdaptiveTextStyle.Caption } } } } }; midTileContent.Children.Add(midGroup); wideTileContent.Children.Add(wideGroup); largeTileContent.Children.Add(largeGroup); } //lc.LogMessage("Assigning Tile Content."); content = new TileContent() { Visual = new TileVisual() { Branding = TileBranding.Name, TileLarge = new TileBinding() { Content = largeTileContent }, TileMedium = new TileBinding() { Content = midTileContent }, TileWide = new TileBinding() { Content = wideTileContent }, } }; } else { //lc.LogMessage("No Course Detected. Creating image tile."); //lc.LogMessage("Getting Image Entries Metadata."); List <HuxiImgEntry> huxiImgEntries = await HuxiImg.GetEntries(); //lc.LogMessage("Creating Randomizer."); Random randomizer = new Random((int)DateTime.Now.Ticks); int index = randomizer.Next(0, huxiImgEntries.Count); if (!IsToastScheduled) { try { ScheduleToast(huxiImgEntries[index]); } catch (Exception ex) { } IsToastScheduled = true; } //lc.LogMessage("Randomly Selected Index: " + index); //lc.LogMessage("Constructing Image Tile."); largeTileContent.BackgroundImage = new TileBackgroundImage() { Source = huxiImgEntries[index].Uri, HintOverlay = 40 }; largeTileContent.Children.Add ( new AdaptiveText() { Text = huxiImgEntries[index].Title, HintStyle = AdaptiveTextStyle.Base } ); largeTileContent.Children.Add ( new AdaptiveText() { Text = huxiImgEntries[index].Author, HintStyle = AdaptiveTextStyle.CaptionSubtle } ); //lc.LogMessage("Assigning Tile Content."); content = new TileContent() { Visual = new TileVisual() { Branding = TileBranding.Name, TileLarge = new TileBinding() { Content = largeTileContent }, TileMedium = new TileBinding() { Content = largeTileContent }, TileWide = new TileBinding() { Content = largeTileContent }, } }; } //lc.LogMessage("Creating Tile Notification."); var notification = new TileNotification(content.GetXml()); //lc.LogMessage("Setting Expiry Time."); notification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(60); //lc.LogMessage("Clearing Existing Tiles"); updater.Clear(); //lc.LogMessage("Updating Tiles"); TileUpdateManager.CreateTileUpdaterForApplication().Update(notification); //lc.LogMessage("Payload Method Complete."); }
private static FrameworkElement GenerateGroup( AdaptiveGroup group, bool isFirstGroup, bool needsImageMargin, Thickness externalMargin) { if (group.Subgroups.Count == 0) { return(null); } double topMarginOffset = 0; if (!isFirstGroup) { topMarginOffset = GetSubgroupsTopMarginOffset(group.Subgroups); } if (needsImageMargin) { // Ensure that top margin will be at least the image margin, even though we haven't an image if (topMarginOffset < AdaptiveConstants.DefaultImageMargin) { topMarginOffset = AdaptiveConstants.DefaultImageMargin; } } Thickness groupMargin = new Thickness( 0, isFirstGroup ? 0.0 : AdaptiveConstants.DefaultGroupTopMargin, 0, 0); if (group.Subgroups.Count == 1) { AdaptiveStackPanel sp = GenerateSubgroup( subgroup: group.Subgroups[0], isFirstGroup: isFirstGroup, topMarginOffset: topMarginOffset, externalMargin: externalMargin); sp.Margin = new Thickness( sp.Margin.Left, sp.Margin.Top + groupMargin.Top, sp.Margin.Right, sp.Margin.Bottom); if (group.ActionId != null) { sp.Background = GetActionBackgroundBrush(); } return(sp); } else { Grid g = new AdaptiveGrid() { Margin = groupMargin }; // Get the calculated weights int[] weights = CalculateWeights(group.Subgroups); for (int i = 0; i < group.Subgroups.Count; i++) { var subgroup = group.Subgroups[i]; int weight = weights[i]; //add column for the subgroup g.ColumnDefinitions.Add(new ColumnDefinition() { Width = weight == AdaptiveSubgroup.WEIGHT_AUTO ? GridLength.Auto : new GridLength(weight, GridUnitType.Star) }); //and create the subgroup visual var subgroupEl = GenerateSubgroup(subgroup, isFirstGroup, topMarginOffset, externalMargin); Grid.SetColumn(subgroupEl, g.ColumnDefinitions.Count - 1); //assign it to this column //set text stacking switch (subgroup.HintTextStacking) { case HintTextStacking.Bottom: subgroupEl.VerticalAlignment = VerticalAlignment.Bottom; break; case HintTextStacking.Center: subgroupEl.VerticalAlignment = VerticalAlignment.Center; break; } //and then add that subgroup visual to the group visual g.Children.Add(subgroupEl); //always add 8 pixel padding between columns (but not on the right, last, side) if (i != group.Subgroups.Count - 1) { g.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(8) }); } if (subgroup.ActionId != null) { subgroupEl.Background = GetActionBackgroundBrush(); } } if (group.ActionId != null) { g.Background = GetActionBackgroundBrush(); } return(g); } }