aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilip Flohr <philip.flohr@student.kit.edu>2015-11-06 11:14:05 +0100
committerPhilip Flohr <philip.flohr@student.kit.edu>2015-12-02 14:25:20 +0100
commit0329c9c7384b4518514555fca70a968241acb1be (patch)
tree0c03661056b9d23b73221f6dd818b35e20a8f2ae /src
parent8455e5b5dd82371d58b2d5e7474779cd6ee5d5f3 (diff)
users are now able to crop their avatar pictures using the android-crop
library
Diffstat (limited to 'src')
-rw-r--r--src/main/AndroidManifest.xml2
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java39
-rw-r--r--src/main/res/values/strings.xml1
4 files changed, 37 insertions, 9 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index fb5df34d..9f434a62 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -153,7 +153,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="eu.siacs.conversations.ui.SettingsActivity"/>
</activity>
-
+ <activity android:name="com.soundcloud.android.crop.CropImageActivity" />
<service android:name=".services.ExportLogsService"/>
</application>
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 35b836a7..36b74505 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 e01490f9..59ca1069 100644
--- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -1,10 +1,14 @@
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;
@@ -13,9 +17,16 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+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;
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;
@@ -32,6 +43,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Button cancelButton;
private Button publishButton;
+ final static int REQUEST_CROP_PICTURE = 92374;
private Uri avatarUri;
private Uri defaultUri;
private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
@@ -147,11 +159,14 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CHOOSE_FILE) {
this.avatarUri = data.getData();
- if (xmppConnectionServiceBound) {
- loadImageIntoPreview(this.avatarUri);
- }
+ Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
+ Crop.of(this.avatarUri, destination).asSquare().start(PublishProfilePictureActivity.this);
}
}
+ if (requestCode == Crop.REQUEST_CROP) {
+ this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
+ loadImageIntoPreview(this.avatarUri);
+ }
}
@Override
@@ -217,9 +232,22 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
}
+ private Bitmap loadScaledBitmap(String filePath, int reqSize) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeFile(filePath,options);
+ options.inSampleSize = FileBackend.calcSampleSize(new File(filePath), reqSize);
+ options.inJustDecodeBounds = false;
+ return BitmapFactory.decodeFile(filePath,options);
+ }
protected void loadImageIntoPreview(Uri uri) {
- Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare(
- uri, 384);
+ Bitmap bm = null;
+ try{
+ bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
if (bm == null) {
disablePublishButton();
this.hintOrWarning.setTextColor(getWarningTextColor());
@@ -261,5 +289,4 @@ public class PublishProfilePictureActivity extends XmppActivity {
public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners
}
-
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 69f964d7..59c5e1c0 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -314,6 +314,7 @@
\n\nhttps://github.com/kyleduo/SwitchButton\n(Apache License, Version 2.0)
\n\nhttps://github.com/WhisperSystems/libaxolotl-java\n(GPLv3)
\n\nhttps://github.com/vinc3m1/RoundedImageView\n(Apache License, Version 2.0)
+ \n\nhttps://github.com/jdamcd/android-crop\n(Apache License, Version 2.0)
</string>
<string name="title_pref_quiet_hours">Quiet Hours</string>
<string name="title_pref_quiet_hours_start_time">Start time</string>