Class WNotification
A notification is a message sent to the user that can be read from outside the webpage. For a
page to be allowed to send notifications, permission must be explicitly given by the user to the
application. The permission can be asked to the user with askPermission() or will be asked automatically the first time send() is called in the application. It is possible to listen to the permissionUpdated() signal to react to the user granting or
denying permission to send notifications.
If the user has previously granted permission to the page to display notifications, the browser will remember it, and JWt will not ask for that permission again.
The WNotification will not be sent to the user if the permission has not yet been
granted. Instead, the notification will wait for the user to accept notifications before being
sent. This will however not happen if the notification was closed or destroyed.
A WNotification represents a notification with a tag. The value of this tag is the id
of the WNotification. If the same WNotification is sent multiple times, this will
update the notification instead of creating a new one, as long as it was not closed.
You can react to a notification being closed or clicked by listening to the closed() and clicked() signals, this does
however require that the WNotification has not been destroyed before the event happens.
Notifications can have an icon and a badge. Those can be set using setIcon() and setBadge(), but since these are likely the same for all the notifications sent by
your application, it is possible to set a default icon and a default badge for all notifications
with setDefaultIcon() and setDefaultBadge().
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration representing the permission status of notifications.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new notification.WNotification(CharSequence title) Creates a new notification.WNotification(CharSequence title, CharSequence body) Creates a new notification. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAsk permission to send notifications to the user.clicked()Signalemitted when the notification is clicked.voidclose()Closes the notification.closed()Signalemitted when the notification is closed.error()Signalemitted when the notification was not shown due to an error.getBadge()Returns the link to the notification's badge.getBody()Returns the body of the notification.static WLinkReturns the link to the notifications default badge.static WLinkReturns the link to the notifications default icon.getIcon()Returns the link to the notification's icon.static WNotification.PermissionReturns the status of the permission to send notifications.getTitle()Returns the title of the notification.booleanReturns whether the notification require interaction to become inactive or not.booleanisSilent()Returns whether the notification should be silent or not.static booleanReturns whether the user supports notifications or not.static Signal1<WNotification.Permission> Signalemitted when the permission to send notification has been updated.voidsend()Sends the notification.voidSets the link to the notification's badge.voidsetBody(CharSequence body) Sets the body of the notification.static voidsetDefaultBadge(WLink badgeLink) Sets the link to the notifications default badge.static voidsetDefaultIcon(WLink iconLink) Sets the link to the notifications default icon.voidSets the link to the notification's icon.final voidSets whether the notification require interaction to become inactive or not.voidsetRequireInteraction(boolean enable) Sets whether the notification require interaction to become inactive or not.final voidSets whether the notification should be silent or not.voidsetSilent(boolean enable) Sets whether the notification should be silent or not.voidsetTitle(CharSequence title) Sets the title of the notification.shown()Signalemitted when the notification is shown.Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, resendFormData, setFormData, setObjectName, tr
-
Constructor Details
-
WNotification
Creates a new notification.Creates a new notification with the given title and body.
-
WNotification
public WNotification()Creates a new notification. -
WNotification
Creates a new notification.
-
-
Method Details
-
setTitle
Sets the title of the notification.This sets the title of the notification.
By default, the title is an empty string.
-
getTitle
Returns the title of the notification.- See Also:
-
setBody
Sets the body of the notification.This sets the body of the notification.
By default, the notification has no body, which is represented by an empty string.
-
getBody
Returns the body of the notification.Returns the body of the notification or an empty string if the notification has no body.
- See Also:
-
setIcon
Sets the link to the notification's icon.This sets the link to the notification's icon which is the image displayed on the left of the notification.
By default, the icon is set to the default icon.
- See Also:
-
getIcon
Returns the link to the notification's icon.Returns the link to the notification's icon or a
nulllink if the notification uses the default icon.By default, the icon is set to the default icon.
- See Also:
-
setBadge
Sets the link to the notification's badge.This sets the link to the notification's badge which is the image displayed when there is not enough space to display the notification.
By default, the badge is set to the default badge.
- See Also:
-
getBadge
Returns the link to the notification's badge.Returns the link to the notification's badge.
By default, the badge is set to the default badge.
- See Also:
-
setSilent
public void setSilent(boolean enable) Sets whether the notification should be silent or not.This sets whether the notification should be silent or not. A silent notification will not make any noise or vibration.
By default, the notification is not silent.
Note: A non silent notification may still make no noise or vibration as it will respect the user's configuration.
-
setSilent
public final void setSilent()Sets whether the notification should be silent or not.Calls
setSilent(true) -
isSilent
public boolean isSilent()Returns whether the notification should be silent or not.- See Also:
-
setRequireInteraction
public void setRequireInteraction(boolean enable) Sets whether the notification require interaction to become inactive or not.This sets whether the notification should remain active until the user click's on it or dismiss it.
By default, this is set to false.
-
setRequireInteraction
public final void setRequireInteraction()Sets whether the notification require interaction to become inactive or not. -
isRequireInteraction
public boolean isRequireInteraction()Returns whether the notification require interaction to become inactive or not.- See Also:
-
send
public void send()Sends the notification.Sends the notification to the user. This only happens if the permission to send notification has been granted by the user.
In case the user has not denied or granted notification to the user, the first call to send will instead ask for permission to send notification. The notification will then be sent after the user granted permission to send notification, unless this notification was closed or destroyed.
Calling
send()multiple times on the same notification will not create multiple notification but replace the previous with the new one, as long as the previous one has not been closed. This means that the user will not be notified again for this notification unless the previous one has been closed.- See Also:
-
close
public void close()Closes the notification.Closes the notification. This does nothing if the notification was not sent or was already closed.
- See Also:
-
clicked
Signalemitted when the notification is clicked. -
closed
Signalemitted when the notification is closed. -
shown
Signalemitted when the notification is shown. -
error
Signalemitted when the notification was not shown due to an error. -
setDefaultIcon
Sets the link to the notifications default icon.By default, this is a
nulllink which means no default icon is used.- See Also:
-
getDefaultIcon
Returns the link to the notifications default icon.- See Also:
-
setDefaultBadge
Sets the link to the notifications default badge.By default, this is a
nulllink which means no default badge is used.- See Also:
-
getDefaultBadge
Returns the link to the notifications default badge.- See Also:
-
isSupported
public static boolean isSupported()Returns whether the user supports notifications or not. -
askPermission
public static void askPermission()Ask permission to send notifications to the user.This ask permission to the user to send notifications. This will only be done once per application. More calls to this function will not do anything.
- See Also:
-
getPermission
Returns the status of the permission to send notifications.- See Also:
-
permissionUpdated
Signalemitted when the permission to send notification has been updated.Signalemitted when the permission to send notification has been updated. This happens when the user answered toaskPermission(), and the new permission status is given by the signal as parameter to all connected functions.- See Also:
-