Exemple #1
0
        public override Task <object> ShowToastAsync(ToastParameters toastParameters)
        {
            UIAlertController alert = UIAlertController.Create(
                toastParameters.Caption?.ToString(),
                toastParameters.Body?.ToString(), UIAlertControllerStyle.Alert);

            var source = new TaskCompletionSource <object>();

            // Configure the alert
            alert.AddAction(UIAlertAction.Create(DefaultOkaySymbol, UIAlertActionStyle.Default, action =>
            {
                source.SetResult(null);
            }));

            var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;

            // Display the alert
            controller.PresentViewController(alert, true, null);

            return(source.Task);
        }
Exemple #2
0
 public abstract Task <object> ShowToastAsync(ToastParameters toastParameters);
Exemple #3
0
        public override Task <object> ShowToastAsync(ToastParameters toastParameters)
        {
            Context context          = ResolveContext();
            var     toastLength      = toastParameters.MillisecondsUntilHidden > 3000 ? ToastLength.Long : ToastLength.Short;
            string  newLineCharacter = Java.Lang.JavaSystem.LineSeparator();

            var content = toastParameters.Caption?.ToString().Parse();

            View toastView = toastParameters.Body as View;

            if (toastView == null)
            {
                if (string.IsNullOrWhiteSpace(content))
                {
                    content = toastParameters.Body?.ToString().Parse();
                }
                else
                {
                    string bodyString = toastParameters.Body?.ToString();
                    if (!string.IsNullOrWhiteSpace(bodyString))
                    {
                        content = content + newLineCharacter + bodyString.Parse();
                    }
                }
            }

            Toast toast;

            if (toastView == null)
            {
                var body = new Java.Lang.String(content);
                toast = Toast.MakeText(context, body, toastLength);
            }
            else
            {
                toast = new Toast(context)
                {
                    View = toastView
                };
            }

            if (toastParameters.VerticalOrientation.HasValue)
            {
                var verticalOrientation = toastParameters.VerticalOrientation.Value;
                if (verticalOrientation == ToastVerticalOrientation.Top)
                {
                    toast.SetGravity(GravityFlags.Top, 0, 0);
                }
                else if (verticalOrientation == ToastVerticalOrientation.Center)
                {
                    toast.SetGravity(GravityFlags.CenterVertical, 0, 0);
                }
                else if (verticalOrientation == ToastVerticalOrientation.Bottom)
                {
                    toast.SetGravity(GravityFlags.Bottom, 0, 0);
                }
            }

            var source = new TaskCompletionSource <object>();

            UIContext.Instance.Send(() =>
            {
                try
                {
                    toast.Show();
                }
                catch (Exception ex)
                {
                    source.SetException(ex);
                    return;
                }

                source.SetResult(null);
            });

            return(source.Task);
        }
Exemple #4
0
        public override Task <object> ShowToastAsync(
            ToastParameters toastParameters)
        {
            AssertArg.IsNotNull(toastParameters, nameof(toastParameters));

            /* TODO: Implement image display. */

            var    template = @"
<toast>
<visual>
<binding template=""ToastGeneric"">
  <text>{0}</text>
  <text>{1}</text>
</binding>
</visual>
</toast>
";
            string body     = toastParameters.Body?.ToString()?.Parse();
            string caption  = toastParameters.Caption?.ToString()?.Parse();

            var xml         = string.Format(template, caption, body);
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);
            var toast = new ToastNotification(xmlDocument);

            if (toastParameters.MillisecondsUntilHidden.HasValue)
            {
                toast.ExpirationTime = DateTimeOffset.Now.AddMilliseconds(
                    toastParameters.MillisecondsUntilHidden.Value);
            }

            var source = new TaskCompletionSource <object>();
            TypedEventHandler <ToastNotification, object> activatedHandler = null;
            TypedEventHandler <ToastNotification, ToastDismissedEventArgs> dismissedHandler = null;
            TypedEventHandler <ToastNotification, ToastFailedEventArgs>    failedHandler    = null;

            activatedHandler = (o, e) =>
            {
                toast.Activated -= activatedHandler;
                toast.Dismissed -= dismissedHandler;
                toast.Failed    -= failedHandler;

                source.SetResult(e);
            };

            dismissedHandler = (o, e) =>
            {
                toast.Activated -= activatedHandler;
                toast.Dismissed -= dismissedHandler;
                toast.Failed    -= failedHandler;

                source.SetResult(e.Reason);
            };

            failedHandler = (o, e) =>
            {
                toast.Activated -= activatedHandler;
                toast.Dismissed -= dismissedHandler;
                toast.Failed    -= failedHandler;

                source.SetResult(e.ErrorCode);
            };

            toast.Activated += activatedHandler;
            toast.Dismissed += dismissedHandler;
            toast.Failed    += failedHandler;

            ToastNotificationManager.CreateToastNotifier().Show(toast);

            return(source.Task);
        }
Exemple #5
0
 public override Task <object> ShowToastAsync(ToastParameters toastParameters)
 {
     throw new NotImplementedException();
 }