@Override
  public int process(BaseProtocolFrame source) {
    if (source != null && source instanceof RequestSendMessage) {
      RequestSendMessage rsm = (RequestSendMessage) source;
      MessageFrame msg = rsm.getMsgEntity();

      switch (source.getReq()) {
        case BaseProtocolFrame.RESPONSE_TYPE_OKAY:
          break;
        case BaseProtocolFrame.RESPONSE_TYPE_NO_LOGIN:
          Toast.makeText(
                  context, context.getText(R.string.response_error_no_login), Toast.LENGTH_SHORT)
              .show();
          if (preference == null) {
            preference = new Preferences(context);
          }
          preference.setLoginState(false);
          Intent logoutIntent = new Intent();
          logoutIntent.setAction("com.forolder.logout.activity");
          context.sendBroadcast(logoutIntent);
          Intent intent = new Intent(context, LoginActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(intent);

          break;
        case BaseProtocolFrame.RESPONSE_TYPE_OTHER_LOGIN:
          Toast.makeText(
                  context,
                  context.getText(R.string.response_error_login_other_phone),
                  Toast.LENGTH_SHORT)
              .show();
          break;
        default:
          break;
      }

      if (msg != null) {
        if (msg.getState() == MessageFrame.SENDSTATE_SENDING) {
          msg.setState(MessageFrame.SENDSTATE_FAULT);
        }
        DatabaseHelper dbHelper = new DatabaseHelper(context);
        ContentValues values = new ContentValues();
        values.put("send_state", msg.getState());
        dbHelper.updateMessage(values, msg.getLoginId(), msg.getDate(), msg.getUserMsgType());
      }
    } else {
      return -100;
    }
    return 0;
  }
  @Override
  protected void onResume() {
    super.onResume();
    adapter.clear();

    Cursor message = dbHelper.getMessage(new String[] {"date", "name", "content"});
    message.moveToPosition(message.getCount());
    while (message.moveToPrevious()) {
      DateInfo dateInfo = new DateInfo(message.getLong(message.getColumnIndex("date")));
      adapter.add(
          dateInfo.getRTime()
              + "\n"
              + message.getString(message.getColumnIndex("name"))
              + "\n"
              + message.getString(message.getColumnIndex("content")));
    }
    message.close();
    dbHelper.close();
  }