Fork us on GitHub

Toast Downloads

Modernizing download progress indication
Post Image

Toast Downloads

I wanted to write about the new kitchen sink demo which I’m trying to finish…​
But I haven’t finished it yet as it’s such a major undertaking. As part of that work I wanted to show some code that downloads themes and didn’t want to use the venerable infinite progress indicator which I generally dislike…​

Over these past few months I’ve enjoyed the ToastBar tremendously and I think it’s probably far better suited for such a use case than the infinite progress. The ToastBar has rudimentary progress indication capabilities that are perfect for such a use case.

I added a relatively simple method to ToastBar but I’m guessing we will add more elaborate versions of this code:

public static void showConnectionProgress(String message, final ConnectionRequest cr, SuccessCallback<NetworkEvent> onSuccess, FailureCallback<NetworkEvent> onError)

This method shows a progress indicator ToastBar with a progress value for the connection request. On completion it will invoke the onSuccess/onError callbacks both of which may be null. E.g. for the case of theme download in the new KitchenSink demo I use the following code:

ConnectionRequest cr = new ConnectionRequest(BASE_URL + currentThemeFile);
ToastBar.showConnectionProgress("Downloading theme", cr, ee -> {
    setTheme(parentForm, currentThemeFile);
    theme.putClientProperty("downloading", null);
}, (sender, err, errorCode, errorMessage) -> {
    ToastBar.showErrorMessage("There was an error downloading the file: " + err);
Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.