users are now able to crop their avatar pictures using the android-crop

library
This commit is contained in:
Philip Flohr 2015-11-06 11:14:05 +01:00
parent 8455e5b5dd
commit 0329c9c738
5 changed files with 41 additions and 9 deletions

View File

@ -14,6 +14,9 @@ allprojects {
repositories { repositories {
jcenter() jcenter()
mavenCentral() mavenCentral()
maven {
url 'http://lorenzo.villani.me/android-cropimage/'
}
} }
} }
@ -27,6 +30,7 @@ repositories {
dependencies { dependencies {
compile project(':libs:MemorizingTrustManager') compile project(':libs:MemorizingTrustManager')
compile 'org.sufficientlysecure:openpgp-api:9.0' compile 'org.sufficientlysecure:openpgp-api:9.0'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.android.support:support-v13:23.0.1' compile 'com.android.support:support-v13:23.0.1'
compile 'org.bouncycastle:bcprov-jdk15on:1.52' compile 'org.bouncycastle:bcprov-jdk15on:1.52'
compile 'org.bouncycastle:bcmail-jdk15on:1.52' compile 'org.bouncycastle:bcmail-jdk15on:1.52'

View File

@ -153,7 +153,7 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="eu.siacs.conversations.ui.SettingsActivity"/> android:value="eu.siacs.conversations.ui.SettingsActivity"/>
</activity> </activity>
<activity android:name="com.soundcloud.android.crop.CropImageActivity" />
<service android:name=".services.ExportLogsService"/> <service android:name=".services.ExportLogsService"/>
</application> </application>

View File

@ -486,14 +486,14 @@ public class FileBackend {
return calcSampleSize(options, size); 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(); 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);
} }
public static int calcSampleSize(BitmapFactory.Options options, int size) { private 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,10 +1,14 @@
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.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;
@ -13,9 +17,16 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -32,6 +43,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Button cancelButton; private Button cancelButton;
private Button publishButton; private Button publishButton;
final static int REQUEST_CROP_PICTURE = 92374;
private Uri avatarUri; private Uri avatarUri;
private Uri defaultUri; private Uri defaultUri;
private OnLongClickListener backToDefaultListener = new OnLongClickListener() { private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
@ -147,12 +159,15 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CHOOSE_FILE) { if (requestCode == REQUEST_CHOOSE_FILE) {
this.avatarUri = data.getData(); this.avatarUri = data.getData();
if (xmppConnectionServiceBound) { 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); loadImageIntoPreview(this.avatarUri);
} }
} }
}
}
@Override @Override
protected void onBackendConnected() { protected void onBackendConnected() {
@ -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) { protected void loadImageIntoPreview(Uri uri) {
Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( Bitmap bm = null;
uri, 384); try{
bm = loadScaledBitmap(uri.getPath(), Config.AVATAR_SIZE);
} catch (Exception e) {
e.printStackTrace();
}
if (bm == null) { if (bm == null) {
disablePublishButton(); disablePublishButton();
this.hintOrWarning.setTextColor(getWarningTextColor()); this.hintOrWarning.setTextColor(getWarningTextColor());
@ -261,5 +289,4 @@ public class PublishProfilePictureActivity extends XmppActivity {
public void refreshUiReal() { public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners //nothing to do. This Activity doesn't implement any listeners
} }
} }

View File

@ -314,6 +314,7 @@
\n\nhttps://github.com/kyleduo/SwitchButton\n(Apache License, Version 2.0) \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/WhisperSystems/libaxolotl-java\n(GPLv3)
\n\nhttps://github.com/vinc3m1/RoundedImageView\n(Apache License, Version 2.0) \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>
<string name="title_pref_quiet_hours">Quiet Hours</string> <string name="title_pref_quiet_hours">Quiet Hours</string>
<string name="title_pref_quiet_hours_start_time">Start time</string> <string name="title_pref_quiet_hours_start_time">Start time</string>