diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:52:15 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:52:15 +0100 |
commit | 35bf13f5effd802f57b9f3633115fed479e14f1e (patch) | |
tree | ab21e6d9f954ce6ad3b30af6ffcf7180d2ca7484 /src/main/java/eu/siacs/conversations/http/HttpConnection.java | |
parent | 07b07115d684b27ebc0c3ee4f70ef2e33a3b2dbb (diff) | |
parent | 41f7848f2ca48b31ad7fd865490347fe26f60c2b (diff) |
Merge branch 'feature/file_transfer' into development
Conflicts:
src/main/res/values/strings.xml
Diffstat (limited to 'src/main/java/eu/siacs/conversations/http/HttpConnection.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpConnection.java | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpConnection.java b/src/main/java/eu/siacs/conversations/http/HttpConnection.java index 147ac42f..68c26c47 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpConnection.java @@ -3,6 +3,7 @@ package eu.siacs.conversations.http; import android.content.Intent; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.SystemClock; import org.apache.http.conn.ssl.StrictHostnameVerifier; @@ -21,6 +22,7 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.X509TrustManager; +import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Downloadable; import eu.siacs.conversations.entities.DownloadableFile; import eu.siacs.conversations.entities.Message; @@ -37,6 +39,8 @@ public class HttpConnection implements Downloadable { private DownloadableFile file; private int mStatus = Downloadable.STATUS_UNKNOWN; private boolean acceptedAutomatically = false; + private int mProgress = 0; + private long mLastGuiRefresh = 0; public HttpConnection(HttpConnectionManager manager) { this.mHttpConnectionManager = manager; @@ -235,10 +239,14 @@ public class HttpConnection implements Downloadable { if (os == null) { throw new IOException(); } + long transmitted = 0; + long expected = file.getExpectedSize(); int count = -1; byte[] buffer = new byte[1024]; while ((count = is.read(buffer)) != -1) { + transmitted += count; os.write(buffer, 0, count); + updateProgress((int) ((((double) transmitted) / expected) * 100)); } os.flush(); os.close(); @@ -246,19 +254,21 @@ public class HttpConnection implements Downloadable { } private void updateImageBounds() { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeFile(file.getAbsolutePath(), options); - int imageHeight = options.outHeight; - int imageWidth = options.outWidth; - message.setBody(mUrl.toString() + "|" + file.getSize() + '|' - + imageWidth + '|' + imageHeight); message.setType(Message.TYPE_IMAGE); + mXmppConnectionService.getFileBackend().updateFileParams(message,mUrl); mXmppConnectionService.updateMessage(message); } } + public void updateProgress(int i) { + this.mProgress = i; + if (SystemClock.elapsedRealtime() - this.mLastGuiRefresh > Config.PROGRESS_UI_UPDATE_INTERVAL) { + this.mLastGuiRefresh = SystemClock.elapsedRealtime(); + mXmppConnectionService.updateConversationUi(); + } + } + @Override public int getStatus() { return this.mStatus; @@ -272,4 +282,14 @@ public class HttpConnection implements Downloadable { return 0; } } + + @Override + public int getProgress() { + return this.mProgress; + } + + @Override + public String getMimeType() { + return ""; + } }
\ No newline at end of file |