// 正在发送文字或语音
 private void sendingTextOrVoice(final ViewHolder holder, Animation sendingAnim, Message msg) {
   holder.sendingIv.setVisibility(View.VISIBLE);
   holder.sendingIv.startAnimation(sendingAnim);
   holder.resend.setVisibility(View.GONE);
   // 消息正在发送,重新注册一个监听消息发送完成的Callback
   if (!msg.isSendCompleteCallbackExists()) {
     msg.setOnSendCompleteCallback(
         new BasicCallback() {
           @Override
           public void gotResult(final int status, final String desc) {
             holder.sendingIv.setVisibility(View.GONE);
             holder.sendingIv.clearAnimation();
             if (status == 803008) {
               CustomContent customContent = new CustomContent();
               customContent.setBooleanValue("blackList", true);
               Message customMsg = mConv.createSendMessage(customContent);
               addMsgToList(customMsg);
             } else if (status != 0) {
               HandleResponseCode.onHandle(mContext, status, false);
               holder.resend.setVisibility(View.VISIBLE);
             }
           }
         });
   }
 }
  private void sendingImage(
      final ViewHolder holder, final Animation sendingAnim, final Message msg) {
    holder.picture.setAlpha(0.75f);
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(sendingAnim);
    holder.progressTv.setVisibility(View.VISIBLE);
    holder.resend.setVisibility(View.GONE);
    // 如果图片正在发送,重新注册上传进度Callback
    if (!msg.isContentUploadProgressCallbackExists()) {
      msg.setOnContentUploadProgressCallback(
          new ProgressUpdateCallback() {
            @Override
            public void onProgressUpdate(double v) {
              String progressStr = (int) (v * 100) + "%";
              Log.d(TAG, "msg.getId: " + msg.getId() + " progress: " + progressStr);
              holder.progressTv.setText(progressStr);
            }
          });
    }
    if (!msg.isSendCompleteCallbackExists()) {
      msg.setOnSendCompleteCallback(
          new BasicCallback() {
            @Override
            public void gotResult(final int status, String desc) {
              Log.d(TAG, "Got result status: " + status);
              if (!mMsgQueue.isEmpty() && mMsgQueue.element().getId() == mSendMsgId) {
                mMsgQueue.poll();
                if (!mMsgQueue.isEmpty()) {
                  Message nextMsg = mMsgQueue.element();
                  JMessageClient.sendMessage(nextMsg);
                  mSendMsgId = nextMsg.getId();
                }
              }
              holder.picture.setAlpha(1.0f);
              holder.sendingIv.clearAnimation();
              holder.sendingIv.setVisibility(View.GONE);
              holder.progressTv.setVisibility(View.GONE);
              if (status == 803008) {
                CustomContent customContent = new CustomContent();
                customContent.setBooleanValue("blackList", true);
                Message customMsg = mConv.createSendMessage(customContent);
                addMsgToList(customMsg);
              } else if (status != 0) {
                HandleResponseCode.onHandle(mContext, status, false);
                holder.resend.setVisibility(View.VISIBLE);
              }

              Message message = mConv.getMessage(msg.getId());
              mMsgList.set(mMsgList.indexOf(msg), message);
              Log.d(TAG, "msg.getId " + msg.getId() + " msg.getStatus " + msg.getStatus());
              Log.d(
                  TAG,
                  "message.getId " + message.getId() + " message.getStatus " + message.getStatus());
            }
          });
    }
  }
 /**
  * 从发送队列中出列,并发送图片
  *
  * @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();
         }
       });
 }
 private void resendImage(final ViewHolder holder, Animation sendingAnim, Message msg) {
   ImageContent imgContent = (ImageContent) msg.getContent();
   final String path = imgContent.getLocalThumbnailPath();
   holder.sendingIv.setVisibility(View.VISIBLE);
   holder.sendingIv.startAnimation(sendingAnim);
   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();
   }
 }
 // 正在发送文字
 private void sendingText(ViewHolder holder, Animation sendingAnim, Message msg) {
   holder.sendSending.setVisibility(View.VISIBLE);
   holder.sendSending.startAnimation(sendingAnim);
   holder.sendFail.setVisibility(View.GONE);
   // 消息正在发送,重新注册一个监听消息发送完成的Callback
   if (!msg.isSendCompleteCallbackExists()) {
     msg.setOnSendCompleteCallback(
         new BasicCallback() {
           @Override
           public void gotResult(final int status, final String desc) {
             mActivity.runOnUiThread(
                 new Runnable() {
                   @Override
                   public void run() {
                     if (status != 0) notifyDataSetChanged();
                   }
                 });
           }
         });
   }
 }
  private void resendText(final ViewHolder holder, Animation sendingAnim, Message msg) {
    holder.sendFail.setVisibility(View.GONE);
    holder.sendSending.setVisibility(View.VISIBLE);
    holder.sendSending.startAnimation(sendingAnim);

    if (!msg.isSendCompleteCallbackExists()) {
      msg.setOnSendCompleteCallback(
          new BasicCallback() {
            @Override
            public void gotResult(final int status, String desc) {
              if (status != 0) {
                holder.sendSending.clearAnimation();
                holder.sendSending.setVisibility(View.GONE);
                holder.sendFail.setVisibility(View.VISIBLE);
              }
              notifyDataSetChanged();
            }
          });
    }

    JMessageClient.sendMessage(msg);
  }
  private void resendTextOrVoice(final ViewHolder holder, Animation sendingAnim, Message msg) {
    holder.resend.setVisibility(View.GONE);
    holder.sendingIv.setVisibility(View.VISIBLE);
    holder.sendingIv.startAnimation(sendingAnim);

    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);
  }
示例#8
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;
    }
  }