Пример #1
0
  /** 根据消息已读\未读状态 */
  private void getMessageByUserId() {

    ArrayList<Entity> entitys = imDataBase.getTheMessageByUserId(UserUtil.userid);
    if (entitys != null) {
      boolean isFind = false;
      for (Entity entity : entitys) {
        // 未读
        if (entity.getIsRead() == 0
            && entity.getFromId() != UserUtil.userid
            && UserUtil.userState == 1) {
          isFind = true;
          break;
        }
      }
      if (isFind) {
        mainMenu.setMessageButtonRes(true);
        messageImageId.setVisibility(View.VISIBLE);
      } else {
        mainMenu.setMessageButtonRes(false);
        messageImageId.setVisibility(View.GONE);
      }

    } else {
      mainMenu.setMessageButtonRes(false);
      messageImageId.setVisibility(View.GONE);
    }
  }
Пример #2
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   final String localRemark = CommonUtil.getRemark(UserPageActivityA.this);
   String remarks = "";
   if (resultCode == RESULT_OK && requestCode == MessageID.REQUEST_SAY_HI) {
     boolean issend = data.getExtras().getBoolean("issend");
     if (issend) {
       String msg = data.getExtras().getString("msg");
       int toUserId = data.getExtras().getInt("uid");
       String toName = data.getExtras().getString("nickname");
       final long tempmessageid = System.currentTimeMillis();
       final String date = CommonUtil.createCommentTime();
       Entity entity = imDataBase.getTheMessage(tempmessageid);
       int repeate = 0;
       // 取得备注名称
       if (localRemark.length() > 0) {
         remarks = localRemark;
       } else {
         remarks = toName;
       }
       if (entity == null) { // type=3, isread=1		
         imDataBase.insertDB(
             UserUtil.userid,
             0L,
             tempmessageid,
             UserUtil.userid,
             toUserId,
             UserUtil.username,
             toName,
             1,
             msg,
             0,
             date,
             remarks,
             0,
             3,
             0);
       } else {
         repeate = 1;
         imDataBase.updataSendStateByTempMessageId(tempmessageid, 1);
       }
       Intent intent = new Intent(ActionID.ACTION_BROADCAST_REQUST_SEND_FRIENDMESSAGE);
       intent.putExtra("revicerUserId", toUserId);
       intent.putExtra("nickname", toName);
       intent.putExtra("remarks", remarks);
       intent.putExtra("repetSend", repeate);
       intent.putExtra("messageId", tempmessageid);
       intent.putExtra("message", msg);
       sendBroadcast(intent);
     }
   } else if (resultCode == RESULT_OK && requestCode == MessageID.REQUEST_SEND_MSG) {
     boolean issend = data.getExtras().getBoolean("issend");
     if (issend) {
       String msg = data.getExtras().getString("msg");
       int toUserId = data.getExtras().getInt("uid");
       String toName = data.getExtras().getString("nickname");
       final long tempmessageid = System.currentTimeMillis();
       final String date = CommonUtil.createCommentTime();
       Entity entity = imDataBase.getTheMessage(tempmessageid);
       int repeate = 0;
       // 取得备注名称
       if (localRemark.length() > 0) {
         remarks = localRemark;
       } else {
         remarks = toName;
       }
       if (entity == null) {
         imDataBase.insertDB(
             UserUtil.userid,
             0L,
             tempmessageid,
             UserUtil.userid,
             toUserId,
             UserUtil.username,
             toName,
             1,
             msg,
             0,
             date,
             remarks,
             0,
             0,
             0);
       } else {
         repeate = 1;
         imDataBase.updataSendStateByTempMessageId(tempmessageid, 1);
       }
       Intent intent = new Intent(ActionID.ACTION_BROADCAST_REQUST_SEND_MESSAGE);
       intent.putExtra("revicerUserId", toUserId);
       intent.putExtra("nickname", toName);
       intent.putExtra("remarks", remarks);
       intent.putExtra("repetSend", repeate);
       intent.putExtra("messageId", tempmessageid);
       intent.putExtra("message", msg);
       sendBroadcast(intent);
     }
   } else if (requestCode == MessageID.REQUEST_GO_SET) {
     connectUserInfo();
   }
 }
Пример #3
0
        @Override
        public void handleMessage(Message msg) {
          // TODO Auto-generated method stub
          super.handleMessage(msg);
          switch (msg.what) {
            case MessageID.MESSAGE_CONNECT_START:
              addProgress();
              break;
            case MessageID.MESSAGE_CONNECT_ERROR:
              if (msg.arg1 == thread_is_addFriend || msg.arg1 == thread_is_refused) {
                ReplayPermit.isMayClick = true;
              }
              closeProgress();
              CommonUtil.ShowToast(getApplicationContext(), (String) msg.obj);
              break;
            case MessageID.MESSAGE_IMAGE_LOAD_ERROR:
              if (gender.equals("男")) {
                imgUser.setImageResource(R.drawable.local_icon_man_big);
              } else {
                imgUser.setImageResource(R.drawable.local_icon_women_big);
              }
              closeProgress();
              break;
            case MessageID.MESSAGE_CONNECT_DOWNLOADOVER:
              closeProgress();
              if ("text/json".equals(msg.getData().getString("content_type"))) {
                final int threadIdx = msg.arg1;
                switch (threadIdx) {
                  case thread_commodInfo:
                    JsonFirstPage((byte[]) msg.obj);
                    setFootRefreshable();
                    break;
                  case thread_commodRefresh:
                    JsonNextPage((byte[]) msg.obj);
                    listView.onFootRefreshComplete();
                    setFootRefreshable();
                    break;
                  case thread_addBlack:
                    Result result = jsonResult((byte[]) msg.obj, "\n");
                    if (result.boolResult) {
                      Toast.makeText(UserPageActivityA.this, "成功加入黑名单", Toast.LENGTH_SHORT).show();
                      refreshUserInfo();
                    } else {
                      Toast.makeText(
                              UserPageActivityA.this,
                              "加入黑名单失败" + result.msgResult,
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                    break;
                  case thread_addFried:
                    result = jsonResult((byte[]) msg.obj, "\n");
                    if (result.boolResult) {
                      Toast.makeText(UserPageActivityA.this, "发送成功", Toast.LENGTH_SHORT).show();
                    } else {
                      Toast.makeText(
                              UserPageActivityA.this, "发送失败" + result.msgResult, Toast.LENGTH_SHORT)
                          .show();
                    }
                    break;
                  case thread_delBlack:
                    result = jsonResult((byte[]) msg.obj, "\n");
                    if (result.boolResult) {
                      Toast.makeText(UserPageActivityA.this, "移出黑名单成功", Toast.LENGTH_SHORT).show();
                      refreshUserInfo();
                    } else {
                      Toast.makeText(
                              UserPageActivityA.this,
                              "移出黑名单失败" + result.msgResult,
                              Toast.LENGTH_SHORT)
                          .show();
                    }
                    break;
                  case thread_is_addFriend:
                    result = jsonResult((byte[]) msg.obj, "");
                    if (result.boolResult) {
                      addFrendButtonClick(1);
                    } else {
                      Toast.makeText(UserPageActivityA.this, result.msgResult, Toast.LENGTH_SHORT)
                          .show();
                      ReplayPermit.isMayClick = true;
                    }
                    break;
                  case thread_is_refused:
                    int isOtherBlack = ReplayPermit.jsonRefused((byte[]) msg.obj);
                    if (isOtherBlack == Friend.BOOL_BLACK) {
                      Toast.makeText(UserPageActivityA.this, "由于对方设置,无法发送消息", Toast.LENGTH_SHORT)
                          .show();
                      ReplayPermit.isMayClick = true;
                    } else {
                      Intent intent = new Intent(UserPageActivityA.this, SendMessageActivity.class);
                      intent.putExtra("uid", uid);
                      intent.putExtra("nickname", nickname);
                      UserPageActivityA.this.startActivityForResult(
                          intent, MessageID.REQUEST_SEND_MSG);
                    }

                    break;
                }

              } else {
                try {
                  String str = new String((byte[]) msg.obj, "UTF-8");
                  str = CommonUtil.formUrlEncode(str);
                  LogPrint.Print("lybjson", "str =" + str);
                } catch (UnsupportedEncodingException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
                renderPage(msg, msg.arg1, msg.getData().getInt("mType"));
                mHandler.sendEmptyMessage(9900);
              }
              break;

            case 998877:
              // 查询消息已读、未读
              long messageId = msg.getData().getLong("messageId");
              int state = imDataBase.getIsReadState(messageId);
              // 已读
              if (state == 1) {
                mainMenu.setMessageButtonRes(false);
                messageImageId.setVisibility(View.GONE);
              } else if (state == 0 && UserUtil.userState == 1) {
                mainMenu.setMessageButtonRes(true);
                messageImageId.setVisibility(View.VISIBLE);
              } else if (state == 0 && UserUtil.userState != 1) {
                mainMenu.setMessageButtonRes(false);
                messageImageId.setVisibility(View.GONE);
              } else if (state == -1) {
                mainMenu.setMessageButtonRes(false);
                messageImageId.setVisibility(View.GONE);
              }
              break;
            case 9900:
              getMessageByUserId();
              messageImageState = true;
          }
        }