首页 > 代码库 > android 如何将电话簿中SDN号码和其他普通号码混合放在一起?
android 如何将电话簿中SDN号码和其他普通号码混合放在一起?
原始默认设计会将SDN单独分出来,小标题为"SDN",
通过如下修改可以达到SDN和普通号码一样排列在一起,按首字母顺序排列。
DefaultContactListAdapter.java 的 configureSelection() 方法中
对 selection 为 IS_SDN_CONTACT + " < 1" 的如下语句注解掉(总共有五处):
/**
* M: New Feature SDN <br>
* Origin code: <br>
* private void configureSelection(<br>
* @{
*/
protected void configureSelection(
CursorLoader loader, long directoryId, ContactListFilter filter) {
if (filter == null) {
return;
}
if (directoryId != Directory.DEFAULT) {
return;
}
StringBuilder selection = new StringBuilder();
List<String> selectionArgs = new ArrayList<String>();
switch (filter.filterType) {
case ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS: {
// We have already added directory=0 to the URI, which takes care of this
// filter
/** M: New Feature SDN @{ */
// 1 selection.append(RawContacts.IS_SDN_CONTACT + " < 1");
selection.append(RawContacts.IS_SDN_CONTACT + " < 2");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_SINGLE_CONTACT: {
// We have already added the lookup key to the URI, which takes care of this
// filter
break;
}
case ContactListFilter.FILTER_TYPE_STARRED: {
selection.append(Contacts.STARRED + "!=0");
break;
}
case ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY: {
selection.append(Contacts.HAS_PHONE_NUMBER + "=1");
/** M: New Feature SDN @{ */
// 2 selection.append(" AND " + RawContacts.IS_SDN_CONTACT + " < 1");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_CUSTOM: {
selection.append(Contacts.IN_VISIBLE_GROUP + "=1");
if (isCustomFilterForPhoneNumbersOnly()) {
selection.append(" AND " + Contacts.HAS_PHONE_NUMBER + "=1");
}
/** M: New Feature SDN @{ */
// 3 selection.append(" AND " + RawContacts.IS_SDN_CONTACT + " < 1");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_ACCOUNT: {
// We use query parameters for account filter, so no selection to add here.
/** M: Change Feature: As Local Phone account contains null account and Phone
* Account, the Account Query Parameter could not meet this requirement. So,
* We should keep to query contacts with selection. @{ */
if (AccountType.ACCOUNT_TYPE_LOCAL_PHONE.equals(filter.accountType)) {
selection.append("EXISTS ("
+ "SELECT DISTINCT " + RawContacts.CONTACT_ID
+ " FROM view_raw_contacts"
+ " WHERE ( ");
// 4 selection.append(RawContacts.IS_SDN_CONTACT + " < 1 AND ");
selection.append(RawContacts.CONTACT_ID + " = " + "view_contacts."
+ Contacts._ID
+ " AND (" + RawContacts.ACCOUNT_TYPE + " IS NULL "
+ " AND " + RawContacts.ACCOUNT_NAME + " IS NULL "
+ " AND " + RawContacts.DATA_SET + " IS NULL "
+ " OR " + RawContacts.ACCOUNT_TYPE + "=? "
+ " AND " + RawContacts.ACCOUNT_NAME + "=? ");
} else {
selection.append("EXISTS ("
+ "SELECT DISTINCT " + RawContacts.CONTACT_ID
+ " FROM view_raw_contacts"
+ " WHERE ( ");
// 5 selection.append(RawContacts.IS_SDN_CONTACT + " < 1 AND ");
selection.append(RawContacts.CONTACT_ID + " = " + "view_contacts."
+ Contacts._ID
+ " AND (" + RawContacts.ACCOUNT_TYPE + "=?"
+ " AND " + RawContacts.ACCOUNT_NAME + "=?");
}
selectionArgs.add(filter.accountType);
selectionArgs.add(filter.accountName);
if (filter.dataSet != null) {
selection.append(" AND " + RawContacts.DATA_SET + "=? )");
selectionArgs.add(filter.dataSet);
} else {
selection.append(" AND " + RawContacts.DATA_SET + " IS NULL )");
}
selection.append("))");
/** @} */
break;
}
}
/// M: Log the selection string.
Log.d(TAG, "[configureSelection] selection: " + selection.toString());
loader.setSelection(selection.toString());
loader.setSelectionArgs(selectionArgs.toArray(new String[0]));
}
通过如下修改可以达到SDN和普通号码一样排列在一起,按首字母顺序排列。
DefaultContactListAdapter.java 的 configureSelection() 方法中
对 selection 为 IS_SDN_CONTACT + " < 1" 的如下语句注解掉(总共有五处):
/**
* M: New Feature SDN <br>
* Origin code: <br>
* private void configureSelection(<br>
* @{
*/
protected void configureSelection(
CursorLoader loader, long directoryId, ContactListFilter filter) {
if (filter == null) {
return;
}
if (directoryId != Directory.DEFAULT) {
return;
}
StringBuilder selection = new StringBuilder();
List<String> selectionArgs = new ArrayList<String>();
switch (filter.filterType) {
case ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS: {
// We have already added directory=0 to the URI, which takes care of this
// filter
/** M: New Feature SDN @{ */
// 1 selection.append(RawContacts.IS_SDN_CONTACT + " < 1");
selection.append(RawContacts.IS_SDN_CONTACT + " < 2");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_SINGLE_CONTACT: {
// We have already added the lookup key to the URI, which takes care of this
// filter
break;
}
case ContactListFilter.FILTER_TYPE_STARRED: {
selection.append(Contacts.STARRED + "!=0");
break;
}
case ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY: {
selection.append(Contacts.HAS_PHONE_NUMBER + "=1");
/** M: New Feature SDN @{ */
// 2 selection.append(" AND " + RawContacts.IS_SDN_CONTACT + " < 1");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_CUSTOM: {
selection.append(Contacts.IN_VISIBLE_GROUP + "=1");
if (isCustomFilterForPhoneNumbersOnly()) {
selection.append(" AND " + Contacts.HAS_PHONE_NUMBER + "=1");
}
/** M: New Feature SDN @{ */
// 3 selection.append(" AND " + RawContacts.IS_SDN_CONTACT + " < 1");
/** @} */
break;
}
case ContactListFilter.FILTER_TYPE_ACCOUNT: {
// We use query parameters for account filter, so no selection to add here.
/** M: Change Feature: As Local Phone account contains null account and Phone
* Account, the Account Query Parameter could not meet this requirement. So,
* We should keep to query contacts with selection. @{ */
if (AccountType.ACCOUNT_TYPE_LOCAL_PHONE.equals(filter.accountType)) {
selection.append("EXISTS ("
+ "SELECT DISTINCT " + RawContacts.CONTACT_ID
+ " FROM view_raw_contacts"
+ " WHERE ( ");
// 4 selection.append(RawContacts.IS_SDN_CONTACT + " < 1 AND ");
selection.append(RawContacts.CONTACT_ID + " = " + "view_contacts."
+ Contacts._ID
+ " AND (" + RawContacts.ACCOUNT_TYPE + " IS NULL "
+ " AND " + RawContacts.ACCOUNT_NAME + " IS NULL "
+ " AND " + RawContacts.DATA_SET + " IS NULL "
+ " OR " + RawContacts.ACCOUNT_TYPE + "=? "
+ " AND " + RawContacts.ACCOUNT_NAME + "=? ");
} else {
selection.append("EXISTS ("
+ "SELECT DISTINCT " + RawContacts.CONTACT_ID
+ " FROM view_raw_contacts"
+ " WHERE ( ");
// 5 selection.append(RawContacts.IS_SDN_CONTACT + " < 1 AND ");
selection.append(RawContacts.CONTACT_ID + " = " + "view_contacts."
+ Contacts._ID
+ " AND (" + RawContacts.ACCOUNT_TYPE + "=?"
+ " AND " + RawContacts.ACCOUNT_NAME + "=?");
}
selectionArgs.add(filter.accountType);
selectionArgs.add(filter.accountName);
if (filter.dataSet != null) {
selection.append(" AND " + RawContacts.DATA_SET + "=? )");
selectionArgs.add(filter.dataSet);
} else {
selection.append(" AND " + RawContacts.DATA_SET + " IS NULL )");
}
selection.append("))");
/** @} */
break;
}
}
/// M: Log the selection string.
Log.d(TAG, "[configureSelection] selection: " + selection.toString());
loader.setSelection(selection.toString());
loader.setSelectionArgs(selectionArgs.toArray(new String[0]));
}
android 如何将电话簿中SDN号码和其他普通号码混合放在一起?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。