aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java5
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java25
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java16
-rw-r--r--src/eu/siacs/conversations/ui/ChooseContactActivity.java9
-rw-r--r--src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java4
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java133
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java8
-rw-r--r--src/eu/siacs/conversations/ui/ShareWithActivity.java207
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java115
-rw-r--r--src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java22
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java4
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java34
12 files changed, 301 insertions, 281 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index 4c55d5ee..8dc9b3ca 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -141,9 +141,8 @@ public class Conversation extends AbstractEntity {
this.messages = msgs;
}
- public String getName(boolean useSubject) {
- if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null)
- && useSubject) {
+ public String getName() {
+ if (getMode() == MODE_MULTI && getMucOptions().getSubject() != null) {
return getMucOptions().getSubject();
} else if (getMode() == MODE_MULTI && bookmark != null
&& bookmark.getName() != null) {
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index 0af9c6e2..2b2aa86e 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -201,17 +201,20 @@ 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) {
+ try {
+ 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);
+ } catch (IllegalArgumentException e) {
return -1;
}
- cursor.moveToFirst();
- return cursor.getInt(0);
} else {
ExifInterface exif;
try {
@@ -376,6 +379,10 @@ public class FileBackend {
if (input == null) {
return null;
} else {
+ int rotation = getRotation(image);
+ if (rotation > 0) {
+ input = rotate(input, rotation);
+ }
return cropCenterSquare(input, size);
}
} catch (FileNotFoundException e) {
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 2656f7c6..98f278bd 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -784,10 +784,22 @@ public class XmppConnectionService extends Service {
return this.conversations;
}
-
+
public void populateWithOrderedConversations(List<Conversation> list) {
+ populateWithOrderedConversations(list,true);
+ }
+
+ public void populateWithOrderedConversations(List<Conversation> list, boolean includeConferences) {
list.clear();
- list.addAll(getConversations());
+ if (includeConferences) {
+ list.addAll(getConversations());
+ } else {
+ for(Conversation conversation : getConversations()) {
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ list.add(conversation);
+ }
+ }
+ }
Collections.sort(list, new Comparator<Conversation>() {
@Override
public int compare(Conversation lhs, Conversation rhs) {
diff --git a/src/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/eu/siacs/conversations/ui/ChooseContactActivity.java
index 83b20cb9..449fc546 100644
--- a/src/eu/siacs/conversations/ui/ChooseContactActivity.java
+++ b/src/eu/siacs/conversations/ui/ChooseContactActivity.java
@@ -95,8 +95,13 @@ public class ChooseContactActivity extends XmppActivity {
InputMethodManager.HIDE_IMPLICIT_ONLY);
Intent request = getIntent();
Intent data = new Intent();
- data.putExtra("contact", contacts.get(position).getJid());
- data.putExtra("account", request.getStringExtra("account"));
+ ListItem mListItem = contacts.get(position);
+ data.putExtra("contact", mListItem.getJid());
+ String account = request.getStringExtra("account");
+ if (account==null && mListItem instanceof Contact) {
+ account = ((Contact) mListItem).getAccount().getJid();
+ }
+ data.putExtra("account", account);
data.putExtra("conversation",
request.getStringExtra("conversation"));
setResult(RESULT_OK, data);
diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index 40c7eca8..2cfa1635 100644
--- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -109,7 +109,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
break;
case R.id.action_edit_subject:
if (conversation != null) {
- quickEdit(conversation.getName(true), new OnValueEdited() {
+ quickEdit(conversation.getName(), new OnValueEdited() {
@Override
public void onValueEdited(String value) {
@@ -200,7 +200,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
private void populateView() {
mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48));
- setTitle(conversation.getName(true));
+ setTitle(conversation.getName());
mFullJid.setText(conversation.getContactJid().split("/")[0]);
mYourNick.setText(conversation.getMucOptions().getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 6504f056..32c77fbe 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -1,10 +1,7 @@
package eu.siacs.conversations.ui;
-import java.io.FileNotFoundException;
-import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
@@ -15,9 +12,7 @@ import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.app.ActionBar;
import android.app.AlertDialog;
@@ -27,14 +22,8 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
-import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -46,7 +35,6 @@ import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
-import android.widget.ImageView;
import android.widget.Toast;
public class ConversationActivity extends XmppActivity {
@@ -75,8 +63,6 @@ public class ConversationActivity extends XmppActivity {
private ListView listView;
private boolean paneShouldBeOpen = true;
- private boolean useSubject = true;
- private boolean showLastseen = false;
private ArrayAdapter<Conversation> listAdapter;
private OnConversationUpdate onConvChanged = new OnConversationUpdate() {
@@ -108,7 +94,6 @@ public class ConversationActivity extends XmppActivity {
};
protected ConversationActivity activity = this;
- private DisplayMetrics metrics;
private Toast prepareImageToast;
private Uri pendingImageUri = null;
@@ -139,9 +124,6 @@ public class ConversationActivity extends XmppActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
-
- metrics = getResources().getDisplayMetrics();
-
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_conversations_overview);
@@ -196,8 +178,7 @@ public class ConversationActivity extends XmppActivity {
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
- ab.setTitle(getSelectedConversation().getName(
- useSubject));
+ ab.setTitle(getSelectedConversation().getName());
}
invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) {
@@ -576,10 +557,6 @@ public class ConversationActivity extends XmppActivity {
@Override
public void onStart() {
super.onStart();
- SharedPreferences preferences = PreferenceManager
- .getDefaultSharedPreferences(this);
- this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
- this.showLastseen = preferences.getBoolean("show_last_seen", false);
if (this.xmppConnectionServiceBound) {
this.onBackendConnected();
}
@@ -755,15 +732,6 @@ public class ConversationActivity extends XmppActivity {
listView.invalidateViews();
}
- public boolean showLastseen() {
- if (getSelectedConversation() == null) {
- return false;
- } else {
- return this.showLastseen
- && getSelectedConversation().getMode() == Conversation.MODE_SINGLE;
- }
- }
-
public void runIntent(PendingIntent pi, int requestCode) {
try {
this.startIntentSenderForResult(pi.getIntentSender(), requestCode,
@@ -772,105 +740,6 @@ public class ConversationActivity extends XmppActivity {
}
}
- class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
- private final WeakReference<ImageView> imageViewReference;
- private Message message = null;
-
- public BitmapWorkerTask(ImageView imageView) {
- imageViewReference = new WeakReference<ImageView>(imageView);
- }
-
- @Override
- protected Bitmap doInBackground(Message... params) {
- message = params[0];
- try {
- return xmppConnectionService.getFileBackend().getThumbnail(
- message, (int) (metrics.density * 288), false);
- } catch (FileNotFoundException e) {
- return null;
- }
- }
-
- @Override
- protected void onPostExecute(Bitmap bitmap) {
- if (imageViewReference != null && bitmap != null) {
- final ImageView imageView = imageViewReference.get();
- if (imageView != null) {
- imageView.setImageBitmap(bitmap);
- imageView.setBackgroundColor(0x00000000);
- }
- }
- }
- }
-
- public void loadBitmap(Message message, ImageView imageView) {
- Bitmap bm;
- try {
- bm = xmppConnectionService.getFileBackend().getThumbnail(message,
- (int) (metrics.density * 288), true);
- } catch (FileNotFoundException e) {
- bm = null;
- }
- if (bm != null) {
- imageView.setImageBitmap(bm);
- imageView.setBackgroundColor(0x00000000);
- } else {
- if (cancelPotentialWork(message, imageView)) {
- imageView.setBackgroundColor(0xff333333);
- final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
- final AsyncDrawable asyncDrawable = new AsyncDrawable(
- getResources(), null, task);
- imageView.setImageDrawable(asyncDrawable);
- try {
- task.execute(message);
- } catch (RejectedExecutionException e) {
- return;
- }
- }
- }
- }
-
- public static boolean cancelPotentialWork(Message message,
- ImageView imageView) {
- final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
-
- if (bitmapWorkerTask != null) {
- final Message oldMessage = bitmapWorkerTask.message;
- if (oldMessage == null || message != oldMessage) {
- bitmapWorkerTask.cancel(true);
- } else {
- return false;
- }
- }
- return true;
- }
-
- private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
- if (imageView != null) {
- final Drawable drawable = imageView.getDrawable();
- if (drawable instanceof AsyncDrawable) {
- final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
- return asyncDrawable.getBitmapWorkerTask();
- }
- }
- return null;
- }
-
- static class AsyncDrawable extends BitmapDrawable {
- private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
-
- public AsyncDrawable(Resources res, Bitmap bitmap,
- BitmapWorkerTask bitmapWorkerTask) {
- super(res, bitmap);
- bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>(
- bitmapWorkerTask);
- }
-
- public BitmapWorkerTask getBitmapWorkerTask() {
- return bitmapWorkerTaskReference.get();
- }
- }
-
public void encryptTextMessage(Message message) {
xmppConnectionService.getPgpEngine().encrypt(message,
new UiCallback<Message>() {
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index 77049e56..b0fd4a03 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -26,10 +26,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
-import android.content.SharedPreferences;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.Selection;
import android.view.Gravity;
@@ -67,7 +65,6 @@ public class ConversationFragment extends Fragment {
private TextView snackbarMessage;
private TextView snackbarAction;
- private boolean useSubject = true;
private boolean messagesLoaded = false;
private IntentSender askForPassphraseIntent = null;
@@ -301,9 +298,6 @@ public class ConversationFragment extends Fragment {
public void onStart() {
super.onStart();
this.activity = (ConversationActivity) getActivity();
- SharedPreferences preferences = PreferenceManager
- .getDefaultSharedPreferences(activity);
- this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (activity.xmppConnectionServiceBound) {
this.onBackendConnected();
}
@@ -344,7 +338,7 @@ public class ConversationFragment extends Fragment {
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
activity.getActionBar().setHomeButtonEnabled(true);
activity.getActionBar().setTitle(
- conversation.getName(useSubject));
+ conversation.getName());
activity.invalidateOptionsMenu();
}
}
diff --git a/src/eu/siacs/conversations/ui/ShareWithActivity.java b/src/eu/siacs/conversations/ui/ShareWithActivity.java
index 461aaec4..93831654 100644
--- a/src/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -1,37 +1,41 @@
package eu.siacs.conversations.ui;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
-import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.utils.UIHelper;
+import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import android.app.PendingIntent;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
-import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
import android.widget.Toast;
public class ShareWithActivity extends XmppActivity {
+
+ private class Share {
+ public Uri uri;
+ public String account;
+ public String contact;
+ public String text;
+ }
+
+ private Share share;
- private LinearLayout conversations;
- private LinearLayout contacts;
- private boolean isImage = false;
+ private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
+ private ListView mListView;
+ private List<Conversation> mConversations = new ArrayList<Conversation>();
private UiCallback<Message> attachImageCallback = new UiCallback<Message>() {
@@ -52,115 +56,107 @@ public class ShareWithActivity extends XmppActivity {
}
};
+
+ protected void onActivityResult(int requestCode, int resultCode,
+ final Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_START_NEW_CONVERSATION
+ && resultCode == RESULT_OK) {
+ share.contact = data.getStringExtra("contact");
+ share.account = data.getStringExtra("account");
+ Log.d(Config.LOGTAG,"contact: "+share.contact+" account:"+share.account);
+ }
+ if (xmppConnectionServiceBound && share != null && share.contact != null && share.account != null) {
+ share();
+ }
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ getActionBar().setDisplayHomeAsUpEnabled(false);
+ getActionBar().setHomeButtonEnabled(false);
+
setContentView(R.layout.share_with);
setTitle(getString(R.string.title_activity_sharewith));
- contacts = (LinearLayout) findViewById(R.id.contacts);
- conversations = (LinearLayout) findViewById(R.id.conversations);
+ mListView = (ListView) findViewById(R.id.choose_conversation_list);
+ ConversationAdapter mAdapter = new ConversationAdapter(this,
+ this.mConversations);
+ mListView.setAdapter(mAdapter);
+ mListView.setOnItemClickListener(new OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View arg1,
+ int position, long arg3) {
+ Conversation conversation = mConversations.get(position);
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ share(mConversations.get(position));
+ }
+ }
+ });
+
+ this.share = new Share();
}
-
- public View createContactView(String name, String msgTxt, Bitmap bm) {
- View view = (View) getLayoutInflater().inflate(R.layout.contact, null);
- view.setBackgroundResource(R.drawable.greybackground);
- TextView contactName = (TextView) view
- .findViewById(R.id.contact_display_name);
- contactName.setText(name);
- TextView msg = (TextView) view.findViewById(R.id.contact_jid);
- msg.setText(msgTxt);
- ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo);
- imageView.setImageBitmap(bm);
- return view;
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.share_with, menu);
+ return true;
}
@Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_add:
+ Intent intent = new Intent(getApplicationContext(),
+ ChooseContactActivity.class);
+ startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ if (getIntent().getType() != null && getIntent().getType()
+ .startsWith("image/")) {
+ this.share.uri = (Uri) getIntent().getParcelableExtra(
+ Intent.EXTRA_STREAM);
+ } else {
+ this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+ }
+ }
+
+ @Override
void onBackendConnected() {
- this.isImage = (getIntent().getType() != null && getIntent().getType()
- .startsWith("image/"));
- SharedPreferences preferences = PreferenceManager
- .getDefaultSharedPreferences(this);
- boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
-
- Set<Contact> displayedContacts = new HashSet<Contact>();
- conversations.removeAllViews();
- List<Conversation> convList = new ArrayList<Conversation>();
- xmppConnectionService.populateWithOrderedConversations(convList);
- Collections.sort(convList, new Comparator<Conversation>() {
- @Override
- public int compare(Conversation lhs, Conversation rhs) {
- return (int) (rhs.getLatestMessage().getTimeSent() - lhs
- .getLatestMessage().getTimeSent());
- }
- });
- for (final Conversation conversation : convList) {
- if (!isImage || conversation.getMode() == Conversation.MODE_SINGLE) {
- View view = createContactView(
- conversation.getName(useSubject),
- conversation.getLatestMessage().getBody().trim(),
- UIHelper.getContactPicture(conversation, 48,
- this.getApplicationContext(), false));
- view.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- share(conversation);
- }
- });
- conversations.addView(view);
- displayedContacts.add(conversation.getContact());
- }
+ if (xmppConnectionServiceBound && share != null && share.contact != null && share.account != null) {
+ share();
+ return;
}
- contacts.removeAllViews();
- List<Contact> contactsList = new ArrayList<Contact>();
- for (Account account : xmppConnectionService.getAccounts()) {
- for (Contact contact : account.getRoster().getContacts()) {
- if (!displayedContacts.contains(contact)
- && (contact.showInRoster())) {
- contactsList.add(contact);
- }
+ xmppConnectionService.populateWithOrderedConversations(mConversations,
+ false);
+ for (Conversation conversation : mConversations) {
+ if (conversation.getMode() == Conversation.MODE_MULTI) {
+ mConversations.remove(conversation);
}
}
-
- Collections.sort(contactsList, new Comparator<Contact>() {
- @Override
- public int compare(Contact lhs, Contact rhs) {
- return lhs.getDisplayName().compareToIgnoreCase(
- rhs.getDisplayName());
- }
- });
-
- for (int i = 0; i < contactsList.size(); ++i) {
- final Contact con = contactsList.get(i);
- View view = createContactView(
- con.getDisplayName(),
- con.getJid(),
- UIHelper.getContactPicture(con, 48,
- this.getApplicationContext(), false));
- view.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- Conversation conversation = xmppConnectionService
- .findOrCreateConversation(con.getAccount(),
- con.getJid(), false);
- share(conversation);
- }
- });
- contacts.addView(view);
+ }
+
+ private void share() {
+ Account account = xmppConnectionService.findAccountByJid(share.account);
+ if (account==null) {
+ return;
}
+ Conversation conversation = xmppConnectionService.findOrCreateConversation(account, share.contact, false);
+ share(conversation);
}
private void share(final Conversation conversation) {
- String sharedText = null;
- if (isImage) {
- final Uri uri = (Uri) getIntent().getParcelableExtra(
- Intent.EXTRA_STREAM);
+ if (share.uri != null) {
selectPresence(conversation, new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
@@ -168,7 +164,7 @@ public class ShareWithActivity extends XmppActivity {
getText(R.string.preparing_image),
Toast.LENGTH_LONG).show();
ShareWithActivity.this.xmppConnectionService
- .attachImageToConversation(conversation, uri,
+ .attachImageToConversation(conversation, share.uri,
attachImageCallback);
switchToConversation(conversation, null, true);
finish();
@@ -176,8 +172,7 @@ public class ShareWithActivity extends XmppActivity {
});
} else {
- sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
- switchToConversation(conversation, sharedText, true);
+ switchToConversation(conversation,this.share.text, true);
finish();
}
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index 11376eb7..78482658 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -1,5 +1,9 @@
package eu.siacs.conversations.ui;
+import java.io.FileNotFoundException;
+import java.lang.ref.WeakReference;
+import java.util.concurrent.RejectedExecutionException;
+
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
@@ -19,16 +23,23 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
+import android.content.res.Resources;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
+import android.widget.ImageView;
public abstract class XmppActivity extends Activity {
@@ -44,6 +55,8 @@ public abstract class XmppActivity extends Activity {
protected int mWarningTextColor;
protected int mPrimaryColor;
+ private DisplayMetrics metrics;
+
protected interface OnValueEdited {
public void onValueEdited(String value);
}
@@ -163,6 +176,7 @@ public abstract class XmppActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ metrics = getResources().getDisplayMetrics();
ExceptionHelper.init(getApplicationContext());
mPrimaryTextColor = getResources().getColor(R.color.primarytext);
mSecondaryTextColor = getResources().getColor(R.color.secondarytext);
@@ -370,7 +384,7 @@ public abstract class XmppActivity extends Activity {
xmppConnectionService.invite(conversation, contactJid);
}
Log.d(Config.LOGTAG, "inviting " + contactJid + " to "
- + conversation.getName(true));
+ + conversation.getName());
}
}
@@ -389,4 +403,103 @@ public abstract class XmppActivity extends Activity {
public int getPrimaryColor() {
return this.mPrimaryColor;
}
+
+ class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
+ private final WeakReference<ImageView> imageViewReference;
+ private Message message = null;
+
+ public BitmapWorkerTask(ImageView imageView) {
+ imageViewReference = new WeakReference<ImageView>(imageView);
+ }
+
+ @Override
+ protected Bitmap doInBackground(Message... params) {
+ message = params[0];
+ try {
+ return xmppConnectionService.getFileBackend().getThumbnail(
+ message, (int) (metrics.density * 288), false);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap bitmap) {
+ if (imageViewReference != null && bitmap != null) {
+ final ImageView imageView = imageViewReference.get();
+ if (imageView != null) {
+ imageView.setImageBitmap(bitmap);
+ imageView.setBackgroundColor(0x00000000);
+ }
+ }
+ }
+ }
+
+ public void loadBitmap(Message message, ImageView imageView) {
+ Bitmap bm;
+ try {
+ bm = xmppConnectionService.getFileBackend().getThumbnail(message,
+ (int) (metrics.density * 288), true);
+ } catch (FileNotFoundException e) {
+ bm = null;
+ }
+ if (bm != null) {
+ imageView.setImageBitmap(bm);
+ imageView.setBackgroundColor(0x00000000);
+ } else {
+ if (cancelPotentialWork(message, imageView)) {
+ imageView.setBackgroundColor(0xff333333);
+ final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
+ final AsyncDrawable asyncDrawable = new AsyncDrawable(
+ getResources(), null, task);
+ imageView.setImageDrawable(asyncDrawable);
+ try {
+ task.execute(message);
+ } catch (RejectedExecutionException e) {
+ return;
+ }
+ }
+ }
+ }
+
+ public static boolean cancelPotentialWork(Message message,
+ ImageView imageView) {
+ final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
+
+ if (bitmapWorkerTask != null) {
+ final Message oldMessage = bitmapWorkerTask.message;
+ if (oldMessage == null || message != oldMessage) {
+ bitmapWorkerTask.cancel(true);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
+ if (imageView != null) {
+ final Drawable drawable = imageView.getDrawable();
+ if (drawable instanceof AsyncDrawable) {
+ final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
+ return asyncDrawable.getBitmapWorkerTask();
+ }
+ }
+ return null;
+ }
+
+ static class AsyncDrawable extends BitmapDrawable {
+ private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
+
+ public AsyncDrawable(Resources res, Bitmap bitmap,
+ BitmapWorkerTask bitmapWorkerTask) {
+ super(res, bitmap);
+ bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>(
+ bitmapWorkerTask);
+ }
+
+ public BitmapWorkerTask getBitmapWorkerTask() {
+ return bitmapWorkerTaskReference.get();
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index fcc57601..c3ff5b22 100644
--- a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -6,6 +6,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity;
+import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.utils.UIHelper;
import android.content.Context;
import android.graphics.Color;
@@ -19,9 +20,9 @@ import android.widget.TextView;
public class ConversationAdapter extends ArrayAdapter<Conversation> {
- ConversationActivity activity;
+ private XmppActivity activity;
- public ConversationAdapter(ConversationActivity activity,
+ public ConversationAdapter(XmppActivity activity,
List<Conversation> conversations) {
super(activity, 0, conversations);
this.activity = activity;
@@ -36,18 +37,21 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
parent, false);
}
Conversation conv = getItem(position);
- if (!activity.getSlidingPaneLayout().isSlideable()) {
- if (conv == activity.getSelectedConversation()) {
- view.setBackgroundColor(0xffdddddd);
+ if (this.activity instanceof ConversationActivity) {
+ ConversationActivity activity = (ConversationActivity) this.activity;
+ if (!activity.getSlidingPaneLayout().isSlideable()) {
+ if (conv == activity.getSelectedConversation()) {
+ view.setBackgroundColor(0xffdddddd);
+ } else {
+ view.setBackgroundColor(Color.TRANSPARENT);
+ }
} else {
view.setBackgroundColor(Color.TRANSPARENT);
}
- } else {
- view.setBackgroundColor(Color.TRANSPARENT);
}
TextView convName = (TextView) view
.findViewById(R.id.conversation_name);
- convName.setText(conv.getName(true));
+ convName.setText(conv.getName());
TextView convLastMsg = (TextView) view
.findViewById(R.id.conversation_lastmsg);
ImageView imagePreview = (ImageView) view
@@ -59,7 +63,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|| latestMessage.getType() == Message.TYPE_PRIVATE) {
if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- convLastMsg.setText(conv.getLatestMessage().getBody());
+ convLastMsg.setText(UIHelper.transformAsciiEmoticons(conv.getLatestMessage().getBody()));
} else {
convLastMsg.setText(activity
.getText(R.string.encrypted_message_received));
diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 637711ab..08388ed8 100644
--- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -215,7 +215,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
if (message.getType() != Message.TYPE_PRIVATE) {
- viewHolder.messageBody.setText(message.getMergedBody());
+ viewHolder.messageBody.setText(UIHelper.transformAsciiEmoticons(message.getMergedBody()));
} else {
String privateMarker;
if (message.getStatus() <= Message.STATUS_RECEIVED) {
@@ -377,7 +377,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
@Override
public void onClick(View v) {
String name = item.getConversation()
- .getName(true);
+ .getName();
String read = getContext()
.getString(
R.string.contact_has_read_up_to_this_point,
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 1f584fe5..41724596 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -215,7 +215,7 @@ public class UIHelper {
List<User> members = conversation.getMucOptions().getUsers();
if (members.size() == 0) {
return getUnknownContactPicture(
- new String[] { conversation.getName(false) }, size,
+ new String[] { conversation.getName() }, size,
bgColor, fgColor);
}
ArrayList<String> names = new ArrayList<String>();
@@ -332,7 +332,6 @@ public class UIHelper {
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context);
- boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
boolean showNofifications = preferences.getBoolean("show_notification",
true);
boolean vibrate = preferences.getBoolean("vibrate_on_notification",
@@ -381,7 +380,7 @@ public class UIHelper {
Conversation conversation = unread.get(0);
targetUuid = conversation.getUuid();
mBuilder.setLargeIcon(conversation.getImage(context, 64));
- mBuilder.setContentTitle(conversation.getName(useSubject));
+ mBuilder.setContentTitle(conversation.getName());
if (notify) {
mBuilder.setTicker(conversation.getLatestMessage()
.getReadableBody(context));
@@ -413,12 +412,12 @@ public class UIHelper {
for (int i = 0; i < unread.size(); ++i) {
targetUuid = unread.get(i).getUuid();
if (i < unread.size() - 1) {
- names.append(unread.get(i).getName(useSubject) + ", ");
+ names.append(unread.get(i).getName() + ", ");
} else {
- names.append(unread.get(i).getName(useSubject));
+ names.append(unread.get(i).getName());
}
style.addLine(Html.fromHtml("<b>"
- + unread.get(i).getName(useSubject)
+ + unread.get(i).getName()
+ "</b> "
+ unread.get(i).getLatestMessage()
.getReadableBody(context)));
@@ -545,4 +544,27 @@ public class UIHelper {
return getContactPicture(account.getJid(), size, context, false);
}
}
+ public static String transformAsciiEmoticons(String body) {
+ if (body != null) {
+ for (String[] r: new String[][]{ // see https://de.wikipedia.org/wiki/Unicodeblock_Smileys
+ {":-?\\)", " 😀 ", },
+ {";-?\\)", " 😉 ", },
+ {":-?D", " 😃 ", },
+ {":-?[Ppb]", " 😋 ", },
+ {"8-?\\)", " 😎 ", },
+ {":-?\\|", " 😐 ", },
+ {":-?[/\\\\]", " 😕 ", },
+ {":-?\\*", " 😗 ", },
+ {":-?[0Oo]", " 😮 ", },
+ {":-?\\(", " 😞 ", },
+ {"\\^\\^", " 😁 ", },
+ }) {
+ String p = r[0];
+ p = "(^" + p + "$|^" + p + "\\s+|\\s+" + p + "\\s+|\\s+" + p + "$)";
+ body = body.replaceAll(p, r[1]);
+ }
+ body = body.trim();
+ }
+ return body;
+ }
}