Exemplo n.º 1
0
        private static UIActivityIndicatorView PrepareImageView(
            UIImageView current, bool showLoadIndicator, UIActivityIndicatorViewStyle loadIndicatorType)
        {
            UIActivityIndicatorView activityIndicator = null;

            if (showLoadIndicator)
            {
                current.InvokeOnMainThread(() =>
                {
                    activityIndicator = current.Subviews
                                        .FirstOrDefault(subview => subview.Tag == ActivityIndicatorTag.GetHashCode())
                                        as UIActivityIndicatorView;

                    if (activityIndicator == null)
                    {
                        activityIndicator = new UIActivityIndicatorView
                        {
                            Tag = ActivityIndicatorTag.GetHashCode(),
                            HidesWhenStopped = true,
                            TranslatesAutoresizingMaskIntoConstraints = false,
                            ActivityIndicatorViewStyle = loadIndicatorType
                        };

                        current.AddSubview(activityIndicator);
                        activityIndicator.TopOf(current).LeftOf(current).RightOf(current).BottomOf(current);
                    }

                    activityIndicator?.StartAnimating();
                });
            }

            current.InvokeOnMainThread(() => current.Image = null);
            return(activityIndicator);
        }
Exemplo n.º 2
0
        public void ShowSpinner(UIView parentView, UIActivityIndicatorViewStyle style)
        {
            _spinner = StyleUtil.AddSpinnerToView(parentView, style);
            StyleUtil.CenterView(_spinner, this);

            Selected = true;
            _spinner.StartAnimating();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a spinner to the parentView but without any constraints set yet.
        /// </summary>
        /// <param name="parentView"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public static UIActivityIndicatorView AddSpinnerToView(UIView parentView, UIActivityIndicatorViewStyle style)
        {
            UIActivityIndicatorView spinner = new UIActivityIndicatorView(style);

            spinner.HidesWhenStopped = true;
            spinner.TranslatesAutoresizingMaskIntoConstraints = false;
            parentView.Add(spinner);

            return(spinner);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates a running spinner and pins it to the center of the parentView.
        /// </summary>
        /// <param name="parentView"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public static UIActivityIndicatorView ShowSpinner(UIView parentView, UIActivityIndicatorViewStyle style)
        {
            UIActivityIndicatorView spinner = AddSpinnerToView(parentView, style);

            CenterView(spinner, parentView);
            spinner.Color = ColorHelper.PRIMARY_COLOR;
            spinner.StartAnimating();

            return(spinner);
        }
Exemplo n.º 5
0
    public void ShowSpinner(UIView parentView, UIActivityIndicatorViewStyle style)
    {
        // We don't want to add the spinner to the button. We  want to add it to another parentView
        // and then just center the spinner on top of the button here.
        _spinner = AddSpinnerToView(parentView, style);
        CenterView(_spinner, this);

        // When we change Selected to true, the title color will change to clear. See line 9.
        Selected = true;
        _spinner.StartAnimating();
    }
Exemplo n.º 6
0
        public static void SetImage(this UIImageView current, string url, ImageLoadType type = ImageLoadType.Xamarin,
                                    Action success          = null, Action <Exception> error = null, Action startLoading = null,
                                    string imagePlaceholder = "error_placeholder.png", bool showLoadIndicator = true,
                                    UIActivityIndicatorViewStyle loadIndicatorType = UIActivityIndicatorViewStyle.Gray)
        {
            if (url.IsNullOrWhiteSpace())
            {
                AppTools.InvokeOnMainThread(() =>
                {
                    current.Image = null;
                });

                return;
            }

            var activityIndicator = PrepareImageView(current, showLoadIndicator, loadIndicatorType);

            TaskParameter loader = null;

            if (!url.Contains("http"))
            {
                loader = ImageService.Instance.LoadCompiledResource(url);
            }
            else
            {
                loader = ImageService.Instance.LoadUrl(url);
            }

            if (url.Contains(".svg"))
            {
                loader
                .WithCustomDataResolver(new SvgDataResolver(200, 0, true))
                .WithCustomLoadingPlaceholderDataResolver(new SvgDataResolver(200, 0, true));
            }

            RunImageLoader(current, success, error, startLoading, imagePlaceholder, activityIndicator, loader);
        }
Exemplo n.º 7
0
        public static void SetImage(this UIImageView current, System.IO.Stream imageStream,
                                    Action success          = null, Action <Exception> error = null, Action startLoading = null,
                                    string imagePlaceholder = "error_placeholder.png", bool showLoadIndicator = true,
                                    UIActivityIndicatorViewStyle loadIndicatorType = UIActivityIndicatorViewStyle.Gray)
        {
            if (!imageStream?.CanRead ?? false)
            {
                return;
            }

            var activityIndicator = PrepareImageView(current, showLoadIndicator, loadIndicatorType);
            var loader            = ImageService.Instance.LoadStream(
                cancelationToken =>
                System.Threading.Tasks.Task.Factory.StartNew(
                    () =>
            {
                cancelationToken.ThrowIfCancellationRequested();

                var streamClone = new System.IO.MemoryStream();
                if (imageStream?.CanSeek ?? false)
                {
                    imageStream?.Seek(0, System.IO.SeekOrigin.Begin);
                }

                imageStream?.CopyTo(streamClone);

                if (streamClone?.CanSeek ?? false)
                {
                    streamClone?.Seek(0, System.IO.SeekOrigin.Begin);
                }

                return(streamClone as System.IO.Stream);
            }, cancelationToken));

            RunImageLoader(current, success, error, startLoading, imagePlaceholder, activityIndicator, loader);
        }
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            tableView.DeselectRow(indexPath, true);

            // cancel progress if we are going to show new or dismiss old
            if (indexPath.Section != 0 || indexPath.Row == 2)
            {
                CancelTimer();
            }

            if (indexPath.Section == 0)
            {
                // current notification controls
                if (indexPath.Row == 0)
                {
                    // show progress
                    if (!StatusBarNotification.IsVisible)
                    {
                        indicatorStyle = UIActivityIndicatorViewStyle.Gray;
                        ShowStatus(StatusBarStyles.Default, "Some Progress...");
                    }
                    StartTimer();
                }
                else if (indexPath.Row == 1)
                {
                    // show activity
                    if (!StatusBarNotification.IsVisible)
                    {
                        indicatorStyle = UIActivityIndicatorViewStyle.Gray;
                        ShowStatus(StatusBarStyles.Default, "Some Activity...");
                    }
                    StatusBarNotification.ShowActivityIndicator(true, indicatorStyle);
                }
                else if (indexPath.Row == 2)
                {
                    // dismiss
                    StatusBarNotification.Dismiss(true);
                }
                else if (indexPath.Row == 3)
                {
                    // auto dismiss
                    autoDismiss = !autoDismiss;
                    var cell = tableView.CellAt(indexPath);
                    cell.Accessory = autoDismiss
                                                ? UITableViewCellAccessory.Checkmark
                                                : UITableViewCellAccessory.None;
                }
            }
            else if (indexPath.Section == 1)
            {
                // default notification styles
                indicatorStyle = UIActivityIndicatorViewStyle.Gray;
                var style   = StatusBarStyles.Default;
                var message = "Better call Saul!";
                if (indexPath.Row == 0)
                {
                    // default style
                }
                else if (indexPath.Row == 1)
                {
                    // success style
                    indicatorStyle = UIActivityIndicatorViewStyle.White;
                    style          = StatusBarStyles.Success;
                    message        = "That's how we roll!";
                }
                else if (indexPath.Row == 2)
                {
                    // error style
                    indicatorStyle = UIActivityIndicatorViewStyle.White;
                    style          = StatusBarStyles.Error;
                    message        = "No, I don't have the money...";
                }
                else if (indexPath.Row == 3)
                {
                    // warning style
                    indicatorStyle = UIActivityIndicatorViewStyle.Gray;
                    style          = StatusBarStyles.Warning;
                    message        = "You know who I am!";
                }
                else if (indexPath.Row == 4)
                {
                    // dark style
                    indicatorStyle = UIActivityIndicatorViewStyle.White;
                    style          = StatusBarStyles.Dark;
                    message        = "Don't mess with me!";
                }
                else if (indexPath.Row == 5)
                {
                    // matrix style
                    indicatorStyle = UIActivityIndicatorViewStyle.White;
                    style          = StatusBarStyles.Matrix;
                    message        = "Wake up Neo...";
                }
                // show
                ShowStatus(style, message);
            }
            else if (indexPath.Section == 2)
            {
                // custom notification styles
                if (indexPath.Row == 0)
                {
                    // custom style 1
                    indicatorStyle = UIActivityIndicatorViewStyle.White;
                    ShowStatus(CustomStyle1, "Oh, I love it!");
                }
                else if (indexPath.Row == 1)
                {
                    // custom style 2
                    indicatorStyle = UIActivityIndicatorViewStyle.Gray;
                    ShowStatus(CustomStyle2, "Level up!");
                }
            }
        }
Exemplo n.º 9
0
 public ThemedUIActivityIndicatorView(UIActivityIndicatorViewStyle style) : base(style)
 {
     Initialize();
 }
Exemplo n.º 10
0
        public AtomDisposableAction ShowBusy(UIActivityIndicatorViewStyle style
                                             = UIActivityIndicatorViewStyle.Gray)
        {
            if (_Progress == null)
            {
                _Progress = new UIActivityIndicatorView(style);
            }

            _Progress.AutoresizingMask =
                UIViewAutoresizing.FlexibleTopMargin |
                UIViewAutoresizing.FlexibleRightMargin |
                UIViewAutoresizing.FlexibleBottomMargin |
                UIViewAutoresizing.FlexibleLeftMargin;

            //_Progress.Frame = new RectangleF(0,0,100, 100);

            //UIImage emptyDot = null;

            //if (_emptyBlock == null)
            //{
            //    var img = CreateEmptyImage();
            //    _emptyBlock = img.AsJPEG();
            //    emptyDot = img;
            //}
            //else {
            //    emptyDot = new UIImage(_emptyBlock);
            //}
            //this.Image = emptyDot;
            //this.InvalidateIntrinsicContentSize();

            this.Image = null;

            UIAtomsApplication.Instance.SetTimeout(() =>
            {
                var bounds = this.Bounds;

                UIView owner = this;

                while (bounds.Width == 0)
                {
                    owner  = owner.Superview;
                    bounds = owner.Bounds;
                }

                // we have image.. forget it...
                if (this.Image != null)
                {
                    return;
                }

                _Progress.Center =
                    new CoreGraphics.CGPoint(bounds.GetMidX(), bounds.GetMidY());



                owner.AddSubview(_Progress);
                _Progress.StartAnimating();
            }, TimeSpan.FromMilliseconds(100));



            return(new AtomDisposableAction(() =>
            {
                try
                {
                    if (_Progress.IsAnimating)
                    {
                        _Progress.StopAnimating();
                    }
                    _Progress.RemoveFromSuperview();
                }
                catch
                {
                }
            }));
        }
        public UIView BindDataToView(string textForLabel, bool hasSadEmoji, bool hasActivityIndicator = false, UIActivityIndicatorViewStyle activityIndicatorStyle = UIActivityIndicatorViewStyle.Gray)
        {
            this.Label.Text = (hasSadEmoji) ? textForLabel + " \ud83d\ude1f" : textForLabel;
            Label.SizeToFit();

            ActivityIndicatorView.ActivityIndicatorViewStyle = activityIndicatorStyle;

            if (!hasActivityIndicator)
            {
                ActivityIndicatorView.Hidden          = true;
                LabelTrailingSpaceConstraint.Constant = 8;
            }

            return(this);
        }