public final class ToastBar
- Object
- 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 types
class ToastBar.Status | Represents a single status message. |
Methods
Inherited methods
Method details
getDefaultMessageTimeout
public static int getDefaultMessageTimeout()Returns
setDefaultMessageTimeout
public static void setDefaultMessageTimeout(int aDefaultMessageTimeout)Parameters
aDefaultMessageTimeoutint- the defaultMessageTimeout to set
getInstance
public static ToastBar getInstance()Gets reference to the singleton StatusBar instance
The singleton shows on whichever com.codename1.ui.Form is current, including
while a desktop window has the focus. To toast on a window use
#getForTopLevel(com.codename1.ui.TopLevelContainer), which is what the static
helpers on this class do.
getForTopLevel
public static ToastBar getForTopLevel(TopLevelContainer top)The toast bar for a given top level.
The singleton follows whichever Form is current, which is the behaviour every
existing application relies on, so a Form or null still gets it. A
com.codename1.ui.Window gets its own instance instead, cached on the window
and dying with it – a settable host on the singleton would have meant one
window silently redirecting another surface’s toasts.
Parameters
topTopLevelContainer- the top level to show on, may be null
Returns
showErrorMessage
public static void showErrorMessage(String msg)Parameters
msgString- the error message
showMessage
public static ToastBar.Status showMessage(String msg, char icon, int timeout, ActionListener listener)Parameters
msgString- the message
iconchar- the material icon to show from
com.codename1.ui.FontImage timeoutint- the timeout value in milliseconds
listenerActionListener- the action to perform when the ToastBar is tapped
Returns
showMessage
public static ToastBar.Status showMessage(String msg, char icon, int timeout)Parameters
msgString- the message
iconchar- the material icon to show from
com.codename1.ui.FontImage timeoutint- the timeout value in milliseconds
Returns
showMessage
public static ToastBar.Status showMessage(String msg, char icon, ActionListener listener)Parameters
msgString- the message
iconchar- the material icon to show from
com.codename1.ui.FontImage listenerActionListener- the action to perform when the ToastBar is tapped
Returns
showMessage
public static ToastBar.Status showMessage(String msg, char icon)Parameters
msgString- the message
iconchar- the material icon to show from
com.codename1.ui.FontImage
Returns
showInfoMessage
public static ToastBar.Status showInfoMessage(String msg)Parameters
msgString- the message
Returns
showErrorMessage
public static ToastBar.Status showErrorMessage(String msg, int timeout)Parameters
msgString- the error message
timeoutint- the timeout value in milliseconds
Returns
showConnectionProgress
public static void showConnectionProgress(String message, ConnectionRequest cr, SuccessCallback<NetworkEvent> onSuccess, FailureCallback<NetworkEvent> onError)getDefaultUIID
public String getDefaultUIID()ToastBar component.
By default this is “ToastBarComponent”.Returns
setDefaultUIID
public void setDefaultUIID(String defaultUIID)ToastBar component. By default
this is “ToastBarComponent”Parameters
defaultUIIDString- the defaultUIID to set
getDefaultMessageUIID
public String getDefaultMessageUIID()ToastBar text. By default
this is “ToastBarMessage”Returns
setDefaultMessageUIID
public void setDefaultMessageUIID(String defaultMessageUIID)ToastBar text. By default this is
“ToastBarMessage”Parameters
defaultMessageUIIDString- the defaultMessageUIID to set
useFormLayeredPane
public ToastBar useFormLayeredPane(boolean 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
useFormLayeredPaneboolean- True to use the form layered pane to display the toastbar.
Returns
getPosition
public int getPosition()Component#TOP or Component#BOTTOM.Returns
setPosition
public void setPosition(int position)Parameters
positionint- the position to set Should be one of
Component#TOPandComponent#BOTTOM
createStatus
public ToastBar.Status createStatus()setVisible
public void setVisible(boolean visible)ToastBar.