Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            var placeholderView = new UIView(new RectangleF(0, 0, 34, 44));

            _rightPlaceholderButton           = new UIBarButtonItem(placeholderView);
            NavigationItem.RightBarButtonItem = _rightPlaceholderButton;

            base.ViewDidLoad();

            View.UserInteractionEnabled = true;
            View.MultipleTouchEnabled   = true;

            _webView = new UIWebView();
            _webView.AutoresizingMask       = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            _webView.UserInteractionEnabled = true;
            _webView.MultipleTouchEnabled   = true;
            _webView.Delegate        = new WebDelegate();
            _webView.ScalesPageToFit = true;

            _webView.LoadStarted += delegate {
                _refreshButton.Enabled = false;
                UpdateNavButtons();
            };

            _webView.LoadFinished += delegate {
                _refreshButton.Enabled = true;
                UpdateNavButtons();
                UpdateTitle();
            };

            _webView.LoadError += (webView, error) => {
                Console.WriteLine("Failed " + error.Error.ToString());
                BTProgressHUD.ShowErrorWithStatus("Failed to load page");

                NSTimer.CreateScheduledTimer(2d, delegate {
                    BTProgressHUD.Dismiss();
                });
            };

            View.AddSubview(_webView);

            _bottomToolbar = new UIToolbar();
            _bottomToolbar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            View.AddSubview(_bottomToolbar);

            _navigateBackButton = new UIBarButtonItem(UIImage.FromFile("back.png"), UIBarButtonItemStyle.Plain, delegate {
                _webView.GoBack();
            });

            _navigateForwardButton = new UIBarButtonItem(UIImage.FromFile("forward.png"), UIBarButtonItemStyle.Plain, delegate {
                _webView.GoForward();
            });

            _refreshButton = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, delegate {
                _webView.Reload();
            });

            _bottomToolbar.SetItems(new [] {
                _navigateBackButton,
                new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                {
                    Width = 5
                },
                _navigateForwardButton,
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                _refreshButton
            },
                                    false);
        }
Ejemplo n.º 2
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)
        {
            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(new TimeSpan(0, 0, 1));
                    }
                });

                SetNeedsDisplay();
            }
        }