use of com.easemob.exceptions.EaseMobException in project wechat by motianhuo.
the class MessageAdapter method handleFileMessage.
/**
* 文件消息
*
* @param message
* @param holder
* @param position
* @param convertView
*/
private void handleFileMessage(final EMMessage message, final ViewHolder holder, int position, View convertView) {
final NormalFileMessageBody fileMessageBody = (NormalFileMessageBody) message.getBody();
final String filePath = fileMessageBody.getLocalUrl();
holder.tv_file_name.setText(fileMessageBody.getFileName());
holder.tv_file_size.setText(TextFormater.getDataSize(fileMessageBody.getFileSize()));
holder.ll_container.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
File file = new File(filePath);
if (file != null && file.exists()) {
// 文件存在,直接打开
FileUtils.openFile(file, (Activity) context);
} else {
// 下载
// TODO 下载文件
context.startActivity(new Intent(context, ShowNormalFileActivity.class).putExtra("msgbody", fileMessageBody));
}
if (message.direct == EMMessage.Direct.RECEIVE && !message.isAcked) {
try {
EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
message.isAcked = true;
} catch (EaseMobException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
String st1 = context.getResources().getString(R.string.Have_downloaded);
String st2 = context.getResources().getString(R.string.Did_not_download);
if (message.direct == EMMessage.Direct.RECEIVE) {
// 接收的消息
System.err.println("it is receive msg");
File file = new File(filePath);
if (file != null && file.exists()) {
holder.tv_file_download_state.setText(st1);
} else {
holder.tv_file_download_state.setText(st2);
}
return;
}
// until here, deal with send voice msg
switch(message.status) {
case SUCCESS:
holder.pb.setVisibility(View.INVISIBLE);
holder.tv.setVisibility(View.INVISIBLE);
holder.staus_iv.setVisibility(View.INVISIBLE);
break;
case FAIL:
holder.pb.setVisibility(View.INVISIBLE);
holder.tv.setVisibility(View.INVISIBLE);
holder.staus_iv.setVisibility(View.VISIBLE);
break;
case INPROGRESS:
if (timers.containsKey(message.getMsgId()))
return;
// set a timer
final Timer timer = new Timer();
timers.put(message.getMsgId(), timer);
timer.schedule(new TimerTask() {
@Override
public void run() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
holder.pb.setVisibility(View.VISIBLE);
holder.tv.setVisibility(View.VISIBLE);
holder.tv.setText(message.progress + "%");
if (message.status == EMMessage.Status.SUCCESS) {
holder.pb.setVisibility(View.INVISIBLE);
holder.tv.setVisibility(View.INVISIBLE);
timer.cancel();
} else if (message.status == EMMessage.Status.FAIL) {
holder.pb.setVisibility(View.INVISIBLE);
holder.tv.setVisibility(View.INVISIBLE);
holder.staus_iv.setVisibility(View.VISIBLE);
Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
timer.cancel();
}
}
});
}
}, 0, 500);
break;
default:
// 发送消息
sendMsgInBackground(message, holder);
}
}
use of com.easemob.exceptions.EaseMobException in project wechat by motianhuo.
the class NewFriendsAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.layout_item_newfriend, parent, false);
}
ImageView img_avar = ViewHolder.get(convertView, R.id.img_photo);
TextView txt_name = ViewHolder.get(convertView, R.id.txt_name);
final TextView txt_add = ViewHolder.get(convertView, R.id.txt_add);
final User user = GloableParams.UserInfos.get(position);
txt_name.setText(user.getUserName());
txt_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
txt_add.setTextColor(context.getResources().getColor(R.color.black1));
txt_add.setBackgroundResource(R.drawable.btn_bg_gray1);
txt_add.setText("已添加");
Utils.showLongToast(context, "添加好友成功,等待对方同意");
try {
EMContactManager.getInstance().addContact(user.getTelephone(), "请求添加你为朋友");
} catch (EaseMobException e) {
e.printStackTrace();
}
}
});
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, FriendMsgActivity.class);
intent.putExtra(Constants.NAME, user.getUserName());
intent.putExtra(Constants.TYPE, ChatActivity.CHATTYPE_SINGLE);
intent.putExtra(Constants.User_ID, user.getTelephone());
context.startActivity(intent);
}
});
return convertView;
}
use of com.easemob.exceptions.EaseMobException in project wechat by motianhuo.
the class GroupSettingActivity method initData.
@Override
protected void initData() {
// 获取传过来的groupid
groupId = getIntent().getStringExtra(Constants.GROUP_ID);
// 获取本地该群数据
group = EMGroupManager.getInstance().getGroup(groupId);
if (group == null) {
try {
// 去网络中查找该群
group = EMGroupManager.getInstance().getGroupFromServer(groupId);
if (group == null) {
Toast.makeText(GroupSettingActivity.this, "该群已经被解散...", Toast.LENGTH_SHORT).show();
setResult(100);
finish();
return;
}
} catch (EaseMobException e) {
e.printStackTrace();
return;
}
}
// 获取封装的群名(里面封装了显示的群名和群组成员的信息)
String group_name = group.getGroupName();
// 获取群成员信息
tv_groupname.setText(group_name);
GroupInfo groupinfo = GloableParams.GroupInfos.get(groupId);
if (groupinfo != null) {
String[] manbers = groupinfo.getMembers().split("、");
if (manbers != null && manbers.length > 0) {
m_total = manbers.length;
txt_title.setText("聊天信息(" + String.valueOf(m_total) + ")");
// 解析群组成员信息
for (int i = 0; i < m_total; i++) {
User user = GloableParams.Users.get(manbers[i]);
if (user == null) {
user = new User();
user.setTelephone(manbers[i]);
}
members.add(user);
}
// 显示群组成员头像和昵称
showMembers(members);
// 判断是否是群主,是群主有删成员的权限,并显示减号按钮
if (null != groupinfo.getOwner_id() && null != hxid && hxid.equals(groupinfo.getOwner_id())) {
is_admin = true;
}
}
}
}
use of com.easemob.exceptions.EaseMobException in project wechat by motianhuo.
the class AddGroupChatActivity method creatNewGroup.
private void creatNewGroup(final List<String> members) {
// TODO 请求服务器创建群组,服务端实现接口
new Thread(new Runnable() {
@Override
public void run() {
// 调用sdk创建群组方法
try {
final String[] strmembers = new String[members.size()];
for (int i = 0; i < members.size(); i++) {
User user = GloableParams.Users.get(members.get(i));
if (user != null) {
if (i < 3) {
if (i == 0)
groupName = user.getUserName();
else
groupName += "、" + user.getUserName();
} else if (i == 4) {
groupName += "...";
}
strmembers[i] = user.getTelephone();
if (i == 0) {
manber = user.getTelephone();
} else {
manber += "、" + user.getTelephone();
}
}
}
final EMGroup group = EMGroupManager.getInstance().createPublicGroup(groupName, "", strmembers, true);
runOnUiThread(new Runnable() {
public void run() {
if (group != null) {
// TODO 保存本地数据库
GloableParams.GroupInfos = new HashMap<String, GroupInfo>();
GroupInfo info = new GroupInfo();
info.setGroup_id(group.getGroupId());
info.setGroup_name(groupName);
info.setMembers(manber);
String owner_id = Utils.getValue(AddGroupChatActivity.this, Constants.User_ID);
info.setOwner_id(owner_id);
GloableParams.GroupInfos.put(group.getGroupId(), info);
FinalDb db = FinalDb.create(AddGroupChatActivity.this, Constants.DB_NAME, false);
db.save(info);
addServieGroup(group.getGroupId(), groupName, manber, // 保存服务器
owner_id);
}
}
});
} catch (final EaseMobException e) {
runOnUiThread(new Runnable() {
public void run() {
Utils.showLongToast(AddGroupChatActivity.this, "创建失败");
getLoadingDialog("正在创建群聊...").dismiss();
}
});
}
}
}).start();
}
Aggregations