Ejemplo n.º 1
0
  public static BitmapDrawable downloadAvatarAndGetMemberStatus() {
    try {
      final String profile =
          BaseUtils.replaceWhitespace(
              Network.getResponseData(Network.getRequest("http://www.geocaching.com/my/")));

      Settings.setMemberStatus(
          BaseUtils.getMatch(profile, GCConstants.PATTERN_MEMBER_STATUS, true, null));
      if (profile.contains(GCConstants.MEMBER_STATUS_RENEW)) {
        Settings.setMemberStatus(GCConstants.MEMBER_STATUS_PM);
      }

      setActualCachesFound(
          Integer.parseInt(
              BaseUtils.getMatch(profile, GCConstants.PATTERN_CACHES_FOUND, true, "-1")
                  .replaceAll("[,.]", "")));

      final String avatarURL =
          BaseUtils.getMatch(profile, GCConstants.PATTERN_AVATAR_IMAGE_PROFILE_PAGE, false, null);
      if (null != avatarURL) {
        final HtmlImage imgGetter = new HtmlImage("", false, 0, false);
        return imgGetter.getDrawable(avatarURL);
      }
      // No match? There may be no avatar set by user.
      Log.d("No avatar set for user");
    } catch (Exception e) {
      Log.w("Error when retrieving user avatar", e);
    }
    return null;
  }
Ejemplo n.º 2
0
  public static String readCachePage(final String geocode) {
    try {
      final InputStream is =
          MockedCache.class.getResourceAsStream("/cgeo/geocaching/test/mock/" + geocode + ".html");
      final BufferedReader br = new BufferedReader(new InputStreamReader(is), 150000);

      final StringBuffer buffer = new StringBuffer();
      String line = null;

      while ((line = br.readLine()) != null) {
        buffer.append(line).append('\n');
      }

      br.close();
      return BaseUtils.replaceWhitespace(buffer.toString());
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }