Android dial supports T9 search and number search and other dial cases _android

Source: Internet
Author: User

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;
}

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.