Search in sources :

Example 6 with TextMessageBody

use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.

the class MessageAdapter method handleTextMessage.

/**
	 * 文本消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 */
private void handleTextMessage(EMMessage message, ViewHolder holder, final int position) {
    TextMessageBody txtBody = (TextMessageBody) message.getBody();
    Spannable span = SmileUtils.getSmiledText(context, txtBody.getMessage());
    // 设置内容
    holder.tv.setText(span, BufferType.SPANNABLE);
    // 设置长按事件监听
    holder.tv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.TXT.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });
    if (message.direct == EMMessage.Direct.SEND) {
        switch(message.status) {
            case // 发送成功
            SUCCESS:
                holder.pb.setVisibility(View.GONE);
                holder.staus_iv.setVisibility(View.GONE);
                break;
            case // 发送失败
            FAIL:
                holder.pb.setVisibility(View.GONE);
                holder.staus_iv.setVisibility(View.VISIBLE);
                break;
            case // 发送中
            INPROGRESS:
                holder.pb.setVisibility(View.VISIBLE);
                holder.staus_iv.setVisibility(View.GONE);
                break;
            default:
                // 发送消息
                sendMsgInBackground(message, holder);
        }
    }
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) Intent(android.content.Intent) ContextMenu(com.juns.wechat.chat.ContextMenu) TextMessageBody(com.easemob.chat.TextMessageBody) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Example 7 with TextMessageBody

use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.

the class CommonUtils method getMessageDigest.

/**
	 * 根据消息内容和消息类型获取消息内容提示
	 * 
	 * @param message
	 * @param context
	 * @return
	 */
public static String getMessageDigest(EMMessage message, Context context) {
    String digest = "";
    switch(message.getType()) {
        case // 位置消息
        LOCATION:
            if (message.direct == EMMessage.Direct.RECEIVE) {
                // 从sdk中提到了ui中,使用更简单不犯错的获取string方法
                // digest = EasyUtils.getAppResourceString(context,
                // "location_recv");
                digest = getStrng(context, R.string.location_recv);
                digest = String.format(digest, message.getFrom());
                return digest;
            } else {
                // digest = EasyUtils.getAppResourceString(context,
                // "location_prefix");
                digest = getStrng(context, R.string.location_prefix);
            }
            break;
        case // 图片消息
        IMAGE:
            digest = getStrng(context, R.string.picture);
            break;
        case // 语音消息
        VOICE:
            digest = getStrng(context, R.string.voice);
            break;
        case // 视频消息
        VIDEO:
            digest = getStrng(context, R.string.video);
            break;
        case // 文本消息
        TXT:
            if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                TextMessageBody txtBody = (TextMessageBody) message.getBody();
                digest = txtBody.getMessage();
            } else {
                TextMessageBody txtBody = (TextMessageBody) message.getBody();
                digest = getStrng(context, R.string.voice_call) + txtBody.getMessage();
            }
            break;
        case // 普通文件消息
        FILE:
            digest = getStrng(context, R.string.file);
            break;
        default:
            System.err.println("error, unknow type");
            return "";
    }
    return digest;
}
Also used : TextMessageBody(com.easemob.chat.TextMessageBody)

Aggregations

TextMessageBody (com.easemob.chat.TextMessageBody)7 EMMessage (com.easemob.chat.EMMessage)3 ImageMessageBody (com.easemob.chat.ImageMessageBody)2 Intent (android.content.Intent)1 Spannable (android.text.Spannable)1 View (android.view.View)1 OnLongClickListener (android.view.View.OnLongClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 User (com.juns.wechat.bean.User)1 ContextMenu (com.juns.wechat.chat.ContextMenu)1 File (java.io.File)1