diff options
author | Christian S <christian@pix-art.de> | 2015-11-07 09:54:44 +0100 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-11-07 09:54:44 +0100 |
commit | f03da70ec8edc1ef5879b2ca2dd18625888473cc (patch) | |
tree | 1658f6df002413187623034c04e75dccdaa91c2d | |
parent | fc4ead341f9015fe106f2f267a113bb13ccb2fd4 (diff) | |
parent | 40d20b2aed7dd54f456202f7348d44a91818644d (diff) |
Merge branch 'refs/heads/philipflohr-master' into development
-rw-r--r-- | build.gradle | 4 | ||||
-rw-r--r-- | src/main/AndroidManifest.xml | 1 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java | 42 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 1 |
4 files changed, 32 insertions, 16 deletions
diff --git a/build.gradle b/build.gradle index 8fe7cabe3..091cd0465 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,9 @@ allprojects { repositories { jcenter() mavenCentral() + maven { + url 'http://lorenzo.villani.me/android-cropimage/' + } } } @@ -27,6 +30,7 @@ repositories { dependencies { compile project(':libs:openpgp-api-lib') compile project(':libs:MemorizingTrustManager') + compile 'com.soundcloud.android:android-crop:1.0.1@aar' compile 'com.android.support:support-v13:23.0.1' compile 'org.bouncycastle:bcprov-jdk15on:1.52' compile 'org.bouncycastle:bcmail-jdk15on:1.52' diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 3e048b25c..27c678036 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -169,6 +169,7 @@ android:theme="@style/ConversationsTheme" android:label="@string/title_activity_updater" > </activity> + <activity android:name="com.soundcloud.android.crop.CropImageActivity" /> <service android:name=".services.UpdaterWebService" /> <service android:name=".services.CheckAppVersionService" /> <service android:name=".services.ExportLogsService" /> diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 9e64a6805..2448d9005 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,6 +17,12 @@ 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; @@ -32,6 +42,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() { @@ -129,12 +140,7 @@ public class PublishProfilePictureActivity extends XmppActivity { @Override public void onClick(View v) { - Intent attachFileIntent = new Intent(); - attachFileIntent.setType("image/*"); - attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); - Intent chooser = Intent.createChooser(attachFileIntent, - getString(R.string.attach_file)); - startActivityForResult(chooser, REQUEST_CHOOSE_FILE); + Crop.pickImage(PublishProfilePictureActivity.this); } }); this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext()); @@ -144,13 +150,13 @@ public class PublishProfilePictureActivity extends XmppActivity { protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - if (requestCode == REQUEST_CHOOSE_FILE) { - this.avatarUri = data.getData(); - if (xmppConnectionServiceBound) { - loadImageIntoPreview(this.avatarUri); - } - } + if (resultCode == RESULT_OK && requestCode == Crop.REQUEST_PICK) { + Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); + Crop.of(data.getData(), destination).withMaxSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE).asSquare().start(PublishProfilePictureActivity.this); + } + if (requestCode == Crop.REQUEST_CROP) { + this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); + loadImageIntoPreview(this.avatarUri); } } @@ -218,8 +224,13 @@ public class PublishProfilePictureActivity extends XmppActivity { } protected void loadImageIntoPreview(Uri uri) { - Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( - uri, Config.AVATAR_SIZE); + Bitmap bm = null; + try{ + bm = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri); + } catch (IOException e) { + e.printStackTrace(); + } + if (bm == null) { disablePublishButton(); this.hintOrWarning.setTextColor(getWarningTextColor()); @@ -261,5 +272,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 953bd1981..16d6d6879 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> |