Class ToastBar
An API to present status messages to the user in an unobtrusive manner. This is useful if there are background tasks that need to display information to the user. E.g. If a network request fails, of let the user know that "Jobs are being synchronized".
Example Usage
Form hi = new Form("ToastBarDemo", BoxLayout.y());
Button basic = new Button("Basic");
Button progress = new Button("Progress");
Button expires = new Button("Expires");
Button delayed = new Button("Delayed");
hi.add(basic).add(progress).add(expires).add(delayed);
basic.addActionListener(e -> {
ToastBar.Status status = ToastBar.getInstance().createStatus();
status.setMessage("Hello world");
status.show();
//... Some time later you must clear the status
// status.clear();
});
progress.addActionListener(e -> {
ToastBar.Status status = ToastBar.getInstance().createStatus();
status.setMessage("Hello world");
status.setShowProgressIndicator(true);
status.show();
// ... Some time later you must clear it
});
expires.addActionListener(e -> {
ToastBar.Status status = ToastBar.getInstance().createStatus();
status.setMessage("Hello world");
status.setExpires(3000); // only show the status for 3 seconds, then have it automatically clear
status.show();
});
delayed.addActionListener(e -> {
ToastBar.Status status = ToastBar.getInstance().createStatus();
status.setMessage("Hello world");
status.showDelayed(300); // Wait 300 ms to show the status
// ... Some time later, clear the status... this may be before it shows at all
});
hi.show();
Advanced Usage
See the StatusBarDemo
Screenshots
Status With Progress Bar
Status With Multi-Line Message
Video Demo
Note: the video above refers to the ToastBar based on its development name of StatusBar. This
was changed to avoid confusion with the iOS StatusBar.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionCreates a new Status.static intThe default timeout for info/error messagesGets the default UIID to be used for the style of theToastBartext.Gets the default UIID to be used for the style of theToastBarcomponent.static ToastBarGets reference to the singleton StatusBar instanceintGets the position of the toast bar on the screen.static voidsetDefaultMessageTimeout(int aDefaultMessageTimeout) The default timeout for info/error messagesvoidsetDefaultMessageUIID(String defaultMessageUIID) Sets the default UIID to be used for the style of theToastBartext.voidsetDefaultUIID(String defaultUIID) Sets the defaults UIID to be used for the style of theToastBarcomponent.voidsetPosition(int position) Sets the position of the toast bar on the screen.voidsetVisible(boolean visible) Shows or hides theToastBar.static voidshowConnectionProgress(String message, ConnectionRequest cr, SuccessCallback<NetworkEvent> onSuccess, FailureCallback<NetworkEvent> onError) static voidshowErrorMessage(String msg) Simplifies a common use case of showing an error message with an error icon that fades out after a few secondsstatic ToastBar.StatusshowErrorMessage(String msg, int timeout) Simplifies a common use case of showing an error message with an error icon that fades out after a few secondsstatic ToastBar.StatusshowInfoMessage(String msg) Simplifies a common use case of showing an information message with an info icon that fades out after a few secondsstatic ToastBar.StatusshowMessage(String msg, char icon) Simplifies a common use case of showing an error message with an error icon that fades out after a few secondsstatic ToastBar.StatusshowMessage(String msg, char icon, int timeout) Simplifies a common use case of showing a message with an icon that fades out after a few secondsstatic ToastBar.StatusshowMessage(String msg, char icon, int timeout, ActionListener listener) Simplifies a common use case of showing a message with an icon that fades out after a few secondsstatic ToastBar.StatusshowMessage(String msg, char icon, ActionListener listener) Simplifies a common use case of showing an error message with an error icon that fades out after a few secondsuseFormLayeredPane(boolean useFormLayeredPane) By default the ToastBar uses the LayeredPane.
-
Method Details
-
getDefaultMessageTimeout
public static int getDefaultMessageTimeout()The default timeout for info/error messages
Returns
the defaultMessageTimeout
-
setDefaultMessageTimeout
public static void setDefaultMessageTimeout(int aDefaultMessageTimeout) The default timeout for info/error messages
Parameters
aDefaultMessageTimeout: the defaultMessageTimeout to set
-
getInstance
Gets reference to the singleton StatusBar instance -
showErrorMessage
Simplifies a common use case of showing an error message with an error icon that fades out after a few seconds
Parameters
msg: the error message
-
showMessage
public static ToastBar.Status showMessage(String msg, char icon, int timeout, ActionListener listener) Simplifies a common use case of showing a message with an icon that fades out after a few seconds
Parameters
-
msg: the message -
icon: the material icon to show fromcom.codename1.ui.FontImage -
timeout: the timeout value in milliseconds -
listener: the action to perform when the ToastBar is tapped
Returns
the status if we want to clear it before timeout elapses
-
-
showMessage
Simplifies a common use case of showing a message with an icon that fades out after a few seconds
Parameters
-
msg: the message -
icon: the material icon to show fromcom.codename1.ui.FontImage -
timeout: the timeout value in milliseconds
Returns
the status if we want to clear it before timeout elapses
-
-
showMessage
Simplifies a common use case of showing an error message with an error icon that fades out after a few seconds
Parameters
-
msg: the message -
icon: the material icon to show fromcom.codename1.ui.FontImage -
listener: the action to perform when the ToastBar is tapped
Returns
the status if we want to clear it before timeout elapses
-
-
showMessage
Simplifies a common use case of showing an error message with an error icon that fades out after a few seconds
Parameters
-
icon: the material icon to show fromcom.codename1.ui.FontImage -
msg: the message
Returns
the status if we want to clear it before timeout elapses
-
-
showInfoMessage
Simplifies a common use case of showing an information message with an info icon that fades out after a few seconds
Parameters
msg: the message
Returns
the status if we want to clear it before timeout elapses
-
showErrorMessage
Simplifies a common use case of showing an error message with an error icon that fades out after a few seconds
Parameters
-
msg: the error message -
timeout: the timeout value in milliseconds
Returns
the status if we want to clear it before timeout elapses
-
-
showConnectionProgress
public static void showConnectionProgress(String message, ConnectionRequest cr, SuccessCallback<NetworkEvent> onSuccess, FailureCallback<NetworkEvent> onError) -
getDefaultUIID
Gets the default UIID to be used for the style of the
ToastBarcomponent. By default this is "ToastBarComponent".Returns
the defaultUIID
-
setDefaultUIID
Sets the defaults UIID to be used for the style of the
ToastBarcomponent. By default this is "ToastBarComponent"Parameters
defaultUIID: the defaultUIID to set
-
getDefaultMessageUIID
Gets the default UIID to be used for the style of the
ToastBartext. By default this is "ToastBarMessage"Returns
the defaultMessageUIID
-
setDefaultMessageUIID
Sets the default UIID to be used for the style of the
ToastBartext. By default this is "ToastBarMessage"Parameters
defaultMessageUIID: the defaultMessageUIID to set
-
useFormLayeredPane
By default the ToastBar uses the LayeredPane. However, it may be better in many cases to use the FormLayerd pane. This allows you to toggle whether to use the FormLayeredPane.
Key use-case is for displaying the ToastBar over a Sheet, which is on the FormLayeredPane. If you don't set this to true, then the ToastBar will be displayed behind the Sheet.
Parameters
useFormLayeredPane: True to use the form layered pane to display the toastbar.
Returns
Self for chaining.
Since
8.0
-
getPosition
public int getPosition()Gets the position of the toast bar on the screen. Either
Component#TOPorComponent#BOTTOM.Returns
the position
-
setPosition
public void setPosition(int position) Sets the position of the toast bar on the screen.
Parameters
position: the position to set Should be one ofComponent#TOPandComponent#BOTTOM
-
createStatus
Creates a new Status. -
setVisible
public void setVisible(boolean visible) Shows or hides the
ToastBar.Parameters
visible
-