Merge pull request #381 from meskio/add_contact

New 'add contact info' option on the conversation contextual menu
This commit is contained in:
Moxie Marlinspike 2013-10-20 16:58:58 -07:00
commit 891e3aeb97
4 changed files with 55 additions and 1 deletions

View File

@ -5,6 +5,10 @@
android:id="@+id/menu_add_attachment" android:id="@+id/menu_add_attachment"
android:icon="@drawable/ic_menu_attach" /> android:icon="@drawable/ic_menu_attach" />
<item android:title="@string/conversation__menu_add_contact_info"
android:id="@+id/menu_add_contact_info"
android:icon="@drawable/ic_contact_picture" />
<item android:title="@string/conversation__menu_delete_thread" <item android:title="@string/conversation__menu_delete_thread"
android:id="@+id/menu_delete_thread" android:id="@+id/menu_delete_thread"
android:icon="@android:drawable/ic_menu_delete" /> android:icon="@android:drawable/ic_menu_delete" />

View File

@ -54,6 +54,7 @@
<string name="ConversationActivity_delete_thread_confirmation">Delete Thread Confirmation</string> <string name="ConversationActivity_delete_thread_confirmation">Delete Thread Confirmation</string>
<string name="ConversationActivity_are_you_sure_that_you_want_to_permanently_delete_this_conversation_question">Are you sure that you want to permanently delete this conversation?</string> <string name="ConversationActivity_are_you_sure_that_you_want_to_permanently_delete_this_conversation_question">Are you sure that you want to permanently delete this conversation?</string>
<string name="ConversationActivity_add_attachment">Add attachment</string> <string name="ConversationActivity_add_attachment">Add attachment</string>
<string name="ConversationActivity_select_contact_info">Select contact info</string>
<string name="ConversationActivity_compose_message">Compose Message</string> <string name="ConversationActivity_compose_message">Compose Message</string>
<string name="ConversationActivity_sorry_there_was_an_error_setting_your_attachment">Sorry, there was an error setting your attachment.</string> <string name="ConversationActivity_sorry_there_was_an_error_setting_your_attachment">Sorry, there was an error setting your attachment.</string>
<string name="ConversationActivity_sorry_the_selected_video_exceeds_message_size_restrictions">Sorry, the selected video exceeds message size restrictions.</string> <string name="ConversationActivity_sorry_the_selected_video_exceeds_message_size_restrictions">Sorry, the selected video exceeds message size restrictions.</string>
@ -524,6 +525,7 @@
<!-- conversation --> <!-- conversation -->
<string name="conversation__menu_add_attachment">Add attachment</string> <string name="conversation__menu_add_attachment">Add attachment</string>
<string name="conversation__menu_add_contact_info">Add contact info</string>
<string name="conversation__menu_delete_thread">Delete thread</string> <string name="conversation__menu_delete_thread">Delete thread</string>
<!-- conversation_group_options --> <!-- conversation_group_options -->

View File

@ -30,6 +30,7 @@ import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
@ -54,6 +55,9 @@ import com.actionbarsherlock.view.MenuItem;
import org.thoughtcrime.securesms.components.EmojiDrawer; import org.thoughtcrime.securesms.components.EmojiDrawer;
import org.thoughtcrime.securesms.components.EmojiToggle; import org.thoughtcrime.securesms.components.EmojiToggle;
import org.thoughtcrime.securesms.components.RecipientsPanel; import org.thoughtcrime.securesms.components.RecipientsPanel;
import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator; import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator;
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor; import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
import org.thoughtcrime.securesms.crypto.KeyUtil; import org.thoughtcrime.securesms.crypto.KeyUtil;
@ -116,6 +120,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
private static final int PICK_IMAGE = 2; private static final int PICK_IMAGE = 2;
private static final int PICK_VIDEO = 3; private static final int PICK_VIDEO = 3;
private static final int PICK_AUDIO = 4; private static final int PICK_AUDIO = 4;
private static final int PICK_CONTACT_INFO = 5;
private MasterSecret masterSecret; private MasterSecret masterSecret;
private RecipientsPanel recipientsPanel; private RecipientsPanel recipientsPanel;
@ -219,6 +224,9 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
case PICK_AUDIO: case PICK_AUDIO:
addAttachmentAudio(data.getData()); addAttachmentAudio(data.getData());
break; break;
case PICK_CONTACT_INFO:
addContactInfo(data.getData());
break;
} }
} }
@ -262,6 +270,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_call: handleDial(getRecipients().getPrimaryRecipient()); return true; case R.id.menu_call: handleDial(getRecipients().getPrimaryRecipient()); return true;
case R.id.menu_delete_thread: handleDeleteThread(); return true; case R.id.menu_delete_thread: handleDeleteThread(); return true;
case R.id.menu_add_contact_info: handleAddContactInfo(); return true;
case R.id.menu_add_attachment: handleAddAttachment(); return true; case R.id.menu_add_attachment: handleAddAttachment(); return true;
case R.id.menu_start_secure_session: handleStartSecureSession(); return true; case R.id.menu_start_secure_session: handleStartSecureSession(); return true;
case R.id.menu_abort_session: handleAbortSecureSession(); return true; case R.id.menu_abort_session: handleAbortSecureSession(); return true;
@ -457,6 +466,11 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
builder.show(); builder.show();
} }
private void handleAddContactInfo() {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT_INFO);
}
private void handleAddAttachment() { private void handleAddAttachment() {
if (this.isMmsEnabled) { if (this.isMmsEnabled) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
@ -729,6 +743,35 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
} }
} }
private void addContactInfo(Uri contactUri) {
ContactAccessor contactDataList = ContactAccessor.getInstance();
ContactData contactData = contactDataList.getContactData(this, contactUri);
if (contactData.numbers.size() == 1) composeText.append(contactData.numbers.get(0).number);
else if (contactData.numbers.size() > 1) selectContactInfo(contactData);
}
private void selectContactInfo(ContactData contactData) {
final CharSequence[] numbers = new CharSequence[contactData.numbers.size()];
final CharSequence[] numberItems = new CharSequence[contactData.numbers.size()];
for (int i = 0; i < contactData.numbers.size(); i++) {
numbers[i] = contactData.numbers.get(i).number;
numberItems[i] = contactData.numbers.get(i).type + ": " + contactData.numbers.get(i).number;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_contact_picture);
builder.setTitle(R.string.ConversationActivity_select_contact_info);
builder.setItems(numberItems, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
composeText.append(numbers[which]);
}
});
builder.show();
}
private List<Draft> getDraftsForCurrentState() { private List<Draft> getDraftsForCurrentState() {
List<Draft> drafts = new LinkedList<Draft>(); List<Draft> drafts = new LinkedList<Draft>();

View File

@ -39,6 +39,7 @@ import org.thoughtcrime.securesms.crypto.InvalidKeyException;
import org.thoughtcrime.securesms.util.Base64; import org.thoughtcrime.securesms.util.Base64;
import java.io.IOException; import java.io.IOException;
import java.lang.Long;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -128,7 +129,11 @@ public class ContactAccessor {
return getContactData(context, return getContactData(context,
cursor.getString(cursor.getColumnIndexOrThrow(Contacts.DISPLAY_NAME)), cursor.getString(cursor.getColumnIndexOrThrow(Contacts.DISPLAY_NAME)),
cursor.getLong(cursor.getColumnIndexOrThrow(Contacts._ID))); cursor.getLong(cursor.getColumnIndexOrThrow(Contacts._ID)));
} }
public ContactData getContactData(Context context, Uri uri) {
return getContactData(context, getNameFromContact(context, uri), Long.parseLong(uri.getLastPathSegment()));
}
private ContactData getContactData(Context context, String displayName, long id) { private ContactData getContactData(Context context, String displayName, long id) {
ContactData contactData = new ContactData(id, displayName); ContactData contactData = new ContactData(id, displayName);