示例#1
0
    public void Init(string text, ToastType alertType, float showTime)
    {
        this.showTime   = showTime;
        textOutput.text = text;

        switch (alertType)
        {
        case ToastType.Error:
            title.text  = errorText;
            title.color = new Color32(255, 0, 0, 255);
            break;

        case ToastType.Warning:
            title.text  = warningText;
            title.color = new Color32(255, 180, 0, 255);
            break;

        case ToastType.Info:
            title.text  = infoText;
            title.color = new Color32(130, 130, 130, 255);
            break;
        }

        StartCoroutine(CloseToast());
    }
示例#2
0
        public static string Show(string message, string title = "",
                                  ToastType type    = ToastType.Info,
                                  Position position = Position.TopRight,
                                  int timeOut       = 5000,
                                  bool closeButton  = true,
                                  bool progressBar  = true,
                                  bool newestOnTop  = true,
                                  string onclick    = null)
        {
            var scriptOption = "<script>";

            scriptOption += "toastr.options = {";

            scriptOption += "'closeButton': '"
                            + closeButton.booToLowerString()
                            + "','debug': false,'newestOnTop': "
                            + newestOnTop.booToLowerString()
                            + ",'progressBar': "
                            + progressBar.booToLowerString()
                            + ",'positionClass': '"
                            + stringValueOf(position)
                            + "','preventDuplicates': false,'onclick': "
                            + (onclick ?? "null")
                            + ",'showDuration': '300','hideDuration': '1000','timeOut': '"
                            + timeOut
                            + "','extendedTimeOut': '1000','showEasing': 'swing','hideEasing': 'linear','showMethod': 'fadeIn','hideMethod': 'fadeOut'";
            scriptOption += "};";
            scriptOption += "toastr['" + stringValueOf(type) + "']('" + message + "', '" + title + "');</script>";

            return(scriptOption);
        }
示例#3
0
        public static void Show(string message, ToastType type, int millisecond = DEFAULT_MILLISECOND)
        {
            var toast = new Toast {
                Message = message
            };

            switch (type)
            {
            case ToastType.Error:
                toast.UIcon           = "\ue644";
                toast.UIconForeground = System.Windows.Media.Brushes.Red;
                break;

            case ToastType.Info:
                toast.UIcon = "\ue659";
                break;

            case ToastType.Success:
                toast.UIcon = "\ue646";
                break;

            case ToastType.Warn:
                toast.UIcon = "\ue60b";
                break;
            }
            toast.Show();
            toast.Wait(Math.Min(millisecond, MAX_MILLISECOND));
        }
示例#4
0
        private static ToasterWindow GetToasterWindow(FrameworkElement owner, ToastType type, string title, string message,
                                                      ToasterPosition position, ToasterAnimation animation, double margin)
        {
            var toaster = new ToasterWindow(owner, title, message, position, animation, margin);

            switch (type)
            {
            case ToastType.Error:
                toaster.Ico.Data = NotificationIcoPath.Error;
                toaster.Notification.Background = NotificationColor.Error;
                break;

            case ToastType.Info:
                toaster.Ico.Data = NotificationIcoPath.Info;
                toaster.Notification.Background = NotificationColor.Info;
                break;

            case ToastType.Warning:
                toaster.Ico.Data = NotificationIcoPath.Warning;
                toaster.Notification.Background = NotificationColor.Warning;
                break;

            case ToastType.Success:
                toaster.Ico.Data = NotificationIcoPath.Success;
                toaster.Notification.Background = NotificationColor.Success;
                break;
            }
            return(toaster);
        }
示例#5
0
        public ToastMessage AddToastMessage(
            string title
            , string message
            , ToastType toastType
            , bool closeButton         = true
            , bool progressBar         = true
            , bool promptToCloseWindow = false
            )
        {
            var toast = new ToastMessage
            {
                Title     = title,
                Message   = message,
                ToastType = toastType,
                CloseWindowButtonShown = promptToCloseWindow,
                IsSticky    = false,
                Position    = ToastrPositionEnum.TopRight,
                ProgressBar = progressBar
            };

            ShowCloseButton       = closeButton;
            ShowProgressBar       = progressBar;
            ShowCloseWindowButton = promptToCloseWindow;

            ToastMessages.Add(toast);

            return(toast);
        }
示例#6
0
        public static void GenerateToast(ToastType type)
        {
            // Contents of the toast
            string template;

            switch (type)
            {
            case ToastType.ControllerConnected:
                template =
                    $"<toast launch=\"app-defined-string\"><visual><binding template =\"ToastGeneric\"><text>{"PlayLeft"}</text><text>{"Controller is connected."}</text></binding></visual></toast>";
                break;

            case ToastType.ControllerDisconnected:
                template =
                    $"<toast launch=\"app-defined-string\"><visual><binding template =\"ToastGeneric\"><text>{"PlayLeft"}</text><text>{"Controller was disconnected."}</text></binding></visual></toast>";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            var xmlToast = new XmlDocument();

            xmlToast.LoadXml(template);

            var notification = new ToastNotification(xmlToast);
            var notifier     = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(notification);
        }
示例#7
0
 private void ShowToast(string title, string message, ToastType type = ToastType.Info, float durationSec = 3.0F)
 {
     SendMessageToClient(new HostShowToast()
     {
         Title = title, Message = message, ToastType = type, Timeout = (int)(durationSec * 1000)
     });
 }
示例#8
0
        /// <summary>
        /// 初始化设置,设置要显示的内容
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="text">内容</param>
        /// <param name="type">类型:w,e,i</param>
        /// <param name="time">显示时间:ms</param>
        private void SetContent(string title, string text, ToastType type, int time)
        {
            Text         = title;   //设置程序标题
            LBTitle.Text = title;   //设置显示标题
            LBText.Text  = text;    //设置内容
            SetType(type);          //设置消息类型
            TMHide.Interval = time; //设置显示时长

            Height = 80;
            try
            {
                int byte_len = Encoding.UTF8.GetBytes(LBText.Text).Length;
                if (byte_len > 105)
                {
                    byte_len -= 105;
                    Height    = 100;

                    while ((byte_len = byte_len - 55) > 0)
                    {
                        Height += 20;
                    }
                }
            }
            catch { }

            TimeSpend = 0;            //初始化运行时间,每次执行动画++
            SetPosition();            //设置初始位置
            TMShowAnim.Interval = 10; //设置显示动画执行间隔
            SetBorder();              //重置边框(因窗口高度发生变化,刷新边框)
        }
示例#9
0
        /// <summary>
        /// 弹出提示框
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="text">内容</param>
        /// <param name="type">类型:w,e,i</param>
        /// <param name="time">显示时间:毫秒</param>
        /// <param name="clickAction">点击触发动作反馈</param>
        public static void Display(string title, string text, char type, int time, Action clickAction = null)
        {
            try
            {
                if (form == null || form.IsDisposed)
                {
                    form = new ToastForm();
                }

                ToastType tt = ToastType.info;
                if (type == 'w' || type == 'W')
                {
                    tt = ToastType.warn;
                }
                if (type == 'e' || type == 'E')
                {
                    tt = ToastType.error;
                }

                form.SetContent(title, text, tt, time); //设置提示框:标题、文本、类型、时间
                form.ClickAction = clickAction;         //设置单击触发事件
                form.Toast();
            }
            catch { }
        }
示例#10
0
        public static ToastMessage AddToastMessage(this Controller controller, Result result)
        {
            ToastType type = ToastType.Info;

            switch (result.Status)
            {
            case System.Net.HttpStatusCode.OK:
            {
                type = ToastType.Success;
                break;
            }

            default:
            {
                type = ToastType.Error;
                break;
            }
            }

            Toastr toastr = controller.TempData["Toastr"] as Toastr;

            toastr = toastr ?? new Toastr();

            var toastMessage = toastr.AddToastMessage(type.ToString(), result.StatusDescription, type);

            controller.TempData["Toastr"] = toastr;
            return(toastMessage);
        }
        public async Task ShowToastAsync(string content, TimeSpan duration, ToastType level = ToastType.Info)
        {
            if (!CanToast)
            {
                return;
            }

            ToastMessage message = new ToastMessage()
            {
                Content = content,
                Level   = level
            };

            toaster.SetCurrentValue(Toaster.MessageProperty, message);
            toaster.SetCurrentValue(Toaster.IsActiveProperty, true);

            var durationWaitHandle = new ManualResetEvent(false);

            StartDuration(duration, durationWaitHandle);

            await WaitForCompletionAsync(durationWaitHandle);

            toaster.SetCurrentValue(Toaster.IsActiveProperty, false);
            await Task.Delay(toaster.DeactivateStoryboardDuration);

            toaster.SetCurrentValue(Toaster.MessageProperty, null);

            durationWaitHandle.Dispose();
        }
示例#12
0
        public static void DoToast(string toast, ToastType toastType, int duration = 2000)
        {
            var toastConfig = new ToastConfig(toast);

            toastConfig.SetDuration(duration);

            switch (toastType)
            {
            case ToastType.Green:
                toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(12, 220, 25));
                break;

            case ToastType.Red:
                toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(220, 12, 25));
                break;

            case ToastType.Yellow:
                toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(193, 193, 25));
                break;

            default:
                toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(12, 131, 193));
                break;
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                UserDialogs.Instance.Toast(toastConfig);
            });
        }
示例#13
0
        public ToastInstance(ToastType toastType, RenderFragment message, string header = "")
        {
            Id        = Guid.NewGuid().ToString();
            TimeStamp = DateTime.Now;
            Message   = message;

            switch (toastType)
            {
            case ToastType.Success:
                ToastTypeClass = "alert-success";
                Header         = string.IsNullOrWhiteSpace(header) ? "Success" : header;
                break;

            case ToastType.Notify:
                ToastTypeClass = "alert-secondary";
                Header         = string.IsNullOrWhiteSpace(header) ? "Notification" : header;
                break;

            case ToastType.Error:
                ToastTypeClass = "alert-danger";
                Header         = string.IsNullOrWhiteSpace(header) ? "Error" : header;
                break;

            default:
                break;
            }
        }
示例#14
0
        private static void SetToastAppearanceByMessageType(Toast thisToast, ToastType messageType)
        {
            switch (messageType)
            {
            case ToastType.WARNING:
                thisToast.ToastBackgroundColor = "#fcf8e3";
                thisToast.ToastBorderColor     = "#faf2cc";
                thisToast.ToastTextColor       = "#8a6d3b";
                break;

            case ToastType.DANGER:
                thisToast.ToastBackgroundColor = "#f2dede";
                thisToast.ToastBorderColor     = "#ebcccc";
                thisToast.ToastTextColor       = "#a94442";
                break;

            case ToastType.SUCCESS:
                thisToast.ToastBackgroundColor = "#dff0d8";
                thisToast.ToastBorderColor     = "#d0e9c6";
                thisToast.ToastTextColor       = "#3c763d";
                break;

            case ToastType.INFO:
                thisToast.ToastBackgroundColor = "#d9edf7";
                thisToast.ToastBorderColor     = "#bcdff1";
                thisToast.ToastTextColor       = "#31708f";
                break;
            }
        }
示例#15
0
        public ToastMessage AddToastMessage(string title, string message, ToastType toastType)
        {
            var toast = new ToastMessage(title, message, toastType);

            ToastMessages.Add(toast);
            return(toast);
        }
示例#16
0
        public void Show(string Message, ToastType type)
        {
            switch (type)
            {
            case ToastType.Default:
                PolishedToast.Create(Android.App.Application.Context, Message).Show();
                break;

            case ToastType.Error:
                PolishedToast.Error(Android.App.Application.Context, Message).Show();
                break;

            case ToastType.Info:
                PolishedToast.Info(Android.App.Application.Context, Message).Show();
                break;

            case ToastType.Success:
                PolishedToast.Success(Android.App.Application.Context, Message).Show();
                break;

            case ToastType.Warning:
                PolishedToast.Warning(Android.App.Application.Context, Message).Show();
                break;
            }
        }
        public ToastMessage AddToastMessage(string title, string message, ToastType toastType)
        {
            var toast = new ToastMessage() { Title = title, Message = message, ToastType = toastType };

            this.ToastMessages.Add(toast);
            return toast;
        }
示例#18
0
        public void Add(ToastType type, string message, string title, Action <ToastOptions> configure)
        {
            if (message.IsEmpty())
            {
                return;
            }

            message = message.Trimmed();
            title   = title.Trimmed();

            var options = new ToastOptions(type, Configuration);

            configure?.Invoke(options);

            var toast = new Toast(title, message, options);

            ToastLock.EnterWriteLock();
            try
            {
                if (Configuration.PreventDuplicates && ToastAlreadyPresent(toast))
                {
                    return;
                }
                toast.OnClose += Remove;
                Toasts.Add(toast);
            }
            finally
            {
                ToastLock.ExitWriteLock();
            }

            OnToastsUpdated?.Invoke();
        }
示例#19
0
 private async Task ShowToastAsync(ToastType toastType, RenderFragment message, string heading)
 {
     await InvokeAsync(() =>
     {
         ToastItems.Add(new ToastInstance(toastType, message, heading));
         StateHasChanged();
     });
 }
 private bool ToastAlreadyPresent(string message, string title, ToastType type)
 {
     return(Toasts.Any(toast =>
                       message.Equals(toast.Message) &&
                       title.Equals(toast.Title) &&
                       type.Equals(toast.State.Options.Type)
                       ));
 }
示例#21
0
 private RectangleShape GetColoredBackground(ToastType type)
 {
     return(new RectangleShape()
     {
         Size = ColoredRegionSize,
         FillColor = GetColorFromType(type)
     });
 }
        public ToastPopUp CreateToast(ToastType toastType)
        {
            var background = new LinearGradientBrush(this.StartColor, this.EndColor, 90);
            var brush      = new SolidColorBrush(this.BorderColor);
            var font       = new SolidColorBrush(this.fontColor);

            NotificationType notificationType = (NotificationType)Enum.Parse(typeof(NotificationType), this.SelectedNotificationType.Value.ToString());
            ToastPopUp       toast            = null;

            switch (toastType)
            {
            case ToastType.Basic:
                toast                   = new ToastPopUp(this.Title, this.Text, this.HyperlinkText, notificationType);
                toast.Background        = background;
                toast.BorderBrush       = brush;
                toast.FontColor         = font;
                toast.HyperlinkClicked += this.ToastHyperlinkClicked;
                toast.ClosedByUser     += this.ToastClosedByUser;

                break;

            case ToastType.Image:
                toast                   = new ToastPopUp(this.Title, this.Text, this.HyperlinkText, Properties.Resources.disk_blue);
                toast.Background        = background;
                toast.BorderBrush       = brush;
                toast.FontColor         = font;
                toast.HyperlinkClicked += this.ToastHyperlinkClicked;
                toast.ClosedByUser     += this.ToastClosedByUser;

                break;

            case ToastType.Inlines:
                var inlines = new List <Inline>();
                inlines.Add(new Run
                {
                    Text = this.Text
                });
                inlines.Add(new Run
                {
                    Text = Environment.NewLine
                });
                inlines.Add(new Run("This text will be italic.")
                {
                    FontStyle = FontStyles.Italic
                });

                toast                   = new ToastPopUp(this.Title, inlines, this.HyperlinkText, notificationType);
                toast.Background        = background;
                toast.BorderBrush       = brush;
                toast.FontColor         = font;
                toast.HyperlinkClicked += this.ToastHyperlinkClicked;
                toast.ClosedByUser     += this.ToastClosedByUser;

                break;
            }

            return(toast);
        }
示例#23
0
        private void SetButton(ToastType type)
        {
            try
            {
                if (IsLoaded)
                {
                    switch (type)
                    {
                    case ToastType.DOWNLOAD:
                        ButtonOk.Visiable         = false;
                        ButtonCancel.Visiable     = false;
                        ButtonOpenFile.Visiable   = true;
                        ButtonOpenFolder.Visiable = true;
                        break;

                    case ToastType.OK:
                        ButtonOk.Visiable         = true;
                        ButtonCancel.Visiable     = false;
                        ButtonOpenFile.Visiable   = false;
                        ButtonOpenFolder.Visiable = false;
                        break;

                    case ToastType.OKCANCEL:
                        ButtonOk.Visiable         = true;
                        ButtonCancel.Visiable     = true;
                        ButtonOpenFile.Visiable   = false;
                        ButtonOpenFolder.Visiable = false;
                        break;

                    case ToastType.YES:
                        ButtonOk.Label            = "Yes";
                        ButtonOk.Visiable         = true;
                        ButtonCancel.Visiable     = false;
                        ButtonOpenFile.Visiable   = false;
                        ButtonOpenFolder.Visiable = false;
                        break;

                    case ToastType.YESNO:
                        ButtonOk.Label            = "Yes";
                        ButtonOk.Visiable         = true;
                        ButtonCancel.Label        = "No";
                        ButtonCancel.Visiable     = true;
                        ButtonOpenFile.Visiable   = false;
                        ButtonOpenFolder.Visiable = false;
                        break;

                    default:
                        ButtonOk.Visiable         = true;
                        ButtonCancel.Visiable     = false;
                        ButtonOpenFile.Visiable   = false;
                        ButtonOpenFolder.Visiable = false;
                        break;
                    }
                }
            }
            catch (Exception ex) { ex.ERROR(); }
        }
        public static ToastMessage AddToastMessage(this Controller controller, string title, string message, ToastType toastType = ToastType.Info)
        {
            Toastr toastr = controller.TempData["Toastr"] as Toastr;
            toastr = toastr ?? new Toastr();

            var toastMessage = toastr.AddToastMessage(title, message, toastType);
            controller.TempData["Toastr"] = toastr;
            return toastMessage;
        }
 public ToastrDecoratorResult(ActionResult innerResult, ToastType style, string title, string message, bool closeButton = true, bool progressBar = true, bool closeWindowButtonShown = false)
 {
     InnerResult            = innerResult;
     Style                  = style;
     Message                = message;
     Title                  = title;
     CloseButton            = closeButton;
     ProgressBar            = progressBar;
     CloseWindowButtonShown = closeWindowButtonShown;
 }
示例#26
0
 public void DisplayToast(
     string message,
     TimeSpan?duration   = null,
     ToastType toastType = ToastType.Primary,
     string id           = "",
     bool overrideSameId = false,
     string?title        = null)
 {
     DisplayToast(builder => builder.AddContent(1, message), duration, toastType, id, overrideSameId, title);
 }
示例#27
0
        public ToastEventArgs(string message, ToastType type)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            this.message = message;
            this.type    = type;
        }
示例#28
0
 public void DisplayToast(
     RenderFragment content,
     TimeSpan?duration   = null,
     ToastType toastType = ToastType.Primary,
     string id           = "",
     bool overrideSameId = false,
     string?title        = null)
 {
     OnToastRequested?.Invoke(this, new(id, Guid.NewGuid(), content, duration, toastType, overrideSameId, title));
 }
示例#29
0
        public Toast(ToastType type, ScreenLocation location, string message, float duration = 5)
        {
            this.Message = message;
            this.Type = type;
            this.Location = location;
            this.Duration = duration;

            timeAlive = 0;
            visual = new ToastVisual(this);            
        }
        public ToastMessage AddToastMessage(string title, string message, ToastType toastType)
        {
            var toast = new ToastMessage()
            {
                Title = title, Message = message, ToastType = toastType
            };

            this.ToastMessages.Add(toast);
            return(toast);
        }
示例#31
0
 public ToastEventArgs(string id, Guid uniqueId, RenderFragment content, TimeSpan?duration, ToastType toastType, bool overrideSameId, string?title)
 {
     Id             = id;
     UniqueId       = uniqueId;
     Content        = content;
     Duration       = duration;
     ToastType      = toastType;
     OverrideSameId = overrideSameId;
     Title          = title;
 }
 public void Toast(string content, ToastType toastType = ToastType.Normal)
 {
     if (IsShowToast)
     {
         IsShowToast = false;
     }
     ToastContent = content;
     IsShowToast  = true;
     ToastType    = toastType;
 }
示例#33
0
        public static string Show(string message, string title = "",
            ToastType type = ToastType.Info,
            Position position = Position.TopRight,
            int timeOut = 5000,
            bool closeButton = true,
            bool progressBar = true,
            bool newestOnTop = true,
            string onclick = null)
        {
            var scriptOption = "<script>";
            scriptOption += "toastr.options = {";

            scriptOption += "'closeButton': '" + closeButton.booToLowerString() + "','debug': false,'newestOnTop': " + newestOnTop.booToLowerString() + ",'progressBar': " + progressBar.booToLowerString() + ",'positionClass': '" + stringValueOf(position) + "','preventDuplicates': false,'onclick': " + (onclick ?? "null") + ",'showDuration': '300','hideDuration': '1000','timeOut': '" + timeOut + "','extendedTimeOut': '1000','showEasing': 'swing','hideEasing': 'linear','showMethod': 'fadeIn','hideMethod': 'fadeOut'";
            scriptOption += "};";
            scriptOption += "toastr['" + stringValueOf(type) + "']('" + message + "', '" + title + "');</script>";

            return scriptOption;
        }
示例#34
0
 public ToastMessage AddToastMessage(string title, string message, ToastType toastType)
 {
     return Toastr.AddToastMessage(title, message, toastType);
 }