Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
Added custom sound support to the ShellToastService
Browse files Browse the repository at this point in the history
(by popular demand! :) )
  • Loading branch information
pedrolamas committed Apr 10, 2014
1 parent 90f1ce7 commit 90dc08b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Expand Up @@ -36,5 +36,23 @@ public interface IShellToastService
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
void Show(string title, string content, Uri navigationUri);

/// <summary>
/// Display a toast message with the specified title and content.
/// </summary>
/// <param name="title">The title of the toast message.</param>
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
/// <param name="soundUri">The sound URI of the toast message.</param>
void Show(string title, string content, Uri navigationUri, Uri soundUri);

/// <summary>
/// Display a toast message with the specified title and content.
/// </summary>
/// <param name="title">The title of the toast message.</param>
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
/// <param name="silent">true if the toast should not use the default sound; otherwise, false.</param>
void Show(string title, string content, Uri navigationUri, bool silent);
}
}
Expand Up @@ -14,6 +14,7 @@
// ****************************************************************************

using System;
using Cimbalino.Phone.Toolkit.Extensions;
using Microsoft.Phone.Shell;

namespace Cimbalino.Phone.Toolkit.Services
Expand All @@ -23,6 +24,10 @@ namespace Cimbalino.Phone.Toolkit.Services
/// </summary>
public class ShellToastService : IShellToastService
{
#if WP8
internal static readonly bool CustomSoundsSupportedStatic = Environment.OSVersion.Version >= new Version(8, 0, 10492);
#endif

/// <summary>
/// Display a toast message with the specified title and content.
/// </summary>
Expand All @@ -40,6 +45,18 @@ public void Show(string title, string content)
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
public void Show(string title, string content, Uri navigationUri)
{
Show(title, content, null, null);
}

/// <summary>
/// Display a toast message with the specified title and content.
/// </summary>
/// <param name="title">The title of the toast message.</param>
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
/// <param name="soundUri">The sound URI of the toast message.</param>
public void Show(string title, string content, Uri navigationUri, Uri soundUri)
{
var toast = new ShellToast()
{
Expand All @@ -48,7 +65,26 @@ public void Show(string title, string content, Uri navigationUri)
NavigationUri = navigationUri
};

#if WP8
if (CustomSoundsSupportedStatic && soundUri != null)
{
toast.SetPropertyValue("Sound", soundUri);
}
#endif

toast.Show();
}

/// <summary>
/// Display a toast message with the specified title and content.
/// </summary>
/// <param name="title">The title of the toast message.</param>
/// <param name="content">The contents of the toast message.</param>
/// <param name="navigationUri">Uri to navigate to if the user taps the toast message.</param>
/// <param name="silent">true if the toast should not use the default sound; otherwise, false.</param>
public void Show(string title, string content, Uri navigationUri, bool silent)
{
Show(title, content, navigationUri, silent ? new Uri(string.Empty, UriKind.RelativeOrAbsolute) : null);
}
}
}

0 comments on commit 90dc08b

Please sign in to comment.