public String getInfo() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("language", "zh-CN");
    map.put("sensor", "false");
    map.put("latlng", getLatlng());

    String url = URLHelper.GOOGLELOCATION;

    String jsonData = null;
    try {
      jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    } catch (WeiboException e) {
      AppLogger.e(e.getMessage());
    }

    try {
      JSONObject jsonObject = new JSONObject(jsonData);
      JSONArray results = jsonObject.optJSONArray("results");
      JSONObject jsonObject1 = results.getJSONObject(0);
      String formatAddress = jsonObject1.optString("formatted_address");
      int index = formatAddress.indexOf(" ");
      if (index > 0) {
        String location = formatAddress.substring(0, index);
        return location;
      } else {
        return formatAddress;
      }
    } catch (JSONException e) {
      AppLogger.e(e.getMessage());
    }

    return "";
  }
Beispiel #2
0
  private String dealWithError(HttpResponse httpResponse) throws WeiboException {

    StatusLine status = httpResponse.getStatusLine();
    int statusCode = status.getStatusCode();

    String result = "";

    if (statusCode != HttpStatus.SC_OK) {

      result = readResult(httpResponse);
      String err = null;
      int errCode = 0;
      try {
        JSONObject json = new JSONObject(result);
        err = json.getString("error");
        errCode = json.getInt("error_code");
        WeiboException exception = new WeiboException();
        exception.setError_code(errCode);
        exception.setOriError(err);
        throw exception;

      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    return result;
  }
 @Override
 protected void onCancelled(String s) {
   super.onCancelled(s);
   progressFragment.dismissAllowingStateLoss();
   if (e != null)
     Toast.makeText(WriteWeiboActivity.this, e.getError(), Toast.LENGTH_SHORT).show();
 }
 @Override
 protected void onCancelled(UserBean userBean) {
   super.onCancelled(userBean);
   if (e != null) {
     Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
   }
 }
    @Override
    protected UserBean doInBackground(Void... params) {

      FriendshipsDao dao = new FriendshipsDao(GlobalContext.getInstance().getSpecialToken());
      if (!TextUtils.isEmpty(bean.getId())) {
        dao.setUid(bean.getId());
      } else {
        dao.setScreen_name(bean.getScreen_name());
      }
      try {
        return dao.followIt();
      } catch (WeiboException e) {
        AppLogger.e(e.getError());
        this.e = e;
        cancel(true);
        return null;
      }
    }
Beispiel #6
0
 @Override
 protected void onCancelled(DBResult dbResult) {
   super.onCancelled(dbResult);
   if (progressFragment != null) {
     progressFragment.dismissAllowingStateLoss();
   }
   if (e != null) Toast.makeText(OAuthActivity.this, e.getError(), Toast.LENGTH_SHORT).show();
   webView.loadUrl(getWeiboOAuthUrl());
 }
Beispiel #7
0
    @Override
    protected DBResult doInBackground(String... params) {

      String token = params[0];
      long expiresInSeconds = Long.valueOf(params[1]);

      try {
        UserBean user = new OAuthDao(token).getOAuthUserInfo();
        AccountBean account = new AccountBean();
        account.setAccess_token(token);
        account.setExpires_time(System.currentTimeMillis() + expiresInSeconds * 1000);
        account.setInfo(user);
        AppLogger.e("token expires in " + Utility.calcTokenExpiresInDays(account) + " days");
        return AccountDBTask.addOrUpdateAccount(account, false);
      } catch (WeiboException e) {
        AppLogger.e(e.getError());
        this.e = e;
        cancel(true);
        return null;
      }
    }
  private String handleError(HttpURLConnection urlConnection) throws WeiboException {

    String result = readError(urlConnection);
    String err = null;
    int errCode = 0;
    try {
      AppLogger.e("error=" + result);
      JSONObject json = new JSONObject(result);
      err = json.optString("error_description", "");
      if (TextUtils.isEmpty(err)) err = json.getString("error");
      errCode = json.getInt("error_code");
      WeiboException exception = new WeiboException();
      exception.setError_code(errCode);
      exception.setOriError(err);
      throw exception;

    } catch (JSONException e) {
      e.printStackTrace();
    }

    return result;
  }
 @Override
 protected void onCancelled(String s) {
   super.onCancelled(s);
   if (e != null)
     Toast.makeText(BlackMagicActivity.this, e.getError(), Toast.LENGTH_SHORT).show();
 }