public void sendSingleTextMessage(JSONArray data, CallbackContext callbackContext) {
    Log.i(TAG, " sendSingleTextMessage \n" + data);

    final CallbackContext cb = callbackContext;
    try {
      String username = data.getString(0);
      String text = data.getString(1);

      Conversation conversation = JMessageClient.getSingleConversation(username);
      if (conversation == null) {
        conversation = Conversation.createSingleConversation(username);
      }
      if (conversation == null) {
        callbackContext.error("无法创建对话");
        return;
      }
      TextContent content = new TextContent(text);
      final Message msg = conversation.createSendMessage(content);

      JMessageClient.sendMessage(msg);
      callbackContext.success("正在发送");

    } catch (JSONException e) {
      e.printStackTrace();
      callbackContext.error("error reading id json");
    }
  }
Пример #2
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
        // 返回按钮
      case R.id.return_btn:
        mConv.resetUnreadCount();
        JMessageClient.exitConversaion();
        mContext.finish();
        break;
        // 聊天详细信息
      case R.id.right_btn:
        if (mIsShowMoreMenu) {
          mChatView.dismissMoreMenu();
          dismissSoftInput();
          mIsShowMoreMenu = false;
        }
        mContext.StartChatDetailActivity(mIsGroup, mTargetID, mGroupID);
        break;
        // 切换输入
      case R.id.switch_voice_ib:
        mChatView.dismissMoreMenu();
        isInputByKeyBoard = !isInputByKeyBoard;
        if (isInputByKeyBoard) {
          mChatView.isKeyBoard();
          mChatView.mChatInputEt.requestFocus();
          mIsShowMoreMenu = true;
          mChatView.focusToInput(true);
        } else {
          mChatView.notKeyBoard(mConv, mChatAdapter);
          mIsShowMoreMenu = false;
          Log.i("ChatController", "setConversation success");
          // 关闭软键盘
          dismissSoftInput();
        }
        break;
      case R.id.chat_input_et:
        mChatView.showMoreMenu();
        //                mChatView.invisibleMoreMenu();
        mIsShowMoreMenu = true;
        showSoftInput();
        break;

        // 发送文本消息
      case R.id.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);
        msg.setOnSendCompleteCallback(
            new BasicCallback() {

              @Override
              public void gotResult(final int status, String desc) {
                Log.i("ChatController", "send callback " + status + " desc " + desc);
                if (status != 0) {
                  mContext.runOnUiThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          HandleResponseCode.onHandle(mContext, status);
                        }
                      });
                }
                // 发送成功或失败都要刷新一次
                android.os.Message msg = handler.obtainMessage();
                msg.what = UPDATE_CHAT_LISTVIEW;
                Bundle bundle = new Bundle();
                bundle.putString("desc", desc);
                msg.setData(bundle);
                msg.sendToTarget();
              }
            });
        mChatAdapter.addMsgToList(msg);
        JMessageClient.sendMessage(msg);
        break;

      case R.id.expression_btn:
        //                if (mMoreMenuVisible) {
        //                    mChatView.invisibleMoreMenu();
        //                    mMoreMenuVisible = false;
        //
        //                }
        break;

        // 点击添加按钮,弹出更多选项菜单
      case R.id.add_file_btn:
        // 如果在语音输入时点击了添加按钮,则显示菜单并切换到输入框
        if (!isInputByKeyBoard) {
          mChatView.isKeyBoard();
          isInputByKeyBoard = true;
          mChatView.showMoreMenu();
          mIsShowMoreMenu = true;
          mChatView.focusToInput(false);
        } else {
          if (mIsShowMoreMenu) {
            if (mMoreMenuVisible) {
              mChatView.focusToInput(true);
              showSoftInput();
              mMoreMenuVisible = false;
            } else {
              dismissSoftInput();
              mChatView.focusToInput(false);
              mMoreMenuVisible = true;
            }
          } else {
            mChatView.focusToInput(false);
            mChatView.showMoreMenu();
            mIsShowMoreMenu = true;
            mMoreMenuVisible = true;
          }
        }
        break;
        // 拍照
      case R.id.pick_from_camera_btn:
        takePhoto();
        if (mIsShowMoreMenu) {
          mChatView.dismissMoreMenu();
          dismissSoftInput();
          mIsShowMoreMenu = false;
        }
        break;
      case R.id.pick_from_local_btn:
        if (mIsShowMoreMenu) {
          mChatView.dismissMoreMenu();
          dismissSoftInput();
          mIsShowMoreMenu = false;
        }
        Intent intent = new Intent();
        if (mIsGroup) {
          intent.putExtra("groupID", mGroupID);
        } else {
          intent.putExtra("targetID", mTargetID);
        }
        intent.putExtra("isGroup", mIsGroup);
        mContext.StartPickPictureTotalActivity(intent);
        break;
      case R.id.send_location_btn:
        break;
    }
  }