org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/NotificationPopup.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Fri, 05 Feb 2010 11:54:28 -0800
changeset 102 30e0796f3ebb
parent 73 c56c874eef47
child 210 0f7abfd6ae62
permissions -rw-r--r--
Warnings in new projects were fixed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     1
/*
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     2
© Copyright 2008 Nokia Corporation. All rights reserved.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     3
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     4
IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     5
Corporation (“Nokia”) in consideration of your agreement to the following terms. Your use, installation
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     6
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     7
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     8
Widget files.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
     9
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    10
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    11
grants you a personal, non-exclusive license, under Nokia’s copyrights in the WRTKit and Example
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    12
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    13
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    14
Widgets.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    15
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    16
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
redistributions of the WRTKit and Example files.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
that include the WRTKit and Example files without the prior written explicit agreement with Nokia.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
Nokia herein, including but not limited to any patent rights that may be infringed by your products that
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
may be incorporated.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
*/
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
// The NotificationPopup class handles the display of notifications such as
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
// warnings, information messages and progress indication.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
// Constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
function NotificationPopup() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
    // create notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
    this.containerElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
    this.containerElement.className = "NotificationPopupContainer";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
    this.popupElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    52
    this.popupElement.className = "NotificationPopup";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
    this.typeIndicatorElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
    this.typeIndicatorElement.className = "NotificationPopupTypeIndicator";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
    this.textElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
    this.textElement.className = "NotificationPopupText";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
    this.progressBarElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
    this.progressBarElement.className = "NotificationPopupProgressBar";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
    // assemble popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
    this.popupElement.appendChild(this.typeIndicatorElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
    this.popupElement.appendChild(this.textElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
    this.popupElement.appendChild(this.progressBarElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
    this.containerElement.appendChild(this.popupElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
    // create progress bar image element and initialize it
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
    this.progressBarImageElement = document.createElement("img");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
    var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
    this.progressBarImageElement.addEventListener("load", function() { self.progressBarImageLoadingCompleted(); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
    this.progressBarImageElement.setAttribute("alt", "");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
    this.progressBarImageURL = this.getProgressBarImage(0);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    72
    this.progressBarImageElement.src = this.progressBarImageURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
    this.progressBarElement.appendChild(this.progressBarImageElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
    // init the popup to be fully down
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    this.popupElement.style.top = "100%";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
    // set default popup contents
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
    this.setPopupContents(null, null, null);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    81
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    82
// Notification container element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    83
NotificationPopup.prototype.containerElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    84
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    85
// Notification popup element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    86
NotificationPopup.prototype.popupElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    87
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    88
// Type indicator element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    89
NotificationPopup.prototype.typeIndicatorElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    90
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    91
// Notification text element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    92
NotificationPopup.prototype.textElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    93
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    94
// Progress bar element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    95
NotificationPopup.prototype.progressBarElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    96
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    97
// Progress bar image element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    98
NotificationPopup.prototype.progressBarImageElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    99
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   100
// Progress bar image URL.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   101
NotificationPopup.prototype.progressBarImageURL = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   102
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   103
// Has the progress bar image been loaded?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   104
NotificationPopup.prototype.progressBarImageLoaded = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   105
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   106
// Flag that tracks whether we're in the middle of starting to
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   107
// show a notification popup.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   108
NotificationPopup.prototype.processingShowNotification = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   109
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   110
// Notification popup position (0 = hidden, 1 = showing).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   111
NotificationPopup.prototype.popupPosition = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   112
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   113
// Interval for timer ticks (in milliseconds)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   114
NotificationPopup.prototype.ANIM_TIMER_INTERVAL = 25;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   115
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   116
// Animation timer identifier or null if no active timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   117
NotificationPopup.prototype.animTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   118
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   119
// Time in milliseconds for the popup animation to complete
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   120
NotificationPopup.prototype.ANIM_TIME = 300;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   121
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   122
// Flag that determines the behavior of showNotification(). If set to true
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   123
// the popup will snap open when showNotification() is called instead of
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   124
// animation.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   125
NotificationPopup.prototype.SHOW_SNAPS_OPEN = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   126
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   127
// Animation direction (0 = no movement, -1 hiding, +1 = showing).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   128
NotificationPopup.prototype.animDir = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   129
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   130
// Auto-hide timer identifier or null if no active timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   131
NotificationPopup.prototype.autoHideTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   132
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   133
// The commanded display time.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   134
NotificationPopup.prototype.displayTime = -1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   135
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   136
// Displays a notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   137
NotificationPopup.prototype.showNotification = function(displayTime, type, text, progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   138
    uiLogger.debug("NotificationPopup.showNotification(" + displayTime + ", " + type + ", " + text + ", " + progress + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   139
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   140
    // mark that showNotification() has been called and that we are in
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   141
    // the middle of starting to show the notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   142
    this.processingShowNotification = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   143
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   144
    // remember the display time
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   145
    this.displayTime = displayTime;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   146
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   147
    // attach the popup to the document if not attached
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   148
    if (this.containerElement.parentNode == null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   149
        document.body.appendChild(this.containerElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   150
        uiLogger.debug("Notification popup attached to document");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   151
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   152
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   153
    // set popup contents and update style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   154
    this.setPopupContents(type, text, progress);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   155
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   156
    // if the progress image is loaded then we can complete the showing
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   157
    // of the notification popup immediately - otherwise the image loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   158
    // allback will complete the process.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   159
    if (this.progressBarImageLoaded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   160
        this.completeShowNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   161
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   162
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   163
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   164
// Completes displaying of a notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   165
// Note: Used internally - don't call this directly.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   166
NotificationPopup.prototype.completeShowNotification = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   167
    uiLogger.debug("NotificationPopup.completeShowNotification()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   168
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   169
    // animation direction is +1 for showing the popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   170
    if (this.popupPosition != 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   171
        if (this.SHOW_SNAPS_OPEN) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   172
            if (this.popupPosition == 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   173
                this.popupPosition = 1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   174
            }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   175
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   176
        this.animatePopup(1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   177
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   178
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   179
    // setup auto hiding if a display time is specified
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   180
    if (this.displayTime > 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   181
        // stop any existing timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   182
        if (this.autoHideTimerId != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   183
            clearTimeout(this.autoHideTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   184
            uiLogger.debug("Auto hide timer stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   185
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   186
        // set timer to hide notification
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   187
        var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   188
        this.autoHideTimerId = setTimeout(function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   189
                                              if (self.displayTime > 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   190
                                                  self.hideNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   191
                                              }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   192
                                          }, this.ANIM_TIME + this.displayTime);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   193
        uiLogger.debug("Auto hide timer started");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   194
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   195
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   196
    // mark us as no longer processing a show notification call
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   197
    this.processingShowNotification = false;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   198
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   199
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   200
// Hides the currently displayed notification.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   201
NotificationPopup.prototype.hideNotification = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   202
    uiLogger.debug("NotificationPopup.hideNotification()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   203
    // mark us as no longer processing a show notification call
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   204
    this.processingShowNotification = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   205
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   206
    // animation direction is -1 for hiding the popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   207
    if (this.popupPosition != 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   208
        this.animatePopup(-1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   209
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   210
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   211
    // stop auto hide timer if one is set
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   212
    if (this.autoHideTimerId != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   213
        clearTimeout(this.autoHideTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   214
        this.autoHideTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   215
        uiLogger.debug("Auto hide timer stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   216
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   217
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   218
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   219
// Starts animation of the popup (1 to show, -1 to hide).
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   220
NotificationPopup.prototype.animatePopup = function(direction) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   221
    uiLogger.debug("NotificationPopup.animatePopup(" + direction + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   222
    // set the direction and star the animation timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   223
    this.animDir = direction;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   224
    if (this.animTimerId == null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   225
        var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   226
        this.animTimerId = setInterval(function() { self.animate(); }, this.ANIM_TIMER_INTERVAL);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   227
        uiLogger.debug("Notification popup animation started");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   228
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   229
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   230
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   231
// Callback for animation timer.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   232
NotificationPopup.prototype.animate = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   233
    // calculate new popup position and clamp
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   234
    var animStep = (this.ANIM_TIMER_INTERVAL / this.ANIM_TIME) * this.animDir;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   235
    var newPos = this.popupPosition + animStep;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   236
    if (newPos < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   237
        newPos = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   238
    } else if (newPos > 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   239
        newPos = 1;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   240
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   241
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   242
    // set the new position to the popup element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   243
    this.popupPosition = newPos;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   244
    this.popupElement.style.top = (100 - Math.round(this.popupPosition * 100)) + "%";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   245
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   246
    // have we reached the end of the animation?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   247
    if (newPos == 0 || newPos == 1) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   248
        // reset animation direction
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   249
        this.animDir = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   250
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   251
        // remove the popup from the body if its hidden
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   252
        if (newPos == 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   253
            document.body.removeChild(this.containerElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   254
            uiLogger.debug("Notification popup detached from document");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   255
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   256
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   257
        // stop timer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   258
        clearTimeout(this.animTimerId);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   259
        this.animTimerId = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   260
        uiLogger.debug("Notification popup animation stopped");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   261
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   262
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   263
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   264
// Returns a URL for the progress bar image to use for the specified progress.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   265
NotificationPopup.prototype.getProgressBarImage = function(progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   266
    // path for progress bar images
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   267
    var progressBarImagePath = "WRTKit/Resources/";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   268
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   269
    if (progress < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   270
        // unknown progress
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   271
        return progressBarImagePath + "ProgressBarUnknown.gif";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   272
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   273
        // known progress (should be between 0 and 1)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   274
        var progPct = Math.round(progress * 10) * 10;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   275
        if (progPct < 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   276
            progPct = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   277
        } else if (progPct > 100) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   278
            progPct = 100;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   279
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   280
        return progressBarImagePath + "ProgressBar" + progPct + ".png";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   281
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   282
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   283
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   284
// Sets the contents of the popup.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   285
NotificationPopup.prototype.setPopupContents = function(type, text, progress) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   286
    uiLogger.debug("NotificationPopup.setPopupContents(" + type + ", " + text + ", " + progress + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   287
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   288
    // figure out notification type style name
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   289
    var typeName = (type == null) ? "none" : type.toLowerCase();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   290
    typeName = typeName.charAt(0).toUpperCase() + typeName.substring(1);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   291
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   292
    // set type element class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   293
    this.typeIndicatorElement.className = "NotificationPopupTypeIndicator NotificationPopupTypeIndicator" + typeName;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   294
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   295
    // set notification text
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   296
    this.textElement.innerHTML = (text == null) ? "" : text;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   297
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   298
    // set progress
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   299
    this.progressBarElement.style.display = (progress == null) ? "none" : "block";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   300
    if (progress != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   301
        var imgURL = this.getProgressBarImage(progress);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   302
        if (imgURL != this.progressBarImageURL) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   303
            // load new image
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   304
            this.progressBarImageLoaded = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   305
            this.progressBarImageURL = imgURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   306
            this.progressBarImageElement.src = imgURL;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   307
        } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   308
            // the correct image is already loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   309
            this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   310
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   311
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   312
        // there is no progress bar so there is no need
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   313
        // to load any progress bar image
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   314
        this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   315
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   316
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   317
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   318
// Callback for notifying the object that its progress bar image completed loading.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   319
NotificationPopup.prototype.progressBarImageLoadingCompleted = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   320
    uiLogger.debug("NotificationPopup.progressBarImageLoadingCompleted()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   321
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   322
    // mark the progress bar image as loaded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   323
    this.progressBarImageLoaded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   324
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   325
    // complete the process of displaying the notification popup
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   326
    // if it has been commanded but not yet completed
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   327
    if (this.processingShowNotification) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   328
        this.completeShowNotification();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   329
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   330
};