Search in sources :

Example 1 with EMCallBack

use of com.easemob.EMCallBack in project wechat by motianhuo.

the class MessageAdapter method handleVoiceMessage.

/**
	 * 语音消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 * @param convertView
	 */
private void handleVoiceMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
    VoiceMessageBody voiceBody = (VoiceMessageBody) message.getBody();
    holder.tv.setText(voiceBody.getLength() + "\"");
    holder.iv.setOnClickListener(new VoicePlayClickListener(message, holder.iv, holder.iv_read_status, this, activity, username));
    holder.iv.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.VOICE.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return true;
        }
    });
    if (((ChatActivity) activity).playMsgId != null && ((ChatActivity) activity).playMsgId.equals(message.getMsgId()) && VoicePlayClickListener.isPlaying) {
        AnimationDrawable voiceAnimation;
        if (message.direct == EMMessage.Direct.RECEIVE) {
            holder.iv.setImageResource(R.anim.voice_from_icon);
        } else {
            holder.iv.setImageResource(R.anim.voice_to_icon);
        }
        voiceAnimation = (AnimationDrawable) holder.iv.getDrawable();
        voiceAnimation.start();
    } else {
        if (message.direct == EMMessage.Direct.RECEIVE) {
            holder.iv.setImageResource(R.drawable.chatfrom_voice_playing);
        } else {
            holder.iv.setImageResource(R.drawable.chatto_voice_playing);
        }
    }
    if (message.direct == EMMessage.Direct.RECEIVE) {
        if (message.isListened()) {
            // 隐藏语音未听标志
            holder.iv_read_status.setVisibility(View.INVISIBLE);
        } else {
            holder.iv_read_status.setVisibility(View.VISIBLE);
        }
        System.err.println("it is receive msg");
        if (message.status == EMMessage.Status.INPROGRESS) {
            holder.pb.setVisibility(View.VISIBLE);
            System.err.println("!!!! back receive");
            ((FileMessageBody) message.getBody()).setDownloadCallback(new EMCallBack() {

                @Override
                public void onSuccess() {
                    activity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            holder.pb.setVisibility(View.INVISIBLE);
                            notifyDataSetChanged();
                        }
                    });
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(int code, String message) {
                    activity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            holder.pb.setVisibility(View.INVISIBLE);
                        }
                    });
                }
            });
        } else {
            holder.pb.setVisibility(View.INVISIBLE);
        }
        return;
    }
    // until here, deal with send voice msg
    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 : VoiceMessageBody(com.easemob.chat.VoiceMessageBody) EMCallBack(com.easemob.EMCallBack) AnimationDrawable(android.graphics.drawable.AnimationDrawable) NormalFileMessageBody(com.easemob.chat.NormalFileMessageBody) FileMessageBody(com.easemob.chat.FileMessageBody) Intent(android.content.Intent) ContextMenu(com.juns.wechat.chat.ContextMenu) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) OnLongClickListener(android.view.View.OnLongClickListener)

Example 2 with EMCallBack

use of com.easemob.EMCallBack in project wechat by motianhuo.

the class MessageAdapter method showDownloadImageProgress.

/*
	 * chat sdk will automatic download thumbnail image for the image message we
	 * need to register callback show the download progress
	 */
private void showDownloadImageProgress(final EMMessage message, final ViewHolder holder) {
    System.err.println("!!! show download image progress");
    // final ImageMessageBody msgbody = (ImageMessageBody)
    // message.getBody();
    final FileMessageBody msgbody = (FileMessageBody) message.getBody();
    if (holder.pb != null)
        holder.pb.setVisibility(View.VISIBLE);
    if (holder.tv != null)
        holder.tv.setVisibility(View.VISIBLE);
    msgbody.setDownloadCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // message.setBackReceive(false);
                    if (message.getType() == EMMessage.Type.IMAGE) {
                        holder.pb.setVisibility(View.GONE);
                        holder.tv.setVisibility(View.GONE);
                    }
                    notifyDataSetChanged();
                }
            });
        }

        @Override
        public void onError(int code, String message) {
        }

        @Override
        public void onProgress(final int progress, String status) {
            if (message.getType() == EMMessage.Type.IMAGE) {
                activity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        holder.tv.setText(progress + "%");
                    }
                });
            }
        }
    });
}
Also used : EMCallBack(com.easemob.EMCallBack) NormalFileMessageBody(com.easemob.chat.NormalFileMessageBody) FileMessageBody(com.easemob.chat.FileMessageBody) SuppressLint(android.annotation.SuppressLint)

Example 3 with EMCallBack

use of com.easemob.EMCallBack in project wechat by motianhuo.

the class MessageAdapter method sendPictureMessage.

/*
	 * send message with new sdk
	 */
private void sendPictureMessage(final EMMessage message, final ViewHolder holder) {
    try {
        String to = message.getTo();
        // before send, update ui
        holder.staus_iv.setVisibility(View.GONE);
        holder.pb.setVisibility(View.VISIBLE);
        holder.tv.setVisibility(View.VISIBLE);
        holder.tv.setText("0%");
        final long start = System.currentTimeMillis();
        // if (chatType == ChatActivity.CHATTYPE_SINGLE) {
        EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

            @Override
            public void onSuccess() {
                Log.d(TAG, "send image message successfully");
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        // send success
                        holder.pb.setVisibility(View.GONE);
                        holder.tv.setVisibility(View.GONE);
                    }
                });
            }

            @Override
            public void onError(int code, String error) {
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        holder.pb.setVisibility(View.GONE);
                        holder.tv.setVisibility(View.GONE);
                        // message.setSendingStatus(Message.SENDING_STATUS_FAIL);
                        holder.staus_iv.setVisibility(View.VISIBLE);
                        Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
                    }
                });
            }

            @Override
            public void onProgress(final int progress, String status) {
                activity.runOnUiThread(new Runnable() {

                    public void run() {
                        holder.tv.setText(progress + "%");
                    }
                });
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EMCallBack(com.easemob.EMCallBack) SuppressLint(android.annotation.SuppressLint) EaseMobException(com.easemob.exceptions.EaseMobException)

Example 4 with EMCallBack

use of com.easemob.EMCallBack in project wechat by motianhuo.

the class MessageAdapter method sendMsgInBackground.

/**
	 * 发送消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 */
public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) {
    holder.staus_iv.setVisibility(View.GONE);
    holder.pb.setVisibility(View.VISIBLE);
    final long start = System.currentTimeMillis();
    // 调用sdk发送异步发送方法
    EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

        @Override
        public void onSuccess() {
            updateSendedView(message, holder);
        }

        @Override
        public void onError(int code, String error) {
            updateSendedView(message, holder);
        }

        @Override
        public void onProgress(int progress, String status) {
        }
    });
}
Also used : EMCallBack(com.easemob.EMCallBack) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)4 EMCallBack (com.easemob.EMCallBack)4 FileMessageBody (com.easemob.chat.FileMessageBody)2 NormalFileMessageBody (com.easemob.chat.NormalFileMessageBody)2 Intent (android.content.Intent)1 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 View (android.view.View)1 OnLongClickListener (android.view.View.OnLongClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 VoiceMessageBody (com.easemob.chat.VoiceMessageBody)1 EaseMobException (com.easemob.exceptions.EaseMobException)1 ContextMenu (com.juns.wechat.chat.ContextMenu)1