add custom phone number type

This commit is contained in:
agrajaghh 2014-05-14 22:58:49 +02:00 committed by Jake McGinty
parent d8cb893681
commit 0f9a6e6296
2 changed files with 11 additions and 2 deletions

View File

@ -68,6 +68,7 @@ public class ContactSelectionListAdapter extends CursorAdapter
private int NAME_COLUMN = -1;
private int NUMBER_COLUMN = -1;
private int NUMBER_TYPE_COLUMN = -1;
private int LABEL_COLUMN = -1;
private int ID_COLUMN = -1;
private final Context context;
@ -104,6 +105,7 @@ public class ContactSelectionListAdapter extends CursorAdapter
public String name;
public String number;
public int numberType;
public String label;
public long id;
}
@ -150,6 +152,7 @@ public class ContactSelectionListAdapter extends CursorAdapter
contactData.name = cursor.getString(NAME_COLUMN);
contactData.number = cursor.getString(NUMBER_COLUMN);
contactData.numberType = cursor.getInt(NUMBER_TYPE_COLUMN);
contactData.label = cursor.getString(LABEL_COLUMN);
contactData.id = cursor.getLong(ID_COLUMN);
if (contactData.type != ContactsDatabase.PUSH_TYPE) {
@ -175,7 +178,7 @@ public class ContactSelectionListAdapter extends CursorAdapter
holder.number.setText(contactData.number);
} else {
final CharSequence label = ContactsContract.CommonDataKinds.Phone.getTypeLabel(context.getResources(),
contactData.numberType, "");
contactData.numberType, contactData.label);
final CharSequence numberWithLabel = contactData.number + " " + label;
final Spannable numberLabelSpan = new SpannableString(numberWithLabel);
numberLabelSpan.setSpan(new ForegroundColorSpan(drawables.getColor(2, 0xff444444)), contactData.number.length(), numberWithLabel.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
@ -250,6 +253,7 @@ public class ContactSelectionListAdapter extends CursorAdapter
this.NAME_COLUMN = cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN);
this.NUMBER_COLUMN = cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN);
this.NUMBER_TYPE_COLUMN = cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN);
this.LABEL_COLUMN = cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN);
this.ID_COLUMN = cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN);
}
}

View File

@ -53,6 +53,7 @@ public class ContactsDatabase {
public static final String NAME_COLUMN = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME;
public static final String NUMBER_TYPE_COLUMN = ContactsContract.CommonDataKinds.Phone.TYPE;
public static final String NUMBER_COLUMN = ContactsContract.CommonDataKinds.Phone.NUMBER;
public static final String LABEL_COLUMN = ContactsContract.CommonDataKinds.Phone.LABEL;
public static final String TYPE_COLUMN = "type";
private static final String FILTER_SELECTION = NAME_COLUMN + " LIKE ? OR " + NUMBER_COLUMN + " LIKE ?";
@ -60,11 +61,13 @@ public class ContactsDatabase {
private static final String[] ANDROID_PROJECTION = new String[]{ID_COLUMN,
NAME_COLUMN,
NUMBER_TYPE_COLUMN,
LABEL_COLUMN,
NUMBER_COLUMN};
private static final String[] CONTACTS_PROJECTION = new String[]{ID_COLUMN,
NAME_COLUMN,
NUMBER_TYPE_COLUMN,
LABEL_COLUMN,
NUMBER_COLUMN,
TYPE_COLUMN};
@ -108,7 +111,7 @@ public class ContactsDatabase {
if (includeAndroidContacts && !Util.isEmpty(filter) && NumberUtil.isValidSmsOrEmail(filter)) {
newNumberCursor = new MatrixCursor(CONTACTS_PROJECTION, 1);
newNumberCursor.addRow(new Object[]{-1L, context.getString(R.string.contact_selection_list__unknown_contact),
0, filter, NORMAL_TYPE});
ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM, "\u21e2", filter, NORMAL_TYPE});
} else {
newNumberCursor = null;
}
@ -173,6 +176,7 @@ public class ContactsDatabase {
ID_COLUMN + " INTEGER PRIMARY KEY, " +
NAME_COLUMN + " TEXT, " +
NUMBER_TYPE_COLUMN + " INTEGER, " +
LABEL_COLUMN + " TEXT, " +
NUMBER_COLUMN + " TEXT, " +
TYPE_COLUMN + " INTEGER);";
@ -211,6 +215,7 @@ public class ContactsDatabase {
values.put(ID_COLUMN, user.id);
values.put(NAME_COLUMN, user.name);
values.put(NUMBER_TYPE_COLUMN, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM);
values.put(LABEL_COLUMN, (String)null);
values.put(NUMBER_COLUMN, user.numbers.get(0).number);
values.put(TYPE_COLUMN, PUSH_TYPE);
mDatabase.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);