Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
Added notification alert/confirm button text. CB-110
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Apr 26, 2012
1 parent e58f709 commit 9e2c49d
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 6 deletions.
119 changes: 113 additions & 6 deletions framework/Cordova/Commands/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
using System.Windows.Resources;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
using WP7CordovaClassLib.Cordova.UI;

namespace WP7CordovaClassLib.Cordova.Commands
{
Expand All @@ -29,6 +30,22 @@ public class Notification : BaseCommand
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
Expand Down Expand Up @@ -73,9 +90,29 @@ public void alert(string options)
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));
}
});
}

Expand All @@ -85,11 +122,81 @@ public void confirm(string options)
{
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);
Expand Down Expand Up @@ -120,10 +227,10 @@ public void beep(string count)
// 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)
{
Expand Down
44 changes: 44 additions & 0 deletions framework/Cordova/UI/NotificationBox.xaml
Original file line number Diff line number Diff line change
@@ -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>
22 changes: 22 additions & 0 deletions framework/Cordova/UI/NotificationBox.xaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
7 changes: 7 additions & 0 deletions framework/WP7CordovaClassLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 9e2c49d

Please sign in to comment.