@Override protected ArrayList<ContactInfo> doInBackground(Cursor... params) { Cursor cursor = params[0]; ArrayList<ContactInfo> ciList = new ArrayList<ContactInfo>(); if (cursor != null && cursor.getCount() > 0) { try { cursor.moveToFirst(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); String name = cursor.getString(1).replace(" ", ""); String number = cursor.getString(2); long contactId = cursor.getLong(4); ContactInfo contactInfo = new ContactInfo(); contactInfo.setId(contactId); contactInfo.setPhoneNum(number); contactInfo.setName(name); if (contactInfo.getName() == null) { contactInfo.setName(contactInfo.getPhoneNum()); } contactInfo.setFormattedNumber(getNameNum(contactInfo.getName() + "")); contactInfo.setPinyin(ToPinYin.getPinYin(contactInfo.getName() + "")); ciList.add(contactInfo); } } catch (BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace(); } } return ciList; }
private String getNameNum(String name) { try { if (name != null && name.length() != 0) { int len = name.length(); char[] nums = new char[len]; for (int i = 0; i < len; i++) { String tmp = name.substring(i); nums[i] = getOneNumFromAlpha(ToPinYin.getPinYin(tmp).toLowerCase().charAt(0)); } return new String(nums); } } catch (BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace(); } return null; }