String getSelectPhones() { String ret = ""; if (selectedList != null) { for (ContactRec item : selectedList) { if (ret.length() == 0) { ret += item.getPhone().replaceAll(" ", ""); } else { ret += "," + item.getPhone().replaceAll(" ", ""); } } return ret; } return null; }
private void getContacts() { HashMap<Integer, ContactRec> temp = new HashMap<Integer, ContactRec>(); Cursor cur1 = mContentResolver.query( ContactsContract.Contacts.CONTENT_URI, new String[] {BaseColumns._ID, ContactsContract.Contacts.DISPLAY_NAME, "sort_key"}, null, null, null); if (cur1 != null) { if (cur1.moveToFirst()) { do { int id = cur1.getInt(0); String name = cur1.getString(1); ContactRec rec = new ContactRec(); rec.setName(name); String sortkey = cur1.getString(2); rec.setSortKey(sortkey); temp.put(id, rec); } while (cur1.moveToNext()); } cur1.close(); } mContactsPhoneHash = new HashMap<String, ContactRec>(); Cursor cur = mContentResolver.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[] { ContactsContract.CommonDataKinds.Phone.CONTACT_ID, ContactsContract.CommonDataKinds.Phone.NUMBER }, null, null, null); if (cur != null) { if (cur.moveToFirst()) { do { int id = cur.getInt(0); ContactRec temprec = temp.get(id); String strAddress = cur.getString(1); ContactRec rec = new ContactRec(); if (temprec == null) { continue; } rec.setName(temprec.getName()); rec.setPhone(strAddress); rec.setSortKey(updateSortKey(temprec.getSortKey())); contactRecList.add(rec); mContactsPhoneHash.put(strAddress, rec); } while (cur.moveToNext()); } cur.close(); } // todo // Collections.sort(contactRecList, new PinyinComparator()); runOnUiThread( new Runnable() { @Override public void run() { listView.setDividerHeight(DensityUtil.dip2px(PhoneContactsActivity.this, 1)); listView.removeHeadView(); adapter = new PhoneContactsAdapter( PhoneContactsActivity.this, listView, ImageCacheManager.getInstance().getImageLoader()); adapter.setOnContactSelectedListener( new PhoneContactsAdapter.OnContactSelectedListener() { @Override public void onContactSelected(ContactRec contactRec) { if (selectedList.contains(contactRec)) { selectedList.remove(contactRec); } else { selectedList.add(contactRec); } } }); adapter.setList(contactRecList); listView.setAdapter(adapter); listView.setOnItemClickListener(adapter); } }); }