Moved some code to ProgressDialogImpltementation

This commit is contained in:
Pavol Zibrita 2011-09-26 23:00:22 +02:00
parent 9470285d3f
commit 8db4893db8
2 changed files with 20 additions and 33 deletions

View file

@ -14,6 +14,7 @@ public class ProgressDialogImplementation implements IProgress {
private String taskName; private String taskName;
private int progress; private int progress;
private int deltaProgress;
private int work; private int work;
private String message = ""; //$NON-NLS-1$ private String message = ""; //$NON-NLS-1$
@ -116,9 +117,13 @@ public class ProgressDialogImplementation implements IProgress {
@Override @Override
public void progress(int deltaWork) { public void progress(int deltaWork) {
this.progress += deltaWork;
final int prg = progress;
if (!isIndeterminate() && dialog != null) { if (!isIndeterminate() && dialog != null) {
this.deltaProgress += deltaWork;
//update only each percent
if ((deltaProgress > (work / 100)) || ((progress + deltaProgress) >= work)) {
this.progress += deltaProgress;
this.deltaProgress = 0;
final int prg = progress;
if (activity != null) { if (activity != null) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
@ -131,6 +136,7 @@ public class ProgressDialogImplementation implements IProgress {
} }
} }
} }
}
@Override @Override
public void remaining(int remainingWork) { public void remaining(int remainingWork) {
@ -182,6 +188,7 @@ public class ProgressDialogImplementation implements IProgress {
this.work = 1; this.work = 1;
} }
progress = 0; progress = 0;
deltaProgress = 0;
} }
@Override @Override

View file

@ -89,24 +89,14 @@ public class DownloadFileHelper {
} }
first = false; first = false;
int prg = 0;
while ((read = is.read(buffer)) != -1) { while ((read = is.read(buffer)) != -1) {
if(interruptDownloading){ if(interruptDownloading){
throw new InterruptedException(); throw new InterruptedException();
} }
out.write(buffer, 0, read); out.write(buffer, 0, read);
if (length > -1) { progress.progress(read);
prg += read;
if (prg > length / 100) {
progress.progress(prg);
prg = 0;
}
}
fileread += read; fileread += read;
} }
if (prg > 0) {
progress.progress(prg);
}
if(length <= fileread){ if(length <= fileread){
triesDownload = 0; triesDownload = 0;
} }
@ -188,19 +178,9 @@ public class DownloadFileHelper {
out = new FileOutputStream(fs); out = new FileOutputStream(fs);
int read; int read;
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
int prg = 0;
while ((read = zipIn.read(buffer)) != -1) { while ((read = zipIn.read(buffer)) != -1) {
out.write(buffer, 0, read); out.write(buffer, 0, read);
if (size > -1) { progress.progress(read);
prg += read;
if (prg > size/100) {
progress.progress(prg);
prg = 0;
}
}
}
if (prg > 0) {
progress.progress(prg);
} }
out.close(); out.close();
} }