示例#1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);

    myProgressDialog2 = new MyProgressDialog(this);
    myProgressDialog2.setMessage("正在请求...");
    myProgressDialog2.show();

    context = this;
    intent = getIntent();
    loadUrl = intent.getStringExtra("loadUrl");

    bt_update = (Button) findViewById(R.id.id_bt_update);
    // commonActivityTopView = (CommonActivityTopView)
    // findViewById(R.id.id_CommonActivityTopView);
    // commonActivityTopView.tv_title.setText("webview");
    rl = (RelativeLayout) findViewById(R.id.id_rl);

    loadWebView();
    webViewListener();
    initListener();
    LogUtil.i(TAG, SharedPrefsUtil.getValue(Constants.TOKEN, null));
    HashMap<String, String> hashmap = new HashMap<String, String>();
    if (null != SharedPrefsUtil.getValue(Constants.TOKEN, null)) {
      hashmap.put("token", SharedPrefsUtil.getValue(Constants.TOKEN, null));
    }
    webview.loadUrl(loadUrl, hashmap);
  }
示例#2
0
 /** JS调用的方法 */
 @JavascriptInterface
 public void reloadUrl(String url) {
   Log.i(TAG, "reloadUrl()");
   HashMap<String, String> hashmap = new HashMap<String, String>();
   if (null != SharedPrefsUtil.getValue(Constants.TOKEN, null)) {
     hashmap.put("token", SharedPrefsUtil.getValue(Constants.TOKEN, null));
   }
   webview.clearView();
   webview.loadUrl(url, hashmap);
 }
示例#3
0
 /** 同步一下cookie */
 public static void synCookies(Context context, String url) {
   CookieSyncManager.createInstance(context);
   CookieManager cookieManager = CookieManager.getInstance();
   cookieManager.setAcceptCookie(true);
   cookieManager.removeSessionCookie(); // 移除
   String token = SharedPrefsUtil.getValue(Constants.TOKEN, null);
   cookieManager.setCookie(url, "token=" + token + ";path=/"); // cookies是在HttpClient中获得的cookie
   CookieSyncManager.getInstance().sync();
 }
示例#4
0
 /** JS调用的方法 */
 @JavascriptInterface
 public void goToReport(String studyid) {
   userModel =
       new Gson().fromJson(SharedPrefsUtil.getValue(Constants.USERMODEL, null), UserModel.class);
   Log.i(TAG, "goToReport()");
   Intent intent = new Intent();
   if (!DBUtilsHelper.getInstance().isOnline()) {
     requestDoctor(studyid);
   } else {
     ToastUtil.showMessage("您当前正在进行在线咨询,结束后才能进行报告解读哦");
     SharedPrefsUtil.putValue(Constants.CHECKEDID_RADIOBT, 1);
     Intent intent2 = new Intent(WebViewActivity.this, MainActivity.class);
     intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     intent2.putExtra("news", "news");
     startActivity(intent2);
     finish();
     return;
   }
   startActivity(intent);
 }
  /** 将修改后的信息上传服务器 */
  public void requestModifyInfo() {

    try {

      // 向服务器发送请求
      // RequestParams params = new RequestParams();
      // params.addHeader(Constants.TOKEN,
      // SharedPrefsUtil.getValue(Constants.TOKEN, ""));

      JSONObject jsonParam = new JSONObject();
      jsonParam.put("photo", "");
      jsonParam.put("fileName", "");
      String userJson = SharedPrefsUtil.getValue(Constants.USERMODEL, "");
      UserModel userModel = new Gson().fromJson(userJson, UserModel.class);
      // String userSex = "";
      // if(userModel.getUserSex().equals("男")){
      // userSex = "Man";
      // }else if(userModel.getUserSex().equals("女")){
      // userSex ="Woman";
      // }
      jsonParam.put("sex", userModel.getUserSex());

      if (title.equals("姓名")) {

        jsonParam.put("Name", et.getText().toString().trim());

        jsonParam.put("IDcard", userModel.getIDcard());

        jsonParam.put("UserAccount", userModel.getUserAccount());

      } else if (title.equals("身份证号")) {
        jsonParam.put("Name", userModel.getUserName());

        jsonParam.put("IDcard", et.getText().toString().trim());

        jsonParam.put("UserAccount", userModel.getUserAccount());

      } else {
        jsonParam.put("Name", userModel.getUserName());

        jsonParam.put("IDcard", userModel.getIDcard());

        jsonParam.put("UserAccount", et.getText().toString().trim());
      }

      // params.addBodyParameter("param", jsonParam.toString());

      LogUtil.i("=====", "===" + userModel.getUserSex() + "===");
      LogUtil.i("=====", jsonParam.toString());

      // params.setBodyEntity(new StringEntity(jsonParam.toString()));
      // HttpUtils httpUtils = new HttpUtils();
      HttpClient.post(
          Constants.MODIFYINFO_URl,
          jsonParam.toString(),
          new RequestCallBack<String>() {

            @Override
            public void onStart() {
              Log.i("HttpUtil", "onStart");
            }

            @Override
            public void onLoading(long total, long current, boolean isUploading) {
              Log.i("HttpUtil", "onLoading");
            }

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
              Log.i("HttpUtil", "onSuccess");

              Log.i("HttpUtil", "onSuccess===" + responseInfo.result.toString());
              ToastUtil.showMessage("修改成功");

              // 存本地
              UserModel userModel =
                  new Gson()
                      .fromJson(SharedPrefsUtil.getValue(Constants.USERMODEL, ""), UserModel.class);
              if (title.equals("姓名")) {
                // 存入修改后的姓名
                userModel.setUserName(et.getText().toString().trim());

              } else if (title.equals("身份证号")) {
                // 存入修改后的身份证号
                userModel.setIDcard(et.getText().toString().trim());

                // 存入年龄
                userModel.setAge(MathUtils.calculateAge(et.getText().toString().trim()));

                // SharedPrefsUtil.putValue(Constants.USERMODEL,
                // userModel.toString());
              } else {
                // 存入修改后的手机号
                // userModel.setMobilephone(et.getText().toString()
                // .trim());

              }

              SharedPrefsUtil.putValue(Constants.USERMODEL, userModel.toString());

              Log.i("HttpUtil", "存入手机");

              finish();
            }

            @Override
            public void onFailure(HttpException error, String msg) {
              Log.i("HttpUtil", "onFailure===" + msg);
              LogUtil.i("===============", error.toString());
              ToastUtil.showMessage("网络获取失败");
              LogUtil.i("=================", Constants.MODIFYINFO_URl);
              // testTextView.setText(error.getExceptionCode() +
              // ":" +
              // msg);
            }
          });

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }