예제 #1
0
 @Override
 protected String doInBackground(String... params) {
   try {
     HashMap<String, String> headers = new HashMap<>();
     if (BuildConfig.MASHAPE_KEY.length() > 0)
       headers.put("X-Mashape-Authorization", BuildConfig.MASHAPE_KEY);
     headers.put("Authorization", "Client-ID " + BuildConfig.IMGUR_KEY);
     JSONObject o = NetworkConnection.getInstance().fetchJSON(IMAGE_URL + params[0], headers);
     if (o.getBoolean("success")) {
       JSONObject data = o.getJSONObject("data");
       if (data.getString("type").startsWith("image/") && !data.getBoolean("animated"))
         return data.getString("link");
       else if (data.getBoolean("animated")) return data.getString("mp4");
     }
   } catch (Exception e) {
   }
   return null;
 }
예제 #2
0
  public class ImgurGalleryTask extends AsyncTaskEx<String, Void, String> {
    private final String GALLERY_URL =
        (BuildConfig.MASHAPE_KEY.length() > 0)
            ? "https://imgur-apiv3.p.mashape.com/3/gallery/"
            : "https://api.imgur.com/3/gallery/";

    @Override
    protected String doInBackground(String... params) {
      try {
        HashMap<String, String> headers = new HashMap<>();
        if (BuildConfig.MASHAPE_KEY.length() > 0)
          headers.put("X-Mashape-Authorization", BuildConfig.MASHAPE_KEY);
        headers.put("Authorization", "Client-ID " + BuildConfig.IMGUR_KEY);
        JSONObject o = NetworkConnection.getInstance().fetchJSON(GALLERY_URL + params[0], headers);
        if (o.getBoolean("success")) {
          JSONObject data = o.getJSONObject("data");
          android.util.Log.e("IRCCloud", "D: " + data.toString());
          if (data.getString("type").startsWith("image/") && !data.getBoolean("animated"))
            return data.getString("link");
          else if (data.getBoolean("animated")) return data.getString("mp4");
        }
      } catch (Exception e) {
      }
      return null;
    }

    @Override
    protected void onPostExecute(String url) {
      if (url != null) {
        if (url.endsWith(".mp4")) {
          loadVideo(url);
          player.setLooping(true);
          player.setVolume(0, 0);
        } else {
          loadImage(url);
        }
      } else {
        fail();
      }
    }
  }