You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/04/27 02:32:14 UTC

[2/9] wp7 commit: Added notification alert/confirm button text. CB-110

Added notification alert/confirm button text. CB-110


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/9e2c49de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/9e2c49de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/9e2c49de

Branch: refs/heads/master
Commit: 9e2c49deca8de5ef6df20ffc36c0a47e98fc48d3
Parents: e58f709
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Apr 26 16:55:58 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Apr 26 16:55:58 2012 -0700

----------------------------------------------------------------------
 framework/Cordova/Commands/Notification.cs   |  119 +++++++++++++++++++-
 framework/Cordova/UI/NotificationBox.xaml    |   44 ++++++++
 framework/Cordova/UI/NotificationBox.xaml.cs |   22 ++++
 framework/WP7CordovaClassLib.csproj          |    7 ++
 4 files changed, 186 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/9e2c49de/framework/Cordova/Commands/Notification.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/Commands/Notification.cs b/framework/Cordova/Commands/Notification.cs
index 1ae182b..12fd16b 100644
--- a/framework/Cordova/Commands/Notification.cs
+++ b/framework/Cordova/Commands/Notification.cs
@@ -21,6 +21,7 @@ using System.Threading;
 using System.Windows.Resources;
 using Microsoft.Phone.Controls;
 using Microsoft.Xna.Framework.Audio;
+using WP7CordovaClassLib.Cordova.UI;
 
 namespace WP7CordovaClassLib.Cordova.Commands
 {
@@ -29,6 +30,22 @@ namespace WP7CordovaClassLib.Cordova.Commands
         static ProgressBar progressBar = null;
         const int DEFAULT_DURATION = 5;
 
+        private NotificationBox notifBox;
+
+        private PhoneApplicationPage Page
+        {
+            get
+            {
+                PhoneApplicationPage page = null;
+                PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
+                if (frame != null)
+                {
+                    page = frame.Content as PhoneApplicationPage;
+                }
+                return page;
+            }
+        }
+
         // alert, confirm, blink, vibrate, beep
         // blink api - doesn't look like there is an equivalent api we can use...
         // vibrate api - http://msdn.microsoft.com/en-us/library/microsoft.devices.vibratecontroller(v=VS.92).aspx
@@ -73,9 +90,29 @@ namespace WP7CordovaClassLib.Cordova.Commands
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 AlertOptions alertOpts = JSON.JsonHelper.Deserialize<AlertOptions>(options);
-                MessageBoxResult res = MessageBox.Show(alertOpts.message, alertOpts.title,MessageBoxButton.OK);
 
-                DispatchCommandResult(new PluginResult(PluginResult.Status.OK,(int)res));
+                PhoneApplicationPage page = Page;
+                if (page != null)
+                {
+                    Grid grid = page.FindName("LayoutRoot") as Grid;
+                    if (grid != null)
+                    {
+                        notifBox = new NotificationBox();
+                        notifBox.PageTitle.Text = alertOpts.title;
+                        notifBox.SubTitle.Text = alertOpts.message;
+                        Button btnOK = new Button();
+                        btnOK.Content = alertOpts.buttonLabel;
+                        btnOK.Click += new RoutedEventHandler(btnOK_Click);
+                        btnOK.Tag = 1;
+                        notifBox.ButtonPanel.Children.Add(btnOK);
+                        grid.Children.Add(notifBox);
+                        page.BackKeyPress += page_BackKeyPress;
+                    }
+                }
+                else
+                {
+                    DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION));
+                }
             });
         }
 
@@ -85,11 +122,81 @@ namespace WP7CordovaClassLib.Cordova.Commands
             {
                 AlertOptions alertOpts = JSON.JsonHelper.Deserialize<AlertOptions>(options);
 
-                MessageBoxResult res = MessageBox.Show(alertOpts.message, alertOpts.title, MessageBoxButton.OKCancel);
-                DispatchCommandResult(new PluginResult(PluginResult.Status.OK, (int)res));
+                PhoneApplicationPage page = Page;
+                if (page != null)
+                {
+                    Grid grid = page.FindName("LayoutRoot") as Grid;
+                    if (grid != null)
+                    {
+                        notifBox = new NotificationBox();
+                        notifBox.PageTitle.Text = alertOpts.title;
+                        notifBox.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);
+                            notifBox.ButtonPanel.Children.Add(btn);
+                        }
+
+                        grid.Children.Add(notifBox);
+                        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;
+            if (page != null && notifBox != null)
+            {
+                Grid grid = page.FindName("LayoutRoot") as Grid;
+                if (grid != null)
+                {
+                    grid.Children.Remove(notifBox);
+                }
+                notifBox = null;
+                page.BackKeyPress -= page_BackKeyPress;
+                e.Cancel = true;
+            }
+
+            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, 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));
+        }
+
+        
+
         public void beep(string count)
         {
             int times = int.Parse(count);
@@ -120,10 +227,10 @@ namespace WP7CordovaClassLib.Cordova.Commands
         // Display an inderminate progress indicator
         public void activityStart(string unused)
         {
+           
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
-                var t1 = Application.Current.RootVisual;
-                PhoneApplicationFrame frame =  t1 as PhoneApplicationFrame;
+                PhoneApplicationFrame frame =  Application.Current.RootVisual as PhoneApplicationFrame;
 
                 if (frame != null)
                 {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/9e2c49de/framework/Cordova/UI/NotificationBox.xaml
----------------------------------------------------------------------
diff --git a/framework/Cordova/UI/NotificationBox.xaml b/framework/Cordova/UI/NotificationBox.xaml
new file mode 100644
index 0000000..62860f5
--- /dev/null
+++ b/framework/Cordova/UI/NotificationBox.xaml
@@ -0,0 +1,44 @@
+<UserControl x:Class="WP7CordovaClassLib.Cordova.UI.NotificationBox"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    mc:Ignorable="d"
+    FontFamily="{StaticResource PhoneFontFamilyNormal}"
+    FontSize="{StaticResource PhoneFontSizeNormal}"
+    Foreground="{StaticResource PhoneForegroundBrush}"
+    d:DesignHeight="800" d:DesignWidth="480" VerticalAlignment="Stretch">
+
+    <Grid x:Name="LayoutRoot" 
+          Background="{StaticResource PhoneSemitransparentBrush}" VerticalAlignment="Stretch">
+        
+        <Grid.RowDefinitions>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition Height="*"/>
+        </Grid.RowDefinitions>
+        
+
+        <!--TitlePanel contains the name of the application and page title-->
+        <StackPanel x:Name="TitlePanel" 
+                    Grid.Row="0" 
+                    Background="{StaticResource PhoneSemitransparentBrush}">
+            <TextBlock x:Name="PageTitle" 
+                       Text="Title" 
+                       Margin="10,10" 
+                       Style="{StaticResource PhoneTextTitle2Style}"/>
+            
+            <TextBlock x:Name="SubTitle" 
+                       Text="Subtitle" 
+                       TextWrapping="Wrap"
+                       Margin="10,10"
+                       Style="{StaticResource PhoneTextTitle3Style}"/>
+            
+            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">       
+            <StackPanel x:Name="ButtonPanel"
+                        Margin="10,10"
+                        Orientation="Horizontal"/>
+            </ScrollViewer>
+
+        </StackPanel>
+    </Grid>
+</UserControl>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/9e2c49de/framework/Cordova/UI/NotificationBox.xaml.cs
----------------------------------------------------------------------
diff --git a/framework/Cordova/UI/NotificationBox.xaml.cs b/framework/Cordova/UI/NotificationBox.xaml.cs
new file mode 100644
index 0000000..3cd1a6e
--- /dev/null
+++ b/framework/Cordova/UI/NotificationBox.xaml.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+
+namespace WP7CordovaClassLib.Cordova.UI
+{
+    public partial class NotificationBox : UserControl
+    {
+        public NotificationBox()
+        {
+            InitializeComponent();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/9e2c49de/framework/WP7CordovaClassLib.csproj
----------------------------------------------------------------------
diff --git a/framework/WP7CordovaClassLib.csproj b/framework/WP7CordovaClassLib.csproj
index e3a623a..7d3630a 100644
--- a/framework/WP7CordovaClassLib.csproj
+++ b/framework/WP7CordovaClassLib.csproj
@@ -103,6 +103,9 @@
     <Compile Include="Cordova\UI\AudioRecorder.xaml.cs">
       <DependentUpon>AudioRecorder.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Cordova\UI\NotificationBox.xaml.cs">
+      <DependentUpon>NotificationBox.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Cordova\UI\VideoCaptureTask.cs" />
     <Compile Include="Cordova\UI\VideoRecorder.xaml.cs">
       <DependentUpon>VideoRecorder.xaml</DependentUpon>
@@ -121,6 +124,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Cordova\UI\NotificationBox.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Cordova\UI\VideoRecorder.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>