From 38f36aa2631f863d927f417b3758eb7969b31111 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 16 Aug 2014 17:31:53 +0200 Subject: [PATCH] more error handling for avatar publication --- src/eu/siacs/conversations/persistance/FileBackend.java | 9 ++++++++- .../conversations/ui/PublishProfilePictureActivity.java | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index 4db460096..f4067f87c 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -285,6 +285,9 @@ public class FileBackend { try { Avatar avatar = new Avatar(); Bitmap bm = cropCenterSquare(image, size); + if (bm==null) { + return null; + } ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream(); Base64OutputStream mBase64OutputSttream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT); MessageDigest digest = MessageDigest.getInstance("SHA-1"); @@ -355,7 +358,11 @@ public class FileBackend { InputStream is = context.getContentResolver() .openInputStream(image); Bitmap input = BitmapFactory.decodeStream(is, null, options); - return cropCenterSquare(input, size); + if (input==null) { + return null; + } else { + return cropCenterSquare(input, size); + } } catch (FileNotFoundException e) { return null; } diff --git a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 3b6ca13da..e874eeb7a 100644 --- a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -129,6 +129,9 @@ public class PublishProfilePictureActivity extends XmppActivity { if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CHOOSE_FILE) { this.avatarUri = data.getData(); + if (xmppConnectionServiceBound) { + loadImageIntoPreview(this.avatarUri); + } } } } @@ -173,6 +176,12 @@ public class PublishProfilePictureActivity extends XmppActivity { protected void loadImageIntoPreview(Uri uri) { Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( uri, 384); + if (bm==null) { + disablePublishButton(); + this.hintOrWarning.setTextColor(getWarningTextColor()); + this.hintOrWarning.setText(R.string.error_publish_avatar_converting); + return; + } this.avatar.setImageBitmap(bm); if (support) { enablePublishButton();