Esempio n. 1
0
        void DismissWorker()
        {
            SetFadeoutTimer(null);

            UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseIn | UIViewAnimationOptions.AllowUserInteraction,
                           delegate {
                HudView.Transform.Scale(0.8f, 0.8f);
                this.Alpha = 0;
            }, delegate {
                if (Alpha == 0)
                {
                    InvokeOnMainThread(delegate {
                        NSNotificationCenter.DefaultCenter.RemoveObserver(this);
                        CancelRingLayerAnimation();
                        StringLabel.RemoveFromSuperview();
                        SpinnerView.RemoveFromSuperview();
                        ImageView.RemoveFromSuperview();
                        CancelHudButton.RemoveFromSuperview();

                        StringLabel     = null;
                        SpinnerView     = null;
                        ImageView       = null;
                        CancelHudButton = null;

                        HudView.RemoveFromSuperview();
                        HudView = null;
                        OverlayView.RemoveFromSuperview();
                        OverlayView = null;
                        this.RemoveFromSuperview();
                    });
                }
            });
        }
Esempio n. 2
0
        void ShowImageWorker(UIImage image, string status, TimeSpan duration)
        {
            _progress = -1;
            CancelRingLayerAnimation();

            //this should happen when Dismiss is called, but it happens AFTER the animation ends
            // so sometimes, the cancel button is left on :(
            if (CancelHudButton != null)
            {
                CancelHudButton.RemoveFromSuperview();
                CancelHudButton = null;
            }

            if (!IsVisible)
            {
                Show();
            }

            ImageView.Image  = image;
            ImageView.Hidden = false;
            StringLabel.Text = status;
            UpdatePosition();
            SpinnerView.StopAnimating();

            StartDismissTimer(duration);
        }
Esempio n. 3
0
        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.Hidden && window.IsKeyWindow)
                    {
                        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();
            }
        }
Esempio n. 4
0
        void UpdatePosition(bool textOnly = false)
        {
            nfloat hudWidth                   = 100f;
            nfloat hudHeight                  = 100f;
            nfloat stringWidth                = 0f;
            nfloat stringHeight               = 0f;
            nfloat stringHeightBuffer         = 20f;
            nfloat stringAndImageHeightBuffer = 80f;

            CGRect labelRect = new CGRect();

            string @string = StringLabel.Text;

            // False if it's text-only
            bool imageUsed = (ImageView.Image != null) || (ImageView.Hidden);

            if (textOnly)
            {
                imageUsed = false;
            }

            if (imageUsed)
            {
                hudHeight = stringAndImageHeightBuffer + stringHeight;
            }
            else
            {
                hudHeight = (textOnly ? stringHeightBuffer : stringHeightBuffer + 40);
            }

            if (!string.IsNullOrEmpty(@string))
            {
                int lineCount = Math.Min(10, @string.Split('\n').Length + 1);

                if (IsIOS7OrNewer)
                {
                    var stringSize = new NSString(@string).GetBoundingRect(new CGSize(200, 30 * lineCount), NSStringDrawingOptions.UsesLineFragmentOrigin,
                                                                           new UIStringAttributes {
                        Font = StringLabel.Font
                    },
                                                                           null);
                    stringWidth  = stringSize.Width;
                    stringHeight = stringSize.Height;
                }
                else
                {
                    var stringSize = new NSString(@string).StringSize(StringLabel.Font, new CGSize(200, 30 * lineCount));
                    stringWidth  = stringSize.Width;
                    stringHeight = stringSize.Height;
                }



                hudHeight += stringHeight;

                if (stringWidth > hudWidth)
                {
                    hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2;
                }

                float labelRectY = imageUsed ? 66 : 9;

                if (hudHeight > 100)
                {
                    labelRect = new CGRect(12, labelRectY, hudWidth, stringHeight);
                    hudWidth += 24;
                }
                else
                {
                    hudWidth += 24;
                    labelRect = new CGRect(0, labelRectY, hudWidth, stringHeight);
                }
            }

            // Adjust for Cancel Button
            var    cancelRect     = new CGRect();
            string @cancelCaption = _cancelHud == null ? null : CancelHudButton.Title(UIControlState.Normal);

            if (!string.IsNullOrEmpty(@cancelCaption))
            {
                const int gap = 20;

                if (IsIOS7OrNewer)
                {
                    var stringSize = new NSString(@cancelCaption).GetBoundingRect(new CGSize(200, 300), NSStringDrawingOptions.UsesLineFragmentOrigin,
                                                                                  new UIStringAttributes {
                        Font = StringLabel.Font
                    },
                                                                                  null);
                    stringWidth  = stringSize.Width;
                    stringHeight = stringSize.Height;
                }
                else
                {
                    var stringSize = new NSString(@cancelCaption).StringSize(StringLabel.Font, new CGSize(200, 300));
                    stringWidth  = stringSize.Width;
                    stringHeight = stringSize.Height;
                }

                if (stringWidth > hudWidth)
                {
                    hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2;
                }

                // Adjust for label
                nfloat cancelRectY = 0f;
                if (labelRect.Height > 0)
                {
                    cancelRectY = labelRect.Y + labelRect.Height + (nfloat)gap;
                }
                else
                {
                    if (string.IsNullOrEmpty(@string))
                    {
                        cancelRectY = 76;
                    }
                    else
                    {
                        cancelRectY = (imageUsed ? 66 : 9);
                    }
                }

                if (hudHeight > 100)
                {
                    cancelRect = new CGRect(12, cancelRectY, hudWidth, stringHeight);
                    labelRect  = new CGRect(12, labelRect.Y, hudWidth, labelRect.Height);
                    hudWidth  += 24;
                }
                else
                {
                    hudWidth  += 24;
                    cancelRect = new CGRect(0, cancelRectY, hudWidth, stringHeight);
                    labelRect  = new CGRect(0, labelRect.Y, hudWidth, labelRect.Height);
                }
                CancelHudButton.Frame = cancelRect;
                hudHeight            += (cancelRect.Height + (string.IsNullOrEmpty(@string) ? 10 : gap));
            }

            HudView.Bounds = new CGRect(0, 0, hudWidth, hudHeight);
            if (!string.IsNullOrEmpty(@string))
            {
                ImageView.Center = new CGPoint(HudView.Bounds.Width / 2, 36);
            }
            else
            {
                ImageView.Center = new CGPoint(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2);
            }


            StringLabel.Hidden = false;
            StringLabel.Frame  = labelRect;

            if (!textOnly)
            {
                if (!string.IsNullOrEmpty(@string) || !string.IsNullOrEmpty(@cancelCaption))
                {
                    SpinnerView.Center = new CGPoint((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, 40.5f);
                    if (_progress != -1)
                    {
                        BackgroundRingLayer.Position = RingLayer.Position = new CGPoint(HudView.Bounds.Width / 2, 36f);
                    }
                }
                else
                {
                    SpinnerView.Center = new CGPoint((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, (float)Math.Ceiling(HudView.Bounds.Height / 2.0f) + 0.5f);
                    if (_progress != -1)
                    {
                        BackgroundRingLayer.Position = RingLayer.Position = new CGPoint(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2.0f + 0.5f);
                    }
                }
            }
        }
Esempio n. 5
0
        void UpdatePosition(bool textOnly = false)
        {
            float      hudWidth     = 100f;
            float      hudHeight    = 100f;
            float      stringWidth  = 0f;
            float      stringHeight = 0f;
            RectangleF labelRect    = new RectangleF();

            string @string = StringLabel.Text;

            // False if it's text-only
            bool imageUsed = (ImageView.Image != null) || (ImageView.Hidden);

            if (textOnly)
            {
                imageUsed = false;
            }

            if (imageUsed)
            {
                hudHeight = 80;
            }
            else
            {
                hudHeight = (textOnly ? 20 : 60);
            }

            if (!string.IsNullOrEmpty(@string))
            {
                SizeF stringSize = new NSString(@string).StringSize(StringLabel.Font, new SizeF(200, 300));
                stringWidth  = stringSize.Width;
                stringHeight = stringSize.Height;

                hudHeight += stringHeight;

                if (stringWidth > hudWidth)
                {
                    hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2;
                }

                float labelRectY = imageUsed ? 66 : 9;

                if (hudHeight > 100)
                {
                    labelRect = new RectangleF(12, labelRectY, hudWidth, stringHeight);
                    hudWidth += 24;
                }
                else
                {
                    hudWidth += 24;
                    labelRect = new RectangleF(0, labelRectY, hudWidth, stringHeight);
                }
            }

            // Adjust for Cancel Button
            var    cancelRect     = new RectangleF();
            string @cancelCaption = CancelHudButton.Title(UIControlState.Normal);

            if (!string.IsNullOrEmpty(@cancelCaption))
            {
                const int gap        = 20;
                SizeF     stringSize = new NSString(@cancelCaption).StringSize(StringLabel.Font, new SizeF(200, 300));
                stringWidth  = stringSize.Width;
                stringHeight = stringSize.Height;

                if (stringWidth > hudWidth)
                {
                    hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2;
                }

                // Adjust for label
                float cancelRectY = 0f;
                if (labelRect.Height > 0)
                {
                    cancelRectY = labelRect.Y + labelRect.Height + gap;
                }
                else
                {
                    cancelRectY = (imageUsed ? 66 : 9);
                }

                if (hudHeight > 100)
                {
                    cancelRect = new RectangleF(12, cancelRectY, hudWidth, stringHeight);
                    labelRect  = new RectangleF(12, labelRect.Y, hudWidth, stringHeight);
                    hudWidth  += 24;
                }
                else
                {
                    hudWidth  += 24;
                    cancelRect = new RectangleF(0, cancelRectY, hudWidth, stringHeight);
                    labelRect  = new RectangleF(0, labelRect.Y, hudWidth, stringHeight);
                }
                CancelHudButton.Frame = cancelRect;
                hudHeight            += (cancelRect.Height + gap);
            }

            HudView.Bounds = new RectangleF(0, 0, hudWidth, hudHeight);
            if (!string.IsNullOrEmpty(@string))
            {
                ImageView.Center = new PointF(HudView.Bounds.Width / 2, 36);
            }
            else
            {
                ImageView.Center = new PointF(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2);
            }


            StringLabel.Hidden = false;
            StringLabel.Frame  = labelRect;

            if (!textOnly)
            {
                if (!string.IsNullOrEmpty(@string))
                {
                    SpinnerView.Center = new PointF((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, 40.5f);
                    if (_progress != -1)
                    {
                        BackgroundRingLayer.Position = RingLayer.Position = new PointF(HudView.Bounds.Width / 2, 36f);
                    }
                }
                else
                {
                    SpinnerView.Center = new PointF((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, (float)Math.Ceiling(HudView.Bounds.Height / 2.0f) + 0.5f);
                    if (_progress != -1)
                    {
                        BackgroundRingLayer.Position = RingLayer.Position = new PointF(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2.0f + 0.5f);
                    }
                }
            }
        }
Esempio n. 6
0
        /*
         * void ShowProgressWorker(string cancelCaption, Delegate cancelCallback, float progress = -1, string status = null, MaskType maskType = MaskType.None){
         *      CancelHudButton.SetTitle(cancelCaption, UIControlState.Normal);
         *      CancelHudButton.TouchUpInside += delegate {
         *              BTProgressHUD.Dismiss();
         *              if(cancelCallback != null){
         *                      cancelCallback.DynamicInvoke(null);
         *              }
         *      };
         *      UpdatePosition();
         *      ShowProgressWorker(progress, status, maskType);
         * }
         */
        void ShowProgressWorker(float progress         = -1, string status = null, MaskType maskType = MaskType.None, bool textOnly = false,
                                bool showToastCentered = true, string cancelCaption = null, Action cancelCallback = null, double timeoutMs = 1000)
        {
            if (OverlayView.Superview == null)
            {
                UIApplication.SharedApplication.KeyWindow.AddSubview(OverlayView);
            }

            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 {
                    BTProgressHUD.Dismiss();
                    if (cancelCallback != null)
                    {
                        obj.InvokeOnMainThread(() => cancelCallback.DynamicInvoke(null));
                        //cancelCallback.DynamicInvoke(null);
                    }
                };
            }

            UpdatePosition(textOnly);

            if (progress >= 0)
            {
                ImageView.Image  = null;
                ImageView.Hidden = false;
                SpinnerView.StopAnimating();
                RingLayer.StrokeEnd = progress;
            }
            else if (textOnly)
            {
                CancelRingLayerAnimation();
                SpinnerView.StopAnimating();
            }
            else
            {
                CancelRingLayerAnimation();
                SpinnerView.StartAnimating();
            }

            if (maskType != MaskType.None)
            {
                OverlayView.UserInteractionEnabled = true;
                //AccessibilityLabel = status;
                //IsAccessibilityElement = true;
            }
            else
            {
                OverlayView.UserInteractionEnabled = true;
                //hudView.IsAccessibilityElement = true;
            }

            OverlayView.Hidden     = false;
            this.showToastCentered = showToastCentered;
            PositionHUD(null);


            if (Alpha != 1)
            {
                RegisterNotifications();
                HudView.Transform.Scale(1.3f, 1.3f);

                UIView.Animate(0.15f, 0,
                               UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.BeginFromCurrentState,
                               delegate {
                    HudView.Transform.Scale((float)1 / 1.3f, (float)1f / 1.3f);
                    Alpha = 1;
                }, delegate {
                    //UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, string);

                    if (textOnly)
                    {
                        StartDismissTimer(TimeSpan.FromMilliseconds(timeoutMs));
                    }
                });

                SetNeedsDisplay();
            }
        }