diff --git a/res/drawable-hdpi/ic_action_person.png b/res/drawable-hdpi/ic_action_person.png new file mode 100644 index 0000000000..9fd81097ba Binary files /dev/null and b/res/drawable-hdpi/ic_action_person.png differ diff --git a/res/drawable-mdpi/ic_action_person.png b/res/drawable-mdpi/ic_action_person.png new file mode 100644 index 0000000000..359da1c124 Binary files /dev/null and b/res/drawable-mdpi/ic_action_person.png differ diff --git a/res/drawable-xhdpi/ic_action_person.png b/res/drawable-xhdpi/ic_action_person.png new file mode 100644 index 0000000000..03eeb8d6a6 Binary files /dev/null and b/res/drawable-xhdpi/ic_action_person.png differ diff --git a/res/drawable-xxhdpi/ic_action_person.png b/res/drawable-xxhdpi/ic_action_person.png new file mode 100644 index 0000000000..fd1bcdd453 Binary files /dev/null and b/res/drawable-xxhdpi/ic_action_person.png differ diff --git a/res/menu/conversation.xml b/res/menu/conversation.xml index 90df2dfd30..a95d63fff0 100644 --- a/res/menu/conversation.xml +++ b/res/menu/conversation.xml @@ -5,10 +5,6 @@ android:id="@+id/menu_add_attachment" android:icon="@drawable/ic_menu_attach" /> - - diff --git a/res/menu/conversation_add_to_contacts.xml b/res/menu/conversation_add_to_contacts.xml new file mode 100644 index 0000000000..498dfb4692 --- /dev/null +++ b/res/menu/conversation_add_to_contacts.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index e092f940fa..7753ab4029 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -54,6 +54,7 @@ Picture Video Audio + Contact info Message size: %d KB @@ -755,9 +756,11 @@ Add attachment Update group Leave group - Add contact info Delete thread + + Add to contacts + Recipients list Delivery diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 458a322c0f..fd16b96615 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -245,7 +245,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity addAttachmentAudio(data.getData()); break; case PICK_CONTACT_INFO: - addContactInfo(data.getData()); + addAttachmentContactInfo(data.getData()); break; case GROUP_EDIT: this.recipients = data.getParcelableExtra(GroupCreateActivity.GROUP_RECIPIENT_EXTRA); @@ -286,6 +286,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } inflater.inflate(R.menu.conversation, menu); + + if (isSingleConversation() && getRecipients().getPrimaryRecipient().getContactUri() == null) { + inflater.inflate(R.menu.conversation_add_to_contacts, menu); + } + super.onPrepareOptionsMenu(menu); return true; } @@ -296,8 +301,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity switch (item.getItemId()) { case R.id.menu_call: handleDial(getRecipients().getPrimaryRecipient()); 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_to_contacts: handleAddToContacts(); 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_verify_identity: handleVerifyIdentity(); return true; @@ -561,9 +566,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity builder.show(); } - private void handleAddContactInfo() { - Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); - startActivityForResult(intent, PICK_CONTACT_INFO); + private void handleAddToContacts() { + final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber()); + intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); + startActivity(intent); } private void handleAddAttachment() { @@ -840,6 +847,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity AttachmentManager.selectVideo(this, PICK_VIDEO); break; case AttachmentTypeSelectorAdapter.ADD_SOUND: AttachmentManager.selectAudio(this, PICK_AUDIO); break; + case AttachmentTypeSelectorAdapter.ADD_CONTACT_INFO: + AttachmentManager.selectContactInfo(this, PICK_CONTACT_INFO); break; } } @@ -886,7 +895,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } } - private void addContactInfo(Uri contactUri) { + private void addAttachmentContactInfo(Uri contactUri) { ContactAccessor contactDataList = ContactAccessor.getInstance(); ContactData contactData = contactDataList.getContactData(this, contactUri); @@ -1176,6 +1185,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } } + private class AddContactButtonListener implements OnClickListener { + @Override + public void onClick(View v) { + final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber()); + intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); + startActivity(intent); + } + } + private class ComposeKeyPressedListener implements OnKeyListener, OnClickListener, TextWatcher, OnFocusChangeListener { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index 6db7dd0f54..8af0bf5198 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -29,6 +29,7 @@ import android.net.Uri; import android.os.Handler; import android.os.Message; import android.provider.Contacts.Intents; +import android.provider.ContactsContract; import android.provider.ContactsContract.QuickContact; import android.util.AttributeSet; import android.util.Log; @@ -423,7 +424,9 @@ public class ConversationItem extends LinearLayout { if (recipient.getContactUri() != null) { QuickContact.showQuickContact(context, contactPhoto, recipient.getContactUri(), QuickContact.MODE_LARGE, null); } else { - Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, Uri.fromParts("tel", recipient.getNumber(), null)); + final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber()); + intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); context.startActivity(intent); } } diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java index 3e32b4e260..92d174111d 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; import android.util.Log; +import android.provider.ContactsContract; import android.view.View; import android.widget.Button; import android.widget.ImageView; @@ -104,6 +105,11 @@ public class AttachmentManager { selectMediaType(activity, "audio/*", requestCode); } + public static void selectContactInfo(Activity activity, int requestCode) { + Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI); + activity.startActivityForResult(intent, requestCode); + } + private static void selectMediaType(Activity activity, String type, int requestCode) { final Intent intent = new Intent(); intent.setType(type); diff --git a/src/org/thoughtcrime/securesms/mms/AttachmentTypeSelectorAdapter.java b/src/org/thoughtcrime/securesms/mms/AttachmentTypeSelectorAdapter.java index e91b0f3ca7..0ff18a1db8 100644 --- a/src/org/thoughtcrime/securesms/mms/AttachmentTypeSelectorAdapter.java +++ b/src/org/thoughtcrime/securesms/mms/AttachmentTypeSelectorAdapter.java @@ -32,86 +32,77 @@ import java.util.List; public class AttachmentTypeSelectorAdapter extends ArrayAdapter { - public static final int ADD_IMAGE = 1; -// public static final int TAKE_PICTURE = 2; - public static final int ADD_VIDEO = 3; -// public static final int RECORD_VIDEO = 4; - public static final int ADD_SOUND = 5; -// public static final int RECORD_SOUND = 6; + public static final int ADD_IMAGE = 1; + public static final int ADD_VIDEO = 2; + public static final int ADD_SOUND = 3; + public static final int ADD_CONTACT_INFO = 4; - private final Context context; + private final Context context; - public AttachmentTypeSelectorAdapter(Context context) { - super(context, R.layout.icon_list_item, getItemList(context)); - this.context = context; - } + public AttachmentTypeSelectorAdapter(Context context) { + super(context, R.layout.icon_list_item, getItemList(context)); + this.context = context; + } - public int buttonToCommand(int position) { - return getItem(position).getCommand(); - } + public int buttonToCommand(int position) { + return getItem(position).getCommand(); + } - @Override - public View getView(int position, View convertView, ViewGroup parent) { - TextView text; - ImageView image; + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view; - View view; - if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflater.inflate(R.layout.icon_list_item, parent, false); - } else { - view = convertView; - } + if (convertView == null) { + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = inflater.inflate(R.layout.icon_list_item, parent, false); + } else { + view = convertView; + } - text = (TextView) view.findViewById(R.id.text1); - text.setText(getItem(position).getTitle()); + TextView text = (TextView) view.findViewById(R.id.text1); + ImageView image = (ImageView) view.findViewById(R.id.icon); - image = (ImageView) view.findViewById(R.id.icon); - image.setImageResource(getItem(position).getResource()); + text.setText(getItem(position).getTitle()); + image.setImageResource(getItem(position).getResource()); - return view; - } + return view; + } - private static List getItemList(Context context) { - List data = new ArrayList(7); - addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_picture), - R.drawable.ic_attach_picture_holo_light, ADD_IMAGE); -// addItem(data, "Capture picture", R.drawable.ic_launcher_camera, TAKE_PICTURE); - addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_video), - R.drawable.ic_attach_video_holo_light, ADD_VIDEO); -// addItem(data, "Capture video", R.drawable.ic_launcher_camera_record, RECORD_VIDEO); - addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_audio), - R.drawable.ic_attach_audio_holo_light, ADD_SOUND); -// addItem(data, "Record audio", R.drawable.ic_launcher_record_audio, RECORD_SOUND); + private static List getItemList(Context context) { + List data = new ArrayList<>(4); + addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_picture), R.drawable.ic_attach_picture_holo_light, ADD_IMAGE); + addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_video), R.drawable.ic_attach_video_holo_light, ADD_VIDEO); + addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_audio), R.drawable.ic_attach_audio_holo_light, ADD_SOUND); + addItem(data, context.getString(R.string.AttachmentTypeSelectorAdapter_contact), R.drawable.ic_action_person, ADD_CONTACT_INFO); - return data; - } + return data; + } - private static void addItem(List list, String text, int resource, int id) { - list.add(new IconListItem(text, resource, id)); - } + private static void addItem(List list, String text, int resource, int id) { + list.add(new IconListItem(text, resource, id)); + } - public static class IconListItem { - private final String mTitle; - private final int mResource; - private final int id; + public static class IconListItem { + private final String title; + private final int resource; + private final int id; - public IconListItem(String title, int resource, int id) { - mResource = resource; - mTitle = title; - this.id = id; - } + public IconListItem(String title, int resource, int id) { + this.resource = resource; + this.title = title; + this.id = id; + } - public int getCommand() { - return id; - } + public int getCommand() { + return id; + } - public String getTitle() { - return mTitle; - } + public String getTitle() { + return title; + } - public int getResource() { - return mResource; - } - } + public int getResource() { + return resource; + } + } }