aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-03-17 23:30:52 +0100
committerChristian Schneppe <christian@pix-art.de>2017-03-17 23:30:52 +0100
commit1199fae5574a45d095f3cef27d375221e890422f (patch)
tree52c9f7eee0411e8775f01fbac433e7dbeb39e98f /src/main/java/de/pixart/messenger/ui
parent423efa8c17d798e5c80785e2a67e85a97b084975 (diff)
fix NPE while sending images directly from GBoard
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java86
1 files changed, 51 insertions, 35 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 62f0dcdb3..efffb1d32 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -1411,7 +1411,7 @@ public class ConversationActivity extends XmppActivity
if (ImageUrisCount == 1) {
Uri uri = mPendingImageUris.get(0);
Log.d(Config.LOGTAG, "ConversationActivity.onBackendConnected() - attaching image to conversations. stopping=" + Boolean.toString(stopping));
- attachImageToConversation(getSelectedConversation(), uri);
+ attachImageToConversation(getSelectedConversation(), uri, false);
} else {
for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
Uri foo = i.next();
@@ -1577,7 +1577,7 @@ public class ConversationActivity extends XmppActivity
if (ImageUrisCount == 1) {
Uri uri = mPendingImageUris.get(0);
Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE");
- attachImageToConversation(getSelectedConversation(), uri);
+ attachImageToConversation(getSelectedConversation(), uri, false);
} else {
for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching images to conversations. CHOOSE_IMAGES");
@@ -1844,24 +1844,36 @@ public class ConversationActivity extends XmppActivity
}
public void attachImageToConversation(Uri uri) {
- this.attachImageToConversation(getSelectedConversation(), uri);
+ this.attachImageToConversation(getSelectedConversation(), uri, true);
}
- private void attachImageToConversation(Conversation conversation, Uri uri) {
+ private void attachImageToConversation(Conversation conversation, Uri uri, boolean sendAsIs) {
if (conversation == null) {
return;
}
+ if (sendAsIs) {
+ sendImage(conversation, uri);
+ return;
+ }
final Conversation conversation_preview = conversation;
final Uri uri_preview = uri;
Bitmap bitmap = BitmapFactory.decodeFile(FileUtils.getPath(this, uri));
- File file = new File(FileUtils.getPath(this, uri));
+ File file = null;
ExifInterface exif = null;
+ int orientation = 0;
try {
- exif = new ExifInterface(file.toString());
- } catch (IOException e) {
+ file = new File(FileUtils.getPath(this, uri));
+ } catch (Exception e) {
e.printStackTrace();
}
- int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
+ if (file != null) {
+ try {
+ exif = new ExifInterface(file.toString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
+ }
Log.d(Config.LOGTAG, "EXIF: " + orientation);
Bitmap rotated_image = null;
Log.d(Config.LOGTAG, "Rotate image");
@@ -1902,33 +1914,7 @@ public class ConversationActivity extends XmppActivity
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
- final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
- prepareFileToast.show();
- xmppConnectionService.attachImageToConversation(conversation_preview, uri_preview,
- new UiCallback<Message>() {
-
- @Override
- public void userInputRequried(PendingIntent pi, Message object) {
- hidePrepareFileToast(prepareFileToast);
- }
-
- @Override
- public void success(Message message) {
- hidePrepareFileToast(prepareFileToast);
- xmppConnectionService.sendMessage(message);
- }
-
- @Override
- public void error(final int error, Message message) {
- hidePrepareFileToast(prepareFileToast);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- replaceToast(getString(error));
- }
- });
- }
- });
+ sendImage(conversation_preview, uri_preview);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@@ -1952,6 +1938,36 @@ public class ConversationActivity extends XmppActivity
}
}
+ private void sendImage(Conversation conversation, Uri uri) {
+ final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
+ prepareFileToast.show();
+ xmppConnectionService.attachImageToConversation(conversation, uri,
+ new UiCallback<Message>() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Message object) {
+ hidePrepareFileToast(prepareFileToast);
+ }
+
+ @Override
+ public void success(Message message) {
+ hidePrepareFileToast(prepareFileToast);
+ xmppConnectionService.sendMessage(message);
+ }
+
+ @Override
+ public void error(final int error, Message message) {
+ hidePrepareFileToast(prepareFileToast);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ replaceToast(getString(error));
+ }
+ });
+ }
+ });
+ }
+
private void hidePrepareFileToast(final Toast prepareFileToast) {
if (prepareFileToast != null) {
runOnUiThread(new Runnable() {