Button dldButton = new Button("download zip");
add(dldButton, CENTER, CENTER);
final ProgressBar progressBar = new ProgressBar();
add(progressBar, CENTER, AFTER + UnitsConverter.toPixels(DP + 16),
PARENTSIZE + 80, PREFERRED);
dldButton.addPressListener((c) -> {
new AsyncTask()<Void, Void, Void> {
UpdateListener updateListener = null;
protected Object doInBackground(Object... objects) {
HttpStream.Options o = new HttpStream.Options();
o.httpType = HttpStream.GET;
final String url = "<INSERT AN URL TO DOWNLOAD A ZIP FILE>";
if(url.startsWith("https:"))
o.socketFactory = new SSLSocketFactory();
HttpStream p = new HttpStream(new URI(url));
File f = new File("file.zip", File.CREATE_EMPTY);
int totalSize = p.contentLength;
byte [] buff = new byte[4096];
BufferedStream bs = new BufferedStream(f, BufferedStream.WRITE, 4096);
int size = p.readBytes(buff, 0, buff.length);
progress = (int)((counter/(double)totalSize)*100);
bs.writeBytes(buff, 0, size);
} catch (IOException e) {
protected void onPreExecute() {
dldButton.setEnabled(false);
MainWindow.getMainWindow().addUpdateListener(updateListener = (elapsed) -> {
progressBar.setValue(progress);
protected void onPostExecute(Object result) {
dldButton.setEnabled(true);
MainWindow.getMainWindow().removeUpdateListener(updateListener);