Before doing the Address book software, which has been making dials for how to achieve T9 input troubles, the Internet to find a lot of posts, there is no satisfactory answer.
But finally realized, look at the community seems to have a lot of friends need to share here.
This is in my project to extract the dial case, the function of the full realization of the current other Address book dial function, but in the loading efficiency is still insufficient, please teach the heroes.
There is a picture of the truth:
At present I use 1g single core CPU Sony Ericsson mt15i test machine, more than 1500 contacts, loading time about 8 seconds, of course, the general user will not have so many contact people.
Because the program I did was not in the beginning of the interface is the dial, so I started the program in the background asynchronously loaded contacts,
Waiting for the dial interface, the contact load is almost complete.
But I think that every time I read the contact data at the beginning of the program, it's a little bit slower to sort them out into T9 search data.
It is best to build a table to store it yourself, and then listen for changes in the Contact table to dynamically update T9 data.
If you have a better and faster idea, hope to share it!
Part of the code:
Copy Code code as follows:
public class Topinyin {
/**
* Convert the passed Chinese character list to Pinyin list
* @param list
*/
public static list<string> getpinyinlist (list<string> List) {
list<string> pinyinlist = new arraylist<string> ();
For (iterator<string> i=list.iterator (); I.hasnext ();) {
String str = (string) i.next ();
try {
String Pinyin = Getpinyin (str);
pinyinlist.add (pinyin);
catch (Badhanyupinyinoutputformatcombination e) {
E.printstacktrace ();
}
}
return pinyinlist;
}
/**
* Convert Chinese to Pinyin
* @param Pinyin-Chinese characters
* @return
*/
public static string Getpinyin (String Zhongwen)
Throws Badhanyupinyinoutputformatcombination {
String zhongwenpinyin = "";
char[] chars = Zhongwen.tochararray ();
for (int i = 0; i < chars.length; i++) {
string[] PinYin = Pinyinhelper.tohanyupinyinstringarray (chars[i), Getdefaultoutputformat ());
Returns NULL when the conversion is not a Chinese character
if (pinYin!= null) {
Zhongwenpinyin + = pinyin[0];
} else {
Zhongwenpinyin + = Chars[i];
}
}
return zhongwenpinyin;
}
/**
* Output format
*
* @return
*/
private static Hanyupinyinoutputformat Getdefaultoutputformat () {
Hanyupinyinoutputformat format = new Hanyupinyinoutputformat ();
Format.setcasetype (hanyupinyincasetype.uppercase);//Uppercase
Format.settonetype (Hanyupinyintonetype.without_tone);//No tone number
Format.setvchartype (Hanyupinyinvchartype.with_u_and_colon);//U Show
return format;
}