fixed avatar loading for non-file uris

This commit is contained in:
Daniel Gultsch 2015-12-02 15:30:03 +01:00
parent 0329c9c738
commit 02c6793ca9
2 changed files with 7 additions and 11 deletions

View file

@ -486,14 +486,14 @@ public class FileBackend {
return calcSampleSize(options, size); 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(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getAbsolutePath(), options); BitmapFactory.decodeFile(image.getAbsolutePath(), options);
return calcSampleSize(options, size); 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 height = options.outHeight;
int width = options.outWidth; int width = options.outWidth;
int inSampleSize = 1; int inSampleSize = 1;

View file

@ -1,14 +1,11 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel;
import android.provider.MediaStore;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
@ -21,7 +18,6 @@ import com.soundcloud.android.crop.Crop;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; 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(); final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath,options); BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
options.inSampleSize = FileBackend.calcSampleSize(new File(filePath), reqSize); options.inSampleSize = FileBackend.calcSampleSize(options, reqSize);
options.inJustDecodeBounds = false; options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(filePath,options); return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
} }
protected void loadImageIntoPreview(Uri uri) { protected void loadImageIntoPreview(Uri uri) {
Bitmap bm = null; Bitmap bm = null;
try{ try{
bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE); bm = loadScaledBitmap(uri, Config.AVATAR_SIZE);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }