Exemplo n.º 1
0
        void DismissCurrent(Context context = null)
        {
            lock (dialogLock)
            {
                if (CurrentDialog != null)
                {
                    waitDismiss.Set();

                    Action actionDismiss = () =>
                    {
                        if (CurrentDialog != null)
                        {
                            CurrentDialog.Hide();
                            CurrentDialog.Dismiss();
                        }

                        statusText    = null;
                        statusObj     = null;
                        imageView     = null;
                        progressWheel = null;
                        CurrentDialog = null;

                        waitDismiss.Reset();
                    };

                    // First try the SynchronizationContext
                    if (Application.SynchronizationContext != null)
                    {
                        Application.SynchronizationContext.Send(state => actionDismiss(), null);
                        return;
                    }

                    // Otherwise try OwnerActivity on dialog
                    var ownerActivity = CurrentDialog.OwnerActivity;
                    if (IsAlive(ownerActivity))
                    {
                        ownerActivity.RunOnUiThread(actionDismiss);
                        return;
                    }

                    // Otherwise try get it from the Window Context
                    if (IsAlive(CurrentDialog?.Window?.Context))
                    {
                        if (CurrentDialog.Window.Context is Activity windowActivity)
                        {
                            windowActivity.RunOnUiThread(actionDismiss);
                            return;
                        }
                    }

                    // Finally if all else fails, let's see if someone passed in a context to dismiss and it
                    // happens to also be an Activity
                    if (context != null && context is Activity activity)
                    {
                        activity?.RunOnUiThread(actionDismiss);
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void DismissCurrent(Context context = null)
        {
            lock (dialogLock)
            {
                if (CurrentDialog != null)
                {
                    waitDismiss.Set();

                    Action actionDismiss = () =>
                    {
                        CurrentDialog.Hide();
                        CurrentDialog.Dismiss();

                        statusText    = null;
                        statusObj     = null;
                        imageView     = null;
                        progressWheel = null;
                        CurrentDialog = null;

                        waitDismiss.Reset();
                    };

                    //First try the SynchronizationContext
                    if (Application.SynchronizationContext != null)
                    {
                        try {
                            Application.SynchronizationContext.Send(state => actionDismiss(), null);
                            return;
                        } catch (Exception e) {
                            Console.WriteLine(e);
                        }
                    }

                    //Next let's try and get the Activity from the CurrentDialog
                    if (CurrentDialog != null && CurrentDialog.Window != null && CurrentDialog.Window.Context != null)
                    {
                        var activity = CurrentDialog.Window.Context as Activity;

                        if (activity != null)
                        {
                            activity.RunOnUiThread(actionDismiss);
                            return;
                        }
                    }

                    //Finally if all else fails, let's see if someone passed in a context to dismiss and it
                    // happens to also be an Activity
                    if (context != null)
                    {
                        var activity = context as Activity;

                        if (activity != null)
                        {
                            activity.RunOnUiThread(actionDismiss);
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        void showProgress(Context context, int progress, string status = null, MaskType maskType = MaskType.Black, TimeSpan?timeout = null, Action clickCallback = null, Action cancelCallback = null, Action <Dialog> prepareDialogCallback = null, Action <Dialog> dialogShownCallback = null)
        {
            if (!timeout.HasValue || timeout == null)
            {
                timeout = TimeSpan.Zero;
            }

            if (CurrentDialog != null && progressWheel == null)
            {
                DismissCurrent(context);
            }

            lock (dialogLock)
            {
                if (CurrentDialog == null)
                {
                    SetupDialog(context, maskType, cancelCallback, (a, d, m) => {
                        var inflater = LayoutInflater.FromContext(context);
                        var view     = inflater.Inflate(Resource.Layout.loadingprogress, null);

                        if (clickCallback != null)
                        {
                            view.Click += (sender, e) => clickCallback();
                        }

                        progressWheel = view.FindViewById <ProgressWheel>(Resource.Id.loadingProgressWheel);
                        statusText    = view.FindViewById <TextView>(Resource.Id.textViewStatus);

                        if (maskType != MaskType.Black)
                        {
                            view.SetBackgroundResource(Resource.Drawable.roundedbgdark);
                        }

                        progressWheel.SetProgress(0);

                        if (statusText != null)
                        {
                            statusText.Text       = status ?? "";
                            statusText.Visibility = string.IsNullOrEmpty(status) ? ViewStates.Gone : ViewStates.Visible;
                        }

                        return(view);
                    }, prepareDialogCallback, dialogShownCallback);

                    RunTimeout(context, timeout);
                }
                else
                {
                    Application.SynchronizationContext.Send(state => {
                        progressWheel?.SetProgress(progress);
                        statusText.Text = status ?? "";
                    }, null);
                }
            }
        }
Exemplo n.º 4
0
        void DismissCurrent(Activity activity)
        {
            lock (dialogLock)
            {
                if (CurrentDialog != null)
                {
                    waitDismiss.Set();

                    activity.RunOnUiThread(() => {
                        CurrentDialog.Hide();
                        CurrentDialog.Cancel();

                        statusText    = null;
                        statusObj     = null;
                        imageView     = null;
                        progressWheel = null;
                        CurrentDialog = null;

                        waitDismiss.Reset();
                    });
                }
            }
        }
Exemplo n.º 5
0
		void DismissCurrent(Context context = null)
		{
			lock (dialogLock)
			{
				if (CurrentDialog != null)
				{
					waitDismiss.Set ();

					Action actionDismiss = () =>
					{
						CurrentDialog.Hide ();
						CurrentDialog.Dismiss ();

						statusText = null;
						statusObj = null;
						imageView = null;
						progressWheel = null;
						CurrentDialog = null;

						waitDismiss.Reset ();
					};
						
					//First try the SynchronizationContext
					if (Application.SynchronizationContext != null)
					{
						Application.SynchronizationContext.Send (state => actionDismiss (), null);
						return;
					}

					//Next let's try and get the Activity from the CurrentDialog
					if (CurrentDialog != null && CurrentDialog.Window != null && CurrentDialog.Window.Context != null)
					{
						var activity = CurrentDialog.Window.Context as Activity;

						if (activity != null)
						{
							activity.RunOnUiThread (actionDismiss);
							return;
						}
					}
				
					//Finally if all else fails, let's see if someone passed in a context to dismiss and it
					// happens to also be an Activity
					if (context != null)
					{
						var activity = context as Activity;

						if (activity != null)
						{
							activity.RunOnUiThread (actionDismiss);
							return;
						}
					}

				}
			}
		}
Exemplo n.º 6
0
		void showProgress(Context context, int progress, string status = null, MaskType maskType = MaskType.Black, TimeSpan? timeout = null, Action clickCallback = null, Action cancelCallback = null)
		{
			if (!timeout.HasValue || timeout == null)
				timeout = TimeSpan.Zero;

			if (CurrentDialog != null && progressWheel == null)
				DismissCurrent (context);

			lock (dialogLock)
			{
				if (CurrentDialog == null)
				{
					SetupDialog (context, maskType, cancelCallback, (a, d, m) => {
						var inflater = LayoutInflater.FromContext(context);
						var view = inflater.Inflate(Resource.Layout.loadingprogress, null);

						if (clickCallback != null)
							view.Click += (sender, e) => clickCallback();

						progressWheel = view.FindViewById<ProgressWheel>(Resource.Id.loadingProgressWheel);
						statusText = view.FindViewById<TextView>(Resource.Id.textViewStatus);

						if (maskType != MaskType.Black)
							view.SetBackgroundResource(Resource.Drawable.roundedbgdark);

						progressWheel.SetProgress(0);

						if (statusText != null)
						{
							statusText.Text = status ?? "";
							statusText.Visibility = string.IsNullOrEmpty(status) ? ViewStates.Gone : ViewStates.Visible;
						}

						return view;
					});

					if (timeout.Value > TimeSpan.Zero)
					{
						Task.Factory.StartNew(() => {
							if (!waitDismiss.WaitOne (timeout.Value))
								DismissCurrent (context);

						}).ContinueWith(ct => {
							var ex = ct.Exception;

							if (ex != null)
								Android.Util.Log.Error("AndHUD", ex.ToString());
						}, TaskContinuationOptions.OnlyOnFaulted);
					}
				}
				else
				{
					Application.SynchronizationContext.Send(state => {
						progressWheel.SetProgress (progress);
						statusText.Text = status ?? "";
					}, null);
				}
			}
		}
Exemplo n.º 7
0
        void showProgress(Context context, int progress, string status = null, MaskType maskType = MaskType.Black, TimeSpan?timeout = null, Action clickCallback = null, Action cancelCallback = null)
        {
            if (!timeout.HasValue || timeout == null)
            {
                timeout = TimeSpan.Zero;
            }

            if (CurrentDialog != null && progressWheel == null)
            {
                DismissCurrent(context);
            }

            lock (dialogLock)
            {
                if (CurrentDialog == null)
                {
                    SetupDialog(context, maskType, cancelCallback, (a, d, m) => {
                        var inflater = LayoutInflater.FromContext(context);
                        var view     = inflater.Inflate(Resource.Layout.loadingprogress, null);

                        if (clickCallback != null)
                        {
                            view.Click += (sender, e) => clickCallback();
                        }

                        progressWheel = view.FindViewById <ProgressWheel>(Resource.Id.loadingProgressWheel);
                        statusText    = view.FindViewById <TextView>(Resource.Id.textViewStatus);

                        if (maskType != MaskType.Black)
                        {
                            view.SetBackgroundResource(Resource.Drawable.roundedbgdark);
                        }

                        progressWheel.SetProgress(0);

                        if (statusText != null)
                        {
                            statusText.Text       = status ?? "";
                            statusText.Visibility = string.IsNullOrEmpty(status) ? ViewStates.Gone : ViewStates.Visible;
                        }

                        return(view);
                    });

                    if (timeout.Value > TimeSpan.Zero)
                    {
                        Task.Factory.StartNew(() => {
                            if (!waitDismiss.WaitOne(timeout.Value))
                            {
                                DismissCurrent(context);
                            }
                        }).ContinueWith(ct => {
                            var ex = ct.Exception;

                            if (ex != null)
                            {
                                Android.Util.Log.Error("AndHUD", ex.ToString());
                            }
                        }, TaskContinuationOptions.OnlyOnFaulted);
                    }
                }
                else
                {
                    Application.SynchronizationContext.Send(state => {
                        progressWheel.SetProgress(progress);
                        statusText.Text = status ?? "";
                    }, null);
                }
            }
        }
Exemplo n.º 8
0
        void DismissCurrent(Context context = null)
        {
            lock (dialogLock)
            {
                if (CurrentDialog != null)
                {
                    waitDismiss.Set ();

                    Application.SynchronizationContext.Post(state => {

                        CurrentDialog.Hide ();
                        CurrentDialog.Cancel ();

                        statusText = null;
                        statusObj = null;
                        imageView = null;
                        progressWheel = null;
                        CurrentDialog = null;

                        waitDismiss.Reset ();

                    }, null);

                }
            }
        }
Exemplo n.º 9
0
        void DismissCurrent(Context context = null)
        {
            lock (dialogLock)
            {
                if (CurrentDialog != null)
                {
                    waitDismiss.Set();

                    Action actionDismiss = () =>
                    {
                        CurrentDialog.Hide();

                        try
                        {
                            // see: http://stackoverflow.com/questions/19510972/illegalargumentexception-in-progressdialog-dismiss
                            if (CurrentDialog != null && CurrentDialog.IsShowing)
                            {
                                CurrentDialog.Dismiss();
                            }
                        }
                        catch (Exception ex)
                        { }


                        statusText    = null;
                        statusObj     = null;
                        imageView     = null;
                        progressWheel = null;
                        CurrentDialog = null;

                        waitDismiss.Reset();
                    };

                    //First try the SynchronizationContext
                    if (Application.SynchronizationContext != null)
                    {
                        Application.SynchronizationContext.Send(state => actionDismiss(), null);
                        return;
                    }

                    //Next let's try and get the Activity from the CurrentDialog
                    if (CurrentDialog != null && CurrentDialog.Window != null && CurrentDialog.Window.Context != null)
                    {
                        var activity = CurrentDialog.Window.Context as Activity;

                        if (activity != null)
                        {
                            activity.RunOnUiThread(actionDismiss);
                            return;
                        }
                    }

                    //Finally if all else fails, let's see if someone passed in a context to dismiss and it
                    // happens to also be an Activity
                    if (context != null)
                    {
                        var activity = context as Activity;

                        if (activity != null)
                        {
                            activity.RunOnUiThread(actionDismiss);
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        void showProgress(Activity activity, int progress, string status = null, MaskType maskType = MaskType.Black, TimeSpan?timeout = null, Action clickCallback = null)
        {
            if (timeout == null)
            {
                timeout = TimeSpan.Zero;
            }

            if (CurrentDialog != null && progressWheel == null)
            {
                DismissCurrent(activity);
            }

            lock (dialogLock)
            {
                if (CurrentDialog == null)
                {
                    SetupDialog(activity, maskType, (a, d, m) => {
                        var view = activity.LayoutInflater.Inflate(Resource.Layout.LoadingProgress, null);

                        if (clickCallback != null)
                        {
                            view.Click += (sender, e) => clickCallback();
                        }

                        progressWheel = view.FindViewById <ProgressWheel>(Resource.Id.LoadingProgressWheel);
                        statusText    = view.FindViewById <TextView>(Resource.Id.textViewStatus);

                        if (maskType != MaskType.Black)
                        {
                            view.SetBackgroundResource(Resource.Drawable.RoundedBgDark);
                        }

                        progressWheel.SetProgress(0);

                        if (statusText != null)
                        {
                            statusText.Text       = status ?? "";
                            statusText.Visibility = string.IsNullOrEmpty(status) ? ViewStates.Gone : ViewStates.Visible;
                        }

                        return(view);
                    });

                    if (timeout > TimeSpan.Zero)
                    {
                        Task.Factory.StartNew(() => {
                            if (!waitDismiss.WaitOne(timeout.Value))
                            {
                                DismissCurrent(activity);
                            }
                        });
                    }
                }
                else
                {
                    activity.RunOnUiThread(() => {
                        progressWheel.SetProgress(progress);
                        statusText.Text = status ?? "";
                    });
                }
            }
        }