Esempio n. 1
1
        public override void Toast(ToastConfig cfg) {
            // TODO: backgroundcolor and image
            var resources = Application.Current.Resources;
            var textColor = new SolidColorBrush(cfg.TextColor.ToNative());
            var bgColor = cfg.BackgroundColor.ToNative();

            var wrapper = new StackPanel {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                //Background = (Brush)resources["PhoneAccentBrush"],
                Background = new SolidColorBrush(bgColor),
                Width = Application.Current.Host.Content.ActualWidth
            };
            wrapper.Children.Add(new TextBlock {
                //Foreground = (Brush)resources["PhoneForegroundBrush"],
                Foreground = textColor,
                FontSize = (double)resources["PhoneFontSizeMedium"],
                Margin = new Thickness(24, 32, 24, 12),
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = cfg.Title
            });

            if (!String.IsNullOrWhiteSpace(cfg.Description)) {
                wrapper.Children.Add(new TextBlock {
                    //Foreground = (Brush)resources["PhoneForegroundBrush"],
                    //FontSize = (double)resources["PhoneFontSizeMedium"],
                    Foreground = textColor,
                    FontSize = (double)resources["PhoneFontSizeSmall"],
                    Margin = new Thickness(24, 32, 24, 12),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Text = cfg.Title
                });
            }

            var popup = new Popup {
                Child = wrapper,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            wrapper.Tap += (sender, args) => {
                SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                popup.IsOpen = false;
                cfg.Action?.Invoke();
            };

            this.Dispatch(() => {
                //SystemTray.BackgroundColor = (Color)resources["PhoneAccentColor"];
                SystemTray.BackgroundColor = bgColor;
                popup.IsOpen = true;
            });
            Task.Delay(cfg.Duration)
                .ContinueWith(x => this.Dispatch(() => {
                    SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                    popup.IsOpen = false;
                }));
        }
Esempio n. 2
0
        protected virtual void TrySetToastTextColor(Snackbar snackBar, ToastConfig cfg)
        {
            var textColor = cfg.MessageTextColor ?? ToastConfig.DefaultMessageTextColor;

            if (textColor == null)
            {
                return;
            }

            var viewGroup = snackBar.View as ViewGroup;

            if (viewGroup != null)
            {
                for (var i = 0; i < viewGroup.ChildCount; i++)
                {
                    var child    = viewGroup.GetChildAt(i);
                    var textView = child as TextView;
                    if (textView != null)
                    {
                        textView.SetTextColor(textColor.Value.ToNative());
                        break;
                    }
                }
            }
        }
        public override void Toast(ToastConfig cfg)
        {
            var top = this.GetTopActivity();
            //var view = top.Window.DecorView.RootView;
            var view = top.Window.DecorView.RootView.FindViewById(Android.Resource.Id.Content);

            var text = $"<b>{cfg.Title}</b>";

            if (!String.IsNullOrWhiteSpace(cfg.Description))
            {
                text += $"\n<br /><i>{cfg.Description}</i>";
            }

            var snackBar = Snackbar.Make(view, text, (int)cfg.Duration.TotalMilliseconds);

            snackBar.View.Background = new ColorDrawable(cfg.BackgroundColor.ToNative());
            var txt = FindTextView(snackBar);

            txt.SetTextColor(cfg.TextColor.ToNative());
            txt.TextFormatted = Html.FromHtml(text);

            snackBar.View.Click += (sender, args) => {
                snackBar.Dismiss();
                cfg.Action?.Invoke();
            };
            Utils.RequestMainThread(snackBar.Show);
        }
Esempio n. 4
0
        protected virtual ISpanned GetSnackbarText(ToastConfig cfg)
        {
            var sb = new SpannableStringBuilder();

            string message = cfg.Message;
            var    hasIcon = (cfg.Icon != null);

            if (hasIcon)
            {
                message = "\u2002\u2002" + message; // add 2 spaces, 1 for the image the next for spacing between text and image
            }
            sb.Append(message);

            if (hasIcon)
            {
                var drawable = cfg.Icon.ToNative();
                drawable.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);

                sb.SetSpan(new ImageSpan(drawable, SpanAlign.Bottom), 0, 1, SpanTypes.ExclusiveExclusive);
            }

            if (cfg.MessageTextColor != null)
            {
                sb.SetSpan(
                    new ForegroundColorSpan(cfg.MessageTextColor.Value.ToNative()),
                    0,
                    sb.Length(),
                    SpanTypes.ExclusiveExclusive
                    );
            }
            return(sb);
        }
Esempio n. 5
0
        public override IDisposable Toast(ToastConfig config)
        {
            ToastPrompt toast = null;

            return(this.DispatchAndDispose(() =>
            {
                toast = new ToastPrompt
                {
                    Message = config.Message,
                    Stretch = Stretch.Fill,
                    MillisecondsUntilHidden = Convert.ToInt32(config.Duration.TotalMilliseconds)
                };
                if (config.MessageTextColor != null)
                {
                    toast.Foreground = new SolidColorBrush(config.MessageTextColor.Value.ToNative());
                }

                if (config.BackgroundColor != null)
                {
                    toast.Background = new SolidColorBrush(config.BackgroundColor.Value.ToNative());
                }

                toast.Show();
            },
                                           () => toast.Hide()));
        }
Esempio n. 6
0
 protected virtual IDisposable ToastFallback(Activity activity, ToastConfig cfg)
 {
     AndHUD.Shared.ShowToast(
         activity,
         cfg.Message,
         AndroidHUD.MaskType.None,
         cfg.Duration,
         false,
         () =>
     {
         AndHUD.Shared.Dismiss();
         cfg.Action?.Action?.Invoke();
     }
         );
     return(new DisposableAction(() =>
     {
         try
         {
             AndHUD.Shared.Dismiss(activity);
         }
         catch
         {
         }
     }));
 }
Esempio n. 7
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            this.currentToast?.Dispose();

            var app = UIApplication.SharedApplication;

            app.InvokeOnMainThread(() =>
            {
                //var snackbar = new TTGSnackbar(cfg.Message)
                var snackbar = new TTGSnackbar
                {
                    Message       = cfg.Message,
                    Duration      = cfg.Duration,
                    AnimationType = TTGSnackbarAnimationType.FadeInFadeOut,
                    ShowOnTop     = cfg.Position == ToastPosition.Top
                };
                if (cfg.Icon != null)
                {
                    snackbar.Icon = cfg.Icon.ToNative();
                }

                if (cfg.BackgroundColor != null)
                {
                    snackbar.BackgroundColor = cfg.BackgroundColor.Value.ToNative();
                }

                if (cfg.MessageTextColor != null)
                {
                    snackbar.MessageLabel.TextColor = cfg.MessageTextColor.Value.ToNative();
                }
                //snackbar.MessageTextColor = cfg.MessageTextColor.Value.ToNative();

                //if (cfg.Position != null)
                //    snackbar.LocationType = cfg.Position == ToastPosition.Top
                //        ? TTGSnackbarLocation.Top
                //        : TTGSnackbarLocation.Bottom;

                if (cfg.Action != null)
                {
                    var color = cfg.Action.TextColor ?? ToastConfig.DefaultActionTextColor;
                    if (color != null)
                    {
                        snackbar.ActionButton.SetTitleColor(color.Value.ToNative(), UIControlState.Normal);
                    }

                    snackbar.ActionText  = cfg.Action.Text;
                    snackbar.ActionBlock = x =>
                    {
                        snackbar.Dismiss();
                        cfg.Action.Action?.Invoke();
                    };
                }
                snackbar.Show();

                this.currentToast = new DisposableAction(
                    () => app.InvokeOnMainThread(() => snackbar.Dismiss())
                    );
            });
            return(this.currentToast);
        }
Esempio n. 8
0
        private void SetLayoutMargins(Snackbar snackBar, ToastConfig cfg)
        {
            var layoutParams = snackBar.View.LayoutParameters as FrameLayout.LayoutParams;

            if (layoutParams != null)
            {
                var scCfg = cfg as SCToastConfig;

                if (scCfg != null)
                {
                    layoutParams.SetMargins(scCfg.LeftMargin, scCfg.TopMargin, scCfg.RightMargin, scCfg.BottomMargin);
                }
                else
                {
                    layoutParams.SetMargins(0, 200, 0, 0);
                }

                if (cfg.Position == ToastPosition.Top)
                {
                    layoutParams.Gravity = GravityFlags.Top;
                }

                layoutParams.Height = 200;

                snackBar.View.LayoutParameters = layoutParams;
            }
        }
Esempio n. 9
0
        public override IDisposable Toast(ToastConfig config)
        {
            ToastPrompt toast = null;

            return(this.DispatchAndDispose(
                       () =>
            {
                toast = new ToastPrompt
                {
                    Message = config.Message,
                    //Stretch = Stretch.Fill,
                    TextWrapping = TextWrapping.WrapWholeWords,
                    MillisecondsUntilHidden = Convert.ToInt32(config.Duration.TotalMilliseconds)
                };
                if (config.Icon != null)
                {
                    toast.ImageSource = new BitmapImage(new Uri(config.Icon));
                }

                if (config.MessageTextColor != null)
                {
                    toast.Foreground = new SolidColorBrush(config.MessageTextColor.Value.ToNative());
                }

                if (config.BackgroundColor != null)
                {
                    toast.Background = new SolidColorBrush(config.BackgroundColor.Value.ToNative());
                }

                toast.Show();
            },
                       () => toast.Hide()
                       ));
        }
        public override void Toast(ToastConfig cfg)
        {
            // TODO: backgroundcolor and image
            var resources = Application.Current.Resources;
            var textColor = new SolidColorBrush(cfg.TextColor.ToNative());
            var bgColor   = cfg.BackgroundColor.ToNative();

            var wrapper = new StackPanel {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                //Background = (Brush)resources["PhoneAccentBrush"],
                Background = new SolidColorBrush(bgColor),
                Width      = Application.Current.Host.Content.ActualWidth
            };

            wrapper.Children.Add(new TextBlock {
                //Foreground = (Brush)resources["PhoneForegroundBrush"],
                Foreground          = textColor,
                FontSize            = (double)resources["PhoneFontSizeMedium"],
                Margin              = new Thickness(24, 32, 24, 12),
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = cfg.Title
            });

            if (!String.IsNullOrWhiteSpace(cfg.Description))
            {
                wrapper.Children.Add(new TextBlock {
                    //Foreground = (Brush)resources["PhoneForegroundBrush"],
                    //FontSize = (double)resources["PhoneFontSizeMedium"],
                    Foreground          = textColor,
                    FontSize            = (double)resources["PhoneFontSizeSmall"],
                    Margin              = new Thickness(24, 32, 24, 12),
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Text = cfg.Title
                });
            }

            var popup = new Popup {
                Child = wrapper,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            wrapper.Tap += (sender, args) => {
                SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                popup.IsOpen = false;
                cfg.Action?.Invoke();
            };

            this.Dispatch(() => {
                //SystemTray.BackgroundColor = (Color)resources["PhoneAccentColor"];
                SystemTray.BackgroundColor = bgColor;
                popup.IsOpen = true;
            });
            Task.Delay(cfg.Duration)
            .ContinueWith(x => this.Dispatch(() => {
                SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                popup.IsOpen = false;
            }));
        }
Esempio n. 11
0
 public override void Toast(ToastConfig cfg)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() => {
         MessageBarManager.SharedInstance.ShowAtTheBottom = ShowToastOnBottom;
         MessageBarManager.SharedInstance.HideAll();
         MessageBarManager.SharedInstance.StyleSheet = new AcrMessageBarStyleSheet(cfg);
         MessageBarManager.SharedInstance.ShowMessage(cfg.Title, cfg.Description ?? String.Empty, MessageType.Success, null, () => cfg.Action?.Invoke());
     });
 }
Esempio n. 12
0
        public override IDisposable Toast(ToastConfig config)
        {
            var a = Alert(new AlertConfig
            {
                Title   = "Error",
                Message = config.Message
            });

            return(a);
        }
        public override IDisposable Toast(ToastConfig config)
        {
            ToastMessage toast = new ToastMessage
            {
                Message = config.Message,
            };

            toast.Post();
            return(new DisposableAction(() => { }));
        }
Esempio n. 14
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            var activity = this.TopActivityFunc();
            var compat   = activity as AppCompatActivity;

            //if (compat == null)
            return(this.ToastFallback(activity, cfg));

            //return this.ToastAppCompat(compat, cfg);
        }
Esempio n. 15
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            var resources = Application.Current.Resources;

            var wrapper = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Width = Application.Current.Host.Content.ActualWidth
            };

            if (cfg.BackgroundColor != null)
            {
                wrapper.Background = new SolidColorBrush(cfg.BackgroundColor.Value.ToNative());
            }

            var txt = new TextBlock
            {
                FontSize            = (double)resources["PhoneFontSizeMedium"],
                Margin              = new Thickness(24, 32, 24, 12),
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = cfg.Message
            };

            if (cfg.MessageTextColor != null)
            {
                txt.Foreground = new SolidColorBrush(cfg.MessageTextColor.Value.ToNative());
            }

            wrapper.Children.Add(txt);
            var popup = new Popup
            {
                Child = wrapper,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            Action close = () =>
            {
                SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                popup.IsOpen = false;
            };

            wrapper.Tap += (sender, args) =>
            {
                close();
                cfg.Action.Action?.Invoke();
            };

            Task.Delay(cfg.Duration)
            .ContinueWith(x => this.Dispatch(close));

            return(this.DispatchWithDispose(() =>
            {
                //SystemTray.BackgroundColor = bgColor;
                popup.IsOpen = true;
            }, close));
        }
        public override IDisposable Toast(ToastConfig cfg)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity compat)
            {
                return(this.ToastAppCompat(compat, cfg));
            }

            return(this.ToastFallback(activity, cfg));
        }
        protected virtual IDisposable ToastAppCompat(AppCompatActivity activity, ToastConfig cfg)
        {
            Snackbar snackBar = null;

            activity.SafeRunOnUi(() =>
            {
                var view = activity.Window.DecorView.RootView.FindViewById(Android.Resource.Id.Content);
                var msg  = this.GetSnackbarText(cfg);

                snackBar = Snackbar.Make(
                    view,
                    msg,
                    (int)cfg.Duration.TotalMilliseconds
                    );
                if (cfg.BackgroundColor != null)
                {
                    snackBar.View.SetBackgroundColor(cfg.BackgroundColor.Value.ToNative());
                }

                if (cfg.Position == ToastPosition.Top)
                {
                    // watch for this to change in future support lib versions
                    var layoutParams = snackBar.View.LayoutParameters as FrameLayout.LayoutParams;
                    if (layoutParams != null)
                    {
                        layoutParams.Gravity = GravityFlags.Top;
                        layoutParams.SetMargins(0, 80, 0, 0);
                        snackBar.View.LayoutParameters = layoutParams;
                    }
                }
                if (cfg.Action != null)
                {
                    snackBar.SetAction(cfg.Action.Text, x =>
                    {
                        cfg.Action?.Action?.Invoke();
                        snackBar.Dismiss();
                    });
                    var color = cfg.Action.TextColor;
                    if (color != null)
                    {
                        snackBar.SetActionTextColor(color.Value.ToNative());
                    }
                }

                snackBar.Show();
            });
            return(new DisposableAction(() =>
            {
                if (snackBar.IsShown)
                {
                    activity.SafeRunOnUi(snackBar.Dismiss);
                }
            }));
        }
Esempio n. 18
0
        protected virtual IDisposable ToastAppCompat(AppCompatActivity activity, ToastConfig cfg)
        {
            Snackbar snackBar = null;

            activity.RunOnUiThread(() =>
            {
                var view = activity.Window.DecorView.RootView.FindViewById(Android.Resource.Id.Content);
                var msg  = this.GetSnackbarText(cfg);

                snackBar = Snackbar.Make(
                    view,
                    msg,
                    (int)cfg.Duration.TotalMilliseconds
                    );
                if (cfg.BackgroundColor != null)
                {
                    snackBar.View.SetBackgroundColor(cfg.BackgroundColor.Value.ToNative());
                }

                if (cfg.Action != null)
                {
                    snackBar.SetAction(cfg.Action.Text, x =>
                    {
                        cfg.Action?.Action?.Invoke();
                        snackBar.Dismiss();
                    });
                    var color = cfg.Action.TextColor;
                    if (color != null)
                    {
                        snackBar.SetActionTextColor(color.Value.ToNative());
                    }
                }

                snackBar.Show();
            });
            return(new DisposableAction(() =>
            {
                if (snackBar.IsShown)
                {
                    activity.RunOnUiThread(() =>
                    {
                        try
                        {
                            snackBar.Dismiss();
                        }
                        catch
                        {
                            // catch and swallow
                        }
                    });
                }
            }));
        }
Esempio n. 19
0
        protected virtual ISpanned GetSnackbarText(ToastConfig cfg)
        {
            var sb = new SpannableStringBuilder();

            string message = cfg.Message;
            var    hasIcon = (cfg.Icon != null);

            if (hasIcon)
            {
                message = "\u2002\u2002" + message; // add 2 spaces, 1 for the image the next for spacing between text and image
            }
            sb.Append(message);

            if (hasIcon)
            {
                var drawable = ImageLoader.Load(cfg.Icon);
                drawable.SetBounds(0, 0, drawable.IntrinsicWidth, drawable.IntrinsicHeight);

                sb.SetSpan(new ImageSpan(drawable, SpanAlign.Bottom), 0, 1, SpanTypes.ExclusiveExclusive);
            }

            if (cfg.MessageTextColor != null)
            {
                sb.SetSpan(
                    new ForegroundColorSpan(cfg.MessageTextColor.Value.ToNative()),
                    0,
                    sb.Length(),
                    SpanTypes.ExclusiveExclusive);
            }

            var scCfg = cfg as SCToastConfig;

            if (scCfg != null)
            {
                sb.SetSpan(
                    new StyleSpan((Android.Graphics.TypefaceStyle)scCfg.TextStyle)
                    , 0
                    , sb.Length(),
                    SpanTypes.ExclusiveExclusive);

                if (scCfg.FontSize > default(int))
                {
                    sb.SetSpan(
                        new AbsoluteSizeSpan(scCfg.FontSize, true)
                        , 0
                        , sb.Length(),
                        SpanTypes.ExclusiveExclusive);
                }
            }

            return(sb);
        }
        protected virtual void ToastAppCompat(AppCompatActivity activity, ToastConfig cfg)
        {
            var view     = activity.Window.DecorView.RootView.FindViewById(Android.Resource.Id.Content);
            var snackBar = Snackbar.Make(view, cfg.Description, (int)cfg.Duration.TotalMilliseconds);

            snackBar.View.SetBackgroundColor(cfg.BackgroundColor.ToNative());
            snackBar.View.Click += (sender, args) =>
            {
                snackBar.Dismiss();
                cfg.Action?.Invoke();
            };
            this.SetSnackbarTextView(snackBar, cfg);
            activity.RunOnUiThread(snackBar.Show);
        }
        public override void Toast(ToastConfig cfg)
        {
            var activity = this.TopActivityFunc();
            var compat   = activity as AppCompatActivity;

            if (compat == null)
            {
                this.ToastFallback(activity, cfg);
            }
            else
            {
                this.ToastAppCompat(compat, cfg);
            }
        }
        public override void Toast(ToastConfig cfg)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                MessageBarManager.SharedInstance.ShowAtTheBottom = cfg.Position == ToastPosition.Bottom;
                MessageBarManager.SharedInstance.HideAll();
                MessageBarManager.SharedInstance.StyleSheet = new AcrMessageBarStyleSheet(cfg);
                MessageBarManager.SharedInstance.ShowMessage(cfg.Title, cfg.Description ?? String.Empty, MessageType.Success, null, () => cfg.Action?.Invoke());

                this.toastTimer.Stop();
                this.toastTimer.Interval = cfg.Duration.TotalMilliseconds;
                this.toastTimer.Start();
            });
        }
Esempio n. 23
0
        protected virtual ISpanned GetSnackbarText(ToastConfig cfg)
        {
            var sb = new SpannableStringBuilder();

            sb.Append(cfg.Message);
            if (cfg.MessageTextColor != null)
            {
                sb.SetSpan(
                    new ForegroundColorSpan(cfg.MessageTextColor.Value.ToNative()),
                    0,
                    cfg.Message.Length,
                    SpanTypes.ExclusiveExclusive
                    );
            }
            return(sb);
        }
Esempio n. 24
0
        public override void Toast(ToastConfig config)
        {
            var toast = new ToastPrompt {
                Background              = new SolidColorBrush(config.BackgroundColor.ToNative()),
                Foreground              = new SolidColorBrush(config.TextColor.ToNative()),
                Title                   = config.Title,
                Message                 = config.Description,
                ImageSource             = config.Icon?.ToNative(),
                Stretch                 = Stretch.Fill,
                MillisecondsUntilHidden = Convert.ToInt32(config.Duration.TotalMilliseconds)
            };

            //toast.Completed += (sender, args) => {
            //    if (args.PopUpResult == PopUpResult.Ok)
            //        config.Action?.Invoke();
            //};
            this.Dispatch(toast.Show);
        }
Esempio n. 25
0
        private Acr.UserDialogs.ToastConfig MapConfigurations(ToastConfig config)
        {
            var acrToastConfig = new Acr.UserDialogs.ToastConfig(config.ToastMessage)
            {
                BackgroundColor  = config.BackgroundColor.ToSystemColor(),
                Duration         = config.Duration,
                MessageTextColor = config.MessageTextColor.ToSystemColor()
            };

            if (config.Action != null)
            {
                acrToastConfig.Action = new ToastAction
                {
                    Action    = config.Action,
                    Text      = config.ActionText,
                    TextColor = config.ActionTextColor.ToSystemColor()
                };
            }

            return(acrToastConfig);
        }
        protected virtual void SetSnackbarTextView(Snackbar bar, ToastConfig cfg)
        {
            var group = (ViewGroup)bar.View;

            for (var i = 0; i < group.ChildCount; i++)
            {
                var txt = group.GetChildAt(i) as TextView;
                if (txt != null)
                {
                    var text = $"<b>{cfg.Title}</b>";
                    if (!String.IsNullOrWhiteSpace(cfg.Description))
                    {
                        text += $"\n<br /><i>{cfg.Description}</i>";
                    }

                    txt.SetTextColor(cfg.TextColor.ToNative());
                    txt.TextFormatted = Html.FromHtml(text);
                    return;
                }
            }
            throw new Exception("No textview found on snackbar");
        }
        public override void Toast(ToastConfig cfg)
        {
            Utils.RequestMainThread(() => {
                var top = this.GetTopActivity();
                var txt = cfg.Title;
                if (!String.IsNullOrWhiteSpace(cfg.Description))
                {
                    txt += Environment.NewLine + cfg.Description;
                }

                AndHUD.Shared.ShowToast(
                    top,
                    txt,
                    AndroidHUD.MaskType.Black,
                    cfg.Duration,
                    false,
                    () => {
                    AndHUD.Shared.Dismiss();
                    cfg.Action?.Invoke();
                }
                    );
            });
        }
        protected virtual void ToastFallback(Activity activity, ToastConfig cfg)
        {
            activity.RunOnUiThread(() =>
            {
                var txt = cfg.Title;
                if (!String.IsNullOrWhiteSpace(cfg.Description))
                {
                    txt += Environment.NewLine + cfg.Description;
                }

                AndHUD.Shared.ShowToast(
                    activity,
                    txt,
                    AndroidHUD.MaskType.None,
                    cfg.Duration,
                    false,
                    () =>
                {
                    AndHUD.Shared.Dismiss();
                    cfg.Action?.Invoke();
                }
                    );
            });
        }
Esempio n. 29
0
        /// <summary> Gets toast configuration. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="config"> The configuration. </param>
        /// <returns> The toast configuration. </returns>
        private AcrDialogs.ToastConfig GetToastConfig(UserDialogToastConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var result = new AcrDialogs.ToastConfig(config.Message);

            if (config.MessageTextColor != null)
            {
                result.MessageTextColor = config.MessageTextColor;
            }
            if (config.BackgroundColor != null)
            {
                result.BackgroundColor = config.BackgroundColor;
            }
            if (config.Position != null)
            {
                result.Position = ConvertToAcrToastPosition(config.Position.Value);
            }
            if (config.Duration != null)
            {
                result.Duration = config.Duration.Value;
            }
            if (config.Action != null)
            {
                result.Action = GetToastAction(config.Action);
            }
            if (config.Icon != null)
            {
                result.Icon = config.Icon;
            }

            return(result);
        }
 public AcrMessageBarStyleSheet(ToastConfig config) {
     this.config = config;
 }
Esempio n. 31
0
        public override void Toast(ToastConfig cfg)
        {
            var top = this.GetTopActivity();
            var view = top.Window.DecorView.RootView;
            //var view = top.Window.DecorView.RootView.FindViewById(Android.Resource.Id.Content);

            var text = $"<b>{cfg.Title}</b>";
            if (!String.IsNullOrWhiteSpace(cfg.Description))
                text += $"\n<br /><i>{cfg.Description}</i>";

            var snackBar = Snackbar.Make(view, text, (int)cfg.Duration.TotalMilliseconds);
            snackBar.View.Background = new ColorDrawable(cfg.BackgroundColor.ToNative());
            var txt = FindTextView(snackBar);
            txt.SetTextColor(cfg.TextColor.ToNative());
            txt.TextFormatted = Html.FromHtml(text);

            snackBar.View.Click += (sender, args) => {
                snackBar.Dismiss();
                cfg.Action?.Invoke();
            };
            Utils.RequestMainThread(snackBar.Show);
        }
Esempio n. 32
0
 public override void Toast(ToastConfig config)
 {
     throw new NotImplementedException();
 }
Esempio n. 33
0
 public abstract IDisposable Toast(ToastConfig config);
        public override void Toast(ToastConfig cfg)
        {
            var top = this.GetTopActivity();
            var view = top.Window.DecorView.RootView;
            var snackBar = Snackbar.Make(view, cfg.Text, (int)cfg.Duration.TotalMilliseconds);
            snackBar.View.Background = new ColorDrawable(cfg.BackgroundColor.ToNative());

            //android.support.design.R.id.snackbar_text // TODO
            //snackBar.View.FindViewById<TextView>().SetTextColor

            snackBar.View.Click += (sender, args) => {
                snackBar.Dismiss();
                cfg.Action?.Invoke();
            };
            ////if (cfg.BackgroundColor != null)
            ////    snackBar.SetActionTextColor()
            //if (cfg.OnTap != null)
            //    snackBar.SetAction("Ok", x => cfg.OnTap?.Invoke());

            Utils.RequestMainThread(snackBar.Show);
        }
Esempio n. 35
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            var resources = Application.Current.Resources;

            var wrapper = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Width = Application.Current.Host.Content.ActualWidth
            };
            if (cfg.BackgroundColor != null)
                wrapper.Background = new SolidColorBrush(cfg.BackgroundColor.Value.ToNative());

            var txt = new TextBlock
            {
                FontSize = (double) resources["PhoneFontSizeMedium"],
                Margin = new Thickness(24, 32, 24, 12),
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = cfg.Message
            };
            if (cfg.MessageTextColor != null)
                txt.Foreground = new SolidColorBrush(cfg.MessageTextColor.Value.ToNative());

            wrapper.Children.Add(txt);
            var popup = new Popup
            {
                Child = wrapper,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            Action close = () =>
            {
                SystemTray.BackgroundColor = (Color)resources["PhoneBackgroundColor"];
                popup.IsOpen = false;
            };

            wrapper.Tap += (sender, args) =>
            {
                close();
                cfg.Action.Action?.Invoke();
            };

            Task.Delay(cfg.Duration)
                .ContinueWith(x => this.Dispatch(close));

            return this.DispatchWithDispose(() =>
            {
                //SystemTray.BackgroundColor = bgColor;
                popup.IsOpen = true;
            }, close);
        }
Esempio n. 36
0
        public override void Toast(ToastConfig cfg)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() => {
                MessageBarManager.SharedInstance.ShowAtTheBottom = ShowToastOnBottom;
                MessageBarManager.SharedInstance.HideAll();
                MessageBarManager.SharedInstance.StyleSheet = new AcrMessageBarStyleSheet(cfg);
                MessageBarManager.SharedInstance.ShowMessage(cfg.Title, cfg.Description ?? String.Empty, MessageType.Success, null, () => cfg.Action?.Invoke());

                this.toastTimer.Stop();
                this.toastTimer.Interval = cfg.Duration.TotalMilliseconds;
                this.toastTimer.Start();
            });
        }
Esempio n. 37
0
        public override IDisposable Toast(ToastConfig config)
        {
            ToastPrompt toast = null;

            return this.DispatchAndDispose(() =>
            {
                toast = new ToastPrompt
                {
                    Message = config.Message,
                    //Stretch = Stretch.Fill,
                    TextWrapping = TextWrapping.Wrap,
                    MillisecondsUntilHidden = Convert.ToInt32(config.Duration.TotalMilliseconds)
                };
                if (config.MessageTextColor != null)
                    toast.Foreground = new SolidColorBrush(config.MessageTextColor.Value.ToNative());

                if (config.BackgroundColor != null)
                    toast.Background = new SolidColorBrush(config.BackgroundColor.Value.ToNative());

                toast.Show();
            },
            () => toast.Hide());
        }
Esempio n. 38
0
 public override void Toast(ToastConfig cfg)
 {
     Utils.RequestMainThread(() => {
         var top = this.GetTopActivity();
         AndHUD.Shared.ShowToast(
             top,
             cfg.Text,
             AndroidHUD.MaskType.Black,
             cfg.Duration,
             false,
             () => {
                 AndHUD.Shared.Dismiss();
                 cfg.Action?.Invoke();
             }
         );
     });
 }
Esempio n. 39
0
        public override void Toast(ToastConfig cfg)
        {
            Utils.RequestMainThread(() => {
                var top = this.GetTopActivity();
                var txt = cfg.Title;
                if (!String.IsNullOrWhiteSpace(cfg.Description))
                    txt += Environment.NewLine + cfg.Description;

                AndHUD.Shared.ShowToast(
                    top,
                    txt,
                    AndroidHUD.MaskType.Black,
                    cfg.Duration,
                    false,
                    () => {
                        AndHUD.Shared.Dismiss();
                        cfg.Action?.Invoke();
                    }
                );
            });
        }
 public abstract void Toast(ToastConfig config);
Esempio n. 41
0
 public override IDisposable Toast(ToastConfig config)
 {
     throw new NotImplementedException();
 }
Esempio n. 42
0
        public override void Toast(ToastConfig config)
        {
            // TODO: action text and action command will work here!
            var stack = new StackPanel { Orientation = Orientation.Horizontal };
            if (config.Icon != null) {
                var icon = config.Icon.ToNative();
                stack.Children.Add(new Image { Source = icon });
            }
            stack.Children.Add(new TextBlock {
                Text = config.Text,
                Foreground = new SolidColorBrush(config.TextColor.ToNative())
            });

            var dialog = new ContentDialog {
                Content = stack,
                Background = new SolidColorBrush(config.BackgroundColor.ToNative())
            };
            dialog.Tapped += (sender, args) => {
                dialog.Hide();
                config.Action?.Invoke();
            };
            dialog.ShowAsync();
            Task.Delay(config.Duration)
                .ContinueWith(x => {
                    try {
                        dialog.Hide();
                    }
                    catch { } // swallow race condition
                });
        }
Esempio n. 43
0
 public override IDisposable Toast(ToastConfig config)
 {
     throw new NotImplementedException();
 }
Esempio n. 44
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            this.currentToast?.Dispose();

            var app = UIApplication.SharedApplication;
            app.InvokeOnMainThread(() =>
            {
                var snackbar = new TTG.TTGSnackbar
                {
                    Message = cfg.Message,
                    Duration = cfg.Duration,
                    AnimationType = TTG.TTGSnackbarAnimationType.FadeInFadeOut
                };
                if (cfg.BackgroundColor != null)
                    snackbar.BackgroundColor = cfg.BackgroundColor.Value.ToNative();

                if (cfg.MessageTextColor != null)
                    snackbar.MessageLabel.TextColor = cfg.MessageTextColor.Value.ToNative();

                if (cfg.Action != null)
                {
                    var color = cfg.Action.TextColor ?? ToastConfig.DefaultActionTextColor;
                    if (color != null)
                        snackbar.ActionButton.SetTitleColor(color.Value.ToNative(), UIControlState.Normal);

                    snackbar.ActionText = cfg.Action.Text;
                    snackbar.ActionBlock = x =>
                    {
                        snackbar.Dismiss();
                        cfg.Action.Action?.Invoke();
                    };
                }
                snackbar.Show();

                this.currentToast = new DisposableAction(
                    () => app.InvokeOnMainThread(() => snackbar.Dismiss())
                );
            });
            return this.currentToast;
        }
Esempio n. 45
0
 public override void Toast(ToastConfig config) {
     var toast = new ToastPrompt {
         Background = new SolidColorBrush(config.BackgroundColor.ToNative()),
         Foreground = new SolidColorBrush(config.TextColor.ToNative()),
         Title = config.Title,
         Message = config.Description,
         ImageSource = config.Icon?.ToNative(),
         Stretch = Stretch.Fill,
         MillisecondsUntilHidden = Convert.ToInt32(config.Duration.TotalMilliseconds)
     };
     //toast.Completed += (sender, args) => {
     //    if (args.PopUpResult == PopUpResult.Ok)
     //        config.Action?.Invoke();
     //};
     this.Dispatch(toast.Show);
 }