示例#1
0
        public Toast(string header, string line1, string line2, ImageSource icon,
                     Uri audio, ToastDuration duration, bool unmuteSpeakers)
        {
            InitializeComponent();

            Title          = header;
            line1Text.Text = line1;
            line2Text.Text = line2;

            //
            // BUG FIX:
            //
            // I'm not sure exactly what the deal is here, but if we
            // don't access a property of the icon, the toast will
            // throw an IOException on load.
            //
            if (icon != null)
            {
                double x = icon.Width;
            }

            Icon = icon;
            mediaElement.Source = audio;

            _toastDuration  = duration;
            _unmuteSpeakers = unmuteSpeakers;
        }
 public void ShowToast(string message, ToastDuration duration)
 {
     TinyIoCContainer.Current.Resolve <IMvxViewDispatcher>().RequestMainThreadAction(() =>
     {
         var toast = Toast.MakeText(Context.Activity, message, duration == ToastDuration.Short ? ToastLength.Short : ToastLength.Long);
         toast.Show();
     });
 }
示例#3
0
        public static void ShowToast(string message, ToastDuration duration = ToastDuration.Short)
        {
            CheckInstance();

            ToastsQueue.Enqueue(ToastStructure.CreateToast(message, duration));
            if (toastCoroutine == null)
            {
                toastCoroutine = Instance.StartCoroutine(ShowToastsQueueCoroutine());
            }
        }
示例#4
0
        /// <summary>
        /// this string 表示扩展string的原方法
        /// 两种调用方式:类名静态方法直接调用;"my string".showAsToast();
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="duration"></param>
        public static void showAsToast(this string msg, ToastDuration duration = ToastDuration.LENGTH_SHORT)
        {
            //new AndroidJavaClass("全类名")  ---new一个Android原生类
            AndroidJavaClass Toast = new AndroidJavaClass("android.widget.Toast");

            RunOnUIThread(() =>
            {
                Toast.CallStatic <AndroidJavaObject>("makeText", UnityAppContext, msg.ToJavaString(), (int)duration).Call("show");
            });
        }
示例#5
0
 async Task ShowToast(ToastDuration duration)
 {
     GetTopViewController(UIApplication.SharedApplication.KeyWindow.RootViewController)?.View.EndEditing(true);
     if (toastContainer != null)
     {
         await UIView.AnimateAsync(0.5, () =>
         {
             toastContainer.Alpha = 1.0f;
         });
     }
     await StartTimer(duration);
 }
示例#6
0
        /// <summary>
        /// Display a toast message with a specific duration.
        /// </summary>
        /// <param name="page">The current page.</param>
        /// <param name="message">The message to display.</param>
        /// <param name="duration">ToastDuration: SHORT, NORMAL, LONG, VERY_LONG</param>
        public static void Show(Page page, String message, ToastDuration duration)
        {
            var cs     = page.ClientScript;
            var jsCode = "$(document).ready(function() { $.Toast('" + message + "', " + (int)duration + "); });";

            var jsLink = new HtmlGenericControl {
                TagName = "script", InnerHtml = jsCode
            };

            jsLink.Attributes.Add("type", "text/javascript");
            page.Controls.Add(jsLink);
        }
示例#7
0
        public void SetToastDurationTest_WithCustomToastDuration_ReturnSelfWithCustomToastDurationSet()
        {
            // Arrange
            ToastDuration testToastDuration = ToastDuration.Long;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.SetToastDuration(testToastDuration);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testToastDuration, builder.Content.Duration);
        }
示例#8
0
        public void Show(string message, ToastDuration duration = ToastDuration.Short)
        {
            if (isVisible)
            {
                if (toastContainer == null)
                {
                    return;
                }

                toastLabel.Text = message;
                toastContainer.Layer.CornerRadius = GetCornerRadius(toastLabel.IntrinsicContentSize);
                toastContainer.LayoutIfNeeded();
                toastContainer.UpdateConstraintsIfNeeded();
                var temp = ShowToast(duration);
                return;
            }

            isVisible = true;
            var superView = GetTopViewController(UIApplication.SharedApplication.KeyWindow.RootViewController)?.View;

            if (superView == null)
            {
                return;
            }

            toastLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LineBreakMode = UILineBreakMode.WordWrap,
                TextAlignment = UITextAlignment.Center,
                TextColor     = UIColor.White,
                Lines         = 0,
                Text          = message,
                Font          = UIFont.SystemFontOfSize(16)
            };

            toastContainer = new UIView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.Black.ColorWithAlpha(0.7f),
                ClipsToBounds   = true,
                Alpha           = 0
            };

            toastContainer.Add(toastLabel);
            superView.Add(toastContainer);
            ApplyConstraint(superView);
            var ignore = ShowToast(duration);

            toastContainer.Layer.CornerRadius = GetCornerRadius(toastLabel.IntrinsicContentSize);
        }
示例#9
0
        public void Show(ToastDuration duration)
        {
            gameObject.SetActive(true);

            switch (duration)
            {
            case ToastDuration.Short:
                Invoke("Hide", 1.5f);
                break;

            case ToastDuration.Long:
                Invoke("Hide", 3f);
                break;
            }
        }
示例#10
0
        //vgl. PersonenDbController
        //Globaler Zugriff erfolgt hier über statische Klasse
        public static void ShowToastMessage(string message, ToastDuration duration)
        {
            switch (duration)
            {
            case ToastDuration.Long:
                DependencyService.Get <IToastService>().ShowLong(message);
                break;

            case ToastDuration.Short:
                DependencyService.Get <IToastService>().ShowShort(message);
                break;

            default:
                break;
            }
        }
示例#11
0
        public static void CreateToast(string displayText, ToastDuration toastDuration, ToastAlignment toastAlignment)
        {
            if (string.IsNullOrEmpty(displayText))
            {
                Debug.Log("Display Text is Null/Empty.");
            }
            else
            {
                Transform canvas = CreateCanvas().transform;

                GameObject parentGO = CreateToastGameObject(canvas, toastAlignment);

                Toast toast = parentGO.AddComponent <Toast>();
                toast.DisplayToast(displayText, toastDuration, toastAlignment);
            }
        }
示例#12
0
        public void ShowToast(string title, string content, ToastDuration duration = ToastDuration.Short, bool isSuppress = false, string luanchContent = null, Action toastActivatedAction = null, params ToastButton[] toastButtons)
        {
            var toust = new ToastContent();

            toust.Visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = title
                        },

                        new AdaptiveText()
                        {
                            Text = content,
                        },
                    }
                }
            };

            toust.Launch   = luanchContent;
            toust.Duration = duration;

            if (toastButtons.Any())
            {
                var actions = new ToastActionsCustom();
                foreach (var button in toastButtons)
                {
                    actions.Buttons.Add(button);
                }
                toust.Actions = actions;
            }
            var toast = new ToastNotification(toust.GetXml());

            toast.SuppressPopup = isSuppress;

            if (toastActivatedAction != null)
            {
                toast.Activated += (ToastNotification sender, object args) => toastActivatedAction();
            }

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
示例#13
0
        /// <inheritdoc />
        public void DisplayToast(string message, ToastDuration duration = ToastDuration.Short)
        {
            using (var handler = new Handler(Looper.MainLooper))
            {
                handler.Post(() =>
                {
                    switch (duration)
                    {
                    case ToastDuration.Short:
                        Toast.MakeText(Android.App.Application.Context, message, ToastLength.Short).Show();
                        break;

                    case ToastDuration.Long:
                        Toast.MakeText(Android.App.Application.Context, message, ToastLength.Long).Show();
                        break;
                    }
                });
            }
        }
示例#14
0
        async Task StartTimer(ToastDuration duration)
        {
            source?.Cancel();
            source = new CancellationTokenSource();

            try
            {
                await Task.Delay(duration == ToastDuration.Short? 4000 : 6000).ContinueWith((arg) =>
                {
                    if (arg.IsCompleted)
                    {
                        DispatchQueue.MainQueue.DispatchAsync(async() => { await HideToast(); });
                    }
                }, source.Token);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#15
0
        private TimeSpan ToastDurationToTimeSpan(ToastDuration tduration)
        {
            TimeSpan ret = Duration;

            switch (tduration)
            {
            case ToastDuration.Short:
                ret = TimeSpan.FromSeconds(2);
                break;

            case ToastDuration.Medium:
                ret = TimeSpan.FromSeconds(3);
                break;

            case ToastDuration.Long:
                ret = TimeSpan.FromSeconds(4);
                break;
            }

            return(ret);
        }
        /* NOT USING THIS ANYMORE
         * public static async Task ShowToastNotifcation(String Message, String ActionLabel, String ActionTag, String PageTag, ToastDuration Length)
         * {
         *  var toastContent = new ToastContent()
         *  {
         *      Visual = new ToastVisual()
         *      {
         *          BindingGeneric = new ToastBindingGeneric()
         *          {
         *              Children =
         *              {
         *                  new AdaptiveText()
         *                  {
         *                      Text = Message
         *                  }
         *              }
         *          }
         *      },
         *      Actions = new ToastActionsCustom()
         *      {
         *          Buttons =
         *          {
         *              new ToastButton(ActionLabel, string.Format("action={0}&page={1}", ActionTag, PageTag))
         *              {
         *                  ActivationType = ToastActivationType.Foreground
         *              }
         *          }
         *      },
         *      Audio = new ToastAudio()
         *      {
         *          Silent = true
         *      }
         *  };
         *
         *  // Create the toast notification
         *  var toastNotif = new ToastNotification(toastContent.GetXml())
         *  {
         *      ExpirationTime = DateTimeOffset.Now.AddMilliseconds((double)Length),
         *      Tag = toastContent.GetHashCode().ToString()
         *  };
         *
         *  // And send the notification
         *  ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
         *
         *  // Remove notification after delay
         *  await Task.Delay((int)Length);
         *  ToastNotificationManager.History.Remove(toastNotif.Tag);
         * }
         */

        public static async Task ShowToastAsync(String Message, ToastDuration Length)
        {
            if (!App.IsInBackground)
            {
                CoreDispatcher Dispatcher;

                if (CoreWindow.GetForCurrentThread() == null)
                {
                    Dispatcher = CoreApplication.MainView.Dispatcher;
                }
                else
                {
                    Dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    /* TODO: Remove all together??? */
                    new Coding4Fun.Toolkit.Controls.ToastPrompt()
                    {
                        Message = Message,
                        MillisecondsUntilHidden = (int)Length,
                        Background                 = new SolidColorBrush(Colors.SlateGray),
                        Foreground                 = new SolidColorBrush(Colors.White),
                        IsHitTestVisible           = false,
                        Margin                     = new Thickness(0, 0, 0, 50),
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        Stretch                    = Stretch.Uniform,
                        VerticalAlignment          = VerticalAlignment.Bottom,
                        HorizontalAlignment        = HorizontalAlignment.Center,
                        Template                   = App.Current.Resources["ToastPromptStyle"] as ControlTemplate
                    }.Show();
                });
            }
            else
            {
                await ShowToastNotifcation(Message, Length);
            }
        }
示例#17
0
        public void ShowText(string title, string content, ToastDuration duration = ToastDuration.Short, bool isSuppress = false, string luanchContent = null, Action toastActivatedAction = null)
        {
            var toust = new ToastContent();

            toust.Visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = title
                        },

                        new AdaptiveText()
                        {
                            Text = content,
                        },
                    }
                }
            };

            toust.Launch   = luanchContent;
            toust.Duration = duration;


            var toast = new ToastNotification(toust.GetXml());

            toast.SuppressPopup = isSuppress;

            if (toastActivatedAction != null)
            {
                toast.Activated += (ToastNotification sender, object args) => toastActivatedAction();
            }

            _Nofifier.Show(toast);
        }
        private static async Task ShowToastNotifcation(String Message, ToastDuration Length)
        {
            var toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = Message
                            }
                        }
                    }
                },
                Audio = new ToastAudio()
                {
                    Silent = true
                }
            };

            // Create the toast notification
            var toastNotif = new ToastNotification(toastContent.GetXml())
            {
                ExpirationTime = DateTimeOffset.Now.AddMilliseconds((double)Length),
                Tag            = toastContent.GetHashCode().ToString()
            };

            // And send the notification
            ToastNotificationManager.CreateToastNotifier().Show(toastNotif);

            // Remove notification after delay
            await Task.Delay((int)Length);

            ToastNotificationManager.History.Remove(toastNotif.Tag);
        }
示例#19
0
 public Toast SetDuration(ToastDuration duration)
 {
     this.Duration = (int)duration;
     return(this);
 }
 /// <summary>
 /// Sets the amount of time the Toast should display. You typically should use the
 /// Scenario attribute instead, which impacts how long a Toast stays on screen.
 /// </summary>
 /// <param name="duration">Duration of the toast</param>
 /// <returns>The current instance of <see cref="ToastContentBuilder"/></returns>
 public ToastContentBuilder SetToastDuration(ToastDuration duration)
 {
     Content.Duration = duration;
     return(this);
 }
示例#21
0
        private XmlDocument CreateToastXml(ToastDuration duration, string audioPath, bool loop, string imageFilename, string alarmAction)
        {
            var          snoozeTimeId = "snoozeTimeId";
            ToastContent content      = new ToastContent()
            {
                Duration = duration,
                Scenario = ToastScenario.Alarm,
                Launch   = "app-defined-string",
                Visual   = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "Alarm", HintAlign = AdaptiveTextAlign.Center, HintStyle = AdaptiveTextStyle.Title
                            },
                            new AdaptiveText()
                            {
                                Text = "Wake up! Wake up!"
                            },
                            new AdaptiveImage()
                            {
                                Source = $"ms-appdata:///local/Images/{imageFilename}"
                            }
                        }
                    }
                },
                Actions = new ToastActionsCustom()
                {
                    Inputs =
                    {
                        new ToastSelectionBox(snoozeTimeId)
                        {
                            DefaultSelectionBoxItemId = "10",
                            Items =
                            {
                                new ToastSelectionBoxItem("5",  "5 minutes"),
                                new ToastSelectionBoxItem("10", "10 minutes"),
                                new ToastSelectionBoxItem("15", "15 minutes"),
                                new ToastSelectionBoxItem("30", "30 minutes"),
                                new ToastSelectionBoxItem("60", "1 hour")
                            }
                        }
                    },
                    Buttons =
                    {
                        new ToastButton("Configure Alarm", $"alarmAction;{alarmAction}")
                        {
                            ImageUri = "check.png"
                        },
                        new ToastButtonSnooze()
                        {
                            SelectionBoxId = snoozeTimeId
                        },
                        new ToastButtonDismiss()
                    }
                },
                Audio = new ToastAudio()
                {
                    Src = new Uri(audioPath), Loop = loop
                }
            };

            return(content.GetXml());
        }
示例#22
0
 public static WindowsToastNotification WithDuration(this WindowsToastNotification notification, ToastDuration duration)
 {
     notification.Duration = duration;
     return notification;
 }
示例#23
0
 public void Show(ToastDuration duration)
 {
     Show(this.Message, ToastDurationToTimeSpan(duration));
 }
示例#24
0
 public void ShowToast(string message, ToastDuration toastDuration = ToastDuration.Short)
 {
     Toast.MakeText(Application.Context, message, GetToastLength(toastDuration))
     .Show();
 }
示例#25
0
 private ToastLength GetToastLength(ToastDuration toastDuration)
 {
     return(toastDuration == ToastDuration.Long ? ToastLength.Long : ToastLength.Short);
 }
示例#26
0
 public static ToastStructure CreateToast(string newMessage, ToastDuration newDuration = ToastDuration.Short)
 => new ToastStructure
 {
     message = newMessage, duration = newDuration
 };