コード例 #1
0
  private void onLoginState() {
    // 获取用户信息列表
    // m_id = Api.getInstance().getLoginUserId();

    if (m_id > 0) {
      Api.getInstance()
          .getUserInfoPage(
              m_id,
              new NetClientCallback() {

                @Override
                public void execute(int status, String response, List<Cookie> cookies) {
                  Looper.prepare();
                  if (status == HttpClientUtil.NET_SUCCESS) {
                    JSONArray jsonArray = JSON.parseArray(response);
                    m_person = jsonArray;

                  } else {
                    Toast.makeText(UserInfoPage.this, "提示:目前网络状况不佳。", Toast.LENGTH_SHORT).show();
                  }
                  m_handler.sendEmptyMessage(status);
                  Looper.loop();
                }
              });
    } else {
      Toast.makeText(UserInfoPage.this, "用户ID" + m_id + "不合法", Toast.LENGTH_SHORT).show();
    }
  }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.show_user_info);

    m_IDView = (TextView) this.findViewById(R.id.peID);
    m_UserNameContentView = (TextView) this.findViewById(R.id.peNameConent);
    m_IDContentView = (TextView) this.findViewById(R.id.peIDConent);
    m_UserTitleView = (TextView) this.findViewById(R.id.peUserTitle);
    m_UserTitleContentView = (TextView) this.findViewById(R.id.peUserTitleConent);
    m_PostsView = (TextView) this.findViewById(R.id.pePosts);
    m_PostsContentView = (TextView) this.findViewById(R.id.pePostsConent);
    m_moneyView = (TextView) this.findViewById(R.id.peMoneny);
    m_MoneyContentView = (TextView) this.findViewById(R.id.peMoneyConent);
    m_GoodnessView = (TextView) this.findViewById(R.id.peGoodness);
    m_GoodnessContentView = (TextView) this.findViewById(R.id.peGoodnessConent);
    Bundle bundle = this.getIntent().getExtras();

    /*从Bundle中获得所需查看用戶的ID*/
    m_id = bundle.getInt("user_id");
    if (Api.getInstance().isLogin()) {
      onLoginState();
    }
  }
コード例 #3
0
  public void onLoginBtnClick(View v) {
    String uname = m_userName.getText().toString();
    String passwd = m_passwd.getText().toString();
    if (uname.length() == 0) {
      Toast.makeText(this, R.string.login_username_alert, Toast.LENGTH_SHORT).show();
      return;
    }

    if (passwd.length() == 0) {
      Toast.makeText(this, R.string.login_passwd_alert, Toast.LENGTH_SHORT).show();
      return;
    }
    m_pd = ProgressDialog.show(this, null, "登录中,请稍后……", true, true);

    Api.getInstance()
        .login(
            uname,
            passwd,
            new NetClientCallback() {

              @Override
              public void execute(int status, String response, List<Cookie> cookies) {
                System.out.println("login:"******"result");
                  if (ret != Api.LOGIN_SUCCESS) {
                    m_handler.post(
                        new Runnable() {

                          @Override
                          public void run() {
                            m_pd.dismiss();
                            switch (ret) {
                              case Api.LOGIN_FAIL_LESS_THAN_FIVE:
                                String alertText =
                                    "用户名或者密码错误,还有"
                                        + (Api.ALLOW_LOGIN_USERNAME_OR_PASSWD_ERROR_NUM
                                            - retObj.getInteger("strikes"))
                                        + "尝试机会";
                                Toast.makeText(LoginPage.this, alertText, Toast.LENGTH_SHORT)
                                    .show();
                                break;
                              case Api.LOGIN_FAIL_MORE_THAN_FIVE:
                                Toast.makeText(
                                        LoginPage.this,
                                        R.string.login_fail_more_than_five,
                                        Toast.LENGTH_SHORT)
                                    .show();
                                break;
                            }
                          }
                        });
                    return;
                  }
                  String token = retObj.getString("securitytoken");
                  Api.getInstance().setToken(token);
                  Api.getInstance()
                      .setLoginUserInfo(
                          retObj.getString("username"),
                          retObj.getInteger("userid"),
                          retObj.getInteger("isavatar"),
                          retObj.getString("email"));

                  for (int i = 0; i < cookies.size(); i++) {
                    Cookie cookie = cookies.get(i);
                    Api.getInstance()
                        .getCookieStorage()
                        .addCookie(cookie.getName(), cookie.getValue());
                  }
                  LoginPage.this.sendBroadcast(new Intent(App.LOGIN_STATE_CHANGE_ACTION));
                }
                m_handler.sendEmptyMessage(status);
              }
            });
  }