Beispiel #1
0
        public static void reloadOption()
        {
            option = null;
            option = UIAlertController.Create("",
                                              null,
                                              UIAlertControllerStyle.ActionSheet);//(null, null, "Отменить", null, "Выйти");
            var titleAttributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.Red,
            };
            var premium_vc = sb.InstantiateViewController(nameof(PremiumViewController));

            // Add Actions
            if (!QRViewController.is_premium)
            {
                option.AddAction(UIAlertAction.Create("Подробнее о Premium", UIAlertActionStyle.Default, (action) =>
                {
                    close_menu();
                    ViewController.navigationController.PushViewController(premium_vc, true);
                }));
                option.SetValueForKey(new NSAttributedString("Вы собираетесь выйти из учетной записи. Облачное хранение данных предусмотрено только для Premium-подписки, поэтому при следующем входе Вам придется создать свою визитку заново",
                                                             titleAttributes),
                                      new NSString("attributedTitle"));
            }
            else
            {
                option.SetValueForKey(new NSAttributedString("Выход", titleAttributes), new NSString("attributedTitle"));
            }
            option.AddAction(UIAlertAction.Create("Выйти из профиля", UIAlertActionStyle.Default, (action) => log_out()));
            option.AddAction(UIAlertAction.Create("Отменить", UIAlertActionStyle.Cancel, null /*, (action) => Console.WriteLine("Cancel button pressed.")*/));
        }
Beispiel #2
0
        void presentDialog()
        {
            alertController.SetValueForKey(title, new NSString("attributedTitle"));
            alertController.SetValueForKey(message, new NSString("attributedMessage"));

            var          appDelegate = ((FormsApplicationDelegate)UIApplication.SharedApplication.Delegate);
            BindingFlags bindFlags   = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
            FieldInfo    field       = (typeof(FormsApplicationDelegate)).GetField("_window", bindFlags);
            UIWindow     window      = (UIWindow)field.GetValue(appDelegate);

            window.RootViewController.PresentViewController(alertController, true, null);
        }
Beispiel #3
0
 private void SetAttributedText(UIAlertController alert, string title, string message)
 {
     if (TitleFont != null && !string.IsNullOrEmpty(title))
     {
         var attributedTitle = TitleFont.BuildAttributedString(title);
         alert.SetValueForKey(attributedTitle, new NSString("attributedTitle"));
     }
     if (MessageFont != null && !string.IsNullOrEmpty(message))
     {
         var attributedMessage = MessageFont.BuildAttributedString(message);
         alert.SetValueForKey(attributedMessage, new NSString("attributedMessage"));
     }
 }
Beispiel #4
0
        public void ShowToastMessage(string message, string backgroundHexColor = null, string textHexColor = null)
        {
            _alertDelay = NSTimer.CreateScheduledTimer(ShortDelay, (obj) =>
            {
                DismissMessage();
            });

            _alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);
            var tView = _alert.View;

            if (!string.IsNullOrEmpty(backgroundHexColor))
            {
                var firstSubView     = tView.Subviews?.FirstOrDefault();
                var alertContentView = firstSubView?.Subviews?.FirstOrDefault();
                if (alertContentView != null)
                {
                    foreach (UIView uiView in alertContentView.Subviews)
                    {
                        uiView.BackgroundColor = UIColor.Clear.FromHexString(backgroundHexColor);
                    }
                }
            }
            var attributedString = new NSAttributedString(message, foregroundColor: UIColor.Clear.FromHexString(textHexColor ?? "#000000"));

            _alert.SetValueForKey(attributedString, new NSString("attributedMessage"));
            IosHelper.GetVisibleViewController().PresentViewController(_alert, true, null);
        }
Beispiel #5
0
        static async Task <BluetoothDevice> PlatformRequestDevice(RequestDeviceOptions options)
        {
#if __IOS__
            EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);

            if (_manager.State != CBCentralManagerState.PoweredOn)
            {
                throw new InvalidOperationException();
            }

            BluetoothDevice selectedDevice = null;

            controller = UIAlertController.Create("Select a Bluetooth accessory", null, UIAlertControllerStyle.Alert);
            controller.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (a) => {
                handle.Set();
                System.Diagnostics.Debug.WriteLine(a == null ? "<null>" : a.ToString());
            }));

            CGRect rect = new CGRect(0, 0, 272, 272);
            var    tvc  = new UITableViewController(UITableViewStyle.Plain)
            {
                PreferredContentSize = rect.Size
            };
            controller.PreferredContentSize = rect.Size;
            var source = new InTheHand.Bluetooth.Platforms.Apple.BluetoothTableViewSource(options);
            source.DeviceSelected += (s, e) =>
            {
                selectedDevice = e;
                handle.Set();
                tvc.DismissViewController(true, null);
            };

            tvc.TableView.Delegate   = source;
            tvc.TableView.DataSource = source;

            tvc.TableView.UserInteractionEnabled = true;
            tvc.TableView.AllowsSelection        = true;
            //controller.AddChildViewController(contentController);
            controller.SetValueForKey(tvc, new Foundation.NSString("contentViewController"));

            UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            while (currentController.PresentedViewController != null)
            {
                currentController = currentController.PresentedViewController;
            }

            currentController.PresentViewController(controller, true, null);

            return(await Task.Run(() =>
            {
                var s2 = source;
                handle.WaitOne();
                return selectedDevice;
            }));
#endif
            return(null);
        }
Beispiel #6
0
        static Task <BluetoothDevice> PlatformRequestDevice(RequestDeviceOptions options)
        {
#if __IOS__
            TaskCompletionSource <BluetoothDevice> tcs = new TaskCompletionSource <BluetoothDevice>();

            if (_manager.State != CBCentralManagerState.PoweredOn)
            {
                throw new InvalidOperationException();
            }

            controller = UIAlertController.Create("Select a Bluetooth accessory", null, UIAlertControllerStyle.Alert);
            controller.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (a) => {
                tcs.SetResult(null);
                StopScanning();
                Debug.WriteLine(a == null ? "<null>" : a.ToString());
            }));

            CGRect rect = new CGRect(0, 0, 272, 272);
            var    tvc  = new UITableViewController(UITableViewStyle.Plain)
            {
                PreferredContentSize = rect.Size
            };
            controller.PreferredContentSize = rect.Size;
            var source = new InTheHand.Bluetooth.Platforms.Apple.BluetoothTableViewSource(options);
            source.DeviceSelected += (s, e) =>
            {
                tvc.DismissViewController(true, null);
                tcs.SetResult(e);
            };

            tvc.TableView.Delegate   = source;
            tvc.TableView.DataSource = source;

            tvc.TableView.UserInteractionEnabled = true;
            tvc.TableView.AllowsSelection        = true;
            controller.SetValueForKey(tvc, new Foundation.NSString("contentViewController"));

            UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            while (currentController.PresentedViewController != null)
            {
                currentController = currentController.PresentedViewController;
            }

            currentController.PresentViewController(controller, true, null);

            return(tcs.Task);
#endif
            return(null);
        }
Beispiel #7
0
        public CustomAlertController(string alertTitle, string chooseMessage = "Choose a Value")
        {
            var attributes = new UIStringAttributes
            {
                Font = UIFont.FromName("Raleway-Light", 18f)
            };

            AlertController = UIAlertController.Create(alertTitle, chooseMessage, UIAlertControllerStyle.ActionSheet);
            AlertController.SetValueForKey(new NSAttributedString(alertTitle, attributes), new NSString("attributedTitle"));

            var actionCancel = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null);

            actionCancel.SetValueForKey(ProspectManagementColors.DarkColor, new NSString("titleTextColor"));
            AlertController.AddAction(actionCancel);
        }
        private void ShowAlert(string message, double seconds)
        {
            this.alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
            {
                this.DismissMessage();
            });

            this.alert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet);

            var messageAttributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.White,
            };

            var subView = this.alert.View.Subviews.First().Subviews.First().Subviews.First();

            subView.BackgroundColor = Color.FromHex(DefaultBackgroundColor).ToUIColor();

            alert.SetValueForKey(new NSAttributedString(message, messageAttributes), new NSString("attributedMessage"));
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(this.alert, true, null);
        }
Beispiel #9
0
        /// <summary>
        /// 画像付きアラートダイアログを表示する。
        /// </summary>
        /// <param name="title">アラートのタイトル文字列</param>
        /// <param name="message">アラートのメッセージ文字列</param>
        /// <param name="imageKind">アラートに表示する画像種</param>
        /// <param name="accepts">受諾ボタンに表示する文字列リスト。このリスト分ボタン受諾ボタンを表示する。</param>
        /// <param name="destructives">破棄ボタンに表示する文字列。このリスト分ボタン破棄ボタンを表示する。</param>
        /// <param name="cancel">中止ボタンに表示する文字列。nullの場合は中止ボタンは表示しない。</param>
        /// <returns>アラートダイアログでボタンをタップしたら結果を返すTask。</returns>
        public Task <CustomAlertResult> Show(string title, string message, EImageKind imageKind
                                             , List <string> accepts, List <string> destructives = null, string cancel = null)
        {
            Debug.WriteLine($"start {MethodBase.GetCurrentMethod().Name}()");

            // 引数で指定したタイトルとメッセージのアラートダイアログを生成する。
            UIAlertController alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);

            // アラートダイアログのメッセージとボタンの間に画像を表示する。
            if (imageKind != EImageKind.Nothing)
            {
                AlertImageViewController view = new AlertImageViewController(imageKind);
                alert.SetValueForKey(view, new NSString("contentViewController"));
            }

            // ボタンをタップしたら結果を返すタスクを生成する。
            var result = new TaskCompletionSource <CustomAlertResult>();

            // 受諾ボタンを作成する。
            foreach (string accept in accepts ?? new List <string>())
            {
                alert.AddAction(UIAlertAction.Create(accept, UIAlertActionStyle.Default, x =>
                {
                    // ボタンをタップしたらタスクを完了させ、結果を返す。
                    result.TrySetResult(
                        new CustomAlertResult
                    {
                        IsCancel           = false,
                        PressedButtonTitle = accept,
                    });
                }));
            }

            // 破棄ボタンを作成する。
            foreach (string destructive in destructives ?? new List <string>())
            {
                alert.AddAction(UIAlertAction.Create(destructive, UIAlertActionStyle.Destructive, x =>
                {
                    // ボタンをタップしたらタスクを完了させ、結果を返す。
                    result.TrySetResult(
                        new CustomAlertResult
                    {
                        IsCancel           = false,
                        PressedButtonTitle = destructive,
                    });
                }));
            }

            // 中止ボタンを作成する。
            if (cancel != null)
            {
                alert.AddAction(UIAlertAction.Create(cancel, UIAlertActionStyle.Cancel, x =>
                {
                    // ボタンをタップしたらタスクを完了させ、結果を返す。
                    result.TrySetResult(
                        new CustomAlertResult
                    {
                        IsCancel           = true,
                        PressedButtonTitle = cancel
                    });
                }));
            }

            // アラートダイアログを表示する。
            // ※ダイアログを表示して処理は戻ってくる。
            //  ボタンタップで完了するタスクを返すので、ダイアログの結果はそのタスクで受け取る。
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alert, true, null);

            // ダイアログのボタンタップ結果を返すタスクを返す。
            Debug.WriteLine($"end {MethodBase.GetCurrentMethod().Name}()");
            return(result.Task);
        }