예제 #1
0
  /**
   * 签到check
   *
   * @param phone
   * @return
   */
  public void signCheck(String phone) {
    HashMap<String, Object> json = new HashMap<String, Object>();
    json.put("mobile", phone);
    String params = ParamsUtil.getUrlParamsByMap(json);
    MyRequest<Object> req =
        new MyRequest<Object>(
            Request.Method.POST,
            null,
            Constant.checkSign,
            new Response.Listener<Object>() {

              @Override
              public void onResponse(Object arg0) {
                Log.e("msg", arg0.toString());
                try {
                  String result = (String) arg0;
                  JSONObject object = new JSONObject(result.toString());
                  if (object.getInt("result") == 1) {
                    // 已签到
                    SpfsUtil.setIsSign(true);
                  } else {
                    // 未签到
                    SpfsUtil.setIsSign(false);
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError arg0) {
                Toast.makeText(LoginActivity.this, "查询是否签到失败!", Toast.LENGTH_LONG).show();
                arg0.printStackTrace();
              }
            },
            params);
    App.getQueue().add(req);
  }
예제 #2
0
  /** 登陆 */
  @OnClick(R.id.btn_login)
  void toLogin() {
    App.loginId = "001";
    String phone = mLoginPhone.getText().toString().trim();
    String pw = mLoginPW.getText().toString().trim();
    if (TextUtils.isEmpty(phone)) {
      ToastUtil.show(this, "手机号为空");
      return;
    }
    if (TextUtils.isEmpty(pw)) {
      ToastUtil.show(this, "密码为空");
      return;
    }
    // 隐藏软键盘
    imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); // 强制隐藏键盘
    String clientId = Kpush.getInstence().getClientId();
    setDiaolog();
    HashMap<String, Object> json = new HashMap<String, Object>();
    json.put("phone_num", phone);
    json.put("password", pw);
    json.put("channel_id", Kpush.getInstence().getClientId());
    String params = ParamsUtil.getUrlParamsByMap(json);
    System.out.println("json-pre:" + params);
    MyRequest<Object> req =
        new MyRequest<Object>(
            Request.Method.POST,
            null,
            Constant.Login,
            new Response.Listener<Object>() {

              @Override
              public void onResponse(Object arg0) {
                if (((BaseActivityForRequest) mContext).stayThisPage) {
                  Log.e("msg", arg0.toString());
                  try {
                    String result = (String) arg0;
                    JSONObject object = new JSONObject(result.toString());
                    if (object.getInt("result") == 1) {
                      // 统计登录数量
                      MobclickAgent.onEvent(mContext, "login");
                      JSONArray resultJson = object.getJSONObject("body").getJSONArray("success");
                      SpfsUtil.saveId(resultJson.getJSONObject(0).getString("sid"));
                      SpfsUtil.savePhone(resultJson.getJSONObject(0).getString("phone_num"));
                      SpfsUtil.saveTelephone(resultJson.getJSONObject(0).getString("telephone"));
                      SpfsUtil.saveAddress(resultJson.getJSONObject(0).getString("address"));
                      SpfsUtil.saveName(resultJson.getJSONObject(0).getString("name"));
                      if (resultJson.getJSONObject(0).getString("image") != null
                          && !resultJson.getJSONObject(0).getString("image").isEmpty()) {
                        String path = FileUtil.getTempFileName();
                        SpfsUtil.saveHeader(path);
                        SpfsUtil.saveHeadImageUrl(path);
                        LogUtil.print("登录头像临时地址:" + path);
                        String photoStr = resultJson.getJSONObject(0).getString("image");
                        LogUtil.print("\r\n\r\n" + photoStr + "\r\n\r\n");
                        Log.e("gongjie", photoStr);
                        FileOutputStream out = null;
                        try {
                          byte[] decodedString = Base64.decode(photoStr, Base64.DEFAULT);
                          Bitmap decodedByte =
                              BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                          out = new FileOutputStream(path);
                          decodedByte.compress(Bitmap.CompressFormat.PNG, 100, out);
                        } catch (Exception e) {
                          e.printStackTrace();
                          rllayout.setVisibility(View.GONE);
                          mAnimation.stop();
                        } finally {
                          finish();
                          rllayout.setVisibility(View.GONE);
                          mAnimation.stop();
                          try {
                            if (out != null) {
                              out.close();
                            }
                          } catch (IOException e) {
                            e.printStackTrace();
                            rllayout.setVisibility(View.GONE);
                            mAnimation.stop();
                          }
                        }
                      } else {
                        finish();
                        rllayout.setVisibility(View.GONE);
                        mAnimation.stop();
                      }
                      rllayout.setVisibility(View.GONE);
                      mAnimation.stop();
                      // 签到check
                      signCheck(SpfsUtil.loadPhone());

                    } else {
                      String error = object.getJSONObject("body").getString("error");
                      ToastUtil.show(LoginActivity.this, error);
                      rllayout.setVisibility(View.GONE);
                      mAnimation.stop();
                    }
                    rllayout.setVisibility(View.GONE);
                    mAnimation.stop();
                  } catch (Exception e) {
                    e.printStackTrace();
                    rllayout.setVisibility(View.GONE);
                    mAnimation.stop();
                  }
                }
              }
            },
            new Response.ErrorListener() {

              @Override
              public void onErrorResponse(VolleyError arg0) {
                Toast.makeText(LoginActivity.this, "登录失败请重试!", Toast.LENGTH_LONG).show();
                arg0.printStackTrace();
                rllayout.setVisibility(View.GONE);
                mAnimation.stop();
              }
            },
            params);
    App.getQueue().add(req);
  }