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

Commit

Permalink
Merge pull request #20736 from snowmantw/issue1027471
Browse files Browse the repository at this point in the history
Bug 1027471 - [LockScreen][System] Split notification.js into LockScreen...
  • Loading branch information
snowmantw committed Jul 9, 2014
2 parents 5886383 + 61ab5bf commit c394b7b
Show file tree
Hide file tree
Showing 28 changed files with 1,253 additions and 613 deletions.
1 change: 1 addition & 0 deletions apps/system/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
<!-- Notifications -->
<link rel="stylesheet" type="text/css" href="style/notifications/notifications.css">
<script defer src="js/notifications.js"></script>
<script defer src="js/lockscreen_notifications.js"></script>

<!-- Downloads -->
<link rel="stylesheet" type="text/css" href="style/notifications/downloads.css">
Expand Down
4 changes: 2 additions & 2 deletions apps/system/js/app_install_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ var AppInstallManager = {
}

appInfo.installNotification = newNode;
NotificationScreen.incExternalNotifications();
window.dispatchEvent(new window.CustomEvent('notification-increase'));
},

getNotificationProgressNode: function ai_getNotificationProgressNode(app) {
Expand Down Expand Up @@ -488,7 +488,7 @@ var AppInstallManager = {

node.parentNode.removeChild(node);
delete appInfo.installNotification;
NotificationScreen.decExternalNotifications();
window.dispatchEvent(new window.CustomEvent('notification-descrease'));
},

requestWifiLock: function ai_requestWifiLock(app) {
Expand Down
26 changes: 26 additions & 0 deletions apps/system/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ window.addEventListener('load', function startup() {
window.textSelectionDialog = new TextSelectionDialog();
}

function setupNotifications() {
if ('mozSettings' in navigator && navigator.mozSettings) {
var key = 'notifications.resend';
var req = navigator.mozSettings.createLock().get(key);
req.onsuccess = function onsuccess() {
var resendEnabled = req.result[key] || false;
if (!resendEnabled) {
return;
}

var resendCallback = (function(number) {
window.dispatchEvent(
new CustomEvent('desktop-notification-resend',
{ detail: { number: number } }));
}).bind(this);

if ('mozChromeNotifications' in navigator) {
navigator.mozChromeNotifications.
mozResendAllNotifications(resendCallback);
}
};
}
}

function safelyLaunchFTU() {
window.addEventListener('homescreen-ready', function onHomescreenReady() {
window.removeEventListener('homescreen-ready', onHomescreenReady);
Expand All @@ -75,6 +99,8 @@ window.addEventListener('load', function startup() {
window.homescreenLauncher = new HomescreenLauncher().start();
}

setupNotifications();

if (applications.ready) {
registerGlobalEntries();
safelyLaunchFTU();
Expand Down
35 changes: 24 additions & 11 deletions apps/system/js/captive_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,30 @@ var CaptivePortal = {
return;
}

this.notification = NotificationScreen.addNotification({
id: id, title: '', text: message, icon: icon
});
this.captiveNotification_onTap = function() {
self.notification.removeEventListener('tap',
self.captiveNotification_onTap);
self.captiveNotification_onTap = null;
NotificationScreen.removeNotification(id);
window.dispatchEvent(new window.CustomEvent('notification-add', { detail:
{ id: id, title: '',
text: message,
icon: icon,
onsuccess: (function onsuccess(notification) {
this.notification = notification;
this.notification.addEventListener('tap',
this.captiveNotification_onTap);
}).bind(this)
}})
);

this.captiveNotification_onTap = (function() {
this.notification.removeEventListener('tap',
this.captiveNotification_onTap);
this.captiveNotification_onTap = null;
window.dispatchEvent(new window.CustomEvent('notification-remove',
{ detail: id }));
new MozActivity({
name: 'view',
data: { type: 'url', url: url }
});
};
this.notification.addEventListener('tap', this.captiveNotification_onTap);
}).bind(this);

},

dismissNotification: function dismissNotification(id) {
Expand All @@ -57,7 +67,10 @@ var CaptivePortal = {
this.captiveNotification_onTap);
this.captiveNotification_onTap = null;
}
NotificationScreen.removeNotification(id);

window.dispatchEvent(new window.CustomEvent('notification-remove',
{ detail: id }));

this.notification = null;
}

Expand Down
16 changes: 10 additions & 6 deletions apps/system/js/carrier_info_notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ var CarrierInfoNotifier = {

// If we are on the lock screen then create a notification
// that invokes the dialog
var notification = NotificationScreen.addNotification({
id: ++this._notificationId,
title: title,
text: message
});
notification.addEventListener('tap', showDialog);
window.dispatchEvent(new window.CustomEvent('notification-add', { detail:
{ id: ++this._notificationId,
title: title,
text: message,
onsuccess: (function(notification) {
notification.addEventListener('tap', showDialog);
}).bind(this)
}
}));

},

playNotification: function cin_playNotification() {
Expand Down
12 changes: 9 additions & 3 deletions apps/system/js/download/download_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function DownloadNotification(download) {
this.state = 'started';
this.id = DownloadFormatter.getUUID(download);

NotificationScreen.addNotification(this._getInfo());
window.dispatchEvent(new window.CustomEvent('notification-add', {
detail: this._getInfo()
}));

// We have to listen for state changes
this.download.onstatechange = this._update.bind(this);
Expand Down Expand Up @@ -69,7 +71,9 @@ DownloadNotification.prototype = {
if (noNotify) {
info.noNotify = true;
}
NotificationScreen.addNotification(info);
window.dispatchEvent(new window.CustomEvent('notification-add', {
detail: info
}));
if (this.state === 'succeeded') {
this._onSucceeded();
}
Expand Down Expand Up @@ -200,7 +204,9 @@ DownloadNotification.prototype = {
* Closes the notification
*/
_close: function dn_close() {
NotificationScreen.removeNotification(this.id);
window.dispatchEvent(new window.CustomEvent('notification-remove', {
detail: this.id
}));
this.onClose();
},

Expand Down
17 changes: 17 additions & 0 deletions apps/system/js/lockscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@
window.removeEventListener('touchend', this);
this.overlay.classList.remove('touched');
break;
case 'lockscreen-notification-occur':
// when we have notifications, show bgcolor from wallpaper
// remove the simple gradient at the same time
this.maskedBackground.style.backgroundColor =
this.maskedBackground.dataset.wallpaperColor;

this.maskedBackground.classList.remove('blank');
break;
case 'lockscreen-notification-empty':
this.maskedBackground.style.backgroundColor =
'transparent';
this.maskedBackground.classList.add('blank');
break;
case 'transitionend':
if (evt.target !== this.overlay) {
return;
Expand Down Expand Up @@ -412,6 +425,10 @@

window.addEventListener('ftuopen', this);

/* to change the notification background color */
window.addEventListener('lockscreen-notification-occur', this);
window.addEventListener('lockscreen-notification-empty', this);

/* mobile connection state on lock screen */
if (window.navigator.mozMobileConnections) {
this._lockscreenConnInfoManager =
Expand Down
Loading

0 comments on commit c394b7b

Please sign in to comment.