/** 异步加载头像位图到ImageLoader内存缓存 */ private static void asyncLoadAvatarBitmapToCache(UserInfoProvider.UserInfo userInfo) { if (userInfo == null || !isImageUriValid(userInfo.getAvatar())) { return; } String url = HeadImageView.getAvatarCacheKey(userInfo.getAvatar()); ImageLoader.getInstance() .loadImage( url, new ImageSize( HeadImageView.DEFAULT_AVATAR_THUMB_SIZE, HeadImageView.DEFAULT_AVATAR_THUMB_SIZE), avatarLoadOption, null); }
@Override public void refresh(ContactDataAdapter adapter, int position, final ContactItem item) { // contact info final IContact contact = item.getContact(); if (contact.getContactType() == IContact.Type.Friend) { head.loadBuddyAvatar(contact.getContactId()); } else { Team team = TeamDataCache.getInstance().getTeamById(contact.getContactId()); head.loadTeamIconByTeam(team); } name.setText(contact.getDisplayName()); headLayout.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (contact.getContactType() == IContact.Type.Friend) { if (NimUIKit.getContactEventListener() != null) { NimUIKit.getContactEventListener() .onAvatarClick(context, item.getContact().getContactId()); } } } }); // query result desc.setVisibility(View.GONE); /* TextQuery query = adapter.getQuery(); HitInfo hitInfo = query != null ? ContactSearch.hitInfo(contact, query) : null; if (hitInfo != null && !hitInfo.text.equals(contact.getDisplayName())) { desc.setVisibility(View.VISIBLE); } else { desc.setVisibility(View.GONE); } */ }
/** 从ImageLoader内存缓存中取出头像位图 */ private static Bitmap getMemoryCachedAvatarBitmap(UserInfoProvider.UserInfo userInfo) { if (userInfo == null || !isImageUriValid(userInfo.getAvatar())) { return null; } String key = HeadImageView.getAvatarCacheKey(userInfo.getAvatar()); // DiskCacheUtils.findInCache(uri, ImageLoader.getInstance().getDiskCache() 查询磁盘缓存示例 List<Bitmap> bitmaps = MemoryCacheUtils.findCachedBitmapsForImageUri( key, ImageLoader.getInstance().getMemoryCache()); if (bitmaps.size() > 0) { return bitmaps.get(0); } return null; }