From 667de6dbddbc2bbfecd7c93c12947e04a55c4b49 Mon Sep 17 00:00:00 2001 From: Philip Flohr Date: Fri, 6 Nov 2015 11:14:05 +0100 Subject: users are now able to crop their avatar pictures using the android-crop library --- .../conversations/persistance/FileBackend.java | 4 +-- .../ui/PublishProfilePictureActivity.java | 30 +++------------------- 2 files changed, 6 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 35b836a7a..36b745053 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); } - private int calcSampleSize(File image, int size) { + public 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); } - public static int calcSampleSize(BitmapFactory.Options options, int size) { + private 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 7a2d3f8dd..11e2b2d93 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -26,6 +26,7 @@ import java.io.IOException; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -231,41 +232,18 @@ public class PublishProfilePictureActivity extends XmppActivity { } } - private int calculateInSampleSize( - BitmapFactory.Options options, int reqWidth, int reqHeight) { - // Raw height and width of image - final int height = options.outHeight; - final int width = options.outWidth; - int inSampleSize = 1; - - if (height > reqHeight || width > reqWidth) { - - final int halfHeight = height / 2; - final int halfWidth = width / 2; - - // Calculate the largest inSampleSize value that is a power of 2 and keeps both - // height and width larger than the requested height and width. - while ((halfHeight / inSampleSize) > reqHeight - && (halfWidth / inSampleSize) > reqWidth) { - inSampleSize *= 2; - } - } - - return inSampleSize; - } - - private Bitmap loadScaledBitmap(String filePath, int reqWidth, int reqHeight) { + private Bitmap loadScaledBitmap(String filePath, int reqSize) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath,options); - options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); + options.inSampleSize = FileBackend.calcSampleSize(new File(filePath), reqSize); options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath,options); } protected void loadImageIntoPreview(Uri uri) { Bitmap bm = null; try{ - bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE, Config.AVATAR_SIZE); + bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE); } catch (Exception e) { e.printStackTrace(); } -- cgit v1.2.3