Toast

The Toast object contains functions for displaying toast notifications.

The functionality of this object allows the developer to display system toast notifications within their WebWorks application.

The following image shows a toast on a device:

Device showing a toast.

The following image shows a toast with an undo button:

Device showing a toast with an undo button.

Installation:

To use this API in your project, add the toast plugin:

webworks plugin add com.blackberry.ui.toast
Functions:
Number show()

Learning Resources:

Sample - Using Toast Sample that demonstrates how to use the BlackBerry Toast API [BlackBerry on GitHub].

show()

Displays a toast notification.

Synopsis:

void blackberry.ui.toast.show(message,options)

Parameters:

message {String}

Message to be displayed in the toast.

options {Object}

The options object that specifies the buttonText, and callback handlers that should be used by the toast.

buttonText {String}

The parameter that specifies the label for the button within the toast.

buttonCallback {Function}

The callback for receiving the button event when the user selects the toast button.

dismissCallback {Function}

The callback for receiving an event when the toast dismisses either through the toast's timeout or when the button is selected.

timeout {Number}

The timeout value that can be used to extend the toast for as long as the user desires. The value specified is parsed in milliseconds.

Returns:

{Number}

A numeric ID to reference this toast by.

Example:

<script type="text/javascript">

    function showCustomToast() {
        var message = "This is my toast!",
            buttonText = "Click Me",
            toastId,
            onButtonSelected = function () {
                console.log('Button was clicked for toast: ' + toastId);
            },
            onToastDismissed = function () {
                console.log('Toast disappeared: ' + toastId);
            },
            options = {
                buttonText : buttonText,
                dismissCallback : onToastDismissed,
                buttonCallback : onButtonSelected
        };

        toastId = blackberry.ui.toast.show(message, options);
    }

    function showCustomToastWithTimeout() {
        var message = "This is my toast!",
            buttonText = "Click Me",
            toastId,
            onButtonSelected = function () {
                console.log('Button was clicked for toast: ' + toastId);
            },
            onToastDismissed = function () {
                console.log('Toast disappeared: ' + toastId);
            },
            options = {
                buttonText : buttonText,
                dismissCallback : onToastDismissed,
                buttonCallback : onButtonSelected,
                timeout : 10000
        };

        toastId = blackberry.ui.toast.show(message, options);
    }
</script>
            

Last modified: 2014-05-14



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus