コード例 #1
0
 @Override
 public void onReaded(String conversionId, String msgTime) {
   // 此处应该过滤掉不是和当前用户的聊天的回执消息界面的刷新
   if (conversionId.split("&")[1].equals(targetId)) {
     // 修改界面上指定消息的阅读状态
     for (BmobMsg msg : mAdapter.getList()) {
       if (msg.getConversationId().equals(conversionId) && msg.getMsgTime().equals(msgTime)) {
         msg.setStatus(BmobConfig.STATUS_SEND_RECEIVERED);
       }
       mAdapter.notifyDataSetChanged();
     }
   }
 }
コード例 #2
0
 public void handleMessage(Message msg) {
   if (msg.what == NEW_MESSAGE) {
     BmobMsg message = (BmobMsg) msg.obj;
     String uid = message.getBelongId();
     BmobMsg m =
         BmobChatManager.getInstance(ChatActivity.this)
             .getMessage(message.getConversationId(), message.getMsgTime());
     if (!uid.equals(targetId)) // 如果不是当前正在聊天对象的消息,不处理
     return;
     mAdapter.add(m);
     // 定位
     mListView.setSelection(mAdapter.getCount() - 1);
     // 取消当前聊天对象的未读标示
     BmobDB.create(ChatActivity.this).resetUnread(targetId);
   }
 }
コード例 #3
0
  /**
   * 重发图片消息 @Title: resendImageMsg
   *
   * @param @param parentV
   * @param @param values
   * @return void
   * @throws
   */
  private void resendFileMsg(final View parentV, final Object values) {
    BmobChatManager.getInstance(ChatActivity.this)
        .resendFileMessage(
            targetUser,
            (BmobMsg) values,
            new UploadListener() {

              @Override
              public void onStart(BmobMsg msg) {}

              @Override
              public void onSuccess() {
                ((BmobMsg) values).setStatus(BmobConfig.STATUS_SEND_SUCCESS);
                parentV.findViewById(R.id.progress_load).setVisibility(View.INVISIBLE);
                parentV.findViewById(R.id.iv_fail_resend).setVisibility(View.INVISIBLE);
                if (((BmobMsg) values).getMsgType() == BmobConfig.TYPE_VOICE) {
                  parentV.findViewById(R.id.tv_send_status).setVisibility(View.GONE);
                  parentV.findViewById(R.id.tv_voice_length).setVisibility(View.VISIBLE);
                } else {
                  parentV.findViewById(R.id.tv_send_status).setVisibility(View.VISIBLE);
                  ((TextView) parentV.findViewById(R.id.tv_send_status)).setText("已发送");
                }
              }

              @Override
              public void onFailure(int arg0, String arg1) {
                ((BmobMsg) values).setStatus(BmobConfig.STATUS_SEND_FAIL);
                parentV.findViewById(R.id.progress_load).setVisibility(View.INVISIBLE);
                parentV.findViewById(R.id.iv_fail_resend).setVisibility(View.VISIBLE);
                parentV.findViewById(R.id.tv_send_status).setVisibility(View.INVISIBLE);
              }
            });
    mAdapter.notifyDataSetChanged();
  }
コード例 #4
0
  /** 重发文本消息 */
  private void resendTextMsg(final View parentV, final Object values) {
    BmobChatManager.getInstance(ChatActivity.this)
        .resendTextMessage(
            targetUser,
            (BmobMsg) values,
            new PushListener() {

              @Override
              public void onSuccess() {
                Log.i("yuyang", "发送成功");
                ((BmobMsg) values).setStatus(BmobConfig.STATUS_SEND_SUCCESS);
                parentV.findViewById(R.id.progress_load).setVisibility(View.INVISIBLE);
                parentV.findViewById(R.id.iv_fail_resend).setVisibility(View.INVISIBLE);
                parentV.findViewById(R.id.tv_send_status).setVisibility(View.VISIBLE);
                ((TextView) parentV.findViewById(R.id.tv_send_status)).setText("已发送");
              }

              @Override
              public void onFailure(int arg0, String arg1) {
                Log.i("yuyang", "发送失败:" + arg1);
                ((BmobMsg) values).setStatus(BmobConfig.STATUS_SEND_FAIL);
                parentV.findViewById(R.id.progress_load).setVisibility(View.INVISIBLE);
                parentV.findViewById(R.id.iv_fail_resend).setVisibility(View.VISIBLE);
                parentV.findViewById(R.id.tv_send_status).setVisibility(View.INVISIBLE);
              }
            });
    mAdapter.notifyDataSetChanged();
  }
コード例 #5
0
 /**
  * 界面刷新 @Title: initOrRefresh
  *
  * @param
  * @return void
  * @throws
  */
 private void initOrRefresh() {
   if (mAdapter != null) {
     if (MyMessageReceiver.mNewNum != 0) { // 用于更新当在聊天界面锁屏期间来了消息,这时再回到聊天页面的时候需要显示新来的消息
       int news = MyMessageReceiver.mNewNum; // 有可能锁屏期间,来了N条消息,因此需要倒叙显示在界面上
       int size = initMsgData().size();
       for (int i = (news - 1); i >= 0; i--) {
         mAdapter.add(initMsgData().get(size - (i + 1))); // 添加最后一条消息到界面显示
       }
       mListView.setSelection(mAdapter.getCount() - 1);
     } else {
       mAdapter.notifyDataSetChanged();
     }
   } else {
     mAdapter = new MessageChatAdapter(this, initMsgData());
     mListView.setAdapter(mAdapter);
   }
 }
コード例 #6
0
  private void initXListView() {
    // 首先不允许加载更多
    mListView.setPullLoadEnable(false);
    // 允许下拉
    mListView.setPullRefreshEnable(true);
    // 设置监听器
    mListView.setXListViewListener(this);
    mListView.pullRefreshing();
    mListView.setDividerHeight(0);
    // 加载数据
    initOrRefresh();
    mListView.setSelection(mAdapter.getCount() - 1);
    mListView.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View arg0, MotionEvent arg1) {
            hideSoftInputView();
            layout_more.setVisibility(View.GONE);
            layout_add.setVisibility(View.GONE);
            btn_chat_voice.setVisibility(View.VISIBLE);
            btn_chat_keyboard.setVisibility(View.GONE);
            btn_chat_send.setVisibility(View.GONE);
            return false;
          }
        });

    // 重发按钮的点击事件
    mAdapter.setOnInViewClickListener(
        R.id.iv_fail_resend,
        new MessageChatAdapter.onInternalClickListener() {

          @Override
          public void OnClickListener(View parentV, View v, Integer position, Object values) {
            // 重发消息
            showResendDialog(parentV, v, values);
          }
        });
  }
コード例 #7
0
 /**
  * 刷新界面 @Title: refreshMessage
  *
  * @param @param messsage
  * @return void
  * @throws
  */
 private void refreshMessage(BmobMsg msg) {
   // 更新界面
   mAdapter.add(msg);
   mListView.setSelection(mAdapter.getCount() - 1);
   edit_user_comment.setText("");
 }