"add contact" button for unknown contacts

Closes #1551
This commit is contained in:
Bastian Köcher 2014-06-04 01:24:44 +02:00 committed by Jake McGinty
parent b05967f2c9
commit 4a088410ae
11 changed files with 106 additions and 78 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1004 B

View File

@ -5,10 +5,6 @@
android:id="@+id/menu_add_attachment"
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_menu_friendslist" />
<item android:title="@string/conversation__menu_delete_thread"
android:id="@+id/menu_delete_thread"
android:icon="@android:drawable/ic_menu_delete" />

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_add_to_contacts"
android:title="@string/conversation_add_to_contacts__menu_add_to_contacts"
app:showAsAction="never" />
</menu>

View File

@ -54,6 +54,7 @@
<string name="AttachmentTypeSelectorAdapter_picture">Picture</string>
<string name="AttachmentTypeSelectorAdapter_video">Video</string>
<string name="AttachmentTypeSelectorAdapter_audio">Audio</string>
<string name="AttachmentTypeSelectorAdapter_contact">Contact info</string>
<!-- ConversationItem -->
<string name="ConversationItem_message_size_d_kb">Message size: %d KB</string>
@ -755,9 +756,11 @@
<string name="conversation__menu_add_attachment">Add attachment</string>
<string name="conversation__menu_update_group">Update group</string>
<string name="conversation__menu_leave_group">Leave group</string>
<string name="conversation__menu_add_contact_info">Add contact info</string>
<string name="conversation__menu_delete_thread">Delete thread</string>
<!-- conversation_callable -->
<string name="conversation_add_to_contacts__menu_add_to_contacts">Add to contacts</string>
<!-- conversation_group_options -->
<string name="convesation_group_options__recipients_list">Recipients list</string>
<string name="conversation_group_options__delivery">Delivery</string>

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);

View File

@ -33,11 +33,9 @@ import java.util.List;
public class AttachmentTypeSelectorAdapter extends ArrayAdapter<AttachmentTypeSelectorAdapter.IconListItem> {
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_VIDEO = 2;
public static final int ADD_SOUND = 3;
public static final int ADD_CONTACT_INFO = 4;
private final Context context;
@ -52,10 +50,8 @@ public class AttachmentTypeSelectorAdapter extends ArrayAdapter<AttachmentTypeSe
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView text;
ImageView image;
View view;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.icon_list_item, parent, false);
@ -63,26 +59,21 @@ public class AttachmentTypeSelectorAdapter extends ArrayAdapter<AttachmentTypeSe
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);
text.setText(getItem(position).getTitle());
image.setImageResource(getItem(position).getResource());
return view;
}
private static List<IconListItem> getItemList(Context context) {
List<IconListItem> data = new ArrayList<IconListItem>(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);
List<IconListItem> 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;
}
@ -92,13 +83,13 @@ public class AttachmentTypeSelectorAdapter extends ArrayAdapter<AttachmentTypeSe
}
public static class IconListItem {
private final String mTitle;
private final int mResource;
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.resource = resource;
this.title = title;
this.id = id;
}
@ -107,11 +98,11 @@ public class AttachmentTypeSelectorAdapter extends ArrayAdapter<AttachmentTypeSe
}
public String getTitle() {
return mTitle;
return title;
}
public int getResource() {
return mResource;
return resource;
}
}
}