List of usage examples for android.view View setTag
public void setTag(final Object tag)
From source file:com.easemob.qixin.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }/*from w w w . ja v a 2 s . c o m*/ } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick holder.tv_usernick.setText(message.getFrom()); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:com.aibasis.parent.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }//from www . j a v a 2 s.co m } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); } if (message.direct == EMMessage.Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:cn.hbm.superwechat.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }//from www . ja v a 2 s . co m } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick // UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); Log.i("main", "1"); UserUtils.setGroupUserNick(username, message.getFrom(), holder.tv_usernick); } if (message.direct == EMMessage.Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:com.easemob.chatuidemo.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }//from w w w . ja v a2 s . co m } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick holder.tv_usernick.setText(message.getFrom()); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? //setUserAvatar(message, holder.iv_avatar); holder.iv_avatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.startActivity( new Intent(context, Activity_boshu_FriMsg.class).putExtra("userId", username)); } }); setAvater(context, message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:cn.ucai.fulicenter.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }/* w w w . ja va 2 s.c o m*/ } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (NetworkImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); UserUtils.setUserBeanNick(message.getFrom(), holder.tv_usernick); //UserUtils.setGroupMembersNick(username, message.getFrom(), holder.tv_usernick); } if (message.direct == EMMessage.Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); UserUtils.setCurrentUserBeanNick(holder.tv_usernick); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:com.easemob.chatui.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }//from www. j a va 2 s . c om } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == Direct.RECEIVE) { //demousername?nick // holder.tv_usernick.setText(message.getFrom()); /**?userid????*/ HttpUtils httpUtils = new HttpUtils(); MyRequestParams params = new MyRequestParams(); params.addQueryStringParameter("userid", BeewayApplication.getInstance().getmUserid(context)); params.addQueryStringParameter("friendid", message.getFrom()); params.addQueryStringParameter("track", 1 + ""); String url = params.myRequestParams(params); httpUtils.send(HttpRequest.HttpMethod.POST, UrlPools.USER_DETAIL + "?" + url, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String result = responseInfo.result; UserDetailBean userDetailBean = UserDetailsActivity.paraseUserDetail(result); holder.tv_usernick.setText(userDetailBean.getData().getFriend().getNickname()); } @Override public void onFailure(HttpException e, String s) { LogUtils.e(s); holder.tv_usernick.setText(""); } }); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == EMMessage.Type.TXT || message.getType() == EMMessage.Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); /**???*/ holder.iv_avatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(activity, UserDetailsActivity.class); intent.putExtra("friendid", EMChatManager.getInstance().getCurrentUser()); activity.startActivity(intent); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); /**???*/ holder.iv_avatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(activity, UserDetailsActivity.class); intent.putExtra("friendid", message.getFrom()); activity.startActivity(intent); } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }// w w w. j a v a 2s . c o m } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // // ?????? // if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE){ // //demousername?nick // UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); // } // if(message.direct == EMMessage.Direct.SEND){ // UserUtils.setCurrentUserNick(holder.tv_usernick); // } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(R.string.confirm_resend)); intent.putExtra("title", activity.getString(R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(R.string.Into_the_blacklist); if (!((ChatMessage) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
@SuppressWarnings("deprecation") public void displaydata(final AccountData result, boolean fromcache) { if (getActivity() == null) { return;/*from w w w . jav a2 s.c o m*/ } svAccount.setVisibility(View.VISIBLE); llLoading.setVisibility(View.GONE); unsupportedErrorView.setVisibility(View.GONE); answerErrorView.setVisibility(View.GONE); errorView.removeAllViews(); this.fromcache = fromcache; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext()); final int tolerance = Integer.parseInt(sp.getString("notification_warning", "3")); tvAccLabel.setText(account.getLabel()); tvAccUser.setText(account.getName()); Library lib; try { lib = app.getLibrary(account.getLibrary()); tvAccCity.setText(lib.getDisplayName()); } catch (IOException e) { ErrorReporter.handleException(e); e.printStackTrace(); } catch (JSONException e) { ErrorReporter.handleException(e); } /* Lent items */ llLent.removeAllViews(); final boolean notification_on = sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false); boolean notification_problems = false; if (tvWarning != null) { if (result.getWarning() != null && result.getWarning().length() > 1) { tvWarning.setVisibility(View.VISIBLE); tvWarning.setText(result.getWarning()); } else { tvWarning.setVisibility(View.GONE); } } if (result.getLent().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.entl_none); llLent.addView(t1); tvLentHeader.setText(getActivity().getString(R.string.lent_head) + " (0)"); } else { tvLentHeader .setText(getActivity().getString(R.string.lent_head) + " (" + result.getLent().size() + ")"); lentManager = new ExpandingCardListManager(getActivity(), llLent) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_lent, container, false); LentViewHolder holder = new LentViewHolder(); holder.findViews(v); final LentItem item = result.getLent().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Status/Deadline) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); if (item.getDeadline() != null && item.getStatus() != null) { holder.tvStatus.setText( fmt.print(item.getDeadline()) + " (" + Html.fromHtml(item.getStatus()) + ")"); } else if (item.getDeadline() != null) { holder.tvStatus.setText(fmt.print(new LocalDate(item.getDeadline()))); } else { setHtmlTextOrHide(item.getStatus(), holder.tvStatus); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); if (item.getLendingBranch() != null && item.getHomeBranch() != null) { holder.tvBranchDetail .setText(Html.fromHtml(item.getLendingBranch() + " / " + item.getHomeBranch())); } else if (item.getLendingBranch() != null) { holder.tvBranchDetail.setText(Html.fromHtml(item.getLendingBranch())); } else { setHtmlTextOrHide(item.getHomeBranch(), holder.tvBranchDetail); } // Color codes for return dates if (item.getDeadline() != null) { if (item.getDeadline().equals(LocalDate.now()) || item.getDeadline().isBefore(LocalDate.now())) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_overdue)); } else if (Days.daysBetween(LocalDate.now(), item.getDeadline()).getDays() <= tolerance) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_warning)); } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } if (item.getProlongData() != null) { holder.ivProlong.setTag(item.getProlongData()); holder.ivProlong.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { prolong((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.VISIBLE); holder.ivProlong.setAlpha(item.isRenewable() ? 255 : 100); } else if (item.getDownloadData() != null && app.getApi() instanceof EbookServiceApi) { holder.ivDownload.setTag(item.getDownloadData()); holder.ivDownload.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { download((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.GONE); holder.ivDownload.setVisibility(View.VISIBLE); } else { holder.ivProlong.setVisibility(View.INVISIBLE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.VISIBLE); setHtmlTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getLent().size(); } }; lentManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { LentViewHolder holder = (LentViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvResHeader, 0); ViewHelper.setTranslationY(llRes, 0); ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getLent().size() >= result.getReservations().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvResHeader, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(llRes, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); for (final LentItem item : result.getLent()) { try { if (notification_on && item.getDeadline() == null && !item.isEbook()) { notification_problems = true; } } catch (Exception e) { notification_problems = true; } } } if (notification_problems) { if (tvError != null) { tvError.setVisibility(View.VISIBLE); tvError.setText(R.string.notification_problems); } } /* Reservations */ llRes.removeAllViews(); if (result.getReservations().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.reservations_none); llRes.addView(t1); tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (0)"); } else { tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (" + result.getReservations().size() + ")"); resManager = new ExpandingCardListManager(getActivity(), llRes) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_reservation, llRes, false); ReservationViewHolder holder = new ReservationViewHolder(); holder.findViews(v); final ReservedItem item = result.getReservations().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Ready/Expire) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); StringBuilder status = new StringBuilder(); if (item.getStatus() != null) status.append(item.getStatus()); boolean needsBraces = item.getStatus() != null && (item.getReadyDate() != null || item.getExpirationDate() != null); if (needsBraces) status.append(" ("); if (item.getReadyDate() != null) { status.append(getString(R.string.reservation_expire_until)).append(" ") .append(fmt.print(item.getReadyDate())); } if (item.getExpirationDate() != null) { if (item.getReadyDate() != null) status.append(", "); status.append(fmt.print(item.getExpirationDate())); } if (needsBraces) status.append(")"); if (status.length() > 0) { holder.tvStatus.setText(Html.fromHtml(status.toString())); } else { holder.tvStatus.setVisibility(View.GONE); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); setHtmlTextOrHide(item.getBranch(), holder.tvBranchDetail); if (item.getBookingData() != null) { holder.ivBooking.setTag(item.getBookingData()); holder.ivBooking.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { bookingStart((String) arg0.getTag()); } }); holder.ivBooking.setVisibility(View.VISIBLE); holder.ivCancel.setVisibility(View.GONE); } else if (item.getCancelData() != null) { holder.ivCancel.setTag(item.getCancelData()); holder.ivCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { cancel((String) arg0.getTag()); } }); holder.ivCancel.setVisibility(View.VISIBLE); holder.ivBooking.setVisibility(View.GONE); } else { holder.ivCancel.setVisibility(View.INVISIBLE); holder.ivBooking.setVisibility(View.GONE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.VISIBLE); setTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getReservations().size(); } }; resManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { ReservationViewHolder holder = (ReservationViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getReservations().size() >= result.getLent().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); } if (result.getPendingFees() != null) { tvPendingFeesLabel.setVisibility(View.VISIBLE); tvPendingFees.setVisibility(View.VISIBLE); tvPendingFees.setText(result.getPendingFees()); } else { tvPendingFeesLabel.setVisibility(View.GONE); tvPendingFees.setVisibility(View.GONE); } if (result.getValidUntil() != null) { tvValidUntilLabel.setVisibility(View.VISIBLE); tvValidUntil.setVisibility(View.VISIBLE); tvValidUntil.setText(result.getValidUntil()); } else { tvValidUntilLabel.setVisibility(View.GONE); tvValidUntil.setVisibility(View.GONE); } refreshage(); }
From source file:cn.ucai.superwechat.adapter.MessageAdapter.java
@SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); ChatType chatType = message.getChatType(); final ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = createViewByMessage(message, position); if (message.getType() == EMMessage.Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); } catch (Exception e) { }/*from w w w. j a v a 2 s .c o m*/ } else if (message.getType() == EMMessage.Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(cn.ucai.superwechat.R.id.ll_layout); } catch (Exception e) { } // ??? if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) { holder.iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_chatcontent); } } else if (message.getType() == EMMessage.Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); holder.iv_read_status = (ImageView) convertView .findViewById(cn.ucai.superwechat.R.id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.VIDEO) { try { holder.iv = ((ImageView) convertView .findViewById(cn.ucai.superwechat.R.id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.percentage); holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.size = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.chatting_size_iv); holder.timeLength = (TextView) convertView .findViewById(cn.ucai.superwechat.R.id.chatting_length_iv); holder.playBtn = (ImageView) convertView .findViewById(cn.ucai.superwechat.R.id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView .findViewById(cn.ucai.superwechat.R.id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.iv_userhead); holder.tv_file_name = (TextView) convertView .findViewById(cn.ucai.superwechat.R.id.tv_file_name); holder.tv_file_size = (TextView) convertView .findViewById(cn.ucai.superwechat.R.id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(cn.ucai.superwechat.R.id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); holder.tv_file_download_state = (TextView) convertView .findViewById(cn.ucai.superwechat.R.id.tv_file_state); holder.ll_container = (LinearLayout) convertView .findViewById(cn.ucai.superwechat.R.id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE) { //demousername?nick //UserUtils.setAppUserNick(message.getFrom(), holder.tv_usernick); UserUtils.setAppMemberNick(username, message.getFrom(), holder.tv_usernick); } if (message.direct == EMMessage.Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.tv_delivered); if (holder.tv_ack != null) { if (message.isAcked) { if (holder.tv_delivered != null) { holder.tv_delivered.setVisibility(View.INVISIBLE); } holder.tv_ack.setVisibility(View.VISIBLE); } else { holder.tv_ack.setVisibility(View.INVISIBLE); // check and display msg delivered ack status if (holder.tv_delivered != null) { if (message.isDelivered) { holder.tv_delivered.setVisibility(View.VISIBLE); } else { holder.tv_delivered.setVisibility(View.INVISIBLE); } } } } } else { // ??group messgae,chatroom message?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) { // ?? if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } //? setUserAvatar(message, holder.iv_avatar); switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false) || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) // ? handleCallMessage(message, holder, position); else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) //?? handleRobotMenuMessage(message, holder, position); else handleTextMessage(message, holder, position); break; case LOCATION: // ? handleLocationMessage(message, holder, position, convertView); break; case VOICE: // handleVoiceMessage(message, holder, position, convertView); break; case VIDEO: // handleVideoMessage(message, holder, position, convertView); break; case FILE: // handleFileMessage(message, holder, position, convertView); break; default: // not supported } if (message.direct == EMMessage.Direct.SEND) { View statusView = convertView.findViewById(cn.ucai.superwechat.R.id.msg_status); // ?? statusView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ???alertdialog Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", activity.getString(cn.ucai.superwechat.R.string.confirm_resend)); intent.putExtra("title", activity.getString(cn.ucai.superwechat.R.string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == EMMessage.Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == EMMessage.Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == EMMessage.Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == EMMessage.Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == EMMessage.Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == EMMessage.Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(cn.ucai.superwechat.R.string.Into_the_blacklist); if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) { // ???? holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", st); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); } } TextView timestamp = (TextView) convertView.findViewById(cn.ucai.superwechat.R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? EMMessage prevMessage = getItem(position - 1); if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } return convertView; }