コード例 #1
0
 @Override
 public void onTrailersReceived(PojoTrailers trailers) {
   if (trailers.getResults() != null && trailers.getResults().size() > 0) {
     Log.d("FragmentDetail", "trailers:" + trailers.getResults().size());
     // Update share
     mFirstTrailer = trailers.getResults().get(0).getKey();
     if (mShareActionProvider != null) {
       mShareActionProvider.setShareIntent(getShareTrailerIntent());
     }
     // Set trailers
     mTrailers = trailers.getResults();
   }
   onReceiveAsyncResults();
 }
コード例 #2
0
  @Override
  protected PojoTrailers doInBackground(ArgsAsyncTrailers... params) {
    InputStream is = null;
    Context context = params[0].getContext();
    int movieId = params[0].getMovieId();

    MovieApi api = new MovieApi(context);

    try {
      URL url = api.getTrailersUrl(movieId);
      Log.d(CLASS_TAG, "myUrl:" + url.toString());

      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setReadTimeout(mTimeout);
      conn.setConnectTimeout(mTimeout);
      conn.setRequestMethod("GET");
      conn.setDoInput(true);
      conn.connect();
      int response = conn.getResponseCode();
      Log.d(CLASS_TAG, "The response is: " + response);
      is = conn.getInputStream();

      // Convert the InputStream into a string
      String contentAsString = readIt(is);

      Gson gson = new Gson();
      PojoTrailers trailers = gson.fromJson(contentAsString, PojoTrailers.class);

      Log.d(CLASS_TAG, "Trailer: " + trailers.getResults().size());

      return trailers;

      // Makes sure that the InputStream is closed after the app is
      // finished using it.
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    return null;
  }