Inheritance: System.Windows.Controls.UserControl
        void btnOK_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            FrameworkElement notifBoxParent = null;
            int retVal = 0;
            if (btn != null)
            {
                retVal = (int)btn.Tag + 1;

                notifBoxParent = btn.Parent as FrameworkElement;
                while ((notifBoxParent = notifBoxParent.Parent as FrameworkElement) != null &&
                       !(notifBoxParent is NotificationBox)) ;
            }
            if (notifBoxParent != null)
            {
                PhoneApplicationPage page = Page;
                if (page != null)
                {
                    Grid grid = page.FindName("LayoutRoot") as Grid;
                    if (grid != null)
                    {
                        grid.Children.Remove(notifBoxParent);
                    }
                    notifyBox = notifBoxParent.Tag as NotificationBox;
                    if (notifyBox == null)
                    {
                        page.BackKeyPress -= page_BackKeyPress;
                    }
                }

            }
            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, retVal));
        }
        void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            PhoneApplicationPage page = sender as PhoneApplicationPage;

            if (page != null && notifyBox != null)
            {
                Grid grid = page.FindName("LayoutRoot") as Grid;
                if (grid != null)
                {
                    grid.Children.Remove(notifyBox);
                    notifyBox = notifyBox.Tag as NotificationBox;
                }
                if (notifyBox == null)
                {
                    page.BackKeyPress -= page_BackKeyPress;
                }
                e.Cancel = true;
            }

            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, 0));
        }
        public void confirm(string options)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
                AlertOptions alertOpts = new AlertOptions();
                alertOpts.message = args[0];
                alertOpts.title = args[1];
                alertOpts.buttonLabel = args[2];

                PhoneApplicationPage page = Page;
                if (page != null)
                {
                    Grid grid = page.FindName("LayoutRoot") as Grid;
                    if (grid != null)
                    {
                        var previous = notifyBox;
                        notifyBox = new NotificationBox();
                        notifyBox.Tag = previous;
                        notifyBox.PageTitle.Text = alertOpts.title;
                        notifyBox.SubTitle.Text = alertOpts.message;

                        string[] labels = alertOpts.buttonLabel.Split(',');
                        for (int n = 0; n < labels.Length; n++)
                        {
                            Button btn = new Button();
                            btn.Content = labels[n];
                            btn.Tag = n;
                            btn.Click += new RoutedEventHandler(btnOK_Click);
                            notifyBox.ButtonPanel.Children.Add(btn);
                        }

                        grid.Children.Add(notifyBox);
                        if (previous == null)
                        {
                            page.BackKeyPress += page_BackKeyPress;
                        }
                    }
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION));
                }
            });
        }
        public void alert(string options)
        {
            string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
            AlertOptions alertOpts = new AlertOptions();
            alertOpts.message = args[0];
            alertOpts.title = args[1];
            alertOpts.buttonLabel = args[2];
            string aliasCurrentCommandCallbackId = args[3];

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                PhoneApplicationPage page = Page;
                if (page != null)
                {
                    Grid grid = page.FindName("LayoutRoot") as Grid;
                    if (grid != null)
                    {
                        var previous = notifyBox;
                        notifyBox = new NotificationBox();
                        notifyBox.Tag = new { previous = previous, callbackId = aliasCurrentCommandCallbackId };
                        notifyBox.PageTitle.Text = alertOpts.title;
                        notifyBox.SubTitle.Text = alertOpts.message;
                        Button btnOK = new Button();
                        btnOK.Content = alertOpts.buttonLabel;
                        btnOK.Click += new RoutedEventHandler(btnOK_Click);
                        btnOK.Tag = 1;
                        notifyBox.ButtonPanel.Children.Add(btnOK);
                        grid.Children.Add(notifyBox);

                        if (previous == null)
                        {
                            page.BackKeyPress += page_BackKeyPress;
                        }
                    }
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION));
                }
            });
        }
        void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            PhoneApplicationPage page = sender as PhoneApplicationPage;
            string callbackId = "";
            if (page != null && notifyBox != null)
            {
                Grid grid = page.FindName("LayoutRoot") as Grid;
                if (grid != null)
                {
                    grid.Children.Remove(notifyBox);
                    dynamic notifBoxData = notifyBox.Tag;
                    notifyBox = notifBoxData.previous as NotificationBox;
                    callbackId = notifBoxData.callbackId as string;
                }
                if (notifyBox == null)
                {
                    page.BackKeyPress -= page_BackKeyPress;
                }
                e.Cancel = true;
            }

            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, 0), callbackId);
        }
        public void prompt(string options)
        {
            string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
            string message = args[0];
            string title = args[1];
            string buttonLabelsArray = args[2];
            string[] buttonLabels = JSON.JsonHelper.Deserialize<string[]>(buttonLabelsArray);
            string defaultText = args[3];
            string aliasCurrentCommandCallbackId = args[4];

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                PhoneApplicationPage page = Page;
                if (page != null)
                {
                    Grid grid = page.FindName("LayoutRoot") as Grid;
                    if (grid != null)
                    {
                        var previous = notifyBox;
                        notifyBox = new NotificationBox();
                        notifyBox.Tag = new NotifBoxData { previous = previous, callbackId = aliasCurrentCommandCallbackId };
                        notifyBox.PageTitle.Text = title;
                        notifyBox.SubTitle.Text = message;

                        //TextBox textBox = new TextBox();
                        //textBox.Text = defaultText;
                        //textBox.AcceptsReturn = true;
                        //notifyBox.ContentScroller.Content = textBox;

                        notifyBox.InputText.Text = defaultText;
                        notifyBox.InputText.Visibility = Visibility.Visible;

                        for (int i = 0; i < buttonLabels.Length; ++i)
                        {
                            Button button = new Button();
                            button.Content = buttonLabels[i];
                            button.Tag = i + 1;
                            button.Click += promptBoxbutton_Click;
                            notifyBox.ButtonPanel.Orientation = Orientation.Vertical;
                            notifyBox.ButtonPanel.Children.Add(button);
                        }

                        grid.Children.Add(notifyBox);
                        if (previous != null)
                        {
                            page.BackKeyPress += page_BackKeyPress;
                        }
                    }
                }
                else
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION));
                }
            });
        }
Example #7
0
 void btnOK_Click(object sender, RoutedEventArgs e)
 {
     Button btn = sender as Button;
     int retVal = 0;
     if (btn != null)
     {
         retVal = (int)btn.Tag + 1;
     }
     if (notifBox != null)
     {
         PhoneApplicationPage page = Page;
         if (page != null)
         {
             Grid grid = page.FindName("LayoutRoot") as Grid;
             if (grid != null)
             {
                 grid.Children.Remove(notifBox);
             }
         }
         notifBox = null;
     }
     DispatchCommandResult(new PluginResult(PluginResult.Status.OK, retVal));
 }