public static void HandleDialogMessage( DialogMessage error, string message = "", int seconds = 2, string backgroundColor = "#333333", ToastPosition position = ToastPosition.Bottom) { switch (error) { case DialogMessage.NetworkError: message = " " + NetworkError + " "; break; case DialogMessage.UndefinedError: message = " " + UndefinedError + " "; break; case DialogMessage.Defined: message = " " + message + " "; break; case DialogMessage.InputError: message = " " + message + InputError + " "; break; } UserDialogs.Instance.Toast(new ToastConfig(message) .SetBackgroundColor(Color.FromHex(backgroundColor)) .SetMessageTextColor(Color.White) .SetDuration(TimeSpan.FromSeconds(seconds)) .SetPosition(position) ); }
/// <summary> /// Shows the specified message. /// </summary> protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource <object> tcs) { Form activeForm = Form.ActiveForm; if (activeForm == null) { tcs.SetResult(null); return; } foreach (var result in activeForm.Controls.Find(ControlName, false).OfType <ToastMessageControl>()) { if (duration >= result.Duration) { ClearControl(result); } } var control = GetToastControl(activeForm, content, duration, tcs); control.Name = ControlName; activeForm.Controls.Add(control); SetPosition(activeForm, control, position); control.BringToFront(); var timer = new Timer { Interval = TimerInterval, Tag = control }; timer.Tick += TimerTick; timer.Start(); control.Tag = timer; }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { View holder = null; var currentActivity = PlatformExtensions.CurrentActivity; if (currentActivity != null) { var selector = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarViewSelector); if (selector != null) { holder = selector(content, position, context); } if (holder == null) { holder = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarView); } } if (holder == null) { return(_defaultPresenter.ShowAsync(content, duration, position, context)); } var toastImpl = new ToastImpl(); if (_threadManager.IsUiThread) { ShowInternal(currentActivity, holder, content, duration, toastImpl); } else { _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(currentActivity, holder, content, duration, toastImpl), OperationPriority.High); } return(toastImpl); }
public ToastView(object content, UIView owner, float displayDuration, ToastPosition position, TaskCompletionSource <object> tcs) { Should.NotBeNull(tcs, "tcs"); Content = content; Owner = owner ?? UIApplication.SharedApplication.KeyWindow; DisplayDuration = displayDuration / 1000; Position = position; TaskCompletionSource = tcs; AnimationDuration = 0.2; ShadowEnabled = true; ShadowOpacity = 0.8f; ShadowOffsetX = 4f; ShadowOffsetY = 4f; ShadowRadius = 4f; HorizontalPadding = 10f; VerticalPadding = 10f; FontSize = 16f; CornerRadius = 4f; if (PlatformExtensions.IsOS7) { BackgroundColor = UIColor.Black.ColorWithAlpha(0.8f); ShadowColor = UIColor.Black.CGColor; TextColor = UIColor.White; } else { BackgroundColor = UIColor.White.ColorWithAlpha(0.8f); ShadowColor = UIColor.White.CGColor; TextColor = UIColor.Black; } }
private static string GetPosition(ToastPosition t) { string Tipo = ""; switch (t) { case ToastPosition.TopRight: Tipo = "toast-top-right"; break; case ToastPosition.BottomRight: Tipo = "toast-bottom-right"; break; case ToastPosition.BottomLeft: Tipo = "toast-bottom-left"; break; case ToastPosition.TopLeft: Tipo = "toast-top-left"; break; case ToastPosition.TopFullWidth: Tipo = "toast-top-full-width"; break; case ToastPosition.BottomFullWidth: Tipo = "toast-bottom-full-width"; break; } return(Tipo); }
public static string Show(TipoMensaje Tipo, string msg, string title, ShowMethod sMethod, HideMethod hMethod, ShowEasing sEasing, HideEasing hEasing, ToastPosition tPosition, bool btnCerrar) { string shortCutFunction = GetTipo(Tipo); string showEasing = GetShowEasing(sEasing); string hideEasing = GetHideEasing(hEasing); string showMethod = GetShowMethod(sMethod); string hideMethod = GetHideMethod(hMethod); string position = GetPosition(tPosition); int toastIndex = 0; int showDuration = 1000; int hideDuration = 1000; int timeOut = 2000; int extendedTimeout = 1000; string ScriptError = @" $(document).ready( function() { MensajeError('" + shortCutFunction + "', '" + msg + "', '" + title + "', " + showDuration + ", " + hideDuration + ", " + timeOut + ", " + extendedTimeout + ", '" + showEasing + "', '" + hideEasing + "', '" + showMethod + "', '" + hideMethod + "', " + toastIndex + ", '" + btnCerrar.ToString().ToLower() + "', '" + position + @"');});"; return(ScriptError); }
public static string ToJsParameter(this ToastPosition position) { switch (position) { case ToastPosition.TopRight: return("top|right"); case ToastPosition.BottomRight: return("bottom|right"); case ToastPosition.BottomLeft: return("bottom|left"); case ToastPosition.TopLeft: return("top|left"); case ToastPosition.TopFullWidth: case ToastPosition.TopCenter: return("top|center"); case ToastPosition.BottomFullWidth: case ToastPosition.BottomCenter: return("bottom|center"); } return(default);
public static string ToClassName(this ToastPosition position) { switch (position) { case ToastPosition.TopRight: return("toast-top-right"); case ToastPosition.BottomRight: return("toast-bottom-right"); case ToastPosition.BottomLeft: return("toast-bottom-left"); case ToastPosition.TopLeft: return("toast-top-left"); case ToastPosition.TopFullWidth: return("toast-top-full-width"); case ToastPosition.BottomFullWidth: return("toast-bottom-full-width"); case ToastPosition.TopCenter: return("toast-top-center"); case ToastPosition.BottomCenter: return("toast-bottom-center"); } return(default);
public void Show(float duration, ToastPosition position) { switch (position) { case ToastPosition.Bottom: _toast.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 0, 0); break; case ToastPosition.Center: _toast.SetGravity(GravityFlags.Center, 0, 0); break; case ToastPosition.Top: _toast.SetGravity(GravityFlags.Top | GravityFlags.CenterHorizontal, 0, 0); break; default: throw new ArgumentOutOfRangeException("position"); } _toast.Duration = ToastLength.Short; _toast.Show(); _delayTimer = new Timer(DelayTimerCallback, this, (uint)duration, int.MaxValue); if (duration > 2000) { _showTimer = new Timer(ShowTimerCallback, this, TimerInterval, TimerInterval); } }
public void Show(Toast toast, float duration, ToastPosition position) { Should.NotBeNull(toast, nameof(toast)); _toast = toast; switch (position) { case ToastPosition.Bottom: _toast.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal, toast.XOffset, toast.YOffset); break; case ToastPosition.Center: _toast.SetGravity(GravityFlags.Center, toast.XOffset, toast.YOffset); break; case ToastPosition.Top: _toast.SetGravity(GravityFlags.Top | GravityFlags.CenterHorizontal, toast.XOffset, toast.YOffset); break; default: throw new ArgumentOutOfRangeException(nameof(position)); } _toast.Duration = ToastLength.Short; _toast.Show(); _delayTimer = new Timer(DelayTimerCallback, this, (uint)duration, int.MaxValue); if (duration > 2000) { _showTimer = new Timer(ShowTimerCallback, this, TimerInterval, TimerInterval); } }
public ToastView(object content, UIView owner, float displayDuration, ToastPosition position, TaskCompletionSource<object> tcs) { Should.NotBeNull(tcs, "tcs"); Content = content; Owner = owner ?? UIApplication.SharedApplication.KeyWindow; DisplayDuration = displayDuration / 1000; Position = position; TaskCompletionSource = tcs; AnimationDuration = 0.2; ShadowEnabled = true; ShadowOpacity = 0.8f; ShadowOffsetX = 4f; ShadowOffsetY = 4f; ShadowRadius = 4f; HorizontalPadding = 10f; VerticalPadding = 10f; FontSize = 16f; CornerRadius = 4f; if (PlatformExtensions.IsOS7) { BackgroundColor = UIColor.Black.ColorWithAlpha(0.8f); ShadowColor = UIColor.Black.CGColor; TextColor = UIColor.White; } else { BackgroundColor = UIColor.White.ColorWithAlpha(0.8f); ShadowColor = UIColor.White.CGColor; TextColor = UIColor.Black; } }
public EventClosure(Popup popup, ToastPosition position, FrameworkElement parent) #endif { _position = position; _parent = parent; _popup = popup; }
public EventClosure(Popup popup, ToastPosition position, FrameworkElement parent) #endif { _position = position; _parent = parent; _reference = ServiceProvider.WeakReferenceFactory(popup, true); }
public void ShowToast(string message, int seconds = 1, ToastPosition position = ToastPosition.Top) { ToastConfig cn = new ToastConfig(message); cn.Position = position; cn.SetDuration(seconds * 1000); UserDialogs.Instance.Toast(cn); }
public void ShowErrorToast(string message, int ts = 3000, ToastPosition position = ToastPosition.Bottom) { var toastConfig = new ToastConfig(message); toastConfig.SetPosition(position); toastConfig.SetDuration(ts); toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(255, 0, 0)); _userDialogs.Toast(toastConfig); }
/// <summary> /// Shows the specified message. /// </summary> public Task ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var tcs = new TaskCompletionSource<object>(); if (_threadManager.IsUiThread) ShowInternal(content, duration, position, context, tcs); else _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, tcs)); return tcs.Task; }
private void Show(string text, float duration, Color color, ToastPosition position) { uiText.text = (text.Length > maxTextLength) ? text.Substring(0, maxTextLength) + "..." : text; uiImage.color = color; uiContentVerticalLayoutGroup.childAlignment = (TextAnchor)((int)position); Dismiss(); StartCoroutine(FadeInOut(duration, fadeDuration)); }
public static void ShowToast(string message, ToastPosition position = ToastPosition.Top) { ToastConfig toastConfig = new ToastConfig(message) { Position = position }; toastConfig.SetDuration(3000); toastConfig.SetBackgroundColor((Color)App.Current.Resources["MainColor"]); UserDialogs.Instance.Toast(toastConfig); }
private void Show(object content, float duration, ToastPosition position, IDataContext context, ToastImpl toastImpl) { UIView owner = GetOwner() ?? UIApplication.SharedApplication.KeyWindow; toastImpl.Toast = CreateToast(content, owner, duration, position, context ?? DataContext.Empty, toastImpl.Tcs); ServiceProvider.AttachedValueProvider.AddOrUpdate(owner, Key, toastImpl.Toast, (item, value, currentValue, state) => { currentValue.Hide(); return(value); }).Show(); }
public static void ShowToast(string message, int howLong = 2, ToastPosition location = ToastPosition.Bottom) { IUserDialogs dialogs = UserDialogs.Instance; ToastConfig.DefaultBackgroundColor = System.Drawing.Color.Black; ToastConfig.DefaultMessageTextColor = System.Drawing.Color.White; ToastConfig.DefaultActionTextColor = System.Drawing.Color.Yellow; dialogs.Toast(new ToastConfig($"{message}") .SetDuration(TimeSpan.FromSeconds(howLong)) .SetPosition(location) ); }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toastImpl = new ToastImpl(); if (_threadManager.IsUiThread) { toastImpl.CloseAction = ShowInternal(content, duration, position, context, toastImpl.Tcs); } else { _threadManager.InvokeOnUiThreadAsync(() => toastImpl.CloseAction = ShowInternal(content, duration, position, context, toastImpl.Tcs)); } return(toastImpl); }
public void Show(string message, ToastPosition toastPosition, string appTheme) { try { Context context = Android.App.Application.Context; Toast toast = Toast.MakeText(context, message, ToastLength.Short); if (Xamarin.Essentials.DeviceInfo.Version.Major <= 10) { toast.View.SetBackgroundResource(Resource.Drawable.CustomToast); toast.SetGravity(Android.Views.GravityFlags.Center, 0, 0); TextView tv = toast.View.FindViewById <TextView>(Android.Resource.Id.Message); tv.Gravity = Android.Views.GravityFlags.CenterVertical | Android.Views.GravityFlags.CenterHorizontal; tv.SetPadding(20, 0, 20, 0); if (appTheme == "Dark") { tv.SetTextColor(Android.Graphics.Color.Black); } else { tv.SetTextColor(Android.Graphics.Color.White); } } switch (toastPosition) { case ToastPosition.Top: toast.SetGravity(Android.Views.GravityFlags.Top, 0, 200); break; case ToastPosition.Center: toast.SetGravity(Android.Views.GravityFlags.CenterVertical, 0, 0); break; case ToastPosition.Bottom: toast.SetGravity(Android.Views.GravityFlags.Bottom, 0, 200); break; default: toast.SetGravity(Android.Views.GravityFlags.Top, 0, 200); break; } toast.Show(); } catch (Exception e) { Log.Error(e, "Show toast error"); } }
/// <summary> /// Shows the specified message. /// </summary> public Task ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var tcs = new TaskCompletionSource <object>(); if (_threadManager.IsUiThread) { ShowInternal(content, duration, position, context, tcs); } else { _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, tcs)); } return(tcs.Task); }
protected virtual Action ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource <object> tcs) { #if WPF var placementTarget = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive); #elif WINDOWS_PHONE var placementTarget = Application.Current.RootVisual as FrameworkElement; #elif WINDOWS_UWP || NETFX_CORE var placementTarget = Window.Current; #endif if (placementTarget == null) { return(null); } var popup = TryGetPopupFromTemplate(content, placementTarget) ?? GetToastPopup(GetToastContentWrapper(GetToastContent(content))); #if WPF popup.PlacementTarget = placementTarget; #endif UpdatePosition(placementTarget, popup, position); popup.IsOpen = true; var closure = new EventClosure(popup, position, placementTarget) { TaskCompletionSource = tcs }; ServiceProvider.AttachedValueProvider.AddOrUpdate(placementTarget, PopupAttachedValuePath, (window, o) => (EventClosure)o, (item, value, currentValue, state) => { currentValue.Clear(); return(value(item, state)); }, closure); #if WPF placementTarget.LocationChanged += closure.Handle; #elif WINDOWS_PHONE var page = placementTarget as PhoneApplicationFrame; if (page != null) { page.OrientationChanged += closure.Handle; } #endif placementTarget.SizeChanged += closure.Handle; var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(duration) }; timer.Tick += (sender, args) => TimerCallback(sender, closure); closure.Timer = timer; BeginOpenAnimation(popup, timer.Start); return(closure.Clear); }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toast = new ToastImpl(); if (_threadManager.IsUiThread) { Show(content, duration, position, context, toast); } else { _threadManager.InvokeOnUiThreadAsync(() => Show(content, duration, position, context, toast)); } return(toast); }
public void ShowToast(string message, ToastPosition toastPosition = ToastPosition.Top) { // Add top and botton space to iOS if (Device.RuntimePlatform == Device.iOS) { message = "\n" + message + "\n"; } UserDialogs.Instance.Toast(new ToastConfig(message) .SetBackgroundColor(TestClientXamarin.Helpers.StyleResources.Gray900Color()) .SetMessageTextColor(TestClientXamarin.Helpers.StyleResources.WhiteColor()) .SetDuration(TimeSpan.FromSeconds(6)) .SetPosition(toastPosition) ); }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toast = new ToastWrapper(new TaskCompletionSource <object>(), _threadManager); if (_threadManager.IsUiThread) { ShowInternal(content, duration, position, context, toast); } else { _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, toast), OperationPriority.High); } return(toast); }
public static Toast MakeToast(ToastGroup group, string text, string style, ToastPosition position) { singleton.SetCurrentToastFields(group, style); var toast = singleton.CreateToast(text); var ret = new Toast(toast.GetComponent <RectTransform>(), singleton); var rect = toast.GetComponent <RectTransform>(); if (position == ToastPosition.Top) { rect.SetAsFirstSibling(); } return(ret); }
/// <summary> /// Shows the specified message. /// </summary> protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource <object> tcs) { #if XAMARIN_FORMS var ctx = Xamarin.Forms.Forms.Context; #else var ctx = _navigationProvider.CurrentContent as Context; #endif if (ctx == null) { tcs.SetResult(null); return; } View view = GetView(content, ctx); Toast toast = view == null ? Toast.MakeText(ctx, content == null? "(null)" : content.ToString(), ToastLength.Long) : new Toast(ctx) { View = view }; var wrapper = new ToastWrapper(toast, tcs, _threadManager); ServiceProvider .AttachedValueProvider .AddOrUpdate(ctx, ToastWrapperMember, (c, o) => { wrapper.Show(duration, position); return(wrapper); }, (item, value, oldValue, state) => { oldValue.Complete(); return(value(item, state)); }); #if !XAMARIN_FORMS var activityView = ctx as IActivityView; if (activityView == null) { return; } ServiceProvider.AttachedValueProvider.GetOrAdd(activityView, DisposedEventHandler, (view1, o) => { view1.Destroyed += ActivityOnDestroyed; return(DisposedEventHandler); }, null); #endif }
/// <summary> /// /// </summary> /// <param name="toastPosition"></param> /// <returns></returns> private static string PositionToastr(ToastPosition toastPosition) { string positionToastr; switch (toastPosition) { case ToastPosition.TopRight: positionToastr = "toast-top-right"; break; case ToastPosition.TopLeft: positionToastr = "toast-top-left"; break; case ToastPosition.BottomRight: positionToastr = "toast-bottom-right"; break; case ToastPosition.BottomLeft: positionToastr = "toast-bottom-left"; break; case ToastPosition.TopFullWidth: positionToastr = "toast-top-full-width"; break; case ToastPosition.BottomFullWidth: positionToastr = "toast-bottom-full-width"; break; case ToastPosition.TopCenter: positionToastr = "toast-top-center"; break; case ToastPosition.BottomCenter: positionToastr = "toast-bottom-center"; break; default: positionToastr = "toast-top-right"; break; } return(positionToastr); }
protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, ToastWrapper wrapper) { #if XAMARIN_FORMS var ctx = XamarinFormsAndroidToolkitExtensions.GetCurrentContext(); #else var ctx = AndroidToolkitExtensions.CurrentActivity; #endif if (ctx == null) { wrapper.Cancel(); return; } Toast toast = null; #if !XAMARIN_FORMS var selector = ctx.GetBindingMemberValue(AttachedMembers.Activity.ToastTemplateSelector); if (selector != null) { toast = (Toast)selector.SelectTemplate(content, ctx); } #endif if (toast == null) { View view = GetView(content, ctx); toast = view == null ? Toast.MakeText(ctx, content?.ToString() ?? "(null)", ToastLength.Long) : new Toast(ctx) { View = view }; } ServiceProvider .AttachedValueProvider .AddOrUpdate(ctx, ToastWrapperMember, (c, o) => { wrapper.Show(toast, duration, position); return(wrapper); }, (item, value, oldValue, state) => { oldValue.Close(); return(value(item, state)); }); }
public static string Show(string message, string title = "", ToastType type = ToastType.Info, ToastPosition position = ToastPosition.TopRight, int timeOut = 6000, 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); }
public void Show(float duration, ToastPosition position) { switch (position) { case ToastPosition.Bottom: _toast.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal, 0, 0); break; case ToastPosition.Center: _toast.SetGravity(GravityFlags.Center, 0, 0); break; case ToastPosition.Top: _toast.SetGravity(GravityFlags.Top | GravityFlags.CenterHorizontal, 0, 0); break; default: throw new ArgumentOutOfRangeException("position"); } _toast.Duration = ToastLength.Short; _toast.Show(); _delayTimer = new Timer(DelayTimerCallback, this, (uint)duration, int.MaxValue); if (duration > 2000) _showTimer = new Timer(ShowTimerCallback, this, TimerInterval, TimerInterval); }
public void Show(Toast toast, float duration, ToastPosition position) { Should.NotBeNull(toast, nameof(toast)); _toast = toast; switch (position) { case ToastPosition.Bottom: _toast.SetGravity(GravityFlags.Bottom | GravityFlags.CenterHorizontal, toast.XOffset, toast.YOffset); break; case ToastPosition.Center: _toast.SetGravity(GravityFlags.Center, toast.XOffset, toast.YOffset); break; case ToastPosition.Top: _toast.SetGravity(GravityFlags.Top | GravityFlags.CenterHorizontal, toast.XOffset, toast.YOffset); break; default: throw new ArgumentOutOfRangeException(nameof(position)); } _toast.Duration = ToastLength.Short; _toast.Show(); _delayTimer = new Timer(DelayTimerCallback, this, (uint)duration, int.MaxValue); if (duration > 2000) _showTimer = new Timer(ShowTimerCallback, this, TimerInterval, TimerInterval); }
protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, ToastWrapper wrapper) { #if XAMARIN_FORMS var ctx = global::Xamarin.Forms.Forms.Context; #else var ctx = PlatformExtensions.CurrentActivity; #endif if (ctx == null) { wrapper.Cancel(); return; } Toast toast = null; #if !XAMARIN_FORMS var selector = ctx.GetBindingMemberValue(AttachedMembers.Activity.ToastTemplateSelector); if (selector != null) toast = (Toast)selector.SelectTemplate(content, ctx); #endif if (toast == null) { View view = GetView(content, ctx); toast = view == null ? Toast.MakeText(ctx, content?.ToString() ?? "(null)", ToastLength.Long) : new Toast(ctx) { View = view }; } ServiceProvider .AttachedValueProvider .AddOrUpdate(ctx, ToastWrapperMember, (c, o) => { wrapper.Show(toast, duration, position); return wrapper; }, (item, value, oldValue, state) => { oldValue.Close(); return value(item, state); }); }
protected virtual ToastView CreateToast(object content, UIView owner, float duration, ToastPosition position, IDataContext context, TaskCompletionSource<object> tcs) { ToastView toastView = null; var factory = Factory; if (factory != null) toastView = factory(content, owner, duration, position, context, tcs); return toastView ?? new ToastView(content, owner, duration, position, tcs); }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toast = new ToastImpl(); if (_threadManager.IsUiThread) Show(content, duration, position, context, toast); else _threadManager.InvokeOnUiThreadAsync(() => Show(content, duration, position, context, toast)); return toast; }
private void ShowInternal(ToastImpl toast, IDataTemplateSelector selector, View snackbarHolderView, object content, float duration, ToastPosition position, IDataContext context) { Snackbar snackbar; if (selector == null) snackbar = Snackbar.Make(snackbarHolderView, content.ToStringSafe("(null)"), (int)duration); else snackbar = (Snackbar)selector.SelectTemplate(content, snackbarHolderView); if (snackbar == null) toast.FromToast(_defaultPresenter.ShowAsync(content, duration, position, context)); else toast.Show(snackbar, duration); }
/// <summary> /// Shows the specified message. /// </summary> protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource<object> tcs) { #if XAMARIN_FORMS var ctx = global::Xamarin.Forms.Forms.Context; #else var ctx = _navigationProvider.CurrentContent as Context; #endif if (ctx == null) { tcs.SetResult(null); return; } View view = GetView(content, ctx); Toast toast = view == null ? Toast.MakeText(ctx, content == null ? "(null)" : content.ToString(), ToastLength.Long) : new Toast(ctx) { View = view }; var wrapper = new ToastWrapper(toast, tcs, _threadManager); ServiceProvider .AttachedValueProvider .AddOrUpdate(ctx, ToastWrapperMember, (c, o) => { wrapper.Show(duration, position); return wrapper; }, (item, value, oldValue, state) => { oldValue.Complete(); return value(item, state); }); #if !XAMARIN_FORMS var activityView = ctx as IActivityView; if (activityView == null) return; ServiceProvider.AttachedValueProvider.GetOrAdd(activityView, DisposedEventHandler, (v, o) => { v.Mediator.Destroyed += ActivityOnDestroyedDelegate; return DisposedEventHandler; }, null); #endif }
void ShowProgressWorker(float progress = -1, string status = null, MaskType maskType = MaskType.None, bool textOnly = false, ToastPosition toastPosition = ToastPosition.Center, string cancelCaption = null, Action cancelCallback = null, double timeoutMs = 1000, bool showContinuousProgress = false, UIImage displayContinuousImage = null) { Ring.ResetStyle(IsiOS7ForLookAndFeel, (IsiOS7ForLookAndFeel ? TintColor : UIColor.White)); if (OverlayView.Superview == null) { var windows = UIApplication.SharedApplication.Windows; Array.Reverse (windows); foreach (UIWindow window in windows) { if (window.WindowLevel == UIWindowLevel.Normal && !window.Hidden) { window.AddSubview (OverlayView); break; } } } if (Superview == null) OverlayView.AddSubview (this); _fadeoutTimer = null; ImageView.Hidden = true; _maskType = maskType; _progress = progress; StringLabel.Text = status; if (!string.IsNullOrEmpty (cancelCaption)) { CancelHudButton.SetTitle (cancelCaption, UIControlState.Normal); CancelHudButton.TouchUpInside += delegate { Dismiss (); if (cancelCallback != null) { obj.InvokeOnMainThread (() => cancelCallback.DynamicInvoke (null)); //cancelCallback.DynamicInvoke(null); } }; } UpdatePosition (textOnly); if (showContinuousProgress) { if (displayContinuousImage != null) { _displayContinuousImage = true; ImageView.Image = displayContinuousImage; ImageView.Hidden = false; } RingLayer.StrokeEnd = 0.0f; StartProgressTimer (TimeSpan.FromMilliseconds (Ring.ProgressUpdateInterval)); } else { if (progress >= 0) { ImageView.Image = null; ImageView.Hidden = false; SpinnerView.StopAnimating (); RingLayer.StrokeEnd = progress; } else if (textOnly) { CancelRingLayerAnimation (); SpinnerView.StopAnimating (); } else { CancelRingLayerAnimation (); SpinnerView.StartAnimating (); } } bool cancelButtonVisible = _cancelHud != null && _cancelHud.IsDescendantOfView (_hudView); // intercept user interaction with the underlying view if (maskType != MaskType.None || cancelButtonVisible) { OverlayView.UserInteractionEnabled = true; //AccessibilityLabel = status; //IsAccessibilityElement = true; } else { OverlayView.UserInteractionEnabled = false; //hudView.IsAccessibilityElement = true; } OverlayView.Hidden = false; this.toastPosition = toastPosition; PositionHUD (null); if (Alpha != 1) { RegisterNotifications (); HudView.Transform.Scale (1.3f, 1.3f); if (isClear) { Alpha = 1f; HudView.Alpha = 0f; } UIView.Animate (0.15f, 0, UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.BeginFromCurrentState, delegate { HudView.Transform.Scale ((float)1 / 1.3f, (float)1f / 1.3f); if (isClear) { HudView.Alpha = 1f; } else { Alpha = 1f; } }, delegate { //UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, string); if (textOnly) StartDismissTimer (TimeSpan.FromMilliseconds (timeoutMs)); }); SetNeedsDisplay (); } }
public void ShowToast(string status, MaskType maskType = MaskType.None, ToastPosition toastPosition = ToastPosition.Center, double timeoutMs = 1000) { obj.InvokeOnMainThread (() => ShowProgressWorker (status: status, textOnly: true, toastPosition: toastPosition, timeoutMs: timeoutMs, maskType: maskType)); }
private static void SetPosition(Control parent, Control control, ToastPosition position) { control.Left = (parent.ClientSize.Width - control.Width) / 2; switch (position) { case ToastPosition.Bottom: control.Top = parent.ClientSize.Height - control.Height - 20; control.Anchor = AnchorStyles.Bottom; break; case ToastPosition.Center: control.Top = (parent.ClientSize.Height - control.Height) / 2; control.Anchor = AnchorStyles.None; break; case ToastPosition.Top: control.Top = 20; control.Anchor = AnchorStyles.Top; break; default: throw new ArgumentOutOfRangeException(nameof(position)); } }
protected virtual ToastMessageControl ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource<object> tcs) { Form activeForm = Form.ActiveForm; if (activeForm == null) { tcs.SetResult(null); return null; } foreach (var result in activeForm.Controls.Find(ControlName, false).OfType<ToastMessageControl>()) ClearControl(result); ToastMessageControl control = null; var selector = activeForm.GetBindingMemberValue(AttachedMembers.Form.ToastTemplateSelector); if (selector != null) control = (ToastMessageControl)selector.SelectTemplate(content, activeForm); if (control == null) control = GetToastControl(activeForm, content); control.Duration = duration; control.TaskCompletionSource = tcs; control.Name = ControlName; activeForm.Controls.Add(control); SetPosition(activeForm, control, position); control.BringToFront(); var timer = new Timer { Interval = TimerInterval, Tag = control }; timer.Tick += TimerTick; timer.Start(); control.Tag = timer; return control; }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toastImpl = new ToastImpl(); if (_threadManager.IsUiThread) toastImpl.Control = ShowInternal(content, duration, position, context, toastImpl.Tcs); else _threadManager.InvokeOnUiThreadAsync(() => toastImpl.Control = ShowInternal(content, duration, position, context, toastImpl.Tcs)); return toastImpl; }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { View holder = null; var currentActivity = PlatformExtensions.CurrentActivity; if (currentActivity != null) { var selector = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarViewSelector); holder = selector == null ? currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarView) : selector(content, position, context); } if (holder == null) return _defaultPresenter.ShowAsync(content, duration, position, context); var templateSelector = currentActivity.GetBindingMemberValue(AttachedMembersDesign.Activity.SnackbarTemplateSelector); var toastImpl = new ToastImpl(); if (_threadManager.IsUiThread) ShowInternal(toastImpl, templateSelector, holder, content, duration, position, context); else _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(toastImpl, templateSelector, holder, content, duration, position, context), OperationPriority.High); return toastImpl; }
public IToast ShowAsync(object content, float duration, ToastPosition position = ToastPosition.Bottom, IDataContext context = null) { var toast = new ToastWrapper(new TaskCompletionSource<object>(), _threadManager); if (_threadManager.IsUiThread) ShowInternal(content, duration, position, context, toast); else _threadManager.InvokeOnUiThreadAsync(() => ShowInternal(content, duration, position, context, toast), OperationPriority.High); return toast; }
/// <summary> /// Shows the specified message. /// </summary> protected virtual void ShowInternal(object content, float duration, ToastPosition position, IDataContext context, TaskCompletionSource<object> tcs) { Form activeForm = Form.ActiveForm; if (activeForm == null) { tcs.SetResult(null); return; } foreach (var result in activeForm.Controls.Find(ControlName, false).OfType<ToastMessageControl>()) { if (duration >= result.Duration) ClearControl(result); } var control = GetToastControl(activeForm, content, duration, tcs); control.Name = ControlName; activeForm.Controls.Add(control); SetPosition(activeForm, control, position); control.BringToFront(); var timer = new Timer { Interval = TimerInterval, Tag = control }; timer.Tick += TimerTick; timer.Start(); control.Tag = timer; }
public static void ShowToastViewAtPosition(this UIView self,UIView toast,double interval,ToastPosition position) { /**************************************************** * * * Displays a view for a given duration & position. * * * ****************************************************/ CGPoint toastPoint = self.GetPositionFor(position,toast); ToastAnimationHolder holder = new ToastAnimationHolder(interval); toast.Center = toastPoint; toast.Frame = CGRectMake (toast.Frame.X, toast.Frame.Y, toast.Frame.Width, toast.Frame.Height); toast.Alpha = 0.0f; self.AddSubview(toast); UIView.BeginAnimations("fade_in",toast.Handle); UIView.SetAnimationDuration(kFadeDuration); UIView.SetAnimationDelegate(holder); UIView.SetAnimationDidStopSelector(new Selector("toastAnimationDidStop:finished:context:")); UIView.SetAnimationCurve(UIViewAnimationCurve.EaseOut); toast.Alpha=1.0f; UIView.CommitAnimations(); }
private static CGPoint GetPositionFor(this UIView self,ToastPosition point,UIView toast) { /************************************************************************************* * * * Converts string literals @"top", @"bottom", @"center", or any point wrapped in an * * NSValue object into a CGPoint * * * *************************************************************************************/ if (point.HasPoint) { CGPoint p = point.Point; p.X = Round (p.X); p.Y = Round (p.Y); return p; } else { string pointS = point.String.ToLower (); if (pointS.Equals("top")) { return CGPointMake(self.Bounds.Size.Width/2, (toast.Frame.Size.Height / 2) + kVerticalPadding); } else if (pointS.Equals("bottom")) { return CGPointMake(self.Bounds.Size.Width/2, (self.Bounds.Size.Height - (toast.Frame.Size.Height / 2)) - kVerticalPadding); } else if (pointS.Equals("center") || pointS.Equals("centre")) { return CGPointMake(self.Bounds.Size.Width / 2, self.Bounds.Size.Height / 2); } } Debug.WriteLine("Error: Invalid position for toast."); return self.GetPositionFor(new ToastPosition(kDefaultPosition),toast); }
private void Show(object content, float duration, ToastPosition position, IDataContext context, ToastImpl toastImpl) { UIView owner = GetOwner() ?? UIApplication.SharedApplication.KeyWindow; toastImpl.Toast = CreateToast(content, owner, duration, position, context ?? DataContext.Empty, toastImpl.Tcs); ServiceProvider.AttachedValueProvider.AddOrUpdate(owner, Key, toastImpl.Toast, (item, value, currentValue, state) => { currentValue.Hide(); return value; }).Show(); }
private static extern int dialog_set_toast_position(IntPtr dialog, ToastPosition position);
protected virtual ToastView CreateToast(object content, UIView owner, float duration, ToastPosition position, IDataContext context, TaskCompletionSource<object> tcs) { ToastView toastView = null; #if !XAMARIN_FORMS var window = owner as UIWindow; if (window != null) { UIViewController controller = window.RootViewController; var navigationController = controller as MvvmNavigationController; if (navigationController != null) controller = navigationController.TopViewController; if (controller != null) { var selector = controller.GetBindingMemberValue(AttachedMembers.UIViewController.ToastTemplateSelector); if (selector != null) toastView = (ToastView)selector.SelectTemplate(content, owner); } } #endif if (toastView == null) { var factory = Factory; if (factory != null) toastView = factory(content, owner, duration, position, context, tcs); } if (toastView == null) toastView = new ToastView(content, owner); toastView.DisplayDuration = duration / 1000; toastView.Position = position; toastView.TaskCompletionSource = tcs; return toastView; }