Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created March 3, 2016 12:10
Show Gist options
  • Save codenameone/051bfa054fd3024c8292 to your computer and use it in GitHub Desktop.
Save codenameone/051bfa054fd3024c8292 to your computer and use it in GitHub Desktop.
Download progress indicator using a slider in Codename One
Form hi = new Form("Download Progress", new BorderLayout());
Slider progress = new Slider();
Button download = new Button("Download");
download.addActionListener((e) -> {
ConnectionRequest cr = new ConnectionRequest("https://www.codenameone.com/img/blog/new_icon.png", false);
SliderBridge.bindProgress(cr, progress);
NetworkManager.getInstance().addToQueueAndWait(cr);
if(cr.getResponseCode() == 200) {
hi.add(BorderLayout.CENTER, new ScaleImageLabel(EncodedImage.create(cr.getResponseData())));
hi.revalidate();
}
});
hi.add(BorderLayout.SOUTH, progress).add(BorderLayout.NORTH, download);
hi.show();
@codenameone
Copy link
Author

Sample usage of SliderBridge.

From the Codename One project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment