Java Code Examples for cn.jpush.im.android.api.JMessageClient#sendMessage()

The following examples show how to use cn.jpush.im.android.api.JMessageClient#sendMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChattingListAdapter.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 从发送队列中出列,并发送图片
 *
 * @param msg 图片消息
 */
private void sendNextImgMsg(Message msg) {
    MessageSendingOptions options = new MessageSendingOptions();
    options.setNeedReadReceipt(mNeedReadReceipt);
    JMessageClient.sendMessage(msg, options);
    msg.setOnSendCompleteCallback(new BasicCallback() {
        @Override
        public void gotResult(int i, String s) {
            //出列
            mMsgQueue.poll();
            //如果队列不为空,则继续发送下一张
            if (!mMsgQueue.isEmpty()) {
                sendNextImgMsg(mMsgQueue.element());
            }
            notifyDataSetChanged();
        }
    });
}
 
Example 2
Source File: ChattingListAdapter.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private void resendTextOrVoice(final ViewHolder holder, Message msg) {
    holder.resend.setVisibility(View.GONE);
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(mController.mSendingAnim);

    if (!msg.isSendCompleteCallbackExists()) {
        msg.setOnSendCompleteCallback(new BasicCallback() {
            @Override
            public void gotResult(final int status, String desc) {
                holder.sendingIv.clearAnimation();
                holder.sendingIv.setVisibility(View.GONE);
                if (status != 0) {
                    HandleResponseCode.onHandle(mContext, status, false);
                    holder.resend.setVisibility(View.VISIBLE);
                }
            }
        });
    }
    MessageSendingOptions options = new MessageSendingOptions();
    options.setNeedReadReceipt(mNeedReadReceipt);
    JMessageClient.sendMessage(msg, options);
}
 
Example 3
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 6 votes vote down vote up
private void resendTextOrVoice(final ViewHolder holder, Message msg) {
    holder.resend.setVisibility(View.GONE);
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(mSendingAnim);

    if (!msg.isSendCompleteCallbackExists()) {
        msg.setOnSendCompleteCallback(new BasicCallback() {
            @Override
            public void gotResult(final int status, String desc) {
                holder.sendingIv.clearAnimation();
                holder.sendingIv.setVisibility(View.GONE);
                if (status != 0) {
                    HandleResponseCode.onHandle(mContext, status, false);
                    holder.resend.setVisibility(View.VISIBLE);
                    Log.i(TAG, "Resend message failed!");
                }
            }
        });
    }

    JMessageClient.sendMessage(msg);
}
 
Example 4
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 6 votes vote down vote up
/**
 * 从发送队列中出列,并发送图片
 *
 * @param msg 图片消息
 */
private void sendNextImgMsg(Message msg) {
    JMessageClient.sendMessage(msg);
    msg.setOnSendCompleteCallback(new BasicCallback() {
        @Override
        public void gotResult(int i, String s) {
            //出列
            mMsgQueue.poll();
            //如果队列不为空,则继续发送下一张
            if (!mMsgQueue.isEmpty()) {
                sendNextImgMsg(mMsgQueue.element());
            }
            notifyDataSetChanged();
        }
    });
}
 
Example 5
Source File: FeedbackActivity.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_sure:
            mLoadingDialog = DialogCreator.createLoadingDialog(FeedbackActivity.this,
                    getString(R.string.creating_msg));
            mLoadingDialog.show();
            //发送文字
            String feedback = mEd_feedback.getText().toString().trim();
            if (!TextUtils.isEmpty(feedback)) {
                Message message = JMessageClient.createSingleTextMessage(JIGUANG_IM_ACCOUNT, feedback);
                JMessageClient.sendMessage(message);
            }
            //发送图片
            sendImage();
            break;
        default:
            break;
    }
}
 
Example 6
Source File: JMessageUtils.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
static void sendMessage(Conversation conversation, MessageContent content, MessageSendingOptions options,
        final Result callback) {
    final Message msg = conversation.createSendMessage(content);
    msg.setOnSendCompleteCallback(new BasicCallback() {
        @Override
        public void gotResult(int status, String desc) {
            if (status == 0) {
                HashMap json = JsonUtils.toJson(msg);
                handleResult(json, status, desc, callback);
            } else {
                handleResult(status, desc, callback);
            }
        }
    });

    if (options == null) {
        JMessageClient.sendMessage(msg);
    } else {
        JMessageClient.sendMessage(msg, options);
    }
}
 
Example 7
Source File: FeedbackActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void sendImage() {
    if (selImageList != null) {
        if (i < selImageList.size()) {
            try {
                Message singleImageMessage = JMessageClient.createSingleImageMessage(JIGUANG_IM_ACCOUNT, new File(selImageList.get(i).path));
                singleImageMessage.setOnSendCompleteCallback(new BasicCallback() {
                    @Override
                    public void gotResult(int responseCode, String responseMessage) {
                        if (responseCode == 0) {
                            i++;
                            sendImage();
                        } else {
                            ToastUtil.shortToast(FeedbackActivity.this, responseMessage);
                        }
                    }
                });
                JMessageClient.sendMessage(singleImageMessage);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            cancelDialog();
        }
    } else {
        cancelDialog();
    }
}
 
Example 8
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 5 votes vote down vote up
private void resendImage(final ViewHolder holder, Message msg) {
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(mSendingAnim);
    holder.picture.setAlpha(0.75f);
    holder.resend.setVisibility(View.GONE);
    holder.progressTv.setVisibility(View.VISIBLE);
    try {
        // 显示上传进度
        msg.setOnContentUploadProgressCallback(new ProgressUpdateCallback() {
            @Override
            public void onProgressUpdate(final double progress) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String progressStr = (int) (progress * 100) + "%";
                        holder.progressTv.setText(progressStr);
                    }
                });
            }
        });
        if (!msg.isSendCompleteCallbackExists()) {
            msg.setOnSendCompleteCallback(new BasicCallback() {
                @Override
                public void gotResult(final int status, String desc) {
                    holder.sendingIv.clearAnimation();
                    holder.sendingIv.setVisibility(View.GONE);
                    holder.progressTv.setVisibility(View.GONE);
                    holder.picture.setAlpha(1.0f);
                    if (status != 0) {
                        HandleResponseCode.onHandle(mContext, status, false);
                        holder.resend.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
        JMessageClient.sendMessage(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: ChatMsgActivity.java    From Android-IM with Apache License 2.0 5 votes vote down vote up
private void sendMessage(String msg) {
    TextContent content = new TextContent(msg);
    Message message1 = conversation.createSendMessage(content);
    final MyMessage myMessage = new MyMessage(msg, SEND_TEXT);
    myMessage.setMessage(message1);
    myMessage.setTimeString(TimeUtils.ms2date("MM-dd HH:mm", message1.getCreateTime()));
    myMessage.setUserInfo(new DefaultUser(JMessageClient.getMyInfo().getUserName(), "DeadPool", imgSend));

    message1.setOnSendCompleteCallback(new BasicCallback() {
        @Override
        public void gotResult(int i, String s) {
            if (i == 0) {
                mAdapter.addToStart(myMessage, true);
                mChatInput.getInputView().setText("");
                mChatInput.dismissMenuLayout();
                mChatInput.dismissEmojiLayout();
                mChatInput.dismissPhotoLayout();
                mChatInput.dismissRecordVoiceLayout();
                onHideKeyboard();
            } else {
                Log.e("发送失败?", s);
            }
        }
    });
    JMessageClient.sendMessage(message1);
    if (mData != null) {
        mData.clear();
    }
}
 
Example 10
Source File: ForwardMsgActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setBusinessCard(String name, final Intent intent, final Conversation conversation) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", intent.getStringExtra("userName"));
                    content.setStringExtra("appKey", intent.getStringExtra("appKey"));
                    content.setStringExtra("businessCard", "businessCard");

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                Toast.makeText(ForwardMsgActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                            } else {
                                HandleResponseCode.onHandle(ForwardMsgActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    mDialog = DialogCreator.createBusinessCardDialog(ForwardMsgActivity.this, listener, name,
            intent.getStringExtra("userName"), intent.getStringExtra("avatar"));
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 11
Source File: ChattingListAdapter.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private void resendFile(final ViewHolder holder, final Message msg) {
    if (holder.contentLl != null)
        holder.contentLl.setBackgroundColor(Color.parseColor("#86222222"));
    holder.resend.setVisibility(View.GONE);
    holder.progressTv.setVisibility(View.VISIBLE);
    try {
        msg.setOnContentUploadProgressCallback(new ProgressUpdateCallback() {
            @Override
            public void onProgressUpdate(final double progress) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String progressStr = (int) (progress * 100) + "%";
                        holder.progressTv.setText(progressStr);
                    }
                });
            }
        });
        if (!msg.isSendCompleteCallbackExists()) {
            msg.setOnSendCompleteCallback(new BasicCallback() {
                @Override
                public void gotResult(final int status, String desc) {
                    holder.progressTv.setVisibility(View.GONE);
                    //此方法是api21才添加的如果低版本会报错找不到此方法.升级api或者使用ContextCompat.getDrawable
                    holder.contentLl.setBackground(ContextCompat.getDrawable(mContext, R.drawable.jmui_msg_send_bg));
                    if (status != 0) {
                        HandleResponseCode.onHandle(mContext, status, false);
                        holder.resend.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
        MessageSendingOptions options = new MessageSendingOptions();
        options.setNeedReadReceipt(mNeedReadReceipt);
        JMessageClient.sendMessage(msg, options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void sendDraftMessage(MethodCall call, final Result result) {
  HashMap<String, Object> map = call.arguments();


  MessageSendingOptions messageSendingOptions = null;
  Conversation conversation;

  try {
    JSONObject params = new JSONObject(map);
    conversation = JMessageUtils.createConversation(params);
    final Message message = conversation.getMessage(Integer.parseInt(params.getString("id")));

    if (params.has("messageSendingOptions")) {
      messageSendingOptions = toMessageSendingOptions(params.getJSONObject("messageSendingOptions"));
    }

    message.setOnSendCompleteCallback(new BasicCallback() {
      @Override
      public void gotResult(int status, String desc) {
        if (status == 0) {
          HashMap json = JsonUtils.toJson(message);
          handleResult(json, status, desc, result);
        } else {
          handleResult(status, desc, result);
        }
      }
    });

    if (messageSendingOptions == null) {
      JMessageClient.sendMessage(message);
    } else {
      JMessageClient.sendMessage(message, messageSendingOptions);
    }

  } catch (Exception e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }
}
 
Example 13
Source File: SearchMoreFriendsActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setSearchContactsBusiness(final Intent intent, final GroupInfo groupInfo, final UserInfo userInfo) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", intent.getStringExtra("userName"));
                    content.setStringExtra("appKey", intent.getStringExtra("appKey"));
                    content.setStringExtra("businessCard", "businessCard");
                    Conversation conversation;
                    if (userInfo == null) {
                        conversation = JMessageClient.getGroupConversation(groupInfo.getGroupID());
                        if (conversation == null) {
                            conversation = Conversation.createGroupConversation(groupInfo.getGroupID());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    } else {
                        conversation = JMessageClient.getSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                        if (conversation == null) {
                            conversation = Conversation.createSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    }

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                Toast.makeText(SearchMoreFriendsActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                            } else {
                                HandleResponseCode.onHandle(SearchMoreFriendsActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    String name;
    if (userInfo == null) {
        name = groupInfo.getGroupName();
    } else {
        name = userInfo.getDisplayName();
    }
    mDialog = DialogCreator.createBusinessCardDialog(SearchMoreFriendsActivity.this, listener, name,
            intent.getStringExtra("userName"), intent.getStringExtra("avatar"));
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 14
Source File: SearchMoreGroupActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setSearchContactsBusiness(final Intent intent, final GroupInfo groupInfo, final UserInfo userInfo) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", intent.getStringExtra("userName"));
                    content.setStringExtra("appKey", intent.getStringExtra("appKey"));
                    content.setStringExtra("businessCard", "businessCard");
                    Conversation conversation;
                    if (userInfo == null) {
                        conversation = JMessageClient.getGroupConversation(groupInfo.getGroupID());
                        if (conversation == null) {
                            conversation = Conversation.createGroupConversation(groupInfo.getGroupID());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    } else {
                        conversation = JMessageClient.getSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                        if (conversation == null) {
                            conversation = Conversation.createSingleConversation(userInfo.getUserName(), userInfo.getAppKey());
                            EventBus.getDefault().post(new Event.Builder()
                                    .setType(EventType.createConversation)
                                    .setConversation(conversation)
                                    .build());
                        }
                    }

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                Toast.makeText(SearchMoreGroupActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                            } else {
                                HandleResponseCode.onHandle(SearchMoreGroupActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    String name;
    if (userInfo == null) {
        name = groupInfo.getGroupName();
    } else {
        name = userInfo.getDisplayName();
    }
    mDialog = DialogCreator.createBusinessCardDialog(SearchMoreGroupActivity.this, listener, name,
            intent.getStringExtra("userName"), intent.getStringExtra("avatar"));
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 15
Source File: SearchFriendBusinessActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setBusinessCard(final UserInfo info, final Conversation conversation) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", info.getUserName());
                    content.setStringExtra("appKey", info.getAppKey());
                    content.setStringExtra("businessCard", "businessCard");

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                SharePreferenceManager.setIsOpen(true);
                                Toast.makeText(SearchFriendBusinessActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                                finish();
                            } else {
                                HandleResponseCode.onHandle(SearchFriendBusinessActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    mDialog = DialogCreator.createBusinessCardDialog(SearchFriendBusinessActivity.this, listener, conversation.getTitle(),
            info.getUserName(), info.getAvatarFile().getAbsolutePath());
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 16
Source File: FriendListActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setBusinessCard(final FriendEntry entry, final Conversation conversation) {
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn_cancel:
                    mDialog.dismiss();
                    break;
                case R.id.btn_sure:
                    mDialog.dismiss();
                    //把名片的userName和appKey通过extra发送给对方
                    TextContent content = new TextContent("推荐了一张名片");
                    content.setStringExtra("userName", entry.username);
                    content.setStringExtra("appKey", entry.appKey);
                    content.setStringExtra("businessCard", "businessCard");

                    Message textMessage = conversation.createSendMessage(content);
                    MessageSendingOptions options = new MessageSendingOptions();
                    options.setNeedReadReceipt(false);
                    JMessageClient.sendMessage(textMessage, options);
                    textMessage.setOnSendCompleteCallback(new BasicCallback() {
                        @Override
                        public void gotResult(int i, String s) {
                            if (i == 0) {
                                SharePreferenceManager.setIsOpen(true);
                                Toast.makeText(FriendListActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                                finish();
                            } else {
                                HandleResponseCode.onHandle(FriendListActivity.this, i, false);
                            }
                        }
                    });
                    break;
            }
        }
    };
    mDialog = DialogCreator.createBusinessCardDialog(FriendListActivity.this, listener, conversation.getTitle(),
            entry.username, entry.avatar);
    mDialog.getWindow().setLayout((int) (0.8 * mWidth), WindowManager.LayoutParams.WRAP_CONTENT);
    mDialog.show();
}
 
Example 17
Source File: ChatActivity.java    From jmessage-android-uikit with MIT License 4 votes vote down vote up
@Override
    public void onClick(View v) {
        if (v.getId() == IdHelper.getViewID(mContext, "jmui_return_btn")) {
            mConv.resetUnreadCount();
            dismissSoftInput();
            JMessageClient.exitConversation();
            //发送保存为草稿事件到会话列表
            if (mIsSingle) {
                EventBus.getDefault().post(new Event.DraftEvent(mTargetId, mTargetAppKey,
                        mChatView.getChatInput()));
            } else {
                EventBus.getDefault().post(new Event.DraftEvent(mGroupId, mChatView.getChatInput()));
            }
            finish();
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_right_btn")) {
            if (mChatView.getMoreMenu().getVisibility() == View.VISIBLE) {
                mChatView.dismissMoreMenu();
            }
            dismissSoftInput();
            //TODO
//            startChatDetailActivity(mTargetId, mTargetAppKey, mGroupId);
            // 切换输入
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_switch_voice_ib")) {
            mChatView.dismissMoreMenu();
            isInputByKeyBoard = !isInputByKeyBoard;
            //当前为语音输入,点击后切换为文字输入,弹出软键盘
            if (isInputByKeyBoard) {
                mChatView.isKeyBoard();
                showSoftInputAndDismissMenu();
            } else {
                //否则切换到语音输入
                mChatView.notKeyBoard(mConv, mChatAdapter, mChatView);
                if (mShowSoftInput) {
                    if (mImm != null) {
                        mImm.hideSoftInputFromWindow(mChatView.getInputView().getWindowToken(), 0); //强制隐藏键盘
                        mShowSoftInput = false;
                    }
                } else if (mChatView.getMoreMenu().getVisibility() == View.VISIBLE) {
                    mChatView.dismissMoreMenu();
                }
                Log.i(TAG, "setConversation success");
            }
            // 发送文本消息
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_send_msg_btn")) {
            String msgContent = mChatView.getChatInput();
            mChatView.clearInput();
            mChatView.setToBottom();
            if (msgContent.equals("")) {
                return;
            }
            TextContent content = new TextContent(msgContent);
            final Message msg = mConv.createSendMessage(content);
            mChatAdapter.addMsgToList(msg);
            JMessageClient.sendMessage(msg);
            // 点击添加按钮,弹出更多选项菜单
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_add_file_btn")) {
            //如果在语音输入时点击了添加按钮,则显示菜单并切换到输入框
            if (!isInputByKeyBoard) {
                mChatView.isKeyBoard();
                isInputByKeyBoard = true;
                mChatView.showMoreMenu();
            } else {
                //如果弹出软键盘 则隐藏软键盘
                if (mChatView.getMoreMenu().getVisibility() != View.VISIBLE) {
                    dismissSoftInputAndShowMenu();
                    mChatView.focusToInput(false);
                    //如果弹出了更多选项菜单,则隐藏菜单并显示软键盘
                } else {
                    showSoftInputAndDismissMenu();
                }
            }
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_pick_from_camera_btn")) {
            takePhoto();
            if (mChatView.getMoreMenu().getVisibility() == View.VISIBLE) {
                mChatView.dismissMoreMenu();
            }
        } else if (v.getId() == IdHelper.getViewID(mContext, "jmui_pick_from_local_btn")){
            if (mChatView.getMoreMenu().getVisibility() == View.VISIBLE) {
                mChatView.dismissMoreMenu();
            }
            Intent intent = new Intent();
            if (mIsSingle) {
                intent.putExtra(TARGET_ID, mTargetId);
                intent.putExtra(TARGET_APP_KEY, mTargetAppKey);
            } else {
                intent.putExtra(GROUP_ID, mGroupId);
            }
//            if (!FileHelper.isSdCardExist()) {
//                Toast.makeText(this, IdHelper.getString(mContext, "sdcard_not_exist_toast"), Toast.LENGTH_SHORT).show();
//            } else {
//                intent.setClass(this, PickPictureTotalActivity.class);
//                startActivityForResult(intent, REQUEST_CODE_SELECT_PICTURE);
//            }
        }
    }
 
Example 18
Source File: MsgListAdapter.java    From jmessage-android-uikit with MIT License 4 votes vote down vote up
private void handleImgMsg(final Message msg, final ViewHolder holder, final int position) {
    final ImageContent imgContent = (ImageContent) msg.getContent();
    // 先拿本地缩略图
    final String path = imgContent.getLocalThumbnailPath();
    // 接收图片
    if (msg.getDirect() == MessageDirect.receive) {
        if (path == null) {
            //从服务器上拿缩略图
            imgContent.downloadThumbnailImage(msg, new DownloadCompletionCallback() {
                @Override
                public void onComplete(int status, String desc, File file) {
                    if (status == 0) {
                        Picasso.with(mContext).load(file).into(holder.picture);
                    }
                }
            });
        } else {
            setPictureScale(path, holder.picture);
            Picasso.with(mContext).load(new File(path)).into(holder.picture);
        }
        //群聊中显示昵称
        if (mIsGroup) {
            holder.displayName.setVisibility(View.VISIBLE);
            if (TextUtils.isEmpty(msg.getFromUser().getNickname())) {
                holder.displayName.setText(msg.getFromUser().getUserName());
            } else {
                holder.displayName.setText(msg.getFromUser().getNickname());
            }
        }

        switch (msg.getStatus()) {
            case receive_fail:
                holder.picture.setImageResource(IdHelper.getDrawable(mContext, "jmui_fetch_failed"));
                break;
            default:
        }
        // 发送图片方,直接加载缩略图
    } else {
        try {
            setPictureScale(path, holder.picture);
            Picasso.with(mContext).load(new File(path))
                    .into(holder.picture);
        } catch (NullPointerException e) {
            Picasso.with(mContext).load(IdHelper.getDrawable(mContext, "jmui_picture_not_found"))
                    .into(holder.picture);
        }
        //检查状态
        switch (msg.getStatus()) {
            case send_success:
                holder.sendingIv.clearAnimation();
                holder.sendingIv.setVisibility(View.GONE);
                holder.picture.setAlpha(1.0f);
                holder.progressTv.setVisibility(View.GONE);
                holder.resend.setVisibility(View.GONE);
                break;
            case send_fail:
                holder.sendingIv.clearAnimation();
                holder.sendingIv.setVisibility(View.GONE);
                holder.picture.setAlpha(1.0f);
                holder.progressTv.setVisibility(View.GONE);
                holder.resend.setVisibility(View.VISIBLE);
                break;
            case send_going:
                sendingImage(msg, holder);
                break;
            default:
                holder.picture.setAlpha(0.75f);
                holder.sendingIv.setVisibility(View.VISIBLE);
                holder.sendingIv.startAnimation(mSendingAnim);
                holder.progressTv.setVisibility(View.VISIBLE);
                holder.progressTv.setText("0%");
                holder.resend.setVisibility(View.GONE);
                //从别的界面返回聊天界面,继续发送
                if (!mMsgQueue.isEmpty()) {
                    Message message = mMsgQueue.element();
                    if (message.getId() == msg.getId()) {
                        Log.d(TAG, "Start sending message");
                        JMessageClient.sendMessage(message);
                        mSendMsgId = message.getId();
                        sendingImage(message, holder);
                    }
                }
        }
        // 点击重发按钮,重发图片
        holder.resend.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                showResendDialog(holder, msg);
            }
        });
    }
    if (holder.picture != null) {
        // 点击预览图片
        holder.picture.setOnClickListener(new BtnOrTxtListener(position, holder));

        holder.picture.setTag(position);
        holder.picture.setOnLongClickListener(mLongClickListener);

    }
}
 
Example 19
Source File: ChattingListAdapter.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void resendImage(final ViewHolder holder, Message msg) {
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(mController.mSendingAnim);
    holder.picture.setAlpha(0.75f);
    holder.resend.setVisibility(View.GONE);
    holder.progressTv.setVisibility(View.VISIBLE);
    try {
        // 显示上传进度
        msg.setOnContentUploadProgressCallback(new ProgressUpdateCallback() {
            @Override
            public void onProgressUpdate(final double progress) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String progressStr = (int) (progress * 100) + "%";
                        holder.progressTv.setText(progressStr);
                    }
                });
            }
        });
        if (!msg.isSendCompleteCallbackExists()) {
            msg.setOnSendCompleteCallback(new BasicCallback() {
                @Override
                public void gotResult(final int status, String desc) {
                    holder.sendingIv.clearAnimation();
                    holder.sendingIv.setVisibility(View.GONE);
                    holder.progressTv.setVisibility(View.GONE);
                    holder.picture.setAlpha(1.0f);
                    if (status != 0) {
                        HandleResponseCode.onHandle(mContext, status, false);
                        holder.resend.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
        MessageSendingOptions options = new MessageSendingOptions();
        options.setNeedReadReceipt(mNeedReadReceipt);
        JMessageClient.sendMessage(msg, options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}