コード例 #1
0
  protected void test(String... urls) {
    InputStream is = null;
    QuotesConstants constants = QuotesConstants.getInstance();
    try {
      System.out.println("Json*************");

      is =
          new URL("http://10.0.2.2:8080/QuotesWebDomain/quotesRest/activityimages/json")
              .openStream();
      is = new URL("https://scorching-inferno-116.firebaseio.com/celebrities.json").openStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
      String jsonText = readAll(rd);
      System.out.println("Json array" + jsonText);
      JSONObject json = new JSONObject(jsonText);
      JSONArray array = json.getJSONArray("leaderHelper");
      HashMap<String, LeaderHelper> hashMap = new HashMap<String, LeaderHelper>();
      int id = 0;
      for (int i = 0; i < array.length(); i++) {
        JSONObject jsonobj = (JSONObject) array.get(i);
        String name = jsonobj.getString("leader_name");
        String active = jsonobj.getString("active");
        String thumbnail = jsonobj.getString("image_url");
        System.out.println("*****" + name + "******" + active + "********" + thumbnail);
        LeaderHelper leaderHelper = new LeaderHelper();
        leaderHelper.setActive(jsonobj.getString("active"));
        leaderHelper.setLeader_name(jsonobj.getString("leader_name"));
        leaderHelper.setImage_url(downloadBitmap(jsonobj.getString("image_url")));
        id++;
        hashMap.put((new Integer(id)).toString(), leaderHelper);
      }
      constants.hashMap = hashMap;

    } catch (Exception ex) {

    } finally {
      try {
        is.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
  @SuppressWarnings("finally")
  protected String doInBackground(String... urls) {
    String status = "failure";
    InputStream is = null;
    QuotesConstants constants = QuotesConstants.getInstance();

    // ********Modified on 20-07-2015*****************//*
    String jsonText = "";
    BufferedReader rd = null;

    try {

      try {
        // **********************************For Old Era*******************************//*
        {
          try {
            is =
                new URL("https://scorching-inferno-116.firebaseio.com/leaderHelper.json")
                    .openStream();
            rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            jsonText = readAll(rd);
            System.out.println("Json array" + jsonText);
            JSONArray array = new JSONArray(jsonText);

            HashMap<String, LeaderHelper> hashMap = new HashMap<String, LeaderHelper>();
            int id = 0;
            for (int i = 0; i < array.length(); i++) {
              JSONObject jsonobj = (JSONObject) array.get(i);
              String name = jsonobj.getString("leader_name");
              String active = jsonobj.getString("active");
              String thumbnail = jsonobj.getString("image_url");
              System.out.println("*****" + name + "******" + active + "********" + thumbnail);
              LeaderHelper leaderHelper = new LeaderHelper();
              leaderHelper.setActive(jsonobj.getString("active"));
              leaderHelper.setLeader_name(jsonobj.getString("leader_name"));
              leaderHelper.setImage_url(
                  downloadBitmap(jsonobj.getString("image_url").replaceAll("\\/", "/")));
              leaderHelper.setId(jsonobj.getString("id"));
              leaderHelper.setContent(jsonobj.getString("content"));
              JSONArray msg = (JSONArray) jsonobj.getJSONArray("quotes");
              String[] quotes = new String[msg.length()];
              for (int j = 0; j < msg.length(); j++) {
                quotes[j] = msg.getString(j);
              }
              System.out.println(
                  "*****"
                      + name
                      + "******"
                      + active
                      + "********"
                      + thumbnail
                      + "*****"
                      + quotes.toString());
              leaderHelper.setQuotes(quotes);
              id++;
              hashMap.put((new Integer(id)).toString(), leaderHelper);
            }
            constants.hashMap = hashMap;
          } catch (Exception ex) {
            System.out.println("Exception in 90" + ex.toString());
          }
        }
        // **********************************For Modern Era*******************************//*
        {
          try {
            is =
                new URL("https://scorching-inferno-116.firebaseio.com/leaderHelper20.json")
                    .openStream();
            rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            jsonText = readAll(rd);
            System.out.println("Json array" + jsonText);
            JSONArray array = new JSONArray(jsonText);
            HashMap<String, LeaderHelper> hashMap = new HashMap<String, LeaderHelper>();
            int id = 0;
            for (int i = 0; i < array.length(); i++) {
              JSONObject jsonobj = (JSONObject) array.get(i);
              String name = jsonobj.getString("leader_name");
              String active = jsonobj.getString("active");
              String thumbnail = jsonobj.getString("image_url");
              System.out.println("*****" + name + "******" + active + "********" + thumbnail);
              LeaderHelper leaderHelper = new LeaderHelper();
              leaderHelper.setActive(jsonobj.getString("active"));
              leaderHelper.setLeader_name(jsonobj.getString("leader_name"));
              leaderHelper.setImage_url(
                  downloadBitmap(jsonobj.getString("image_url").replaceAll("\\/", "/")));
              leaderHelper.setId(jsonobj.getString("id"));
              leaderHelper.setContent(jsonobj.getString("content"));
              JSONArray msg = (JSONArray) jsonobj.getJSONArray("quotes");
              String[] quotes = new String[msg.length()];
              for (int j = 0; j < msg.length(); j++) {
                quotes[j] = msg.getString(j);
              }
              System.out.println(
                  "*****"
                      + name
                      + "******"
                      + active
                      + "********"
                      + thumbnail
                      + "*****"
                      + quotes.toString());
              leaderHelper.setQuotes(quotes);
              id++;
              hashMap.put((new Integer(id)).toString(), leaderHelper);
            }
            constants.hashMap20 = hashMap;
          } catch (Exception ex) {
            System.out.println("Exception in 20" + ex.toString());
          }
        }

        // **********************************For Filmy
        // Era*******************************//*
        {
          try {
            is =
                new URL("https://scorching-inferno-116.firebaseio.com/filmyHelpers.json")
                    .openStream();
            rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            jsonText = readAll(rd);
            System.out.println("Json array" + jsonText);
            JSONArray array = new JSONArray(jsonText);
            HashMap<String, FilmyHelper> hashMap = new HashMap<String, FilmyHelper>();
            int id = 0;
            for (int i = 0; i < array.length(); i++) {
              JSONObject jsonobj = (JSONObject) array.get(i);
              String movie_name = jsonobj.getString("movie_name");
              String starring = jsonobj.getString("starring");
              String thumbnail = jsonobj.getString("image_url");
              System.out.println(
                  "*****" + movie_name + "******" + starring + "********" + thumbnail);
              FilmyHelper filmHelper = new FilmyHelper();
              filmHelper.setStarring(jsonobj.getString("starring"));
              filmHelper.setMovie_name(jsonobj.getString("movie_name"));
              filmHelper.setImage_url(
                  downloadBitmap(jsonobj.getString("image_url").replaceAll("\\/", "/")));
              filmHelper.setId(jsonobj.getString("id"));
              filmHelper.setContent(jsonobj.getString("content"));
              JSONArray msg = (JSONArray) jsonobj.getJSONArray("quotes");
              String[] quotes = new String[msg.length()];
              for (int j = 0; j < msg.length(); j++) {
                quotes[j] = msg.getString(j);
              }
              System.out.println(
                  "*****"
                      + movie_name
                      + "******"
                      + starring
                      + "********"
                      + thumbnail
                      + "*****"
                      + quotes.toString());
              filmHelper.setQuotes(quotes);
              id++;
              hashMap.put((new Integer(id)).toString(), filmHelper);
            }
            constants.hashMapfilmy = hashMap;

          } catch (Exception ex) {
            System.out.println("Exception In Film" + ex.toString());
          }
        }
        status = "success";
      } catch (Exception ex) {
        System.out.println("exception" + ex.toString());
      }
      return status;

    } catch (Exception ex) {

    } finally {
      try {
        is.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return status;
    }
  }