Example usage for android.view View setTag

List of usage examples for android.view View setTag

Introduction

In this page you can find the example usage for android.view View setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public void showNewMessage(final MsgGroups mensaje) {
    activity.runOnUiThread(new Runnable() {
        @Override//from  w  ww.  ja  va  2s .co m
        public void run() {
            if (!messagesList.isShown()) {
                messagesList.setVisibility(View.VISIBLE);
            }
            messagesListScroll.setVerticalScrollBarEnabled(false);
            mensajesTotal = mensajesTotal + 1;
            View v = addBoxMessage(-1, getActivity(), mensaje, getActivity().getLayoutInflater());
            v.setTag(mensaje.mensajeId);
            messagesList.addView(v);
            if (!mensaje.emisor.equals(u.id)) {
                if (mensaje.receptores != null) {
                    try {
                        JSONArray contactos = new JSONArray(mensaje.receptores);
                        Log.w("RECEPTORES", contactos.toString());
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            if (contacto.getString("name").equals(u.id)) {
                                if (contacto.getInt("status") != 4) {
                                    JSONObject notifyMessage = new JSONObject();
                                    notifyMessage.put("type", mensaje.tipo);
                                    notifyMessage.put("message_id", mensaje.mensajeId);
                                    notifyMessage.put("source", mensaje.emisor);
                                    notifyMessage.put("target", u.id);
                                    notifyMessage.put("status", 4);
                                    if (SpeakSocket.mSocket != null)
                                        if (SpeakSocket.mSocket.connected()) {
                                            SpeakSocket.mSocket.emit("message-status", notifyMessage);
                                            contacto.put("status", 4);
                                            new Update(MsgGroups.class)
                                                    .set("receptores = ?", contactos.toString())
                                                    .where("mensajeId = ?", mensaje.mensajeId).execute();
                                            if (mensaje.delay > 0) {
                                                startCounterToDelete((mensaje.delay * 1000), mensaje);
                                            }
                                        }
                                }
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            System.gc();
        }
    });
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public void showPreviousMessages(int mensajesOffset) {
    messagesListScroll.setVerticalScrollBarEnabled(false);
    mensajesTotal = new Select().all().from(MsgGroups.class).where("grupoId = ?", grupo.grupoId).count();
    List<MsgGroups> mensajes = new Select().from(MsgGroups.class).limit(mensajesLimit)
            .offset(mensajesTotal - mensajesOffset).where("grupoId = ?", grupo.grupoId).orderBy("emitedAt ASC")
            .execute();/*from   w  w w . ja v  a2s. c  o  m*/
    Collections.reverse(mensajes);

    if (!mensajes.isEmpty()) {
        int position = mensajesLimit - 1;
        for (MsgGroups mensaje : mensajes) {
            final View v = addBoxMessage(position, getActivity(), mensaje, getActivity().getLayoutInflater());
            v.setTag(mensaje.mensajeId);
            messagesList.addView(v, 0);
            position = position - 1;
            if (!mensaje.emisor.equals(u.id)) {
                if (mensaje.receptores != null) {
                    try {
                        JSONArray contactos = new JSONArray(mensaje.receptores);
                        Log.w("RECEPTORES", contactos.toString());
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            if (contacto.getString("name").equals(u.id)) {
                                if (contacto.getInt("status") != 4) {
                                    JSONObject notifyMessage = new JSONObject();
                                    notifyMessage.put("type", mensaje.tipo);
                                    notifyMessage.put("message_id", mensaje.mensajeId);
                                    notifyMessage.put("source", mensaje.emisor);
                                    notifyMessage.put("target", u.id);
                                    notifyMessage.put("status", 4);
                                    Log.w("SEND STATUS CHAT: ", notifyMessage.toString());
                                    SpeakSocket.mSocket.emit("message-status", notifyMessage);
                                    contacto.put("status", 4);
                                }
                            }
                        }
                        new Update(MsgGroups.class).set("receptores = ?", contactos.toString())
                                .where("mensajeId = ?", mensaje.mensajeId).execute();
                        if (mensaje.delay > 0) {
                            startCounterToDelete((mensaje.delay * 1000), mensaje);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public void initAdapter() {
    messagesList.removeAllViews();//from ww w. j a v  a 2s  .  c o  m
    mensajesTotal = new Select().all().from(MsgGroups.class).where("grupoId = ?", grupo.grupoId).count();
    List<MsgGroups> mensajes = new Select().from(MsgGroups.class).limit(mensajesLimit)
            .offset(mensajesTotal - mensajesLimit).where("grupoId = ?", grupo.grupoId).orderBy("emitedAt ASC")
            .execute();
    Collections.reverse(mensajes);
    if (!mensajes.isEmpty()) {
        int position = mensajesLimit - 1;
        for (MsgGroups mensaje : mensajes) {
            messagesListScroll.setVerticalScrollBarEnabled(false);
            final View v = addBoxMessage(position, getActivity(), mensaje, getActivity().getLayoutInflater());
            v.setTag(mensaje.mensajeId);
            messagesList.addView(v, 0);
            position = position - 1;
            Log.e("Receptores", mensaje.receptores + " : " + mensaje.emisorEmail);
            if (!mensaje.emisor.equals(u.id)) {
                if (mensaje.receptores != null) {
                    try {
                        Log.w("Receptores", mensaje.receptores + " : " + mensaje.emisorEmail);
                        JSONArray contactos = new JSONArray(mensaje.receptores);
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            if (contacto.getString("name").equals(u.id)) {
                                if (contacto.getInt("status") != 4) {
                                    JSONObject notifyMessage = new JSONObject();
                                    notifyMessage.put("type", mensaje.tipo);
                                    notifyMessage.put("message_id", mensaje.mensajeId);
                                    notifyMessage.put("source", mensaje.emisor);
                                    notifyMessage.put("target", u.id);
                                    notifyMessage.put("status", 4);
                                    Log.w("SEND STATUS CHAT: ", notifyMessage.toString());
                                    SpeakSocket.mSocket.emit("message-status", notifyMessage);
                                    contacto.put("status", 4);
                                }
                            }
                        }

                        new Update(MsgGroups.class).set("receptores = ?", contactos.toString())
                                .where("mensajeId = ?", mensaje.mensajeId).execute();
                        if (mensaje.delay > 0) {
                            startCounterToDelete((mensaje.delay * 1000), mensaje);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        messagesList.setVisibility(View.VISIBLE);
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void showNewMessage(final Message mensaje) {
    activity.runOnUiThread(new Runnable() {
        @Override//from  w  ww. j a  v  a 2  s  .  c  o m
        public void run() {
            if (!messagesList.isShown()) {
                messagesList.setVisibility(View.VISIBLE);
            }
            messagesListScroll.setVerticalScrollBarEnabled(false);
            mensajesTotal = mensajesTotal + 1;
            View v = addBoxMessage(-1, getActivity(), mensaje, getActivity().getLayoutInflater());
            v.setTag(mensaje.mensajeId);

            messagesList.addView(v);
            if (!mensaje.emisor.equals(u.id)) {
                Chats chats = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor)
                        .executeSingle();
                if (chats.mensajeId.equals(mensaje.mensajeId)) {
                    chats.notRead = 0;
                    chats.save();
                }
                JSONObject notifyMessage = new JSONObject();
                try {
                    notifyMessage.put("type", mensaje.tipo);
                    notifyMessage.put("message_id", mensaje.mensajeId);
                    notifyMessage.put("source", mensaje.emisor);
                    notifyMessage.put("status", 4);
                    if (SpeakSocket.isRunning()) {
                        if (SpeakSocket.mSocket.connected()) {
                            SpeakSocket.mSocket.emit("message-status", notifyMessage);
                            new Update(Message.class).set("status = ?", 4)
                                    .where("mensajeId = ?", mensaje.mensajeId).execute();
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                if (mensaje.delay > 0) {
                    startCounterToDelete((mensaje.delay * 1000), mensaje);
                }
            }
            if (mensaje.status == 4) {
                if (mensaje.delay > 0) {
                    startCounterToDelete((mensaje.delay * 1000), mensaje);
                }
            }
            messagesList.setVisibility(View.VISIBLE);
            System.gc();
        }
    }

    );
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void showPreviousMessages(int mensajesOffset) {
    messagesListScroll.setVerticalScrollBarEnabled(false);
    mensajesTotal = new Select().all().from(Message.class).where("emisor = ?", contact.idContacto)
            .or("receptor = ?", contact.idContacto).count();
    List<Message> mensajes = new Select().from(Message.class).limit(mensajesLimit)
            .offset(mensajesTotal - mensajesOffset).where("emisor = ?", contact.idContacto)
            .or("receptor = ?", contact.idContacto).orderBy("emitedAt ASC").execute();
    Collections.reverse(mensajes);

    if (!mensajes.isEmpty()) {
        int position = mensajesLimit - 1;
        for (Message mensaje : mensajes) {
            final View v = addBoxMessage(position, getActivity(), mensaje, getActivity().getLayoutInflater());
            v.setTag(mensaje.mensajeId);
            messagesList.addView(v, 0);/*from   www. ja va 2 s.  co m*/
            position = position - 1;
            if (!mensaje.emisor.equals(u.id) && mensaje.status == 0) {
                Chats chats = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor)
                        .executeSingle();
                if (chats.mensajeId.equals(mensaje.mensajeId)) {
                    chats.notRead = 0;
                    chats.save();
                }
                JSONObject notifyMessage = new JSONObject();
                try {
                    notifyMessage.put("type", mensaje.tipo);
                    notifyMessage.put("message_id", mensaje.mensajeId);
                    notifyMessage.put("source", mensaje.emisor);
                    notifyMessage.put("status", 4);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                if (SpeakSocket.isRunning()) {
                    SpeakSocket.mSocket.emit("message-status", notifyMessage);
                    new Update(Message.class).set("status = ?", 4).where("mensajeId = ?", mensaje.mensajeId)
                            .execute();
                }
                if (mensaje.delay > 0) {
                    startCounterToDelete((mensaje.delay * 1000), mensaje);
                }
            }
            if (mensaje.status == 4) {
                if (mensaje.delay > 0) {
                    startCounterToDelete((mensaje.delay * 1000), mensaje);
                }
            }
        }
        System.gc();
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void initAdapter() {
    activity.runOnUiThread(new Runnable() {
        @Override//from  w  w  w.j  av  a 2 s  .  c o m
        public void run() {
            messagesList.removeAllViews();
            mensajesTotal = new Select().all().from(Message.class).where("emisor = ?", contact.idContacto)
                    .or("receptor = ?", contact.idContacto).count();
            List<Message> mensajes = new Select().from(Message.class).limit(mensajesLimit)
                    .offset(mensajesTotal - mensajesLimit).where("emisor = ?", contact.idContacto)
                    .or("receptor = ?", contact.idContacto).orderBy("emitedAt ASC").execute();
            Collections.reverse(mensajes);
            if (!mensajes.isEmpty()) {
                int position = mensajesLimit - 1;
                for (Message mensaje : mensajes) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final View v = addBoxMessage(position, getActivity(), mensaje,
                            getActivity().getLayoutInflater());
                    v.setTag(mensaje.mensajeId);
                    messagesList.addView(v, 0);
                    position = position - 1;
                    if (!mensaje.emisor.equals(u.id) && mensaje.status == 0) {
                        Chats chats = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor)
                                .executeSingle();
                        if (chats.mensajeId.equals(mensaje.mensajeId)) {
                            chats.notRead = 0;
                            chats.save();
                        }
                        JSONObject notifyMessage = new JSONObject();
                        try {
                            notifyMessage.put("type", mensaje.tipo);
                            notifyMessage.put("message_id", mensaje.mensajeId);
                            notifyMessage.put("source", mensaje.emisor);
                            notifyMessage.put("status", 4);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        if (SpeakSocket.isRunning()) {
                            if (SpeakSocket.mSocket.connected()) {
                                SpeakSocket.mSocket.emit("message-status", notifyMessage);
                                new Update(Message.class).set("status = ?", 4)
                                        .where("mensajeId = ?", mensaje.mensajeId).execute();
                            }
                        }

                        if (mensaje.delay > 0) {
                            startCounterToDelete((mensaje.delay * 1000), mensaje);
                        }
                    }

                    if (mensaje.status == 4) {

                        if (mensaje.delay > 0) {
                            startCounterToDelete((mensaje.delay * 1000), mensaje);
                        }
                    }
                }
                System.gc();
                messagesList.setVisibility(View.VISIBLE);
            }
        }
    });

}

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 w  w . j av  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);
            } 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.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) {
            }/*from w w  w . j a v 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.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) {
            }/*  w  ww.ja va  2 s . c om*/

        } 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) {
            }/*from  w  ww  .  j  av  a 2 s  . 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;
}