public static boolean handleTokenPinyinFullSearch( String key, PinYinElement pinYinElement, SearchElement searchElement) { if (TextUtils.isEmpty(key)) { return false; } String searchKey = key.toUpperCase(); // onLoginOut the old search result searchElement.reset(); int tokenCnt = pinYinElement.tokenPinyinList.size(); int startIndex = -1; int endIndex = -1; for (int i = 0; i < tokenCnt; ++i) { String tokenPinyin = pinYinElement.tokenPinyinList.get(i); int tokenPinyinSize = tokenPinyin.length(); int searchKeySize = searchKey.length(); int keyCnt = Math.min(searchKeySize, tokenPinyinSize); String keyPart = searchKey.substring(0, keyCnt); if (tokenPinyin.startsWith(keyPart)) { if (startIndex == -1) { startIndex = i; } endIndex = i + 1; } else { continue; } if (searchKeySize <= tokenPinyinSize) { searchKey = ""; break; } searchKey = searchKey.substring(keyCnt, searchKeySize); } if (!searchKey.isEmpty()) { return false; } if (startIndex >= 0 && endIndex > 0) { searchElement.startIndex = startIndex; searchElement.endIndex = endIndex; return true; } return false; }
public static boolean handleNameSearch(String name, String key, SearchElement searchElement) { int index = name.indexOf(key); if (index == -1) { return false; } searchElement.startIndex = index; searchElement.endIndex = index + key.length(); return true; }