List of usage examples for android.view View getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:com.xiaoyu.DoctorHelp.chat.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 ww. j av a2 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); } 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 (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.android.launcher3.Workspace.java
/** * Adds the specified child in the specified screen. The position and dimension of * the child are defined by x, y, spanX and spanY. * * @param child The child to add in one of the workspace's screens. * @param screenId The screen in which to add the child. * @param x The X position of the child in the screen's grid. * @param y The Y position of the child in the screen's grid. * @param spanX The number of cells spanned horizontally by the child. * @param spanY The number of cells spanned vertically by the child. * @param insert When true, the child is inserted at the beginning of the children list. * @param computeXYFromRank When true, we use the rank (stored in screenId) to compute * the x and y position in which to place hotseat items. Otherwise * we use the x and y position to compute the rank. */// www . jav a 2 s . co m void addInScreen(View child, long container, long screenId, int x, int y, int spanX, int spanY, boolean insert, boolean computeXYFromRank) { if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { if (getScreenWithId(screenId) == null) { Log.e(TAG, "Skipping child, screenId " + screenId + " not found"); // DEBUGGING - Print out the stack trace to see where we are adding from new Throwable().printStackTrace(); return; } } if (screenId == EXTRA_EMPTY_SCREEN_ID) { // This should never happen throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); } final CellLayout layout; if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { layout = mLauncher.getHotseat().getLayout(); child.setOnKeyListener(new HotseatIconKeyEventListener()); // Hide folder title in the hotseat if (child instanceof FolderIcon) { ((FolderIcon) child).setTextVisible(false); } if (computeXYFromRank) { x = mLauncher.getHotseat().getCellXFromOrder((int) screenId); y = mLauncher.getHotseat().getCellYFromOrder((int) screenId); } else { screenId = mLauncher.getHotseat().getOrderInHotseat(x, y); } } else { // Show folder title if not in the hotseat if (child instanceof FolderIcon) { ((FolderIcon) child).setTextVisible(true); } layout = getScreenWithId(screenId); child.setOnKeyListener(new IconKeyEventListener()); } ViewGroup.LayoutParams genericLp = child.getLayoutParams(); CellLayout.LayoutParams lp; if (genericLp == null || !(genericLp instanceof CellLayout.LayoutParams)) { lp = new CellLayout.LayoutParams(x, y, spanX, spanY); } else { lp = (CellLayout.LayoutParams) genericLp; lp.cellX = x; lp.cellY = y; lp.cellHSpan = spanX; lp.cellVSpan = spanY; } if (spanX < 0 && spanY < 0) { lp.isLockedToGrid = false; } // Get the canonical child id to uniquely represent this view in this screen ItemInfo info = (ItemInfo) child.getTag(); int childId = mLauncher.getViewIdForItem(info); boolean markCellsAsOccupied = !(child instanceof Folder); if (!layout.addViewToCellLayout(child, insert ? 0 : -1, childId, lp, markCellsAsOccupied)) { // TODO: This branch occurs when the workspace is adding views // outside of the defined grid // maybe we should be deleting these items from the LauncherModel? Launcher.addDumpLog(TAG, "Failed to add to item at (" + lp.cellX + "," + lp.cellY + ") to CellLayout", true); } if (!(child instanceof Folder)) { child.setHapticFeedbackEnabled(false); //CG wujiangwei Add B for Launcher for Glass 2015.09.30 //child.setOnLongClickListener(mLongClickListener); } if (child instanceof DropTarget) { mDragController.addDropTarget((DropTarget) child); } }
From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java
@Override @SuppressLint("NewApi") public View getView(final int position, View convertView, ViewGroup parent) { final EMMessage message = getItem(position); System.out.println("message.getMsgId()" + message.getMsgId()); 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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { }// w ww . ja v a2 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.head_iv = (CircleImageView) convertView.findViewById(R.id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent); holder.tv_userId = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { System.out.println(e.toString()); } // ? if (message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice); } catch (Exception e) { System.out.println(e.toString()); } } else if (message.getType() == EMMessage.Type.LOCATION) { try { holder.head_iv = (CircleImageView) 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_userId = (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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } else if (message.getType() == EMMessage.Type.FILE) { try { holder.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid); } catch (Exception e) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // ?????? if (chatType == ChatType.GroupChat && message.direct == EMMessage.Direct.RECEIVE) // demousernamenick holder.tv_userId.setText(message.getFrom()); // ??????textview if (message.direct == EMMessage.Direct.SEND && chatType != ChatType.GroupChat) { 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?? if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked && chatType != ChatType.GroupChat) { // ?? if (!message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); // ?? message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } } } switch (message.getType()) { // ??typeitem case IMAGE: // handleImageMessage(message, holder, position, convertView); break; case TXT: // if (!message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)) handleTextMessage(message, holder, position); else // ? handleVoiceCallMessage(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); } }); // ? System.out.println("?:" + appContext.getUserInfo().getUserLogoUrl()); ImageLoaderUtil.getImageLoader().displayImage( DisplayUtils.getAbsolutelyUrl(appContext.getUserInfo().getUserLogoUrl()), holder.head_iv); // ? holder.head_iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(activity, PerssonalInfoAcitivity.class); intent.putExtra("userId", AppContext.getApplication().getUserInfo().getUserId()); activity.startActivity(intent); } }); } else { // ???? holder.head_iv.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent = new Intent(activity, AlertDialog.class); intent.putExtra("msg", "???"); intent.putExtra("cancel", true); intent.putExtra("position", position); activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST); return true; } }); // ? String imgUrl = ""; try { imgUrl = message.getStringAttribute("imgurl"); } catch (EaseMobException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // ? ImageLoaderUtil.getImageLoader().displayImage(DisplayUtils.getAbsolutelyUrl(imgUrl), holder.head_iv); // ?mumu?userId String username = conversation.getUserName(); findUserIdByAccount(username, holder.head_iv); // ImageLoaderUtil.getImageLoader().displayImage( // DisplayUtils.getAbsolutelyUrl(ImageUrl), holder.head_iv); } TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp); if (position == 0) { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } else { // ??? if (DateUtils.isCloseEnough(message.getMsgTime(), conversation.getMessage(position - 1).getMsgTime())) { timestamp.setVisibility(View.GONE); } else { timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime()))); timestamp.setVisibility(View.VISIBLE); } } // System.out.println("message from "+message); return convertView; }
From source file:com.shengtao.chat.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() == Type.IMAGE) { try { holder.iv = ((ImageView) convertView.findViewById(id.iv_sendPicture)); holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); holder.tv = (TextView) convertView.findViewById(id.percentage); holder.pb = (ProgressBar) convertView.findViewById(id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid); } catch (Exception e) { }/*ww w . jav a2 s .c o m*/ } else if (message.getType() == Type.TXT) { try { holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); // holder.tv = (TextView) convertView.findViewById(id.tv_chatcontent); holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid); holder.tvTitle = (TextView) convertView.findViewById(id.tvTitle); holder.tvList = (LinearLayout) convertView.findViewById(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(id.iv_call_icon); holder.tv = (TextView) convertView.findViewById(id.tv_chatcontent); } } else if (message.getType() == Type.VOICE) { try { holder.iv = ((ImageView) convertView.findViewById(id.iv_voice)); holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); holder.tv = (TextView) convertView.findViewById(id.tv_length); holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid); holder.iv_read_status = (ImageView) convertView.findViewById(id.iv_unread_voice); } catch (Exception e) { } } else if (message.getType() == Type.LOCATION) { try { holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); holder.tv = (TextView) convertView.findViewById(id.tv_location); holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid); } catch (Exception e) { } } else if (message.getType() == Type.VIDEO) { try { holder.iv = ((ImageView) convertView.findViewById(id.chatting_content_iv)); holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); holder.tv = (TextView) convertView.findViewById(id.percentage); holder.pb = (ProgressBar) convertView.findViewById(id.progressBar); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.size = (TextView) convertView.findViewById(id.chatting_size_iv); holder.timeLength = (TextView) convertView.findViewById(id.chatting_length_iv); holder.playBtn = (ImageView) convertView.findViewById(id.chatting_status_btn); holder.container_status_btn = (LinearLayout) convertView.findViewById(id.container_status_btn); holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid); } catch (Exception e) { } } else if (message.getType() == Type.FILE) { try { holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead); holder.tv_file_name = (TextView) convertView.findViewById(id.tv_file_name); holder.tv_file_size = (TextView) convertView.findViewById(id.tv_file_size); holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending); holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status); holder.tv_file_download_state = (TextView) convertView.findViewById(id.tv_file_state); holder.ll_container = (LinearLayout) convertView.findViewById(id.ll_file_container); // holder.tv = (TextView) convertView.findViewById(id.percentage); } catch (Exception e) { } try { holder.tv_usernick = (TextView) convertView.findViewById(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 UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); } if (message.direct == Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); } // ??????textview if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == Direct.SEND) { holder.tv_ack = (TextView) convertView.findViewById(id.tv_ack); holder.tv_delivered = (TextView) convertView.findViewById(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.tv_usernick); 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(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(string.confirm_resend)); intent.putExtra("title", activity.getString(string.resend)); intent.putExtra("cancel", true); intent.putExtra("position", position); if (message.getType() == Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == Type.VIDEO) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO); } }); } else { final String st = context.getResources().getString(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(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.xpple.jahoqy.adapter.MessageAdapter.java
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() == 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 ww.j av a 2s. com*/ } else if (message.getType() == 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() == 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() == 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() == 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() == 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 UserUtils.setUserNick(message.getFrom(), holder.tv_usernick); } if (message.direct == Direct.SEND) { UserUtils.setCurrentUserNick(holder.tv_usernick); } // ??????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() == 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 == 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() == Type.TXT) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT); else if (message.getType() == Type.VOICE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE); else if (message.getType() == Type.IMAGE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE); else if (message.getType() == Type.LOCATION) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION); else if (message.getType() == Type.FILE) activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE); else if (message.getType() == 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.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 w w w . j a 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 = (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 w ww .j a 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 // 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 www .j ava2s . 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) { }/* www. j a 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 = (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; }