diff --git a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java b/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java index cccb18520d..ba305991d9 100644 --- a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java +++ b/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java @@ -14,6 +14,7 @@ public class ProgressDialogImplementation implements IProgress { private String taskName; private int progress; + private int deltaProgress; private int work; private String message = ""; //$NON-NLS-1$ @@ -116,18 +117,23 @@ public class ProgressDialogImplementation implements IProgress { @Override public void progress(int deltaWork) { - this.progress += deltaWork; - final int prg = progress; if (!isIndeterminate() && dialog != null) { - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - dialog.setProgress(prg); - } - }); - } else { - dialog.setProgress(prg); + 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) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + dialog.setProgress(prg); + } + }); + } else { + dialog.setProgress(prg); + } } } } @@ -182,6 +188,7 @@ public class ProgressDialogImplementation implements IProgress { this.work = 1; } progress = 0; + deltaProgress = 0; } @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java index 9b51f31dfe..d6eac741fa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java @@ -89,24 +89,14 @@ public class DownloadFileHelper { } first = false; - int prg = 0; while ((read = is.read(buffer)) != -1) { if(interruptDownloading){ throw new InterruptedException(); } out.write(buffer, 0, read); - if (length > -1) { - prg += read; - if (prg > length / 100) { - progress.progress(prg); - prg = 0; - } - } + progress.progress(read); fileread += read; } - if (prg > 0) { - progress.progress(prg); - } if(length <= fileread){ triesDownload = 0; } @@ -188,19 +178,9 @@ public class DownloadFileHelper { out = new FileOutputStream(fs); int read; byte[] buffer = new byte[BUFFER_SIZE]; - int prg = 0; while ((read = zipIn.read(buffer)) != -1) { out.write(buffer, 0, read); - if (size > -1) { - prg += read; - if (prg > size/100) { - progress.progress(prg); - prg = 0; - } - } - } - if (prg > 0) { - progress.progress(prg); + progress.progress(read); } out.close(); }