Exemplo n.º 1
0
  class YelpGetCategoriesFromUrl extends AsyncTask<String, Void, Void> {
    final BhLogger bhrel = BhLogger.bhrel();

    protected Void doInBackground(String... stringArray) {
      try {
        URL url;
        InputStream in;
        url = new URL(CATEGORIES_URL);
        URLConnection urlConnection = url.openConnection();
        in = new BufferedInputStream(urlConnection.getInputStream());
        List<Category> urlCategories = JsonParserSystem.getCategories(in);
        if (urlCategories == null) {
          bhrel.log("*** Failed to get Yelp Categories from url!");
          in.close();
          return null;
        }
        categories = urlCategories;
        categorySource = CategorySource.WEB;
        in.close();
      } catch (IOException e) {
        String msg = String.format("Yelp Categories Request Failed: %s", e.getMessage());
        Toaster.toastLong(msg);
        bhrel.log(msg);
      }
      return null;
    }
  }
Exemplo n.º 2
0
  // </editor-fold>
  // <editor-fold desc="DOWNLOAD CATEGORIES">
  class YelpGetCategoriesFromFile {
    final BhLogger bhrel = BhLogger.bhrel();

    YelpGetCategoriesFromFile() {
      try {
        InputStream in =
            ActivityMain.getActivity().getResources().openRawResource(R.raw.yelp_categories);
        List<Category> fileCategories = JsonParserSystem.getCategories(in);
        if (fileCategories == null) {
          bhrel.log("*** Failed to get Yelp Categories from local file!");
          in.close();
          return;
        }
        categories = fileCategories;
        categorySource = CategorySource.FILE;
        in.close();
      } catch (IOException e) {
        bhrel.log("getCategoriesStreamFromFile(): IO Exception");
      }
      // Hack to shut up Lint. Lint complains about this being unused, but when I try
      // to fix it with the link provided in the Inspector, Android Studio throws an
      // "Assertion failed" exception.
      @SuppressWarnings("UnusedAssignment")
      int hack = R.raw.yelp_categories_test;
    }
  }