aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/eu/siacs/conversations/crypto/PgpEngine.java37
-rw-r--r--src/eu/siacs/conversations/entities/Account.java2
-rw-r--r--src/eu/siacs/conversations/entities/Contact.java2
-rw-r--r--src/eu/siacs/conversations/generator/AbstractGenerator.java2
-rw-r--r--src/eu/siacs/conversations/parser/PresenceParser.java9
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java95
-rw-r--r--src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java7
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java24
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java2
-rw-r--r--src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java21
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java4
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java4
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java6
13 files changed, 146 insertions, 69 deletions
diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java
index 2d0c56e1..65b7ccc7 100644
--- a/src/eu/siacs/conversations/crypto/PgpEngine.java
+++ b/src/eu/siacs/conversations/crypto/PgpEngine.java
@@ -54,9 +54,18 @@ public class PgpEngine {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
- message.setBody(os.toString());
- message.setEncryption(Message.ENCRYPTION_DECRYPTED);
- callback.success(message);
+ try {
+ os.flush();
+ if (message.getEncryption() == Message.ENCRYPTION_PGP) {
+ message.setBody(os.toString());
+ message.setEncryption(Message.ENCRYPTION_DECRYPTED);
+ callback.success(message);
+ }
+ } catch (IOException e) {
+ callback.error(R.string.openpgp_error, message);
+ return;
+ }
+
return;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequried((PendingIntent) result
@@ -64,6 +73,8 @@ public class PgpEngine {
message);
return;
case OpenPgpApi.RESULT_CODE_ERROR:
+ OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
+ Log.d("xmppService",error.getMessage());
callback.error(R.string.openpgp_error, message);
return;
default:
@@ -153,14 +164,20 @@ public class PgpEngine {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,
OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
- StringBuilder encryptedMessageBody = new StringBuilder();
- String[] lines = os.toString().split("\n");
- for (int i = 3; i < lines.length - 1; ++i) {
- encryptedMessageBody.append(lines[i].trim());
+ try {
+ os.flush();
+ StringBuilder encryptedMessageBody = new StringBuilder();
+ String[] lines = os.toString().split("\n");
+ for (int i = 3; i < lines.length - 1; ++i) {
+ encryptedMessageBody.append(lines[i].trim());
+ }
+ message.setEncryptedBody(encryptedMessageBody
+ .toString());
+ callback.success(message);
+ } catch (IOException e) {
+ callback.error(R.string.openpgp_error, message);
}
- message.setEncryptedBody(encryptedMessageBody
- .toString());
- callback.success(message);
+
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
callback.userInputRequried((PendingIntent) result
diff --git a/src/eu/siacs/conversations/entities/Account.java b/src/eu/siacs/conversations/entities/Account.java
index a35acb8a..b734c6ee 100644
--- a/src/eu/siacs/conversations/entities/Account.java
+++ b/src/eu/siacs/conversations/entities/Account.java
@@ -326,7 +326,7 @@ public class Account extends AbstractEntity{
public Bitmap getImage(Context context, int size) {
if (this.avatar!=null) {
- Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar));
+ Bitmap bm = FileBackend.getAvatar(this.avatar, size, context);
if (bm==null) {
return UIHelper.getContactPicture(getJid(), size, context, false);
} else {
diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java
index db120200..47a3a0d7 100644
--- a/src/eu/siacs/conversations/entities/Contact.java
+++ b/src/eu/siacs/conversations/entities/Contact.java
@@ -321,7 +321,7 @@ public class Contact implements ListItem {
@Override
public Bitmap getImage(int size, Context context) {
if (this.avatar!=null) {
- Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar));
+ Bitmap bm = FileBackend.getAvatar(avatar, size, context);
if (bm==null) {
return UIHelper.getContactPicture(this, size, context, false);
} else {
diff --git a/src/eu/siacs/conversations/generator/AbstractGenerator.java b/src/eu/siacs/conversations/generator/AbstractGenerator.java
index 0de15092..d9839572 100644
--- a/src/eu/siacs/conversations/generator/AbstractGenerator.java
+++ b/src/eu/siacs/conversations/generator/AbstractGenerator.java
@@ -46,6 +46,6 @@ public abstract class AbstractGenerator {
s.append(feature+"<");
}
byte[] sha1 = md.digest(s.toString().getBytes());
- return new String(Base64.encode(sha1, Base64.DEFAULT));
+ return new String(Base64.encode(sha1, Base64.DEFAULT)).trim();
}
}
diff --git a/src/eu/siacs/conversations/parser/PresenceParser.java b/src/eu/siacs/conversations/parser/PresenceParser.java
index 3582653f..ea19df6f 100644
--- a/src/eu/siacs/conversations/parser/PresenceParser.java
+++ b/src/eu/siacs/conversations/parser/PresenceParser.java
@@ -24,16 +24,23 @@ public class PresenceParser extends AbstractParser implements
Conversation muc = mXmppConnectionService.find(account, packet
.getAttribute("from").split("/")[0]);
if (muc != null) {
+ boolean before = muc.getMucOptions().online();
muc.getMucOptions().processPacket(packet, mPgpEngine);
+ if (before!=muc.getMucOptions().online()) {
+ mXmppConnectionService.updateConversationUi();
+ }
}
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
Conversation muc = mXmppConnectionService.find(account, packet
.getAttribute("from").split("/")[0]);
if (muc != null) {
+ boolean before = muc.getMucOptions().online();
muc.getMucOptions().processPacket(packet, mPgpEngine);
+ if (before!=muc.getMucOptions().online()) {
+ mXmppConnectionService.updateConversationUi();
+ }
}
}
- mXmppConnectionService.updateConversationUi();
}
public void parseContactPresence(PresencePacket packet, Account account) {
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index c00b197b..4db46009 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -13,6 +13,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import android.content.Context;
+import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@@ -21,6 +22,7 @@ import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Environment;
+import android.provider.MediaStore;
import android.util.Base64;
import android.util.Base64OutputStream;
import android.util.Log;
@@ -30,6 +32,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.ImageProvider;
import eu.siacs.conversations.utils.CryptoHelper;
+import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.jingle.JingleFile;
import eu.siacs.conversations.xmpp.pep.Avatar;
@@ -158,21 +161,11 @@ public class FileBackend {
if (originalBitmap == null) {
throw new ImageCopyException(R.string.error_not_an_image_file);
}
- if (image == null) {
- getIncomingFile().delete();
- }
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
originalBitmap = null;
- ExifInterface exif = new ExifInterface(image.toString());
- if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
- .equalsIgnoreCase("6")) {
- scalledBitmap = rotate(scalledBitmap, 90);
- } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
- .equalsIgnoreCase("8")) {
- scalledBitmap = rotate(scalledBitmap, 270);
- } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
- .equalsIgnoreCase("3")) {
- scalledBitmap = rotate(scalledBitmap, 180);
+ int rotation = getRotation(image);
+ if (rotation > 0) {
+ scalledBitmap = rotate(scalledBitmap, rotation);
}
OutputStream os = new FileOutputStream(file);
boolean success = scalledBitmap.compress(
@@ -203,6 +196,38 @@ public class FileBackend {
}
}
}
+
+ private int getRotation(Uri image) {
+ if ("content".equals(image.getScheme())) {
+ Cursor cursor = context.getContentResolver().query(image,
+ new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
+
+ if (cursor.getCount() != 1) {
+ return -1;
+ }
+ cursor.moveToFirst();
+ return cursor.getInt(0);
+ } else {
+ ExifInterface exif;
+ try {
+ exif = new ExifInterface(image.toString());
+ if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("6")) {
+ return 90;
+ } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("8")) {
+ return 270;
+ } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("3")) {
+ return 180;
+ } else {
+ return 0;
+ }
+ } catch (IOException e) {
+ return -1;
+ }
+ }
+ }
public Bitmap getImageFromMessage(Message message) {
return BitmapFactory.decodeFile(getJingleFile(message)
@@ -330,26 +355,30 @@ public class FileBackend {
InputStream is = context.getContentResolver()
.openInputStream(image);
Bitmap input = BitmapFactory.decodeStream(is, null, options);
- int w = input.getWidth();
- int h = input.getHeight();
-
- float scale = Math.max((float) size / h, (float) size / w);
-
- float outWidth = scale * w;
- float outHeight = scale * h;
- float left = (size - outWidth) / 2;
- float top = (size - outHeight) / 2;
- RectF target = new RectF(left, top, left + outWidth, top
- + outHeight);
-
- Bitmap output = Bitmap.createBitmap(size, size, input.getConfig());
- Canvas canvas = new Canvas(output);
- canvas.drawBitmap(input, null, target, null);
- return output;
+ return cropCenterSquare(input, size);
} catch (FileNotFoundException e) {
return null;
}
}
+
+ public static Bitmap cropCenterSquare(Bitmap input, int size) {
+ int w = input.getWidth();
+ int h = input.getHeight();
+
+ float scale = Math.max((float) size / h, (float) size / w);
+
+ float outWidth = scale * w;
+ float outHeight = scale * h;
+ float left = (size - outWidth) / 2;
+ float top = (size - outHeight) / 2;
+ RectF target = new RectF(left, top, left + outWidth, top
+ + outHeight);
+
+ Bitmap output = Bitmap.createBitmap(size, size, input.getConfig());
+ Canvas canvas = new Canvas(output);
+ canvas.drawBitmap(input, null, target, null);
+ return output;
+ }
private int calcSampleSize(Uri image, int size)
throws FileNotFoundException {
@@ -395,4 +424,12 @@ public class FileBackend {
return resId;
}
}
+
+ public static Bitmap getAvatar(String avatar, int size, Context context) {
+ Bitmap bm = BitmapFactory.decodeFile(FileBackend.getAvatarPath(context, avatar));
+ if (bm==null) {
+ return null;
+ }
+ return cropCenterSquare(bm, UIHelper.getRealPx(size, context));
+ }
}
diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index c22dd26f..c33277f9 100644
--- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -199,8 +199,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
}
private void populateView() {
- mYourPhoto.setImageBitmap(UIHelper.getContactPicture(conversation
- .getMucOptions().getActualNick(), 48, this, false));
+ mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48));
setTitle(conversation.getName(true));
mFullJid.setText(conversation.getContactJid().split("/")[0]);
mYourNick.setText(conversation.getMucOptions().getActualNick());
@@ -234,7 +233,6 @@ public class ConferenceDetailsActivity extends XmppActivity {
.findViewById(R.id.contact_display_name);
TextView key = (TextView) view.findViewById(R.id.key);
TextView role = (TextView) view.findViewById(R.id.contact_jid);
- role.setText(getReadableRole(user.getRole()));
if (user.getPgpKeyId() != 0) {
key.setVisibility(View.VISIBLE);
key.setOnClickListener(new OnClickListener() {
@@ -252,15 +250,18 @@ public class ConferenceDetailsActivity extends XmppActivity {
if (contact.showInRoster()) {
bm = contact.getImage(48, this);
name.setText(contact.getDisplayName());
+ role.setText(user.getName() + " \u2022 " + getReadableRole(user.getRole()));
} else {
bm = UIHelper.getContactPicture(user.getName(), 48, this,
false);
name.setText(user.getName());
+ role.setText(getReadableRole(user.getRole()));
}
} else {
bm = UIHelper
.getContactPicture(user.getName(), 48, this, false);
name.setText(user.getName());
+ role.setText(getReadableRole(user.getRole()));
}
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
iv.setImageBitmap(bm);
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index ab7ece23..b3aed2e4 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -62,17 +62,17 @@ public class ConversationActivity extends XmppActivity {
public static final String TEXT = "text";
public static final String PRESENCE = "eu.siacs.conversations.presence";
- public static final int REQUEST_SEND_MESSAGE = 0x75441;
- public static final int REQUEST_DECRYPT_PGP = 0x76783;
- private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502;
- private static final int REQUEST_IMAGE_CAPTURE = 0x33788;
- private static final int REQUEST_RECORD_AUDIO = 0x46189;
- private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
- public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
-
- private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x92734;
- private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x84123;
- private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x75291;
+ public static final int REQUEST_SEND_MESSAGE = 0x0201;
+ public static final int REQUEST_DECRYPT_PGP = 0x0202;
+ private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0203;
+ private static final int REQUEST_IMAGE_CAPTURE = 0x0204;
+ private static final int REQUEST_RECORD_AUDIO = 0x0205;
+ private static final int REQUEST_SEND_PGP_IMAGE = 0x0206;
+ public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
+
+ private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
+ private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
+ private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303;
protected SlidingPaneLayout spl;
@@ -768,7 +768,7 @@ public class ConversationActivity extends XmppActivity {
}
private void attachAudioToConversation(Conversation conversation, Uri uri) {
-
+
}
private void attachImageToConversation(Conversation conversation, Uri uri) {
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index fced1e38..1270d23a 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -499,7 +499,9 @@ public class ConversationFragment extends Fragment {
protected void showSnackbar(int message, int action,
OnClickListener clickListener) {
snackbar.setVisibility(View.VISIBLE);
+ snackbar.setOnClickListener(null);
snackbarMessage.setText(message);
+ snackbarMessage.setOnClickListener(null);
snackbarAction.setText(action);
snackbarAction.setOnClickListener(clickListener);
}
diff --git a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
index 0661f1a9..434d1d4d 100644
--- a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -154,16 +154,23 @@ public class PublishProfilePictureActivity extends XmppActivity {
this.support = this.account.getXmppConnection().getFeatures().pubsub();
}
if (this.avatarUri == null) {
- if (this.account.getAvatar() != null) {
+ if (this.account.getAvatar() != null || this.defaultUri == null) {
this.avatar.setImageBitmap(this.account.getImage(
getApplicationContext(), 384));
- this.avatar
- .setOnLongClickListener(this.backToDefaultListener);
- } else {
if (this.defaultUri != null) {
- this.avatarUri = this.defaultUri;
- loadImageIntoPreview(this.defaultUri);
+ this.avatar
+ .setOnLongClickListener(this.backToDefaultListener);
+ } else {
+ this.secondaryHint.setVisibility(View.INVISIBLE);
}
+ if (!support) {
+ this.hintOrWarning.setTextColor(getWarningTextColor());
+ this.hintOrWarning.setText(R.string.error_publish_avatar_no_server_support);
+ }
+ } else {
+ this.avatarUri = this.defaultUri;
+ loadImageIntoPreview(this.defaultUri);
+ this.secondaryHint.setVisibility(View.INVISIBLE);
}
} else {
loadImageIntoPreview(avatarUri);
@@ -191,7 +198,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (this.defaultUri != null && uri.equals(this.defaultUri)) {
this.secondaryHint.setVisibility(View.INVISIBLE);
this.avatar.setOnLongClickListener(null);
- } else {
+ } else if (this.defaultUri != null ) {
this.secondaryHint.setVisibility(View.VISIBLE);
this.avatar.setOnLongClickListener(this.backToDefaultListener);
}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index 592430c5..32750b98 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -31,8 +31,8 @@ import android.widget.EditText;
public abstract class XmppActivity extends Activity {
- public static final int REQUEST_ANNOUNCE_PGP = 0x73731;
- protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x341830;
+ protected static final int REQUEST_ANNOUNCE_PGP = 0x0101;
+ protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102;
protected final static String LOGTAG = "xmppService";
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 46a91154..335b471a 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -15,6 +15,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions.User;
+import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.ManageAccountActivity;
import android.app.Activity;
@@ -376,8 +377,7 @@ public class UIHelper {
} else if (unread.size() == 1) {
Conversation conversation = unread.get(0);
targetUuid = conversation.getUuid();
- mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation, 64,
- context, true));
+ mBuilder.setLargeIcon(conversation.getImage(context, 64));
mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) {
mBuilder.setTicker(conversation.getLatestMessage()
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index b1f580d8..d8c9f4b9 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -416,8 +416,14 @@ public class XmppConnection implements Runnable {
NoSuchAlgorithmException {
tagReader.readTag(); // read tag close
+ if (!tagWriter.isActive()) {
+ throw new IOException();
+ }
tagWriter.setOutputStream(new ZLibOutputStream(tagWriter
.getOutputStream()));
+ if (tagReader.getInputStream() == null) {
+ throw new IOException();
+ }
tagReader
.setInputStream(new ZLibInputStream(tagReader.getInputStream()));