private void CreateToastButton_Click(object sender, EventArgs e) { var actionButton = new ToastButton(); actionButton.AddArgument("action", "buttonAction"); actionButton.SetContent("Action Button"); var dismissButton = new ToastButton(); dismissButton.SetContent("Dismiss Button"); dismissButton.SetDismissActivation(); var toast = new ToastContentBuilder(); toast.AddAttributionText("Attribute Text"); toast.AddText("Title"); toast.AddText("Text 1"); toast.AddText("Text 2"); toast.AddButton(actionButton); toast.AddButton(dismissButton); toast.Show(toast => { toast.ExpirationTime = DateTime.Now.AddSeconds(5); toast.Priority = Windows.UI.Notifications.ToastNotificationPriority.High; }); }
private static void AssertButtonPayload(string expectedButtonXml, ToastButton button) { AssertActionsPayload("<actions>" + expectedButtonXml + "</actions>", new ToastActionsCustom() { Buttons = { button } }); }
public static void SendLocalNotification(string title, string message) { //VISUALS SETUP var bindingGeneric = new ToastBindingGeneric(); bindingGeneric.Children.Add(new AdaptiveText() { Text = title }); bindingGeneric.Children.Add(new AdaptiveText() { Text = message }); var visual = new ToastVisual() { BindingGeneric = bindingGeneric }; //ACTIONS SETUP var actions = new ToastActionsCustom(); var more_info_button = new ToastButton("More Info", new QueryString() { { "action", "view_details" } } .ToString()) { ActivationType = ToastActivationType.Foreground }; actions.Buttons.Add(more_info_button); actions.Buttons.Add(new ToastButtonDismiss("Dismiss")); //CONTENT SETUP var content = new ToastContent() { Visual = visual, Actions = actions, Launch = new QueryString() { { "action", "view_details" } }.ToString(), Scenario = ToastScenario.Alarm, ActivationType = ToastActivationType.Foreground, }; //TOAST SETUP var toast = new ToastNotification(content.GetXml()) { Tag = Guid.NewGuid().ToString() }; ToastNotificationManager.CreateToastNotifier().Show(toast); }
public void Test_Toast_Xml_Button_ActivationType_Background() { ToastButton button = new ToastButton("my content", "myArgs") { ActivationType = ToastActivationType.Background }; AssertButtonPayload("<action content='my content' arguments='myArgs' activationType='background' />", button); }
public void Test_Toast_Xml_Button_TextBoxId_Value() { ToastButton button = new ToastButton("my content", "myArgs") { TextBoxId = "myTextBox" }; AssertButtonPayload("<action content='my content' arguments='myArgs' hint-inputId='myTextBox' />", button); }
public void Test_Toast_Xml_Button_ImageUri_Value() { ToastButton button = new ToastButton("my content", "myArgs") { ImageUri = "Assets/button.png" }; AssertButtonPayload("<action content='my content' arguments='myArgs' imageUri='Assets/button.png' />", button); }
public void Test_Toast_Xml_Button_ActivationType_Protocol() { ToastButton button = new ToastButton("my content", "myArgs") { ActivationType = ToastActivationType.Protocol }; AssertButtonPayload("<action content='my content' arguments='myArgs' activationType='protocol' />", button); }
public void ToastButtonBuilders_ProtocolActivation_ReturnSelf() { ToastButton button = new ToastButton(); ToastButton anotherReference = button .SetContent("View") .SetProtocolActivation(new Uri("https://msn.com")); Assert.AreSame(button, anotherReference); Assert.AreEqual("View", button.Content); Assert.AreEqual("https://msn.com/", button.Arguments); Assert.AreEqual(ToastActivationType.Protocol, button.ActivationType); }
public void ToastButtonBuilders_General_ReturnSelf() { ToastButton button = new ToastButton(); ToastButton anotherReference = button .SetContent("View") .AddArgument("action", "view") .AddArgument("imageId", 601); Assert.AreSame(button, anotherReference); Assert.AreEqual("View", button.Content); Assert.AreEqual("action=view;imageId=601", button.Arguments); Assert.AreEqual(ToastActivationType.Foreground, button.ActivationType); }
private static ToastContent BuildToastContent(Music music, MediaPlaybackState state, NotificationDisplayMode display) { ToastButton controlButton = null; switch (state) { case MediaPlaybackState.Paused: controlButton = BuildToastButton("Play"); break; case MediaPlaybackState.Playing: controlButton = BuildToastButton("Pause"); break; } var toastContent = new ToastContent() { Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = music.GetToastText() }, new AdaptiveProgressBar() { Value = new BindableProgressBarValue("MediaControlPosition"), ValueStringOverride = MusicDurationConverter.ToTime(music.Duration), Title = new BindableString("Lyrics"), Status = new BindableString("MediaControlPositionTime") } } } }, Actions = new ToastActionsCustom() { Buttons = { controlButton, BuildToastButton("Next") } }, ActivationType = ToastActivationType.Background, Launch = "Launch", Audio = SlientToast, Scenario = display == NotificationDisplayMode.Reminder || state == MediaPlaybackState.Paused ? ToastScenario.Reminder : ToastScenario.Default }; return(toastContent); }
private void OnSendNotificationWithExtension(object sender, RoutedEventArgs e) { ToastVisual visual = new ToastVisual { AppLogoOverride = new ToastAppLogo { Crop = ToastImageCrop.None, Source = new ToastImageSource("ms-appx:///Assets/MicrosoftLogo.png") }, TitleText = new ToastText { Text = "DotNet Spain Conference" }, BodyTextLine1 = new ToastText { Text = "How much do you like my session ?" } }; ToastSelectionBox selection = new ToastSelectionBox("rating"); selection.Items.Add(new ToastSelectionBoxItem("1", "1 (Not very much)")); selection.Items.Add(new ToastSelectionBoxItem("2", "2")); selection.Items.Add(new ToastSelectionBoxItem("3", "3")); selection.Items.Add(new ToastSelectionBoxItem("4", "4")); selection.Items.Add(new ToastSelectionBoxItem("5", "5 (A lot!)")); ToastButton button = new ToastButton("Vote", "vote"); button.ActivationType = ToastActivationType.Background; ToastContent toast = new ToastContent { Visual = visual, ActivationType = ToastActivationType.Background, Actions = new ToastActionsCustom { Inputs = { selection }, Buttons = { button } } }; XmlDocument doc = toast.GetXml(); ToastNotification notification = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(notification); }
public void ToastButtonBuilders_AllProperties_ReturnSelf() { ToastButton button = new ToastButton(); ToastButton anotherReference = button .SetContent("View") .SetImageUri(new Uri("ms-appx:///Assets/view.png")) .AddArgument("action", "view") .SetBackgroundActivation() .SetAfterActivationBehavior(ToastAfterActivationBehavior.PendingUpdate) .SetHintActionId("viewImage"); Assert.AreSame(button, anotherReference); Assert.AreEqual("View", button.Content); Assert.AreEqual("action=view", button.Arguments); Assert.AreEqual("ms-appx:///Assets/view.png", button.ImageUri); Assert.AreEqual(ToastActivationType.Background, button.ActivationType); Assert.AreEqual(ToastAfterActivationBehavior.PendingUpdate, button.ActivationOptions.AfterActivationBehavior); Assert.AreEqual("viewImage", button.HintActionId); }
private IEnumerable <ToastButton> MergeButtons(IEnumerable <ToastButton> actions) { List <ToastButton> result = new List <ToastButton>(5); Dictionary <ToastButton, WwwFormUrlDecoder> queries = actions.ToDictionary(x => x, x => new WwwFormUrlDecoder(x.Arguments), ToastButtonEqualityComparer.EqualityComparer); List <ToastButton> _actions = actions.OrderBy(x => ACTION_PRIORITY[queries[x].GetFirstValueByName(ACTION)]).ToList(); ToastButton answer = _actions.FirstOrDefault(x => queries[x].GetFirstValueByName(ACTION) == ANSWER); ToastButton hold = _actions.FirstOrDefault(x => queries[x].GetFirstValueByName(ACTION) == HOLD); ToastButton end = _actions.FirstOrDefault(x => queries[x].GetFirstValueByName(ACTION) == END); if (answer != null) { if (hold != null || end != null) { _actions.Remove(answer); } if (end != null) { _actions.RemoveAll(x => queries[x].GetFirstValueByName(ACTION) == END); end = new ToastButton(App.Current.ResourceLoader.GetString("Button_End_And_Answer\\Text"), $"{ACTION}={END_AND_ANSWER}&{ACTIVE_CALL_ID}={queries[end].GetFirstValueByName(ACTIVE_CALL_ID)}&{INCOMING_CALL_ID}={queries[answer].GetFirstValueByName(INCOMING_CALL_ID)}") { ActivationType = ToastActivationType.Foreground }; queries.Add(end, new WwwFormUrlDecoder(end.Arguments)); _actions.Insert(0, end); } if (hold != null) { _actions.RemoveAll(x => queries[x].GetFirstValueByName(ACTION) == HOLD); hold = new ToastButton(App.Current.ResourceLoader.GetString("Button_Hold_And_Answer\\Text"), $"{ACTION}={HOLD_AND_ANSWER}&{ACTIVE_CALL_ID}={queries[hold].GetFirstValueByName(ACTIVE_CALL_ID)}&{INCOMING_CALL_ID}={queries[answer].GetFirstValueByName(INCOMING_CALL_ID)}") { ActivationType = ToastActivationType.Foreground }; queries.Add(hold, new WwwFormUrlDecoder(hold.Arguments)); _actions.Insert(0, hold); } } for (int i0 = 0; i0 < 5 && i0 < _actions.Count; i0++) { result.Add(_actions[i0]); } return(result.OrderByDescending(x => ACTION_PRIORITY[queries[x].GetFirstValueByName(ACTION)])); }
static void ShowOutdatedNotification(int num, string pcks) { Log.Debug("Show outdated notification. Packages: {Packages}", pcks); // enforce max length if (pcks.Length > 103) { pcks = pcks.Substring(0, 100) + "..."; } // Construct the content var updateAll = new ToastButton("Update all", CunNotificationActivator.UpdateAllAction); updateAll.ActivationType = ToastActivationType.Background; var update = new ToastButton("Update", CunNotificationActivator.UpdateAction); update.ActivationType = ToastActivationType.Background; var content = new ToastContentBuilder() .AddToastActivationInfo("list", ToastActivationType.Background) .AddHeader(MsgId, $"Chocolatey Packages outdated: {num}", "list") .AddText(pcks, AdaptiveTextStyle.Body) .AddButton(updateAll) .AddButton(update) .GetToastContent(); // Create the notification var notif = new ToastNotification(content.GetXml()) { ExpirationTime = DateTimeOffset.Now.AddMinutes(10) }; notif.Dismissed += Notif_Dismissed; // And show it! var oNotifier = DesktopNotificationManagerCompat.CreateToastNotifier(); oNotifier.Show(notif); }
private static ToastActionsCustom SetupToastActionsComponent(NotificationButton[] buttons) { ToastActionsCustom actions = new ToastActionsCustom(); foreach (NotificationButton button in buttons) { ToastButton toastButton = new ToastButton(button.Label, button.Action.ToString()) { ActivationType = ToastActivationType .Foreground }; if (!string.IsNullOrWhiteSpace(button.IconReference)) { toastButton.ImageUri = button.IconReference; } actions.Buttons.Add(toastButton); } return(actions); }
private void OnRafflesWon(object sender, RafflesWonArgs e) { bool enableToast = Properties.UserConfig.Default.ToastNotifications; if (enableToast) { string logo = Files.LogoFile; if (!File.Exists(logo)) { using (var http = new HttpClient()) { string url = string.Format("https://scrap.tf/apple-touch-icon.png?{0}", Guid.NewGuid()); byte[] data = http.GetByteArrayAsync(url).Result; File.WriteAllBytes(logo, data); } } string message = e.Message; var viewButton = new ToastButton(); viewButton.AddArgument("action", "viewRafflesWonPage"); viewButton.SetContent("View Won Raffles"); var dismissButton = new ToastButton(); dismissButton.SetContent("Dismiss"); dismissButton.SetDismissActivation(); var toast = new ToastContentBuilder(); toast.AddAppLogoOverride(new Uri(logo), ToastGenericAppLogoCrop.Circle, null, false); toast.AddAttributionText(string.Format("Scraps {0}", Common.Constants.Version.Full)); toast.AddText("Items Need Withdrawing"); toast.AddText(message); toast.AddButton(viewButton); toast.AddButton(dismissButton); toast.Show(); } }
public void ToastButtonBuilders_InvalidArgumentsAfterCustomArguments_ReturnSelf() { var button = new ToastButton("View", "viewArgs"); button.AddArgument("action", "view"); }
public void Test_Toast_Xml_Button_Defaults() { ToastButton button = new ToastButton("my content", "myArgs"); AssertButtonPayload("<action content='my content' arguments='myArgs' />", button); }