public override void ActionSheet(ActionSheetOptions options) {
     this.Dispatch(() => {
         var alert = new ActionSheetPopUp { Title = options.Title };
         alert.ActionPopUpButtons.Clear();
         options.Options.ToList().ForEach(x => alert.AddButton(x.Text, x.Action));
         alert.Show();
     });
 }
        public override void ActionSheet(ActionSheetOptions options) {
            this.Dispatch(() => {
                var action = new UIActionSheet(options.Title);
                options.Options.ToList().ForEach(x => action.AddButton(x.Text));

                action.Clicked += (sender, btn) => options.Options[btn.ButtonIndex].Action();
                var view = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
                action.ShowInView(view);
            });
        }
示例#3
0
        public override void ActionSheet(ActionSheetOptions options)
        {
            this.Dispatch(() => {
                var action = new UIActionSheet(options.Title);
                options.Options.ToList().ForEach(x => action.AddButton(x.Text));

                action.Clicked += (sender, btn) => options.Options[btn.ButtonIndex].Action();
                var view        = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
                action.ShowInView(view);
            });
        }
示例#4
0
 public override void ActionSheet(ActionSheetOptions options)
 {
     this.Dispatch(() => {
         var alert = new ActionSheetPopUp {
             Title = options.Title
         };
         alert.ActionPopUpButtons.Clear();
         options.Options.ToList().ForEach(x => alert.AddButton(x.Text, x.Action));
         alert.Show();
     });
 }
        public override void ActionSheet(ActionSheetOptions options) {
            var array = options
                .Options
                .Select(x => x.Text)
                .ToArray();

            Droid.RequestMainThread(() => 
                new AlertDialog
                    .Builder(Forms.Context)
                    .SetTitle(options.Title)
                    .SetItems(array, (sender, args) => options.Options[args.Which].Action())
                    .Show()
            );
        }
示例#6
0
        public override void ActionSheet(ActionSheetOptions options)
        {
            var array = options
                        .Options
                        .Select(x => x.Text)
                        .ToArray();

            Droid.RequestMainThread(() =>
                                    new AlertDialog
                                    .Builder(Forms.Context)
                                    .SetTitle(options.Title)
                                    .SetItems(array, (sender, args) => options.Options[args.Which].Action())
                                    .Show()
                                    );
        }
示例#7
0
        public void show(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize <string[]>(options)[0];
                actionSheetOptions = JsonHelper.Deserialize <ActionSheetOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // attach a backbutton listener to the view and dim it a bit
                CordovaView cView = getCordovaView();
                cView.Browser.Dispatcher.BeginInvoke(() =>
                {
                    cView.Browser.InvokeScript("eval", "document.addEventListener('backbutton', window.plugins.actionsheet.hide, false)");
                    cView.Browser.Opacity = 0.5d;
                });

                Border border     = new Border();
                border.Width      = Application.Current.Host.Content.ActualWidth;
                border.Background = darkBrush;
                border.Padding    = new Thickness(10, 10, 10, 10);


                // container for the buttons
                StackPanel panel          = new StackPanel();
                panel.HorizontalAlignment = HorizontalAlignment.Stretch;
                panel.VerticalAlignment   = VerticalAlignment.Center;
                panel.Width = Application.Current.Host.Content.ActualWidth - 60;


                // title
                if (actionSheetOptions.title != null)
                {
                    TextBlock textblock1    = new TextBlock();
                    textblock1.Text         = actionSheetOptions.title;
                    textblock1.TextWrapping = TextWrapping.Wrap;
                    textblock1.Margin       = new Thickness(20, 10, 20, 0); // left, top, right, bottom
                    textblock1.FontSize     = 22;
                    textblock1.Foreground   = new SolidColorBrush(Colors.White);
                    panel.Children.Add(textblock1);
                }

                int buttonIndex = 1;

                // desctructive button
                if (actionSheetOptions.addDestructiveButtonWithLabel != null)
                {
                    Button button     = new Button();
                    button.TabIndex   = buttonIndex++;
                    button.Content    = actionSheetOptions.addDestructiveButtonWithLabel;
                    button.Background = darkBrush; // new SolidColorBrush(Colors.White);
                    button.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 69, 0));
                    button.Padding    = new Thickness(10);
                    button.Margin     = new Thickness(5);
                    button.Click     += new RoutedEventHandler(buttonClickListener);
                    panel.Children.Add(button);
                }


                // regular buttons
                if (actionSheetOptions.buttonLabels != null)
                {
                    foreach (String buttonLabel in actionSheetOptions.buttonLabels)
                    {
                        Button button     = new Button();
                        button.TabIndex   = buttonIndex++;
                        button.Content    = buttonLabel;
                        button.Background = darkBrush;
                        button.Foreground = new SolidColorBrush(Colors.White);
                        button.Padding    = new Thickness(10);
                        button.Margin     = new Thickness(5);
                        button.Click     += new RoutedEventHandler(buttonClickListener);
                        panel.Children.Add(button);
                    }
                }

                // cancel button
                if (actionSheetOptions.winphoneEnableCancelButton && actionSheetOptions.addCancelButtonWithLabel != null)
                {
                    Button button = new Button();
                    button.HorizontalAlignment = HorizontalAlignment.Left;
                    button.TabIndex            = buttonIndex++;
                    button.Content             = actionSheetOptions.addCancelButtonWithLabel;
                    button.Padding             = new Thickness(50, 10, 50, 10);
                    button.Margin     = new Thickness(5, 0, 20, 5);
                    button.FontSize   = 17;
                    button.Background = darkBrush;
                    button.Foreground = new SolidColorBrush(Colors.White);

                    button.Click += new RoutedEventHandler(buttonClickListener);
                    panel.Children.Add(button);
                }

                border.Child = panel;
                popup.Child  = border;

                // Set where the popup will show up on the screen.
                popup.VerticalOffset = 30;

                // Open the popup.
                popup.IsOpen = true;
            });
        }
        public void show(string options)
        {
            try
            {
                String jsonOptions = JsonHelper.Deserialize<string[]>(options)[0];
                actionSheetOptions = JsonHelper.Deserialize<ActionSheetOptions>(jsonOptions);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                return;
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // attach a backbutton listener to the view and dim it a bit
                CordovaView cView = getCordovaView();
                cView.Browser.Dispatcher.BeginInvoke(() =>
                {
                    cView.Browser.InvokeScript("execScript", "document.addEventListener('backbutton', window.plugins.actionsheet.hide, false)");
                    cView.Browser.Opacity = 0.5d;
                });

                Border border = new Border();
                border.Width = Application.Current.Host.Content.ActualWidth;
                border.Background = darkBrush;
                border.Padding = new Thickness(10, 10, 10, 10);

                // container for the buttons
                StackPanel panel = new StackPanel();
                panel.HorizontalAlignment = HorizontalAlignment.Stretch;
                panel.VerticalAlignment = VerticalAlignment.Center;
                panel.Width = Application.Current.Host.Content.ActualWidth - 60;

                // title
                if (actionSheetOptions.title != null)
                {
                    TextBlock textblock1 = new TextBlock();
                    textblock1.Text = actionSheetOptions.title;
                    textblock1.TextWrapping = TextWrapping.Wrap;
                    textblock1.Margin = new Thickness(20, 10, 20, 0); // left, top, right, bottom
                    textblock1.FontSize = 22;
                    textblock1.Foreground = new SolidColorBrush(Colors.White);
                    panel.Children.Add(textblock1);
                }

                int buttonIndex = 1;

                // desctructive button
                if (actionSheetOptions.addDestructiveButtonWithLabel != null)
                {
                    Button button = new Button();
                    button.TabIndex = buttonIndex++;
                    button.Content = actionSheetOptions.addDestructiveButtonWithLabel;
                    button.Background = darkBrush; // new SolidColorBrush(Colors.White);
                    button.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 69, 0));
                    button.Padding = new Thickness(10);
                    button.Margin = new Thickness(5);
                    button.Click += new RoutedEventHandler(buttonClickListener);
                    panel.Children.Add(button);
                }

                // regular buttons
                if (actionSheetOptions.buttonLabels != null)
                {
                    foreach (ButtonClass buttonLabel in actionSheetOptions.buttonLabels)
                    {
                        if (buttonLabel.disabled == false) {
                            Button button = new Button();
                            button.TabIndex = buttonIndex++;
                            button.Content = buttonLabel.text;
                            button.Background = darkBrush;
                            button.Foreground = new SolidColorBrush(Colors.White);
                            button.Padding = new Thickness(10);
                            button.Margin = new Thickness(5);
                            button.Click += new RoutedEventHandler(buttonClickListener);
                            panel.Children.Add(button);
                        }
                    }
                }

                // cancel button
                if (actionSheetOptions.winphoneEnableCancelButton && actionSheetOptions.addCancelButtonWithLabel != null)
                {
                    Button button = new Button();
                    button.HorizontalAlignment = HorizontalAlignment.Left;
                    button.TabIndex = buttonIndex++;
                    button.Content = actionSheetOptions.addCancelButtonWithLabel;
                    button.Padding = new Thickness(50, 10, 50, 10);
                    button.Margin = new Thickness(5, 0, 20, 5);
                    button.FontSize = 17;
                    button.Background = darkBrush;
                    button.Foreground = new SolidColorBrush(Colors.White);

                    button.Click += new RoutedEventHandler(buttonClickListener);
                    panel.Children.Add(button);

                }

                border.Child = panel;
                popup.Child = border;

                // Set where the popup will show up on the screen.
                popup.VerticalOffset = 30;

                // Open the popup.
                popup.IsOpen = true;
            });
        }