icfans

如何让短信中匹配联系人不会把匹配输入的字母转换成数字?

0
阅读(28) 评论(0)

如何让短信中匹配联系人不会把匹配输入的字母转换成数字?

[QUESTION]
如何让短信中匹配联系人不会把匹配输入的字母转换成数字?
[ANSWER]
【修改samplecode】
参考代码基于6.0,其他版本或分支,原理相icfans
diff --git a/src/com/android/providers/contacts/ContactLocaleUtils.java b/src/com/android/providers/contacts/ContactLocaleUtils.java
in
dex 57a52bc..699ac1a 100644
--- a/src/com/android/providers/contacts/ContactLocaleUtils.java
+++ b/src/com/android/providers/contacts/ContactLocaleUtils.java
@@ -441,8 +441,8 @@ public class ContactLocaleUtils {
final StringBuilder keyPinyin = new StringBuilder();
final StringBuilder keyInitial = new StringBuilder();
/* SPRD: DIALER SEARCH FEATURE @ { */
- final StringBuilder keyNineGrid = new StringBuilder();
- final StringBuilder allKeyNineGrid = new StringBuilder();
+// final StringBuilder keyNineGrid = new StringBuilder();
+// final StringBuilder allKeyNineGrid = new StringBuilder();
/* @} */
// There is no space among the Chinese Characters, the variant name
@@ -453,8 +453,8 @@ public class ContactLocaleUtils {
for (ArrayList<Token> tokens : tokenlists) {
keyPinyin.setLength(0);
keyInitial.setLength(0);
- keyNineGrid.setLength(0);
- allKeyNineGrid.setLength(0);
+// keyNineGrid.setLength(0);
+// allKeyNineGrid.setLength(0);
keyOriginal.setLength(0);
int
tokenCount = tokens.size();
/* @} */
@@ -467,17 +467,17 @@ public class ContactLocaleUtils {
keyPinyin.insert(0, token.target);
keyInitial.insert(0, token.target.charAt(0));
/* SPRD: DIALER SEARCH FEATURE @ { */
- int firstIndex = Character.toUpperCase(token.target.charAt(0)) - 'A';
- if (firstIndex >= 0 && firstIndex < sNineGridMapping.length) {
- keyNineGrid.insert(0, sNineGridMapping[firstIndex]);
- int index;
- for (int m = 0; m < token.target.length(); ++m) {
- index = Character.toUpperCase(token.target.charAt(m)) - 'A';
- if (index >= 0 && index < sNineGridMapping.length) {
- allKeyNineGrid.insert(m, sNineGridMapping[index]);
- }
- }
- }
+// int firstIndex = Character.toUpperCase(token.target.charAt(0)) - 'A';
+// if (firstIndex >= 0 && firstIndex < sNineGridMapping.length) {
+// keyNineGrid.insert(0, sNineGridMapping[firstIndex]);
+// int index;
+// for (int m = 0; m < token.target.length(); ++m) {
+// index = Character.toUpperCase(token.target.charAt(m)) - 'A';
+// if (index >= 0 && index < sNineGridMapping.length) {
+// allKeyNineGrid.insert(m, sNineGridMapping[index]);
+// }
+// }
+// }
/* @} */
} else if (Token.LATIN == token.type) {
// Avoid adding space at the end of String.
@@ -490,23 +490,23 @@ public class ContactLocaleUtils {
keyPinyin.insert(0, token.source);
keyInitial.insert(0, token.source.charAt(0));
/* SPRD: DIALER SEARCH FEATURE @ { */
- int length = token.source.length();
- char add = ' ';
- for (int m = 0; m < length; m++) {
- if (Character.isLetter(token.source.charAt(m))) {
- int index = Character.toUpperCase(token.source.charAt(m)) - 'A';
- if (index >= 0 && index < sNineGridMapping.length) {
- keyNineGrid.insert(m, sNineGridMapping[index]);
- allKeyNineGrid.insert(m, sNineGridMapping[index]);
- } else {
- keyNineGrid.insert(m, add);
- allKeyNineGrid.insert(m, add);
- }
- } else {
- keyNineGrid.insert(m, token.source.charAt(m));
- allKeyNineGrid.insert(m, token.source.charAt(m));
- }
- }
+// int length = token.source.length();
+// char add = ' ';
+// for (int m = 0; m < length; m++) {
+// if (Character.isLetter(token.source.charAt(m))) {
+// int index = Character.toUpperCase(token.source.charAt(m)) - 'A';
+// if (index >= 0 && index < sNineGridMapping.length) {
+// keyNineGrid.insert(m, sNineGridMapping[index]);
+// allKeyNineGrid.insert(m, sNineGridMapping[index]);
+// } else {
+// keyNineGrid.insert(m, add);
+// allKeyNineGrid.insert(m, add);
+// }
+// } else {
+// keyNineGrid.insert(m, token.source.charAt(m));
+// allKeyNineGrid.insert(m, token.source.charAt(m));
+// }
+// }
/* @} */
}
@@ -526,16 +526,16 @@ public class ContactLocaleUtils {
charinstead = 0x0400;
mChar = sNineGridMappingForCyrillic;
}
- for (int m = 0; m < length; m++) {
- int index = token.source.charAt(m) - charinstead;
- if (index < mChar.length) {
- keyNineGrid.insert(m, mChar[index]);
- allKeyNineGrid.insert(m, mChar[index]);
- } else {
- keyNineGrid.insert(m, add);
- allKeyNineGrid.insert(m, add);
- }
- }
+// for (int m = 0; m < length; m++) {
+// int index = token.source.charAt(m) - charinstead;
+// if (index < mChar.length) {
+// keyNineGrid.insert(m, mChar[index]);
+// allKeyNineGrid.insert(m, mChar[index]);
+// } else {
+// keyNineGrid.insert(m, add);
+// allKeyNineGrid.insert(m, add);
+// }
+// }
} /*
@} */
keyOriginal.insert(0, token.source);
@@ -543,8 +543,8 @@ public class ContactLocaleUtils {
keys.add(keyPinyin.toString());
keys.add(keyInitial.toString());
/* SPRD: DIALER SEARCH FEATURE @ { */
- keys.add(keyNineGrid.toString());
- keys.add(allKeyNineGrid.toString());
+// keys.add(keyNineGrid.toString());
+// keys.add(allKeyNineGrid.toString());
/* @} */
}
}
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
in
dex d2b621e..aa74821 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -6554,7 +6554,8 @@ public class ContactsProvider2 extends AbstractContactsProvider
} if
(searchPhoneNumber) {
- final String number = PhoneNumberUtils.normalizeNumber(filterParam);
+ //final String number = PhoneNumberUtils.normalizeNumber(filterParam);
+ final String number = filterParam;
if (!TextUtils.isEmpty(number)) {
if (hasCondition) {
sb.append(" OR ");