Ejemplo n.º 1
0
  // 更新服务端数据
  private void reayToSaveUserInfo() {
    if (!NetworkUtil.getInstance().existNetwork(HomePageActivity.this)) {
      Toast.makeText(HomePageActivity.this, R.string.network_disable_error, Toast.LENGTH_LONG)
          .show();
      return;
    }
    final String currMethod = "readyToSaveUserInfo:";
    if (null == rec) {
      Log.e(TAG, currMethod + "userRec == null");
      Toast.makeText(HomePageActivity.this, R.string.user_basic_send_failed_rem, Toast.LENGTH_SHORT)
          .show();
      return;
    }
    lockScreen(getString(R.string.user_basic_send_ing));
    UserService us = new UserService();
    AjaxCallBack<Object> callBack =
        new AjaxCallBack<Object>() {
          @Override
          public void onFailure(Throwable t, String strMsg) {
            releaseScreen();
            Log.e(TAG, currMethod + "onFailure,Msg->" + strMsg, t);
            if (BuildConfig.isDebug) {
              String msg = strMsg;
              if (StringUtil.getInstance().IsEmpty(msg)) {
                msg = null == t ? "Exception t is null." : t.toString();
              }
              ExceptionRemHelper.showExceptionReport(HomePageActivity.this, msg);
            } else {
              Toast.makeText(
                      HomePageActivity.this,
                      R.string.user_basic_send_failed_rem,
                      Toast.LENGTH_SHORT)
                  .show();
            }
            super.onFailure(t, strMsg);
          }

          @Override
          public void onSuccess(Object t) {
            releaseScreen();
            if (null != t) {
              String json = t.toString();
              Trace.d(TAG, currMethod + ",Json->" + json);
              ServerResponseParser parser = new ServerResponseParser();
              BaseResponse br = parser.parseUpdateUserInfo(json);
              if (null != br && ErrorCodeStant.getInstance().isSucceed(br.getErrorCode())) {
                Toast.makeText(
                        HomePageActivity.this, R.string.user_basic_succeed_rem, Toast.LENGTH_SHORT)
                    .show();
                ResponseUser user = (ResponseUser) br;
                UserRec userRec = user.getUserRec();
                SettingUtil.getInstance(HomePageActivity.this)
                    .saveUserInfo(userRec.getUserId(), userRec);
                String flag = "back";
                FragmentChangeActivity.slideMenu.setTag(flag);
              } else {
                InitPersonalInfo();
                String message = getString(R.string.user_basic_send_failed_rem);
                String msg = getString(R.string.user_basic_send_failed_rem);
                if (null == br) {
                  msg = "parseUploadPic: Result:BaseResponse is null.";
                } else {
                  message = br.getMessage();
                }
                int errorCode = br.getErrorCode();
                switch (errorCode) {
                  default:
                    msg = br.getMessage();
                    break;
                    // }
                }
                Log.e(
                    TAG,
                    currMethod + "errorCode:" + br.getErrorCode() + "--Message:" + br.getMessage());
                if (BuildConfig.isDebug) {
                  ExceptionRemHelper.showExceptionReport(HomePageActivity.this, msg);
                } else {
                  Toast.makeText(HomePageActivity.this, message, Toast.LENGTH_SHORT).show();
                }
              }
            } else {
              Log.d(TAG, currMethod + "Result t is null");
              if (BuildConfig.isDebug) {
                String msg = "result t is null.";
                ExceptionRemHelper.showExceptionReport(HomePageActivity.this, msg);
              } else {
                Toast.makeText(
                        HomePageActivity.this,
                        R.string.get_user_info_failed_rem,
                        Toast.LENGTH_SHORT)
                    .show();
              }
            }
            super.onSuccess(t);
          }
        };
    String email = etEmail.getText().toString();
    String realName = etRealName.getText().toString();
    String sex = String.valueOf(rec.getSex());
    String birthday = rec.getBirthday();
    String msn = etMsn.getText().toString();
    String QQ = etQQ.getText().toString();
    String officePhone = etOfficePhone.getText().toString();
    String homePhone = etHomePhone.getText().toString();
    String mobilePhone = etMobilePhone.getText().toString();
    us.updateUserInfo(
        HomePageActivity.this,
        email,
        realName,
        sex,
        birthday,
        msn,
        QQ,
        officePhone,
        homePhone,
        mobilePhone,
        callBack);
  }
Ejemplo n.º 2
0
  private void InitPersonalInfo() {
    // 更换头像

    Trace.d(TAG, "InitPersonalInfo:" + rec.getAvatar().toString());
    if (!StringUtil.getInstance().IsEmpty(rec.getAvatar().getBig())) {
      String url = RequestUrls.SERVER_BASIC_URL + rec.getAvatar().getBig();
      try {
        avatarFB = FinalBitmap.create(HomePageActivity.this);
        avatarFB.flushCache();
        avatarFB.closeCache();
        //				avatarFB.configLoadfailImage(R.drawable.menu_default_head);
        avatarFB.display(ivAvatar, url, true);
        //				avatarFB.display(ivAvatar, url, false);
      } catch (Exception e) {
        Log.e(TAG, "refreshAvatarView:display user avatar error.", e);
      }
    } else {
      Log.e(TAG, "refreshAvatarView:url is empty.");
    }
    ivAvatar.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent(HomePageActivity.this, BigPicImgActivity.class);
            intent.putExtra(BigPicImgActivity.KET_FOR_BIGPIC, rec.getAvatar().getBig());
            startActivityForResult(intent, BIGPIC_FOR_RESULT);
            HomePageActivity.this.overridePendingTransition(
                R.anim.my_scale_action, R.anim.my_alpha_action);
          }
        });

    tvUserName.setText(rec.getUserName());

    long sendCount = rec.getOnSaleNum() + rec.getOffSaleNum();
    tvSendCount.setText(String.valueOf(sendCount));

    long favCount = rec.getFavNum();
    tvFavCount.setText(String.valueOf(favCount));

    tvAttentionCount.setText(rec.getAttendNum());

    tvVisitCount.setText(
        String.format(getString(R.string.visit_count_format), rec.getVisitCount()));

    btnOperation.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            showChangeLogoRem();
          }
        });

    // 电子邮箱
    emailGroup = (ViewGroup) findViewById(R.id.email);
    TextView tvEmailTitle = (TextView) emailGroup.findViewById(R.id.info_title);
    tvEmailTitle.setText(R.string.home_page_item_title_email);
    etEmail = (EditText) emailGroup.findViewById(R.id.info_content);
    System.out.println("====etEmail==" + rec.getEmail());
    String regMacth = "[\\w]+@[\\w]+.[\\w]+";

    if (!StringUtil.getInstance().IsEmpty(rec.getEmail())
        && rec.getEmail() != null
        && rec.getEmail().matches(regMacth)) {

      etEmail.setText(rec.getEmail());
    } else {
      etEmail.setText("");
    }

    ((TextView) emailGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 真实姓名
    realNameGroup = (ViewGroup) findViewById(R.id.real_name);
    TextView tvRealNameTitle = (TextView) realNameGroup.findViewById(R.id.info_title);
    tvRealNameTitle.setText(R.string.home_page_item_title_real_name);
    etRealName = (EditText) realNameGroup.findViewById(R.id.info_content);
    if (!StringUtil.getInstance().IsEmpty(rec.getRealName()) && rec.getRealName() != null) {
      etRealName.setText(rec.getRealName());
    }

    ((TextView) realNameGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 性别
    sexGroup = (ViewGroup) findViewById(R.id.gender);
    TextView tvSexTitle = (TextView) sexGroup.findViewById(R.id.info_title);
    tvSexTitle.setText(R.string.home_page_item_title_sex);
    etSex = (EditText) sexGroup.findViewById(R.id.info_content);
    sexGroup.setBackgroundResource(R.drawable.light_item_bg_selector);

    switch (rec.getSex()) {
      case 0:
        etSex.setText(R.string.sex_secrecy);
        break;
      case 1:
        etSex.setText(R.string.sex_male);
        break;
      case 2:
        etSex.setText(R.string.sex_female);
        break;
      default:
        break;
    }
    ((TextView) sexGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 生日
    birthdayGroup = (ViewGroup) findViewById(R.id.birthday);
    TextView tvBirthdayTitle = (TextView) birthdayGroup.findViewById(R.id.info_title);
    tvBirthdayTitle.setText(R.string.home_page_item_title_birthday);
    etBirthday = (EditText) birthdayGroup.findViewById(R.id.info_content);

    if (!StringUtil.getInstance().IsEmpty(rec.getBirthday())
        && rec.getBirthday() != null
        && !rec.getBirthday().equalsIgnoreCase("0000-00-00")) {
      etBirthday.setText(rec.getBirthday());
    }
    birthdayGroup.setBackgroundResource(R.drawable.light_item_bg_selector);

    ((TextView) birthdayGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // MSN
    msnGroup = (ViewGroup) findViewById(R.id.msn);
    TextView tvMSNTitle = (TextView) msnGroup.findViewById(R.id.info_title);
    tvMSNTitle.setText(R.string.home_page_item_title_msn);
    etMsn = (EditText) msnGroup.findViewById(R.id.info_content);

    if (!StringUtil.getInstance().IsEmpty(rec.getMsn()) && rec.getMsn() != null) {
      etMsn.setText(rec.getMsn());
    }
    ((TextView) msnGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // QQ
    qqGroup = (ViewGroup) findViewById(R.id.qq);
    TextView tvQQ = (TextView) qqGroup.findViewById(R.id.info_title);
    tvQQ.setText(R.string.home_page_item_title_qq);
    etQQ = (EditText) qqGroup.findViewById(R.id.info_content);
    if (!StringUtil.getInstance().IsEmpty(rec.getQq()) && rec.getQq() != null) {
      etQQ.setText(rec.getQq());
    }
    ((TextView) qqGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 工作电话
    officePhoneGroup = (ViewGroup) findViewById(R.id.office_phone);
    TextView tvOfficePhone = (TextView) officePhoneGroup.findViewById(R.id.info_title);
    tvOfficePhone.setText(R.string.home_page_item_title_office_phone);
    etOfficePhone = (EditText) officePhoneGroup.findViewById(R.id.info_content);
    if (!StringUtil.getInstance().IsEmpty(rec.getOfficePhone()) && rec.getOfficePhone() != null) {
      etOfficePhone.setText(rec.getOfficePhone());
    }
    ((TextView) officePhoneGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 手机
    mobilePhoneGroup = (ViewGroup) findViewById(R.id.mobile_phone);
    TextView tvMobilePhone = (TextView) mobilePhoneGroup.findViewById(R.id.info_title);
    tvMobilePhone.setText(R.string.home_page_item_title_mobile_phone);
    etMobilePhone = (EditText) mobilePhoneGroup.findViewById(R.id.info_content);
    if (!StringUtil.getInstance().IsEmpty(rec.getMobilePhone()) && rec.getMobilePhone() != null) {
      etMobilePhone.setText(rec.getMobilePhone());
    }
    ((TextView) mobilePhoneGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // 座机
    homePhoneGroup = (ViewGroup) findViewById(R.id.home_phone);
    TextView tvHomePhone = (TextView) homePhoneGroup.findViewById(R.id.info_title);
    tvHomePhone.setText(R.string.home_page_item_title_home_phone);
    etHomePhone = (EditText) homePhoneGroup.findViewById(R.id.info_content);
    if (!StringUtil.getInstance().IsEmpty(rec.getHomePhone()) && rec.getHomePhone() != null) {
      etHomePhone.setText(rec.getHomePhone());
    }
    ((TextView) homePhoneGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);

    // attentionGroup = (ViewGroup) findViewById(R.id.attention);
    // TextView tvAttention = (TextView) attentionGroup
    // .findViewById(R.id.info_title);
    // tvAttention.setText(R.string.home_page_item_title_attention);
    // etAttention = (EditText)
    // attentionGroup.findViewById(R.id.info_content);
    // ((TextView) attentionGroup.findViewById(R.id.info_hint))
    // .setText(R.string.attention_hint_text);
    // // ((TextView)
    // //
    // attentionGroup.findViewById(R.id.info_hint)).setVisibility(View.VISIBLE);
  }