From aa24a0f779c82c555e3f3f6f76485301c9757c89 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 4 Mar 2016 14:32:38 +0100 Subject: [PATCH] don't automatically crop avatar --- .../ui/PublishProfilePictureActivity.java | 62 +++++++++++------- .../res/drawable-hdpi/ic_crop_white_24dp.png | Bin 0 -> 302 bytes .../res/drawable-mdpi/ic_crop_white_24dp.png | Bin 0 -> 214 bytes .../res/drawable-xhdpi/ic_crop_white_24dp.png | Bin 0 -> 272 bytes .../drawable-xxhdpi/ic_crop_white_24dp.png | Bin 0 -> 326 bytes .../drawable-xxxhdpi/ic_crop_white_24dp.png | Bin 0 -> 394 bytes src/main/res/menu/publish_avatar.xml | 8 +++ src/main/res/values/strings.xml | 1 + 8 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_crop_white_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_crop_white_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_crop_white_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_crop_white_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_crop_white_24dp.png create mode 100644 src/main/res/menu/publish_avatar.xml diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index a457bf966..ee70ee43b 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -7,6 +7,8 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; @@ -27,13 +29,12 @@ import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.utils.ExifHelper; import eu.siacs.conversations.utils.FileUtils; import eu.siacs.conversations.utils.PhoneHelper; -import eu.siacs.conversations.xmpp.jid.InvalidJidException; -import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.pep.Avatar; public class PublishProfilePictureActivity extends XmppActivity { - private static final int REQUEST_CHOOSE_FILE = 0xac23; + private static final int REQUEST_CHOOSE_FILE_AND_CROP = 0xac23; + private static final int REQUEST_CHOOSE_FILE = 0xac24; private ImageView avatar; private TextView accountTextView; private TextView hintOrWarning; @@ -138,7 +139,7 @@ public class PublishProfilePictureActivity extends XmppActivity { @Override public void onClick(View v) { if (hasStoragePermission(REQUEST_CHOOSE_FILE)) { - chooseAvatar(); + chooseAvatar(false); } } @@ -146,32 +147,52 @@ public class PublishProfilePictureActivity extends XmppActivity { this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext()); } - private void chooseAvatar() { + private void chooseAvatar(boolean crop) { 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); + startActivityForResult(chooser, crop ? REQUEST_CHOOSE_FILE_AND_CROP : REQUEST_CHOOSE_FILE); } @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { if (grantResults.length > 0) if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - if (requestCode == REQUEST_CHOOSE_FILE) { - chooseAvatar(); + if (requestCode == REQUEST_CHOOSE_FILE_AND_CROP) { + chooseAvatar(true); + } else if (requestCode == REQUEST_CHOOSE_FILE) { + chooseAvatar(false); } } else { Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.publish_avatar, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if (item.getItemId() == R.id.action_crop_image) { + if (hasStoragePermission(REQUEST_CHOOSE_FILE_AND_CROP)) { + chooseAvatar(true); + } + return true; + } else { + return onOptionsItemSelected(item); + } + } + @Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { switch (requestCode) { - case REQUEST_CHOOSE_FILE: + case REQUEST_CHOOSE_FILE_AND_CROP: Uri source = data.getData(); String original = FileUtils.getPath(this, source); if (original != null) { @@ -181,9 +202,17 @@ public class PublishProfilePictureActivity extends XmppActivity { final int size = getPixel(192); Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this); break; + case REQUEST_CHOOSE_FILE: + this.avatarUri = data.getData(); + if (xmppConnectionServiceBound) { + loadImageIntoPreview(this.avatarUri); + } + break; case Crop.REQUEST_CROP: this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); - loadImageIntoPreview(this.avatarUri); + if (xmppConnectionServiceBound) { + loadImageIntoPreview(this.avatarUri); + } break; } } else { @@ -248,21 +277,10 @@ public class PublishProfilePictureActivity extends XmppActivity { } } - private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException { - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); - int rotation = ExifHelper.getOrientation(getContentResolver().openInputStream(uri)); - options.inSampleSize = FileBackend.calcSampleSize(options, reqSize); - options.inJustDecodeBounds = false; - Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options); - return FileBackend.rotate(bm,rotation); - } - protected void loadImageIntoPreview(Uri uri) { Bitmap bm = null; try { - bm = loadScaledBitmap(uri, getPixel(192)); + bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, getPixel(192)); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/res/drawable-hdpi/ic_crop_white_24dp.png b/src/main/res/drawable-hdpi/ic_crop_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6cbb87ce8bce2d7112e5c4c2bd3db67b64e75e06 GIT binary patch literal 302 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K;Lb6AYF9SoB8UsT^3j@P1pisjL z28L1t28LG&3=CE?7#PG0=Ijcz0ZK3>dAqwX{BQ3+vmeOgEbxddW?Wu- zvf};%nX0U1J|PTOuQVKe<}{1XAfvI4d8eQ4?y$WI^>@!7IdNc5+a1k678!g0o$EcV zK9$Sy@Pz1Dw=Wl+-TUUOEfc58g?9}<{>SHbGs?xEGwtSG*j9aLhUp7|pf7X09Tr#= uKG|@4tCmLn;w>{=_9{1?atOR1RV0@Frk}B=y0H@IVg^rFKbLh*2~7Y%8E>Tk literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_crop_white_24dp.png b/src/main/res/drawable-mdpi/ic_crop_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..d606c0725678127e42397a9be68dc4055b77bbf3 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1g=CK)Uj~LMH3o);76yi2K%s^g z3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO=~G=WkM1 z=jq}YVsSe8&v^%_1eZ$;Nk)8uyeIypr8qooK9JoO($>2qBO#&UsDfYDoeOn|?(vpk=tOZq79GMP`3>lZL8Re8Mvw$Wuc)I$ztaD0e0su&j BJ$3*9 literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xhdpi/ic_crop_white_24dp.png b/src/main/res/drawable-xhdpi/ic_crop_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..983af77f18bb4277e010e154228c5cad079f695c GIT binary patch literal 272 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}tg=CK)Uj~LMH3o);76yi2K%s^g z3=E|}g|8AA7_4S6Fo+k-*%fF5lweBoc6VX;-`;;_Kaj^+;1OBOz`!jG!i)^F=12eq zJ3L(+Ln02py|IzA!9bw(q5amb>=c&l>O$%A0$KJAWh~bPwp=^q)}!!*<3;t;!VjVk zAL!*BH`C)S5Sz=uXwT$y`I%mVhP1NmW?6;}0e1yIGDu|PHcmbCYNGrvRt^CLhXef# zZ(Tn&PSrX0Rgj5ID*AwNU=-7Xmn%=cZ78p_&0u1w5%BnVyNJPhNjam*=DHG~n;1M@ L{an^LB{Ts5d$d;s literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_crop_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_crop_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..8c9eecb9cd2767e14c5304ecd4011989ee340cab GIT binary patch literal 326 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhaw6p}rHd>I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g$s z6x`?O;uw-~@9m9^oKA)!4i{%@z2NFoxOGDQkgUvsPx(q=dJlN?9&K;ub7#c z(}4y2d$#koTy7DM+aq0;Lh+Aj1vT-~>!N$%Fh&5W}j*aJP!z~JfX=d#Wz Gp$P!69B+vL literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/ic_crop_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_crop_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..35d5434af85d7caed59a79c930c68453e00219d6 GIT binary patch literal 394 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD0wg^q?%xcg6p}rHd>I(3)EF2VS{N990fib~ zFff!FFfhDIU|_JC!N4G1FlSew4N!t9$=lt9;eUJonf*W>XMsm#F#`j)FbFd;%$g&? zz`)4l>EaktaqI1^jhsx50<90Xcg9JpHBF3YOh{2(o|L5NrWKZ?645v#Gfi^d$(KrM zYWLRN*{J-#dwL^(S_Ip%sheck861Ke&bRXcZGeM%W{$f#cf=Di-tEd--|H8~_+Beo zw`4Q-2g{6@xf7He&b!UJ$u>nQWNxbo<0Y@++YOtmwlTIEWy?pV)WQuxXEY=_q=3a7 zoEw~Umx_pU?O2g5z2VvwvjyvuwQA+rKcssI-)``+=GA4kNnB|&(XESVPnzO&58172 qnO=Fl<>o~;aT4p1ccu&sf2OhPU3t&Avaj?dNY>NU&t;ucLK6T%9CTj* literal 0 HcmV?d00001 diff --git a/src/main/res/menu/publish_avatar.xml b/src/main/res/menu/publish_avatar.xml new file mode 100644 index 000000000..1bffb2961 --- /dev/null +++ b/src/main/res/menu/publish_avatar.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6a36233ce..7368d0dc9 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -602,4 +602,5 @@ Correct message Send corrected message You already trust this contact. By selecting \'done\' you are just confirming that %s is part of this conference. + Select image and crop