Android 腾讯 云通信 用户头像更新
来源:互联网 发布:天下3捏脸数据女萝莉 编辑:程序博客网 时间:2024/06/10 09:47
最近项目中用到腾讯的即时通讯(云通信),做到C2C聊天这块。需要将聊天界面的己方和对方的默认头像替换掉。
具体操作如下:
1:对ChatAdapter.java类新增
private TIMUserProfile mMySelfProfile;
private TIMUserProfile mMyFriendProfile; 成员变量。通过get或者set方式注入。
对ChatAdapter.ViewHolder也新增
public TIMUserProfile mMySelfProfile;
public TIMUserProfile mMyFriendProfile; 成员变量.
通过ChatAdapter对ChatAdapter.ViewHolder的成员变量赋值;
2:对Message类的子类的showMessage(ChatAdapter.ViewHolder viewHolder, Context context)方法,
已TextMessage为例,其他子类依次类推:
@Override
public void showMessage(ChatAdapter.ViewHolder viewHolder, Context context) {
clearView(viewHolder);
if (checkRevoke(viewHolder)) return;
boolean hasText = false;
TextView tv = new TextView(MyApplication.getContext());
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
tv.setTextColor(MyApplication.getContext().getResources().getColor(isSelf() ? R.color.color_666666 : R.color.color_666666));
List<TIMElem> elems = new ArrayList<>();
for (int i = 0; i < message.getElementCount(); ++i){
elems.add(message.getElement(i));
if (message.getElement(i).getType() == TIMElemType.Text){
hasText = true;
}
}
SpannableStringBuilder stringBuilder = getString(elems, context);
if (!hasText){
stringBuilder.insert(0," ");
}
tv.setText(stringBuilder);
getBubbleView(viewHolder).addView(tv);
if(viewHolder.mMySelfProfile!=null){//这里采用的是facebook的图片加载,请大家自己按照自己的图片加载方式加载,这里不多叙述
Utils.setImageByUrlOfPicasso(context.getApplicationContext(),viewHolder.mMySelfProfile.getFaceUrl(),viewHolder.rightAvatar,R.drawable.head_me);
}
if(viewHolder.mMyFriendProfile!=null){
Utils.setImageByUrlOfPicasso(context.getApplicationContext(),viewHolder.mMyFriendProfile.getFaceUrl(),viewHolder.leftAvatar,R.drawable.head_other);
}
showStatus(viewHolder);
}
3:ChatActivity类的改造:
通过TIMFriendshipManager.getInstance().getUsersProfile(users, cb);异步加载用户资料获取自己和用户的资料
/**
*
* @Title: initTIMAction
* @Description: 获取聊天2个人资料
* @return void
* @throws
*/
private void initTIMAction() {
List<String> users = new ArrayList<String>();
users.add(identify);
final String user = (String) SPUtil.get(getApplicationContext(),
ContentValue2.TX_IDENTIFIER_FLAG, "");
if (!TextUtils.isEmpty(user)) {
users.add(user);
}
mISigModel.getUsersProfile(users,
new TIMValueCallBack<List<TIMUserProfile>>() {
@Override
public void onSuccess(List<TIMUserProfile> result) {
TIMUserProfile mySelf = null;
TIMUserProfile myFriend = null;
for(TIMUserProfile bea:result){
if(bea.getIdentifier().equals(user)){//自己
mySelf = bea;
}else{
myFriend= bea;
}
}
if( mySelf!=null && myFriend!=null){
startTX(mySelf, myFriend);
mySelf = null;
myFriend= null;
}
}
@Override
public void onError(int code, String desc) {
LogUtil.e("addFriend failed: code=" + code + " ,desc="
+ desc);
startTX(null, null);
}
});
}
private void startTX(TIMUserProfile mySelf, TIMUserProfile myFriend) {
input = (ChatInput) findViewById(R.id.input_panel);
input.setChatView(this);
adapter = new ChatAdapter(this, R.layout.item_message, messageList);
if (mySelf != null)
adapter.setmMySelfProfile(mySelf);
if (myFriend != null)
adapter.setmMyFriendProfile(myFriend);
listView.setAdapter(adapter);
registerForContextMenu(listView);
voiceSendingView = (VoiceSendingView) findViewById(R.id.voice_sending);
presenter.start();
}
至此。可以测试!
- Android 腾讯 云通信 用户头像更新
- android用户头像截取
- Android更改用户头像
- android用户头像截取
- Android设置用户头像代码
- Android用户头像的设置
- 腾讯云通信批量导入用户(用于给未登录过的用户发送消息)
- Android 更新联系人头像失败问题
- Android 离线用户的灰色头像处理
- Android 离线用户的灰色头像处理
- android开发之用户头像上传
- Android中设置用户的头像
- Android开发实现用户头像更换
- android开发之用户头像上传
- android开发之用户头像上传
- android开发之用户头像上传
- Android开发实现用户头像更换
- android开发之用户头像上传
- 3930: [CQOI2015]选数
- 第二周项目3
- git-推送本地项目至github
- 七大查找算法
- <Hibernate>Eclipse安装Hibernate插件
- Android 腾讯 云通信 用户头像更新
- 12个最应该使用的Linux服务器OS(中)
- git修改远程仓库地址
- java && 和|| 的区别 “”和null的区别
- 分步骤安装lnmp完整版
- 3S基础知识:MapInfo MapX中如何保存专题地图
- PHP 换行符的一些说明
- shell高级编程(2)——特殊字符
- 12个最应该使用的Linux服务器OS(下)