In Contacts, the sorting of surnames and polyphonic words is incorrect.

Source: Internet
Author: User

In Contacts, the sorting of surnames and polyphonic words is incorrect.

When talking about Chinese names, you have to consider the problem of polyphonic words. For example, for 'singles' name, you should read them as 'shan' instead of 'dan '. however, the Contacts program uses 'D' as the bucket label!
Why? How can we solve this problem?

Contains the pronunciation of some Chinese characters when they are used as surnames. If the Transliterator object is created, the Chinese characters contained in Han-Latin/else are used ). that is to say, the HanziToPinyin class can obtain the correct pronunciation when processing the polyphonic words as surnames. for example, when HanziToPinyin is used to obtain 'shan tianfang', its pronunciation is 'shan tian fang '. even if the name is 'shan tianfang ', People are still listed below 'd! Why?
Through the parsing code, we can find that the contact column is determined by the phonebook_label value in the raw_contacts table, and the phonebook_label value in the database is indeed 'D ', it is mainly because the getBucketLabel function of AlphabeticIndex $ ImmutableIndex is used to obtain the phonebook_label, which does not have any special processing on the surnames and polyphonic words, so the final result is 'D' (see Appendix 1 for the processing process of phonebook_label ).

Currently, if you want to solve this problem more easily, you can avoid using the getBucketLabel function of AlphabeticIndex $ ImmutableIndex when obtaining phonebook_label, instead, use HanziToPinyin to obtain the first character of sortKeyPrimary in pinyin ).

Post Code modification (based on 4.4.4 _ r2)
-----------------------------------------------------------------------------
--- A/src/com/android/providers/contacts/ContactsDatabaseHelper. java
++ B/src/com/android/providers/contacts/ContactsDatabaseHelper. java
@-78,6 + 78,7 @ import android. text. util. Rfc822Tokenizer;
Import android. util. Log;
 
Import com. android. common. content. SyncStateContentProviderHelper;
+ Import com. android. providers. contacts. HanziToPinyin. Token;
Import com. android. providers. contacts. aggregation. util. CommonNicknameCache;
Import com. android. providers. contacts. database. ContactsTableUtil;
Import com. android. providers. contacts. database. DeletedContactsTableUtil;
@-85,6 + 86,7 @ import com. android. providers. contacts. database. MoreDatabaseUtils;
Import com. android. providers. contacts. util. NeededForTesting;
Import com. google. android. collect. Sets;
 
+ Import java. util. ArrayList;
Import java. util. HashMap;
Import java. util. Locale;
Import java. util. Set;
@-5388,8 + 5390,25 @ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
ContactLocaleUtils localeUtils = ContactLocaleUtils. getInstance ();
 
If (sortKeyPrimary! = Null ){
-PhonebookBucketPrimary = localeUtils. getBucketIndex (sortKeyPrimary );
-PhonebookLabelPrimary = localeUtils. getBucketLabel (phonebookBucketPrimary );
+ Boolean flag = false;
+ If (displayNameStyle = FullNameStyle. CHINESE
+ & HanziToPinyin. getInstance (). hasChineseTransliterator ()){
+ String target = sortKeyPrimary. substring (0, 1 );
+ ArrayList <Token> tokens = HanziToPinyin. getInstance (). get (target );
+ If (tokens! = Null & tokens. size ()> 0 ){
+ Char label = tokens.get(0).tar get. charAt (0 );
+ If (label> = 'A' & label <= 'Z '){
+ PhonebookLabelPrimary = String. valueOf (label );
+ PhonebookBucketPrimary = localeUtils. getBucketIndex (phonebookLabelPrimary );
+ Flag = true;
+}
+}
+}
+
+ If (! Flag ){
+ PhonebookBucketPrimary = localeUtils. getBucketIndex (sortKeyPrimary );
+ PhonebookLabelPrimary = localeUtils. getBucketLabel (phonebookBucketPrimary );
+}
}
If (sortKeyAlternative! = Null ){
PhonebookBucketAlternative = localeUtils. getBucketIndex (sortKeyAlternative );

-----------------------------------------------------------------------------
The above analysis shows a problem, that is, the contact cannot be searched by 'Dan tian fang 'on the Contacts homepage. You can only search by 'shan tian fang, however, this contact is placed under the 'D' group during display! The root cause is that NameLookupBuilder actually uses HanziToPinyin to obtain the pronunciation when calling the delimiter. In this case, the pronunciation is obtained as the last name, and phonebook_label is obtained using the getBucketLabel function of AlphabeticIndex $ ImmutableIndex, however, it does not perform any special processing on the surname polyphones, which leads to the problem mentioned above.
In addition, one problem with HanziToPinyin is that the pronunciation of all Chinese characters that can be used as surnames is the pronunciation of surnames. For example, the 'unit sing' Pinyin is 'shan wei Sha '. how can this problem be solved? In fact, there is no good method under the existing conditions (except for the dictionary-adding method), and it can only be avoided as much as possible. in Chinese, the first Chinese Character in the name is used as the last name to obtain the pronunciation (using the Transliterator object created by Han-Latin/Names; Latin-Ascii; Any-Upper ), other Chinese characters are used as normal Chinese characters to obtain the pronunciation (the Transliterator object created using Han-Latin; Latin-Ascii; Any-Upper needs to be created in HanziToPinyin and a new Transliterator object ).

Appendix 1
The process for obtaining phonebook_label in the raw_contacts table is as follows:
The phonebook_label in the raw_contacts table is inserted/updated by calling the updateRawContactDisplayName function of ContactsDatabaseHelper. the value of the phonebookLabelPrimary variable is used. phonebookLabelPrimary is obtained by getBucketLabel in ContactLocaleUtils. getBucketLabel actually calls getBucketLabel of ImmutableIndex in ICU ().

PS: find strong ROM development team. I am mainly responsible for Dialer, Contacts related modules, three years of experience. Interested parties can email me: gaojx0809@gmail.com

 


EXCEL name Sorting Problem high score Solution

By default, excel is sorted by the first letter of Pinyin in the Multi-phoneme in the A-Z sequence.
For example
Long
Zhang, chang
They will be sorted by chang, if they are only sorted by polyphonic words.
If you want to sort multiple phonograph words, you must add more annotations to differentiate them.
Wish you success!
 
Multi-tone answer in last name

Sorry. I haven't answered yet. I accidentally submitted it.

In the last name, "park" reads (pi áo)
In the last name, "discount" reads (zh é)
In the last name, "single" Read (shà n)
 

Related Article

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.