use of com.juns.wechat.chat.adpter.MessageAdapter in project wechat by motianhuo.
the class ChatActivity method setUpView.
private void setUpView() {
activityInstance = this;
iv_emoticons_normal.setOnClickListener(this);
iv_emoticons_checked.setOnClickListener(this);
// position = getIntent().getIntExtra("position", -1);
clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
// 判断单聊还是群聊
chatType = getIntent().getIntExtra(Constants.TYPE, CHATTYPE_SINGLE);
Name = getIntent().getStringExtra(Constants.NAME);
img_right.setVisibility(View.VISIBLE);
if (chatType == CHATTYPE_SINGLE) {
// 单聊
toChatUsername = getIntent().getStringExtra(Constants.User_ID);
img_right.setImageResource(R.drawable.icon_chat_user);
if (TextUtils.isEmpty(Name)) {
initUserInfo();
} else {
txt_title.setText(Name);
}
} else {
// 群聊
if (TextUtils.isEmpty(Name)) {
initGroupInfo();
} else {
txt_title.setText(Name);
}
findViewById(R.id.view_location_video).setVisibility(View.GONE);
toChatUsername = getIntent().getStringExtra(Constants.GROUP_ID);
img_right.setImageResource(R.drawable.icon_groupinfo);
}
conversation = EMChatManager.getInstance().getConversation(toChatUsername);
// 把此会话的未读数置为0
conversation.resetUnreadMsgCount();
adapter = new MessageAdapter(this, toChatUsername, chatType);
// 显示消息
listView.setAdapter(adapter);
listView.setOnScrollListener(new ListScrollListener());
int count = listView.getCount();
if (count > 0) {
listView.setSelection(count);
}
listView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
hideKeyboard();
more.setVisibility(View.GONE);
iv_emoticons_normal.setVisibility(View.VISIBLE);
iv_emoticons_checked.setVisibility(View.INVISIBLE);
emojiIconContainer.setVisibility(View.GONE);
btnContainer.setVisibility(View.GONE);
return false;
}
});
// 注册接收消息广播
receiver = new NewMessageBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
// 设置广播的优先级别大于Mainacitivity,这样如果消息来的时候正好在chat页面,直接显示消息,而不是提示消息未读
intentFilter.setPriority(5);
registerReceiver(receiver, intentFilter);
// 注册一个ack回执消息的BroadcastReceiver
IntentFilter ackMessageIntentFilter = new IntentFilter(EMChatManager.getInstance().getAckMessageBroadcastAction());
ackMessageIntentFilter.setPriority(5);
registerReceiver(ackMessageReceiver, ackMessageIntentFilter);
// 注册一个消息送达的BroadcastReceiver
IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
deliveryAckMessageIntentFilter.setPriority(5);
registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);
// 监听当前会话的群聊解散被T事件
groupListener = new GroupListener();
EMGroupManager.getInstance().addGroupChangeListener(groupListener);
// show forward message if the message is not null
String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
if (forward_msg_id != null) {
// 显示发送要转发的消息
forwardMessage(forward_msg_id);
}
}
Aggregations