org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/NotificationPopup.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 18:01:11 -0700
changeset 273 b1f63c2c240c
parent 211 7b148352159e
permissions -rw-r--r--
Bug 2072 - Update .js files with EPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     1
/**
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     2
 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     3
 * All rights reserved.
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     4
 * This component and the accompanying materials are made available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     6
 * which accompanies this distribution, and is available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     8
 *
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     9
 * Initial Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    10
 * Nokia Corporation - initial contribution.
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    11
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    12
 * Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    13
 * 
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    14
 * Description:
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    15
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    16
 */
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// The NotificationPopup class handles the display of notifications such as
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
// warnings, information messages and progress indication.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
// Constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
function NotificationPopup() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
    // create notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
    this.containerElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
    this.containerElement.className = "NotificationPopupContainer";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
    this.popupElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
    this.popupElement.className = "NotificationPopup";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
    this.typeIndicatorElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
    this.typeIndicatorElement.className = "NotificationPopupTypeIndicator";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
    this.textElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
    this.textElement.className = "NotificationPopupText";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
    this.progressBarElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
    this.progressBarElement.className = "NotificationPopupProgressBar";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
    // assemble popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
    this.popupElement.appendChild(this.typeIndicatorElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
    this.popupElement.appendChild(this.textElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
    this.popupElement.appendChild(this.progressBarElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
    this.containerElement.appendChild(this.popupElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
    // create progress bar image element and initialize it
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
    this.progressBarImageElement = document.createElement("img");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
    var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
    this.progressBarImageElement.addEventListener("load", function() { self.progressBarImageLoadingCompleted(); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
    this.progressBarImageElement.setAttribute("alt", "");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
    this.progressBarImageURL = this.getProgressBarImage(0);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
    this.progressBarImageElement.src = this.progressBarImageURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
    this.progressBarElement.appendChild(this.progressBarImageElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
    // init the popup to be fully down
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    52
    this.popupElement.style.top = "100%";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
    // set default popup contents
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
    this.setPopupContents(null, null, null);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
// Notification container element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
NotificationPopup.prototype.containerElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
// Notification popup element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
NotificationPopup.prototype.popupElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
// Type indicator element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
NotificationPopup.prototype.typeIndicatorElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
// Notification text element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
NotificationPopup.prototype.textElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
// Progress bar element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
NotificationPopup.prototype.progressBarElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    72
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
// Progress bar image element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
NotificationPopup.prototype.progressBarImageElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
// Progress bar image URL.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
NotificationPopup.prototype.progressBarImageURL = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
// Has the progress bar image been loaded?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
NotificationPopup.prototype.progressBarImageLoaded = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    81
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    82
// Flag that tracks whether we're in the middle of starting to
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    83
// show a notification popup.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    84
NotificationPopup.prototype.processingShowNotification = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    85
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    86
// Notification popup position (0 = hidden, 1 = showing).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    87
NotificationPopup.prototype.popupPosition = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    88
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    89
// Interval for timer ticks (in milliseconds)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    90
NotificationPopup.prototype.ANIM_TIMER_INTERVAL = 25;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    91
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    92
// Animation timer identifier or null if no active timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    93
NotificationPopup.prototype.animTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    94
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    95
// Time in milliseconds for the popup animation to complete
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    96
NotificationPopup.prototype.ANIM_TIME = 300;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    97
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    98
// Flag that determines the behavior of showNotification(). If set to true
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    99
// the popup will snap open when showNotification() is called instead of
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   100
// animation.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   101
NotificationPopup.prototype.SHOW_SNAPS_OPEN = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   102
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   103
// Animation direction (0 = no movement, -1 hiding, +1 = showing).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   104
NotificationPopup.prototype.animDir = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   105
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   106
// Auto-hide timer identifier or null if no active timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   107
NotificationPopup.prototype.autoHideTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   108
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   109
// The commanded display time.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   110
NotificationPopup.prototype.displayTime = -1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   111
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   112
// Displays a notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   113
NotificationPopup.prototype.showNotification = function(displayTime, type, text, progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   114
    uiLogger.debug("NotificationPopup.showNotification(" + displayTime + ", " + type + ", " + text + ", " + progress + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   115
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   116
    // mark that showNotification() has been called and that we are in
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   117
    // the middle of starting to show the notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   118
    this.processingShowNotification = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   119
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   120
    // remember the display time
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   121
    this.displayTime = displayTime;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   122
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   123
    // attach the popup to the document if not attached
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   124
    if (this.containerElement.parentNode == null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   125
        document.body.appendChild(this.containerElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   126
        uiLogger.debug("Notification popup attached to document");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   127
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   128
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   129
    // set popup contents and update style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   130
    this.setPopupContents(type, text, progress);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   131
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   132
    // if the progress image is loaded then we can complete the showing
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   133
    // of the notification popup immediately - otherwise the image loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   134
    // allback will complete the process.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   135
    if (this.progressBarImageLoaded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   136
        this.completeShowNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   137
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   138
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   139
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   140
// Completes displaying of a notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   141
// Note: Used internally - don't call this directly.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   142
NotificationPopup.prototype.completeShowNotification = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   143
    uiLogger.debug("NotificationPopup.completeShowNotification()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   144
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   145
    // animation direction is +1 for showing the popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   146
    if (this.popupPosition != 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   147
        if (this.SHOW_SNAPS_OPEN) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   148
            if (this.popupPosition == 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   149
                this.popupPosition = 1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   150
            }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   151
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   152
        this.animatePopup(1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   153
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   154
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   155
    // setup auto hiding if a display time is specified
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   156
    if (this.displayTime > 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   157
        // stop any existing timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   158
        if (this.autoHideTimerId != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   159
            clearTimeout(this.autoHideTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   160
            uiLogger.debug("Auto hide timer stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   161
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   162
        // set timer to hide notification
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   163
        var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   164
        this.autoHideTimerId = setTimeout(function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   165
                                              if (self.displayTime > 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   166
                                                  self.hideNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   167
                                              }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   168
                                          }, this.ANIM_TIME + this.displayTime);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   169
        uiLogger.debug("Auto hide timer started");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   170
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   171
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   172
    // mark us as no longer processing a show notification call
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   173
    this.processingShowNotification = false;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   174
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   175
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   176
// Hides the currently displayed notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   177
NotificationPopup.prototype.hideNotification = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   178
    uiLogger.debug("NotificationPopup.hideNotification()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   179
    // mark us as no longer processing a show notification call
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   180
    this.processingShowNotification = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   181
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   182
    // animation direction is -1 for hiding the popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   183
    if (this.popupPosition != 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   184
        this.animatePopup(-1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   185
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   186
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   187
    // stop auto hide timer if one is set
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   188
    if (this.autoHideTimerId != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   189
        clearTimeout(this.autoHideTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   190
        this.autoHideTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   191
        uiLogger.debug("Auto hide timer stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   192
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   193
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   194
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   195
// Starts animation of the popup (1 to show, -1 to hide).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   196
NotificationPopup.prototype.animatePopup = function(direction) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   197
    uiLogger.debug("NotificationPopup.animatePopup(" + direction + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   198
    // set the direction and star the animation timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   199
    this.animDir = direction;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   200
    if (this.animTimerId == null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   201
        var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   202
        this.animTimerId = setInterval(function() { self.animate(); }, this.ANIM_TIMER_INTERVAL);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   203
        uiLogger.debug("Notification popup animation started");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   204
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   205
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   206
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   207
// Callback for animation timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   208
NotificationPopup.prototype.animate = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   209
    // calculate new popup position and clamp
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   210
    var animStep = (this.ANIM_TIMER_INTERVAL / this.ANIM_TIME) * this.animDir;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   211
    var newPos = this.popupPosition + animStep;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   212
    if (newPos < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   213
        newPos = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   214
    } else if (newPos > 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   215
        newPos = 1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   216
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   217
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   218
    // set the new position to the popup element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   219
    this.popupPosition = newPos;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   220
    this.popupElement.style.top = (100 - Math.round(this.popupPosition * 100)) + "%";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   221
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   222
    // have we reached the end of the animation?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   223
    if (newPos == 0 || newPos == 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   224
        // reset animation direction
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   225
        this.animDir = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   226
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   227
        // remove the popup from the body if its hidden
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   228
        if (newPos == 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   229
            document.body.removeChild(this.containerElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   230
            uiLogger.debug("Notification popup detached from document");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   231
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   232
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   233
        // stop timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   234
        clearTimeout(this.animTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   235
        this.animTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   236
        uiLogger.debug("Notification popup animation stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   237
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   238
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   239
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   240
// Returns a URL for the progress bar image to use for the specified progress.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   241
NotificationPopup.prototype.getProgressBarImage = function(progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   242
    // path for progress bar images
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   243
    var progressBarImagePath = "WRTKit/Resources/";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   244
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   245
    if (progress < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   246
        // unknown progress
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   247
        return progressBarImagePath + "ProgressBarUnknown.gif";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   248
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   249
        // known progress (should be between 0 and 1)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   250
        var progPct = Math.round(progress * 10) * 10;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   251
        if (progPct < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   252
            progPct = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   253
        } else if (progPct > 100) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   254
            progPct = 100;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   255
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   256
        return progressBarImagePath + "ProgressBar" + progPct + ".png";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   257
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   258
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   259
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   260
// Sets the contents of the popup.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   261
NotificationPopup.prototype.setPopupContents = function(type, text, progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   262
    uiLogger.debug("NotificationPopup.setPopupContents(" + type + ", " + text + ", " + progress + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   263
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   264
    // figure out notification type style name
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   265
    var typeName = (type == null) ? "none" : type.toLowerCase();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   266
    typeName = typeName.charAt(0).toUpperCase() + typeName.substring(1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   267
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   268
    // set type element class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   269
    this.typeIndicatorElement.className = "NotificationPopupTypeIndicator NotificationPopupTypeIndicator" + typeName;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   270
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   271
    // set notification text
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   272
    this.textElement.innerHTML = (text == null) ? "" : text;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   273
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   274
    // set progress
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   275
    this.progressBarElement.style.display = (progress == null) ? "none" : "block";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   276
    if (progress != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   277
        var imgURL = this.getProgressBarImage(progress);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   278
        if (imgURL != this.progressBarImageURL) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   279
            // load new image
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   280
            this.progressBarImageLoaded = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   281
            this.progressBarImageURL = imgURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   282
            this.progressBarImageElement.src = imgURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   283
        } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   284
            // the correct image is already loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   285
            this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   286
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   287
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   288
        // there is no progress bar so there is no need
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   289
        // to load any progress bar image
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   290
        this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   291
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   292
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   293
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   294
// Callback for notifying the object that its progress bar image completed loading.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   295
NotificationPopup.prototype.progressBarImageLoadingCompleted = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   296
    uiLogger.debug("NotificationPopup.progressBarImageLoadingCompleted()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   297
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   298
    // mark the progress bar image as loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   299
    this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   300
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   301
    // complete the process of displaying the notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   302
    // if it has been commanded but not yet completed
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   303
    if (this.processingShowNotification) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   304
        this.completeShowNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   305
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   306
};