Source:
private int createList(final int maxListCount, final int listStartOffset, final String searchValue, StringBuilder result, String type) { int itemsFound = 0; ArrayList<String> nameList = mVcardManager.getPhonebookNameList(mOrderBy); final int requestSize = nameList.size() >= maxListCount ? maxListCount : nameList.size(); final int listSize = nameList.size(); String compareValue = "", currentValue; if (D) Log.d(TAG, "search by " + type + ", requestSize=" + requestSize + " offset=" + listStartOffset + " searchValue=" + searchValue); if (type.equals("number")) { ArrayList<String> names = mVcardManager.getContactNamesByNumber(searchValue); for (int i = 0; i < names.size(); i++) { compareValue = names.get(i).trim(); if (D) Log.d(TAG, "compareValue=" + compareValue); for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); if (D) Log.d(TAG, "currentValue=" + currentValue); if (currentValue.equals(compareValue)) { itemsFound++; if (currentValue.contains(",")) currentValue = currentValue.substring(0, currentValue.lastIndexOf(',')); writeVCardEntry(pos, currentValue,result); } } if (itemsFound >= requestSize) { break; } } } else { if (searchValue != null) { compareValue = searchValue.trim(); } for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); if (currentValue.contains(",")) currentValue = currentValue.substring(0, currentValue.lastIndexOf(',')); if (searchValue.isEmpty() || ((currentValue.toLowerCase()).startsWith(compareValue.toLowerCase()))) { itemsFound++; writeVCardEntry(pos, currentValue,result); } } } return itemsFound; }

Target:
private int createList(final int maxListCount, final int listStartOffset, final String searchValue, StringBuilder result, String type) { int itemsFound = 0; ArrayList<String> nameList = mVcardManager.getPhonebookNameList(mOrderBy); final int requestSize = nameList.size() >= maxListCount ? maxListCount : nameList.size(); final int listSize = nameList.size(); String compareValue = "", currentValue; if (D) Log.d(TAG, "search by " + type + ", requestSize=" + requestSize + " offset=" + listStartOffset + " searchValue=" + searchValue); if (type.equals("number")) { ArrayList<String> names = mVcardManager.getContactNamesByNumber(searchValue); for (int i = 0; i < names.size(); i++) { compareValue = names.get(i).trim(); if (D) Log.d(TAG, "compareValue=" + compareValue); for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); if (D) Log.d(TAG, "currentValue=" + currentValue); if (currentValue.equals(compareValue)) { itemsFound++; if (currentValue.contains(",")) currentValue = currentValue.substring(0, currentValue.lastIndexOf(',')); writeVCardEntry(pos, currentValue,result); } } if (itemsFound >= requestSize) { break; } } } else { if (searchValue != null) { compareValue = searchValue.trim().toLowerCase(); } for (int pos = listStartOffset; pos < listSize && itemsFound < requestSize; pos++) { currentValue = nameList.get(pos); if (currentValue.contains(",")) currentValue = currentValue.substring(0, currentValue.lastIndexOf(',')); if (searchValue.isEmpty() || ((currentValue.toLowerCase()).startsWith(compareValue))) { itemsFound++; writeVCardEntry(pos, currentValue,result); } } } return itemsFound; }