Browse Source

Basic WP8 support through LiveTiles

Sebastián Katzer 12 years ago
parent
commit
94eaef3ed2
3 changed files with 141 additions and 0 deletions
  1. 1 0
      plugin.xml
  2. 81 0
      src/wp8/LocalNotification.cs
  3. 59 0
      src/wp8/LocalNotificationOptions.cs

+ 1 - 0
plugin.xml

@@ -77,6 +77,7 @@
         <config-file target="config.xml" parent="/*">
             <feature name="LocalNotification">
                 <param name="wp-package" value="LocalNotification"/>
+                <param name="wp-package" value="LocalNotificationOptions"/>
             </feature>
         </config-file>
 

+ 81 - 0
src/wp8/LocalNotification.cs

@@ -16,10 +16,91 @@ using WPCordovaClassLib.Cordova;
 using WPCordovaClassLib.Cordova.Commands;
 using WPCordovaClassLib.Cordova.JSON;
 
+using De.APPPlant.Cordova.Plugin.LocalNotification;
+
 namespace Cordova.Extension.Commands
 {
+    /// <summary>
+    /// Implementes access to application live tiles
+    /// http://msdn.microsoft.com/en-us/library/hh202948(v=VS.92).aspx
+    /// </summary>
     public class LocalNotification : BaseCommand
     {
+        /// <summary>
+        /// Sets application live tile
+        /// </summary>
+        public void add (string jsonArgs)
+        {
+            string[] args                    = JsonHelper.Deserialize<string[]>(jsonArgs);
+            LocalNotificationOptions options = JsonHelper.Deserialize<LocalNotificationOptions>(args[0]);
+            // Application Tile is always the first Tile, even if it is not pinned to Start.
+            ShellTile AppTile                = ShellTile.ActiveTiles.First();
+
+            if (AppTile != null)
+            {
+                // Set the properties to update for the Application Tile
+                // Empty strings for the text values and URIs will result in the property being cleared.
+                StandardTileData TileData = CreateTileData(options);
+
+                // Update the Application Tile
+                AppTile.Update(TileData);
+            }
+
+            DispatchCommandResult();
+        }
+
+        /// <summary>
+        /// Clears the application live tile
+        /// </summary>
+        public void cancel (string jsonArgs)
+        {
+            cancelAll(jsonArgs);
+        }
+
+        /// <summary>
+        /// Clears the application live tile
+        /// </summary>
+        public void cancelAll (string jsonArgs)
+        {
+            // Application Tile is always the first Tile, even if it is not pinned to Start.
+            ShellTile AppTile = ShellTile.ActiveTiles.First();
+
+            if (AppTile != null)
+            {
+                // Set the properties to update for the Application Tile
+                // Empty strings for the text values and URIs will result in the property being cleared.
+                StandardTileData TileData = new StandardTileData
+                {
+                    Title       = "",
+                    BackTitle   = "",
+                    BackContent = ""
+                };
+
+                // Update the Application Tile
+                AppTile.Update(TileData);
+            }
+
+            DispatchCommandResult();
+        }
+
+        /// <summary>
+        /// Creates tile data
+        /// </summary>
+        private StandardTileData CreateTileData (LocalNotificationOptions options)
+        {
+            StandardTileData tile = new StandardTileData();
+
+            // Badge sollte nur gelöscht werden, wenn expliziet eine `0` angegeben wurde
+            if (options.Badge != 0)
+            {
+                tile.Count = options.Badge;
+            }
+
+            tile.BackTitle   = options.Title;
+            tile.Title       = options.Title;
+            tile.BackContent = options.Message;
 
+            return tile;
+        }
     }
 }

+ 59 - 0
src/wp8/LocalNotificationOptions.cs

@@ -0,0 +1,59 @@
+using System.Runtime.Serialization;
+
+namespace De.APPPlant.Cordova.Plugin.LocalNotification
+{
+    /// <summary>
+    /// Represents LiveTile options
+    /// </summary>
+    [DataContract]
+    class LocalNotificationOptions
+    {
+        /// <summary>
+        /// The Title that is displayed
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "title")]
+        public string Title { get; set; }
+
+        /// <summary>
+        /// The message that is displayed
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "message")]
+        public string Message { get; set; }
+
+        /// <summary>
+        /// Displays number badge to notification
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "badge")]
+        public int Badge { get; set; }
+
+        /// <summary>
+        /// Tile count
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "Date")]
+        public int Date { get; set; }
+
+        /// <summary>
+        /// Has the options of daily', 'weekly',''monthly','yearly')
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "repeat")]
+        public string Repeat { get; set; }
+
+        /// <summary>
+        /// Message-ID
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "id")]
+        public string ID { get; set; }
+
+        /// <summary>
+        /// A javascript function to be called if the app is in the background
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "background")]
+        public string Background { get; set; }
+
+        /// <summary>
+        /// A javascript function to be called if the app is running
+        /// </summary>
+        [DataMember(IsRequired = false, Name = "foreground")]
+        public string Foreground { get; set; }
+    }
+}