# Using notification popups

Notification popup dialogs are an easy way to show information to users. In the WRTKit notification popups are used using two methods in the UIManager class: showNotification() and hideNotification(). If a notification is already showing when another is commanded to be shown then the current notification is replaced with the new one. Notifications can be either auto-hiding after a specified time or manually hidden by calling hideNotification(). Auto-hiding is an easy way in situations where a message just needs to be shown but doesn't require user acknowledgement, e.g. to let the user know that new content has loaded or similar.

Figure 1. Wait notification with unknown progress

The API for showNotification() takes four arguments: displayTime, type, text and progress. The "displayTime" argument is an integer that specifies how long the notification popup dialog should be shown for before automatically hiding. The value is given in milliseconds (1000ms = 1s) and negative values can be used to specify that the dialog should not automatically hide. The second argument "type" is used to specify a visual style for the popup. There are three types of notifications: "info", "warning" and "wait". Info is intended for informative messages, warning for errors or other similar negative messages and finally wait is intended for dialogs that are letting the user know that some process (e.g. loading data from the Internet) is taking a long time. The fourth argument "progress" is a decimal number that should be omitted or null in all other cases except when the dialog should be a progress dialog (typically notifications of type "wait"). For progress dialogs the value should be between 0.0 and 1.0 to specify how far along the process is (0.0 for "0% done" and 1.0 for "100% done"). A negative value can be specified if the progress is unknown, resulting in an animated progress bar that indicates that the wait time and progress is not known.

The code below show various examples of how to show notification popup dialogs. The examples assume that the UIManager has been instantiated and that a variable called uiManager refers to that instance.

    // show an info notification - auto-hide in 3 seconds
    uiManager.showNotification(3000, "info", "Informative message here");

    // show a warning notification - no auto-hide
    uiManager.showNotification(-1, "warning", "Warning message here");

    // show a progress notification - no auto-hide, 40% progress
    uiManager.showNotification(-1, "wait", "Loading...", 0.4);

    // show a progress notification - no auto-hide, unknown progress
    uiManager.showNotification(-1, "wait", "Loading...", -1.0);

The example below shows how to hide a notification. If no notification is showing when the method is called then the call is ignored.

    // hide the current notification (if any)
    uiManager.hideNotification();

Parent topic: Common WRTKit tasks