Commit c4a5a7cb by Sebastián Katzer

Update project

parent ccc2ad34
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -41,7 +41,7 @@
</Resources>
<Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements ToastCapable="true" DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
......@@ -16,42 +16,36 @@
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="e8de53c0-cf2d-11e4-8bb0-9369d008f7b1" Version="1.0.0.0" Publisher="CN=$username$" />
<mp:PhoneIdentity PhoneProductId="e8de53c0-cf2d-11e4-8bb0-9369d008f7b1" PhonePublisherId="db093ed5-53b1-45f7-af72-751e8f36ab80" />
<Properties>
<DisplayName>NotificationExample</DisplayName>
<PublisherDisplayName>$username$</PublisherDisplayName>
<Logo>images\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.3.1</OSMinVersion>
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements ToastCapable="true" DisplayName="NotificationExample"
Square150x150Logo="images\Square150x150Logo.png"
Square44x44Logo="images\Square44x44Logo.png"
Description="CordovaApp"
ForegroundText="light"
BackgroundColor="transparent">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png"
Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
<m3:ShowOn Tile="wide310x150Logo" />
</m3:ShowNameOnTiles>
</m3:DefaultTile>
<m3:SplashScreen Image="images\SplashScreenPhone.png" />
</m3:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClientServer" />
</Capabilities>
-->
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="e8de53c0-cf2d-11e4-8bb0-9369d008f7b1" Version="1.0.0.0" Publisher="CN=$username$" />
<mp:PhoneIdentity PhoneProductId="e8de53c0-cf2d-11e4-8bb0-9369d008f7b1" PhonePublisherId="db093ed5-53b1-45f7-af72-751e8f36ab80" />
<Properties>
<DisplayName>NotificationExample</DisplayName>
<PublisherDisplayName>$username$</PublisherDisplayName>
<Logo>images\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.3.1</OSMinVersion>
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
<m3:ShowOn Tile="wide310x150Logo" />
</m3:ShowNameOnTiles>
</m3:DefaultTile>
<m3:SplashScreen Image="images\SplashScreenPhone.png" />
</m3:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClientServer" />
</Capabilities>
</Package>
\ No newline at end of file
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -54,8 +54,8 @@ exports.core = {
* 'schedule' or 'update'
*/
schedule: function (notifications) {
var triggerFn = function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
};
......@@ -128,6 +128,25 @@ exports.core = {
},
/**
* Updates the badge number of the active tile.
*
* @param {Number} badge
* The badge number. Zero will clean the badge.
*/
updateBadge: function (badge) {
var notifications = Windows.UI.Notifications,
type = notifications.BadgeTemplateType.badgeNumber,
xml = notifications.BadgeUpdateManager.getTemplateContent(type),
attrs = xml.getElementsByTagName('badge'),
notification = new notifications.BadgeNotification(xml);
attrs[0].setAttribute('value', badge);
notifications.BadgeUpdateManager.createBadgeUpdaterForApplication()
.update(notification);
},
/**
* Updates a single local notification.
*
* @param {Object} notification
......
......@@ -87,58 +87,76 @@ exports.parseSound = function (path) {
return audio;
};
/**
* Builds the xml payload for a local notification based on its options.
*
* @param {Object} options
* Local notification properties
*
* @return {String}
* Windows.Data.Xml.Dom.XmlDocument
*/
exports.build = function (options) {
var title = options.title,
message = options.text || '',
sound = '';
if (!title || title === '') {
title = 'Notification';
}
if (options.sound) {
sound = this.parseSound(options.sound);
}
var payload =
"<toast> " +
"<visual version='2'>" +
"<binding template='ToastText02'>" +
"<text id='2'>" + message + "</text>" +
"<text id='1'>" + title + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + JSON.stringify(options) + "</json>" +
"</toast>";
var notification = new Windows.Data.Xml.Dom.XmlDocument();
try {
notification.loadXml(payload);
} catch (e) {
console.error(
'LocalNotification#schedule',
'Error loading the xml, check for invalid characters.');
}
// Launch Attribute to enable onClick event
var launchAttr = notification.createAttribute('launch'),
toastNode = notification.selectSingleNode('/toast');
launchAttr.value = options.id.toString();
toastNode.attributes.setNamedItem(launchAttr);
return notification;
/**
* Builds the xml payload for a local notification based on its options.
*
* @param {Object} options
* Local notification properties
*
* @return Windows.Data.Xml.Dom.XmlDocument
*/
exports.build = function (options) {
var template = this.buildToastTemplate(options),
notification = new Windows.Data.Xml.Dom.XmlDocument();
try {
notification.loadXml(template);
} catch (e) {
console.error(
'LocalNotification#schedule',
'Error loading the xml, check for invalid characters.');
}
// Launch Attribute to enable onClick event
var launchAttr = notification.createAttribute('launch'),
toastNode = notification.selectSingleNode('/toast');
launchAttr.value = options.id.toString();
toastNode.attributes.setNamedItem(launchAttr);
return notification;
};
/**
* Builds the toast template with the right style depend on the options.
*
* @param {Object} options
* Local notification properties
*
* @return String
*/
exports.buildToastTemplate = function (options) {
var title = options.title,
message = options.text || '',
json = JSON.stringify(options),
sound = '';
if (options.sound && options.sound !== '') {
sound = this.parseSound(options.sound);
}
if (title && title !== '') {
return "<toast>" +
"<visual>" +
"<binding template='ToastText02'>" +
"<text id='1'>" + title + "</text>" +
"<text id='2'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
} else {
return "<toast>" +
"<visual>" +
"<binding template='ToastText01'>" +
"<text id='1'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
}
};
/**
......
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment