Permalink
Browse files

Fix download progress issue if content length can't be retrieved.

  • Loading branch information...
1 parent 8d0a3cd commit 7cf791bfff893567b64eea7ac725e876973547a6 @Nilhcem committed May 23, 2012
@@ -32,6 +32,14 @@ public void setTitle(int resId) {
}
public void setProgress(Integer progress) {
+ // Range check
+ if (progress < 0) {
+ progress = 0;
+ }
+ if (progress > ProgressBar.MAX_PROGRESS) {
+ progress = ProgressBar.MAX_PROGRESS;
+ }
+
// Do not display 0%
if (progress != 0) {
mProgressBar.setProgress(progress);
@@ -11,6 +11,7 @@
import com.nilhcem.frcndict.core.AbstractCancellableObservable;
public final class HttpDownloader extends AbstractCancellableObservable {
+ private static final int GENERIC_SIZE = 6000000;
private final File mOutput;
private final URL mUrl;
@@ -28,6 +29,9 @@ public void start() throws IOException {
connection.connect();
int totalSize = connection.getContentLength();
+ if (totalSize == -1) { // Small hack if this field is not set
+ totalSize = HttpDownloader.GENERIC_SIZE;
+ }
FileOutputStream fos = new FileOutputStream(mOutput);
InputStream is = connection.getInputStream();
byte[] buffer = new byte[1024];

0 comments on commit 7cf791b

Please sign in to comment.