第一个兑换神秘星玩家头像像上的那个8是怎么弄的?

1个节目被提到
评分:6.3 /
奥利维尔·米加顿 /
玛姬·格蕾斯
/ 福里斯特·惠特克
作者其他文章热门文章最新推荐2016
/ 樱井孝宏
/ 大塚明夫超能力不能让自己成绩变好,也不能让暗恋的女神喜欢自己。顶个屁用。就像他自己说的—…&02017
/ 基特·哈灵顿
/ 艾米莉亚·克拉克龙妈一生中要升起三把火,一次为生,一次为死,一次为爱。每次浴火后都性格大变。如果…&02003
/ 妮可·基德曼
/ 劳伦·白考尔复仇欲,是人类在遭受迫害后,随之产生的一种合理而直接的情感反应。&02016
/ 佐久本宝
/ 渡边谦很震撼,也很绝望。还好,有一丝难能可贵的光明。&12017
/ 徐静蕾影片的很多细节都是为了最后的结局埋了很多伏笔的。&2009
/ 路易·西霍尤斯
/ John Chisholm万万没想到,当年那些在《海豚湾》中捕杀海豚后,还以传统的名义给自己洗白的人,我们…&7 1个节目被提到
评分:6.3 /2015 / 奥利维尔·米加顿 /
玛姬·格蕾斯
/ 福里斯特·惠特克android 4.4.3上面,联系人的头像默认显示首字母,但是不支持中文字符,修改支持中文
在android 4 4 3上面,联系人的头像默认显示首字母,但是不支持中文字符,如下图:
如果联系人名字的第一位是英文字符(a-z || A-Z),则默认头像将显示该首字母。
如果支持中文时显示第一个汉字,那就hap
在android 4.4.3上面,联系人的头像默认显示首字母,但是不支持中文字符,如下图:
如果联系人名字的第一位是英文字符(a-z "| A-Z),则默认头像将显示该首字母。
如果支持中文时显示第一个汉字,那就happy了。
那就看看如何通过修改源代码来实现这一小功能吧~
我们还是先了解下联系人头像加载的流程吧~
联系人头像加载这个问题还是很有意思的,在Contacts中使用ContactPhotoManager类(严格来讲是这个类的子类)来实现头像的异步加载。
这个类还使用了LruCache来缓存图片,相当的强大,对图像的异步加载和缓存有兴趣的同志们可以看看。
以主页面的联系人列表加载头像为例。大致的调用流程为(只针对没有设置头像的联系人,即photoUri是null):
DefaultContactListAdapter->bindView()
  ContactEntryListAdapter->buildQuickContact()
    ContactEntryListAdapter->getDefaultImageRequestFromCursor()
      ContactPhotoManagerImpl->loadPhoto()->provider:LetterTileDefaultImageProvider // 注意,使用的是DEFAULT_AVATAR对象
        LetterTileDefaultImageProvider->applyDefaultImage()
          LetterTileDefaultImageProvider->getDefaultImageForContact()
            LetterTileDrawable->drawLetterTile()->firsr char:高
在drawLetterTile函数执行drawText之前会调用isEnglishLetter来判断字符串的首字符是否为英文字符,如果是,则将首字母画上去;
否则,使用默认头像
private static boolean isEnglishLetter(final char c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
通过上面的流程解析,我们可以确定,是isEnglishLetter函数导致在中文字符不被描画。
嗯,那我们就改造一下这个函数吧。不废话,直接上代码~
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));
至于isChinese函数的实现,代码就不贴了,有兴趣的可以参考我的一篇判断字符为中文、日文、韩文的文章(/Lefter/p/3804051.html)
经过这个改造后,我们就可以让默认头像显示中文名字的第一个汉字了!
具体修改如下。严重OK
private static boolean isEnglishLetter(final char c) {
return ("A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
private static boolean isChineseLetter(final char c) {
return isChinese(c);
boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
//具体路径 com.mon. LetterTileDrawable.java
private void drawLetterTile(final Canvas canvas) {
// Draw background color.
sPaint.setColor(pickColor(mIdentifier));
sPaint.setAlpha(mPaint.getAlpha());
canvas.drawRect(getBounds(), sPaint);
// Draw letter/digit only if the first character is an english letter
if (mDisplayName != null && (isEnglishLetter(mDisplayName.charAt(0)) || isChineseLetter(mDisplayName.charAt(0)))) {
// Draw letter or digit.
sFirstChar[0] = Character.toUpperCase(mDisplayName.charAt(0));
// Scale text by canvas bounds and user selected scaling factor
final int minDimension = Math.min(getBounds().width(), getBounds().height());
sPaint.setTextSize(mScale * sLetterToTileRatio * minDimension);
//sPaint.setTextSize(sTileLetterFontSize);
sPaint.getTextBounds(sFirstChar, 0, 1, sRect);
sPaint.setColor(sTileFontColor);
final Rect bounds = getBounds();
// Draw the letter in the canvas, vertically shifted up or down by the user-defined
canvas.drawText(sFirstChar, 0, 1, bounds.centerX(),
bounds.centerY() &#43; mOffset * bounds.height() &#43; sRect.height() / 2,
// Draw the default image if there is no letter/digit to be drawn
final Bitmap bitmap = getBitmapForContactType(mContactType);
drawBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(),
//为什么头像的背景会有8种颜色
/** This should match the total number of colors defined in colors.xml for letter_tile_color */
private static final int NUM_OF_TILE_COLORS = 8;
//八种颜色随机生成
//获取颜色
private int pickColor(final String identifier) {
if (TextUtils.isEmpty(identifier) || mContactType == TYPE_VOICEMAIL) {
return sDefaultC
// String.hashCode() implementation is not supposed to change across java versions, so
// this should guarantee the same email address always maps to the same color.
// The email should already have been normalized by the ContactRequest.
//随机取得颜色&#20540;
final int color = Math.abs(identifier.hashCode()) % NUM_OF_TILE_COLORS;
return sColors.getColor(color, sDefaultColor);android 4.4.3上面,联系人的头像默认显示首字母,但是不支持中文字符,修改支持中文
在android 4.4.3上面,联系人的头像默认显示首字母,但是不支持中文字符,如下图:
如果联系人名字的第一位是英文字符(a-z "| A-Z),则默认头像将显示该首字母。
如果支持中文时显示第一个汉字,那就happy了。
那就看看如何通过修改源代码来实现这一小功能吧~
我们还是先了解下联系人头像加载的流程吧~
联系人头像加载这个问题还是很有意思的,在Contacts中使用ContactPhotoManager类(严&#26684;来讲是这个类的子类)来实现头像的异步加载。
这个类还使用了LruCache来缓存图片,相当的强大,对图像的异步加载和缓存有兴趣的同志们可以看看。
以主页面的联系人列表加载头像为例。大致的调用流程为(只针对没有设置头像的联系人,即photoUri是null):
DefaultContactListAdapter->bindView()
  ContactEntryListAdapter->buildQuickContact()
    ContactEntryListAdapter->getDefaultImageRequestFromCursor()
      ContactPhotoManagerImpl->loadPhoto()->provider:LetterTileDefaultImageProvider // 注意,使用的是DEFAULT_AVATAR对象
        LetterTileDefaultImageProvider->applyDefaultImage()
          LetterTileDefaultImageProvider->getDefaultImageForContact()
            LetterTileDrawable->drawLetterTile()->firsr char:高
在drawLetterTile函数执行drawText之前会调用isEnglishLetter来判断字符串的首字符是否为英文字符,如果是,则将首字母画上去;
否则,使用默认头像
private static boolean isEnglishLetter(final char c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
通过上面的流程解析,我们可以确定,是isEnglishLetter函数导致在中文字符不被描画。
嗯,那我们就改造一下这个函数吧。不废话,直接上代码~
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));
至于isChinese函数的实现,代码就不贴了,有兴趣的可以参考我的一篇判断字符为中文、日文、韩文的文章(/Lefter/p/3804051.html)
经过这个改造后,我们就可以让默认头像显示中文名字的第一个汉字了!
具体修改如下。严重OK
private static boolean isEnglishLetter(final char c) {
return ("A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
private static boolean isChineseLetter(final char c) {
return isChinese(c);
boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
//具体路径 com.mon. LetterTileDrawable.java
private void drawLetterTile(final Canvas canvas) {
// Draw background color.
sPaint.setColor(pickColor(mIdentifier));
sPaint.setAlpha(mPaint.getAlpha());
canvas.drawRect(getBounds(), sPaint);
// Draw letter/digit only if the first character is an english letter
if (mDisplayName != null && (isEnglishLetter(mDisplayName.charAt(0)) || isChineseLetter(mDisplayName.charAt(0)))) {
// Draw letter or digit.
sFirstChar[0] = Character.toUpperCase(mDisplayName.charAt(0));
// Scale text by canvas bounds and user selected scaling factor
final int minDimension = Math.min(getBounds().width(), getBounds().height());
sPaint.setTextSize(mScale * sLetterToTileRatio * minDimension);
//sPaint.setTextSize(sTileLetterFontSize);
sPaint.getTextBounds(sFirstChar, 0, 1, sRect);
sPaint.setColor(sTileFontColor);
final Rect bounds = getBounds();
// Draw the letter in the canvas, vertically shifted up or down by the user-defined
canvas.drawText(sFirstChar, 0, 1, bounds.centerX(),
bounds.centerY() &#43; mOffset * bounds.height() &#43; sRect.height() / 2,
// Draw the default image if there is no letter/digit to be drawn
final Bitmap bitmap = getBitmapForContactType(mContactType);
drawBitmap(bitmap, bitmap.getWidth(), bitmap.getHeight(),
//为什么头像的背景会有8种颜色
/** This should match the total number of colors defined in colors.xml for letter_tile_color */
private static final int NUM_OF_TILE_COLORS = 8;
//八种颜色随机生成
//获取颜色
private int pickColor(final String identifier) {
if (TextUtils.isEmpty(identifier) || mContactType == TYPE_VOICEMAIL) {
return sDefaultC
// String.hashCode() implementation is not supposed to change across java versions, so
// this should guarantee the same email address always maps to the same color.
// The email should already have been normalized by the ContactRequest.
//随机取得颜色&#20540;
final int color = Math.abs(identifier.hashCode()) % NUM_OF_TILE_COLORS;
return sColors.getColor(color, sDefaultColor);}

我要回帖

更多关于 电脑玩家头像 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信