android 如何将电话簿SDN数字和其他普通的数字混合在一起?

时间:2023-03-09 07:40:36
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]));

    }

版权声明:本文博客原创文章。博客,未经同意,不得转载。