use of org.aisen.android.component.bitmaploader.download.DownloadProcess in project AisenWeiBo by wangdan.
the class ProfilePagerFragment method setProfile.
private void setProfile() {
// 封面
ImageConfig coverConfig = new ImageConfig();
coverConfig.setLoadfaildRes(R.drawable.bg_banner_dialog);
coverConfig.setLoadingRes(R.drawable.bg_banner_dialog);
coverConfig.setDisplayer(new DefaultDisplayer());
BitmapLoader.getInstance().display(this, mUser.getCover_image_phone(), imgCover, coverConfig);
// 名字
// fuck 2014-09-04 当名字过长大于10个字时,截取部分文字
// int maxLength = AisenUtils.getStrLength("一二三四五六七八九十");
int maxLength = AisenUtils.getStrLength("一二三四五");
if (AisenUtils.getStrLength(mUser.getName()) > maxLength) {
StringBuffer sb = new StringBuffer();
int index = 0;
while (AisenUtils.getStrLength(sb.toString()) < maxLength) {
if (index >= mUser.getName().length())
break;
sb.append(mUser.getName().charAt(index));
index++;
}
sb.append("...");
txtName.setText(sb.toString());
} else {
txtName.setText(mUser.getScreen_name());
}
// 头像
File avatarFile = BitmapLoader.getInstance().getCacheFile(AisenUtils.getUserPhoto(mUser));
if (avatarFile.exists()) {
Bitmap bitmap = BitmapFactory.decodeFile(avatarFile.getAbsolutePath());
imgAvatar.setImageBitmap(bitmap);
collapsingToolbarLayout.setAvatarBitmap(bitmap);
} else {
ImageConfig config = new ImageConfig();
config.setId("large");
config.setDisplayer(new DefaultDisplayer());
config.setLoadingRes(R.drawable.user_placeholder);
config.setLoadfaildRes(R.drawable.user_placeholder);
config.setProgress(new DownloadProcess() {
@Override
public void finishedDownload(byte[] bytes) {
super.finishedDownload(bytes);
collapsingToolbarLayout.setAvatarBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));
}
});
BitmapLoader.getInstance().display(this, AisenUtils.getUserPhoto(mUser), imgAvatar, config);
}
// 性别
imgGender.setVisibility(View.VISIBLE);
if ("m".equals(mUser.getGender()))
imgGender.setImageResource(R.drawable.list_male);
else if ("f".equals(mUser.getGender()))
imgGender.setImageResource(R.drawable.list_female);
else
imgGender.setVisibility(View.GONE);
// 认证
AisenUtils.setImageVerified(imgVerified, mUser);
// 关注数
txtFriendsCounter.setText(String.format(getString(R.string.profile_friends), AisenUtils.getCounter(mUser.getFriends_count())));
// 粉丝数
txtFollowersCounter.setText(String.format(getString(R.string.profile_followers), AisenUtils.getCounter(mUser.getFollowers_count())));
// 简介
txtDesc.setText(mUser.getDescription());
// 简介
if (!TextUtils.isEmpty(mUser.getDescription()))
txtDesc.setText(mUser.getDescription());
else
txtDesc.setText(getString(R.string.profile_des_none));
}
Aggregations