예제 #1
0
 protected override void RunOnMainThread(Action action)
 {
     if (action != null)
     {
         AppTools.InvokeOnMainThread(action);
     }
 }
 private static void AnimateNotifyInternal(double duration, Action animation, Action <bool> onCompletion)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         UIView.AnimateNotify(duration, 0, UIViewAnimationOptions.CurveEaseInOut, animation,
                              finished => { onCompletion?.Invoke(finished); });
     });
 }
예제 #3
0
 public BaseWindow(Type nameView) : base(nameView.Name)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         AppTools.RootNavigationController.ModalPresentationStyle = UIModalPresentationStyle.OverFullScreen;
         AppTools.RootNavigationController.ModalTransitionStyle   = UIModalTransitionStyle.CoverVertical;
     });
 }
예제 #4
0
 public virtual void Close()
 {
     this.AnimationFade(AnimationType.Out, onCompletion: obj =>
     {
         AppTools.InvokeOnMainThread(Hide);
         this.Alpha = 1.0f;
     });
 }
예제 #5
0
 public virtual void ShowError(string message = null, int timeSecond = 3)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         WindowShare.Instance.ShowError(DialogConfig.Instance.Error,
                                        Core.Application.Window.Contract.TimeIWindow.Normal);
     });
 }
예제 #6
0
 public virtual void Show()
 {
     AppTools.InvokeOnMainThread(() =>
     {
         WindowShare.Instance.Show(DialogConfig.Instance.Wait,
                                   Core.Application.Window.Contract.TimeIWindow.Normal);
     });
 }
        public void ShowWarning(string text, TimeIWindow time)
        {
            base.Show();

            AppTools.InvokeOnMainThread(() => { CentreImage.SetImageFromResource("warning.svg"); });

            ShowInternal(text, time);
        }
예제 #8
0
        public override void Show(string text)
        {
            base.Show();

            AppTools.InvokeOnMainThread(() =>
            {
                WindowShare.Instance.Show(text, TimeIWindow.Normal);
            });
        }
예제 #9
0
        public static void ResizeTableView(this UITableView table, int count)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                table.SetNeedsLayout();
                table.LayoutIfNeeded();

                table.RowHeight = table.Frame.Height / count;
            });
        }
예제 #10
0
 public override void GoBack()
 {
     AppTools.InvokeOnMainThread(() =>
     {
         if (AppTools.RootNavigationController?.ViewControllers?.Length <= 1)
         {
             return;
         }
         AppTools.RootNavigationController?.PopViewController(true);
     });
 }
예제 #11
0
        public override void ShowSuccess(string message = "", int timeSecond = 3)
        {
            base.ShowSuccess(message, timeSecond);

            AppTools.InvokeOnMainThread(() =>
            {
                WindowShare.Instance.ShowSuccess(message.IsNullOrWhiteSpace()
                    ? DialogConfig.Instance.Success
                                                 : message, TimeIWindow.Normal);
            });
        }
        public override void Show()
        {
            base.Show();

            AppTools.InvokeOnMainThread(() =>
            {
                CentreImage.SetImageFromResource("loading_default.gif");
                TopText.Text    = "";
                CentreText.Text = "";
                BottomText.Text = "Please wait...";
            });
        }
예제 #13
0
 public override void GoPage(Type type, object parm = null)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         if (AppTools.RootNavigationController == null || AppTools.Storyboard == null)
         {
             return;
         }
         AppTools.RootNavigationController?.PushViewController(
             AppTools.Storyboard?.InstantiateViewController(type?.Name), true);
     });
 }
예제 #14
0
        public virtual void Show()
        {
            AppTools.InvokeOnMainThread(() =>
            {
                if (!ModelView.IsNull())
                {
                    new CrossViewInjector(this);
                }

                Frame = AppTools.TopViewController.View.Frame;
                AppTools.TopViewController.View.AddSubview(this);
            });
        }
예제 #15
0
 public static void SetFont(this UITextView textView, string fontType,
                            float size)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         var font = FontManager.Instance.GetFont(fontType);
         if (font.IsNull())
         {
             return;
         }
         SetSize(textView, size, font);
     });
 }
        public static void AnimationFade(this UIView view, AnimationType type,
                                         double duration            = 0.3,
                                         Action <bool> onCompletion = null)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                view.Alpha     = type == AnimationType.In ? MinAlpha : MaxAlpha;
                view.Transform = CGAffineTransform.MakeIdentity();

                AnimateNotifyInternal(duration,
                                      () => { view.Alpha = type == AnimationType.In ? MaxAlpha : MinAlpha; }, onCompletion);
            });
        }
예제 #17
0
 public static void ClearGestures(this UIView view)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         var gestures = view.GestureRecognizers;
         if (gestures == null)
         {
             return;
         }
         foreach (var gesture in gestures)
         {
             view.RemoveGestureRecognizer(gesture);
         }
     });
 }
예제 #18
0
 public static void SetFont(this UILabel label, string fontType)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         if (label.IsNull())
         {
             return;
         }
         var font = FontManager.Instance.GetFont(fontType);
         if (font.IsNull())
         {
             return;
         }
         label.Font = font?.WithSize(label.Font.PointSize);
     });
 }
예제 #19
0
 public static void SetFont(this UIButton label, string fontType, float size = 17)
 {
     AppTools.InvokeOnMainThread(() =>
     {
         if (label.IsNull())
         {
             return;
         }
         var font = FontManager.Instance.GetFont(fontType);
         if (font.IsNull())
         {
             return;
         }
         SetSize(label, size, font);
     });
 }
        public void Show(string text, TimeIWindow?time)
        {
            base.Show();

            AppTools.InvokeOnMainThread(() =>
            {
                CentreImage.SetImageFromResource("loading_default.gif");
                TopText.Text    = "";
                CentreText.Text = "";
                BottomText.Text = text;

                if (time.HasValue)
                {
                    this.TimerReponse(Close, int.Parse(time.GetStringValue()));
                }
            });
        }
예제 #21
0
        public static void GoToScreen(this UIViewController controller, Type type, bool animation = true,
                                      int clearStackCount = 0)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                if (clearStackCount > 0)
                {
                    AppTools.RootNavigationController.ClearStack(clearStackCount);
                }

                if (AppTools.RootNavigationController != null && AppTools.Storyboard != null)
                {
                    AppTools.RootNavigationController.PushViewController(
                        AppTools.Storyboard.InstantiateViewController(type.Name), animation);
                }
            });
        }
예제 #22
0
        public static void SetLineSpacing(this UILabel label, nfloat spacing)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                var paragraphStyle = new NSMutableParagraphStyle
                {
                    LineSpacing = spacing
                };
                var attrString = new NSMutableAttributedString(label.Text);
                var style      = UIStringAttributeKey.ParagraphStyle;
                var range      = new NSRange(0, attrString.Length);

                attrString.AddAttribute(style, paragraphStyle, range);


                label.AttributedText = attrString;
            });
        }
        private void ShowInternal(string text, TimeIWindow time)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                TopText.Text    = "";
                CentreText.Text = "";
                BottomText.Text = text;

                if (!Settings.BlockWindow)
                {
                    this.TimerReponse(Close);
                }
                else
                {
                    ContentView.Click += ContentView_Click;
                }
            });
        }
예제 #24
0
        public static UIGestureRecognizer OnLongClick(this UIView view, Action action)
        {
            if (view.IsNull())
            {
                return(null);
            }

            UILongPressGestureRecognizer longPress = null;

            AppTools.InvokeOnMainThread(() =>
            {
                view.UserInteractionEnabled = true;
                longPress = new UILongPressGestureRecognizer(action);
                view.AddGestureRecognizer(longPress);
            });

            return(longPress);
        }
예제 #25
0
        /// <summary>
        ///     Sets the placeholder.
        ///     Placeholder takes font from target <see cref="textView" />.
        /// </summary>
        /// <param name="textView">Text view.</param>
        /// <param name="text"></param>
        /// <param name="textColor">Placeholder text color.</param>
        public static void SetPlaceholder(this UITextView textView, string text, UIColor textColor)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                var backgroundLabel = new UILabel();
                var backgroundColor = textView.BackgroundColor ?? UIColor.Clear;

                backgroundLabel.TranslatesAutoresizingMaskIntoConstraints = false;
                backgroundLabel.Lines           = 0;
                backgroundLabel.Text            = text;
                backgroundLabel.Font            = textView.Font;
                backgroundLabel.TextColor       = textColor;
                backgroundLabel.TextAlignment   = textView.TextAlignment;
                backgroundLabel.BackgroundColor = backgroundColor;

                textView.Text            = string.Empty;
                textView.BackgroundColor = UIColor.Clear;

                textView.Superview.InsertSubviewBelow(backgroundLabel, textView);

                var topConstraint = NSLayoutConstraint.Create(textView, NSLayoutAttribute.TopMargin,
                                                              NSLayoutRelation.Equal, backgroundLabel, NSLayoutAttribute.Top, 1, 0);
                var leadingConstraint = NSLayoutConstraint.Create(textView, NSLayoutAttribute.LeadingMargin,
                                                                  NSLayoutRelation.Equal, backgroundLabel, NSLayoutAttribute.Leading, 1, 0);
                var trailingConstraint = NSLayoutConstraint.Create(textView, NSLayoutAttribute.TrailingMargin,
                                                                   NSLayoutRelation.Equal, backgroundLabel, NSLayoutAttribute.Trailing, 1, 0);

                textView.Superview.AddConstraints(new[] { topConstraint, leadingConstraint, trailingConstraint });

                textView.Changed += (sender, e) =>
                {
                    if (string.IsNullOrWhiteSpace((sender as UITextView)?.Text))
                    {
                        backgroundLabel.Hidden   = false;
                        textView.BackgroundColor = UIColor.Clear;
                    }
                    else
                    {
                        backgroundLabel.Hidden   = true;
                        textView.BackgroundColor = backgroundColor;
                    }
                };
            });
        }
        public static void AnimationRotate(this UIView view, AnimationType type, bool fromLeft = true,
                                           double duration = 0.3, Action <bool> onCompletion = null)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                var minTransform = CGAffineTransform.MakeRotation((fromLeft ? -1f : 1) * 720);
                var maxTransform = CGAffineTransform.MakeRotation(0f);

                switch (type)
                {
                case AnimationType.In:
                    view.Alpha     = MinAlpha;
                    view.Transform = minTransform;
                    break;

                case AnimationType.Out:
                    view.Alpha     = MaxAlpha;
                    view.Transform = maxTransform;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }

                AnimateNotifyInternal(duration, () =>
                {
                    switch (type)
                    {
                    case AnimationType.In:
                        view.Alpha     = MaxAlpha;
                        view.Transform = maxTransform;
                        break;

                    case AnimationType.Out:
                        view.Alpha     = MinAlpha;
                        view.Transform = minTransform;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(type), type, null);
                    }
                }, onCompletion);
            });
        }
예제 #27
0
        private void ApplyImageTint()
        {
            AppTools.InvokeOnMainThread(() =>
            {
                if (ImageView?.Image == null)
                {
                    return;
                }

                _originalImage = new UIImage(ImageView?.Image?.CGImage);

                if (_colorTint == null)
                {
                    return;
                }

                ImageView?.ChangeColorTint(_colorTint);
            });
        }
예제 #28
0
        public static UIView SetViewState(this UIView view, ViewState viewState)
        {
            AppTools.InvokeOnMainThread(() =>
            {
                switch (viewState)
                {
                case ViewState.Visible:
                    view.Hidden = false;
                    break;

                case ViewState.Gone:
                case ViewState.Invisible:
                    view.Hidden = true;
                    break;
                }
            });

            return(view);
        }
            private void CentreCell()
            {
                AppTools.InvokeOnMainThread(() =>
                {
                    _collectionView.Superview.LayoutIfNeeded();
                    _collectionView.Superview.SetNeedsDisplay();

                    var insets             = _collectionView.ContentInset;
                    var collectioViewWidth = _collectionView.Superview.Bounds.Width;

                    nfloat left = 0;

                    if ((_centreCell.Item1 * _centreCell.Item2) < collectioViewWidth)
                    {
                        left = (collectioViewWidth - (_centreCell.Item1 * _centreCell.Item2)) / 2;
                    }

                    insets.Left = left;
                    _collectionView.ContentInset = insets;
                });
            }
예제 #30
0
        public static UIGestureRecognizer OnClick(this UIView view, Action action,
                                                  uint tapsRequired = 1)
        {
            if (view.IsNull())
            {
                return(null);
            }

            UITapGestureRecognizer tap = null;

            AppTools.InvokeOnMainThread(() =>
            {
                view.UserInteractionEnabled = true;
                tap = new UITapGestureRecognizer(action)
                {
                    NumberOfTapsRequired = tapsRequired
                };
                view.AddGestureRecognizer(tap);
            });

            return(tap);
        }