Case study of Android dial support for T9 search and number search

Source: Internet
Author: User

I previously worked on the address book software, where I had been worried about how to implement T9 input while I was working on a dial. I found a lot of posts online and I was not satisfied with the answer.
However, it was finally implemented. It seems that many friends in the community need it. Let's share it here.
This is the dial case extracted from my project. It fully implements the dial function in other address books, but it still lacks loading efficiency. Please kindly advise.

There is a picture with the truth:

At present, I use a 1G Single-core cpu Sony Ericsson mt15i testing machine, more than 1500 contacts, loading time is about 8 seconds, of course, the average user does not have so many contacts.
Since the program I made was either a dial disk or an interface at the beginning, I asynchronously loaded contacts at the beginning of the program in the background,
When the dial page is displayed, the contact loading is almost complete.
However, I think it is a little slow to read the contact data at the beginning of the program and sort them into the data needed for t9 search,
It is best to create a table to store it, and then listen to the changes in the contact table to dynamically update t9 data.

If you have better and faster ideas, I hope you can share them!

Some code:

Copy codeThe Code is as follows: public class ToPinYin {

/**
* Convert the passed Chinese Character list to the 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 ());
// If the conversion is not a Chinese character, null is returned.
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 display
Return format;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.