diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-12-02 15:30:03 +0100 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-12-04 09:43:41 +0100 |
commit | 64a4085d9a626010e27c6f28bd3ea6c04594eb13 (patch) | |
tree | 2d0a99939304fe7c411276e54e547954398697ce /src | |
parent | 667de6dbddbc2bbfecd7c93c12947e04a55c4b49 (diff) |
fixed avatar loading for non-file uris
Diffstat (limited to 'src')
-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 11e2b2d93..5e0c86e58 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(); } |