aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilip Flohr <philip.flohr@student.kit.edu>2015-11-06 11:14:05 +0100
committerChristian S <christian@pix-art.de>2015-12-04 09:43:23 +0100
commit667de6dbddbc2bbfecd7c93c12947e04a55c4b49 (patch)
tree9e6cb4049021aed0d2e01a12b7c64f5c0a3d5c9d /src
parentbff0463c3b1ed54a1ae05ac81090a811abe92088 (diff)
users are now able to crop their avatar pictures using the android-crop
library
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java30
2 files changed, 6 insertions, 28 deletions
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();
}