diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-12-02 15:30:03 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-12-02 15:30:03 +0100 |
commit | 02c6793ca9ae195494c7be86f7e0d7a6c08a04c0 (patch) | |
tree | a45e629d6c6702d930726ca8dc94256d92a1a88d /src | |
parent | 0329c9c7384b4518514555fca70a968241acb1be (diff) |
fixed avatar loading for non-file uris
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 4 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java | 14 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 36b745053..febb09705 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -486,14 +486,14 @@ public class FileBackend { return calcSampleSize(options, size); } - public static int calcSampleSize(File image, int size) { + private static int calcSampleSize(File image, int size) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(image.getAbsolutePath(), options); return calcSampleSize(options, size); } - private static int calcSampleSize(BitmapFactory.Options options, int size) { + public static int calcSampleSize(BitmapFactory.Options options, int size) { int height = options.outHeight; int width = options.outWidth; int inSampleSize = 1; diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 59ca10693..542c27432 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -1,14 +1,11 @@ package eu.siacs.conversations.ui; import android.app.PendingIntent; -import android.content.ActivityNotFoundException; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Parcel; -import android.provider.MediaStore; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; @@ -21,7 +18,6 @@ import com.soundcloud.android.crop.Crop; import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -232,18 +228,18 @@ public class PublishProfilePictureActivity extends XmppActivity { } } - private Bitmap loadScaledBitmap(String filePath, int reqSize) { + private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeFile(filePath,options); - options.inSampleSize = FileBackend.calcSampleSize(new File(filePath), reqSize); + BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); + options.inSampleSize = FileBackend.calcSampleSize(options, reqSize); options.inJustDecodeBounds = false; - return BitmapFactory.decodeFile(filePath,options); + return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); } protected void loadImageIntoPreview(Uri uri) { Bitmap bm = null; try{ - bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE); + bm = loadScaledBitmap(uri, Config.AVATAR_SIZE); } catch (Exception e) { e.printStackTrace(); } |