コード例 #1
0
 // 正在发送文字或语音
 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);
             }
           }
         });
   }
 }
コード例 #2
0
  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());
            }
          });
    }
  }
コード例 #3
0
 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();
   }
 }
コード例 #4
0
 // 正在发送文字
 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();
                   }
                 });
           }
         });
   }
 }
コード例 #5
0
  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);
  }
コード例 #6
0
  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);
  }