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) { #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 }
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)); }); }
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); }); }
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) { #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 }
static public void Show(string inMessage, TOAST_DURATION inDuration = TOAST_DURATION.LENGTH_SHORT) { ToastWrapper wrapper = new ToastWrapper(inMessage, inDuration); AndroidHelper.RunOnUIThread(wrapper.ShowAndDispose); }