In android4.4.3The first letter of the contact's profile picture is displayed by default, but Chinese characters are not supported, such:
If the first contact name is an English character (a-z | A-Z), the default Avatar displays the first letter.
If the first Chinese character is displayed when Chinese characters are supported, it will be happy.
Let's take a look at how to implement this small function by modifying the source code ~
Let's take a look at the process of loading a contact's profile picture first ~
The question of loading the contact profile picture is still very interesting. In Contacts, the ContactPhotoManager class (strictly speaking, it is a subclass of this class) is used to implement asynchronous loading of the profile picture.
This class also uses LruCache to cache images, which is quite powerful. You can check if you are interested in asynchronous image loading and slowing down.
Take the contact list on the home page as an example. The general calling process is as follows (only for contacts without an avatar set, that is, photoUri is null ):
DefaultContactListAdapter-> bindView ()
ContactEntryListAdapter-> buildQuickContact ()
ContactEntryListAdapter-> getDefaultImageRequestFromCursor ()
ContactPhotoManagerImpl-> loadPhoto ()-> provider: LetterTileDefaultImageProvider // note that the DEFAULT_AVATAR object is used.
LetterTileDefaultImageProvider-> applyDefaultImage ()
LetterTileDefaultImageProvider-> getDefaultImageForContact ()
LetterTileDrawable-> drawLetterTile ()-> firsr char: high
Before the drawLetterTile function executes drawText, isEnglishLetter is called to determine whether the first character of a string is an English character. If yes, the first letter is drawn;
Otherwise, use the default Avatar
private static boolean isEnglishLetter(final char c) { return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); }
Through the above process analysis, we can determine that the isEnglishLetter function causes Chinese characters not to be drawn.
Well, let's modify this function. Don't talk nonsense, directly go to the Code ~
private static boolean isEnglishLetter(final char c) { return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || isChineseLetter(c); }
private static boolean isChineseLetter(final char c) { return isChinese(String.valueOf(c)); }
As for the isChinese function implementation, the code will not post, interested can refer to my article to judge the character for Chinese, Japanese, Korean (http://www.cnblogs.com/Lefter/p/3804051.html)
After this transformation, we can have the default Avatar display the first Chinese character of the Chinese name!