Android Open Source - KangarooImageSearch Image Data






From Project

Back to project page KangarooImageSearch.

License

The source code is released under:

MIT License

If you think the Android project KangarooImageSearch listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nickrasband.kangarooimagesearchv2;
// w  w  w . ja v  a  2  s. c  om
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * The ImageData class is the model containing all information relating to images
 * retrieved from the Google Image API. The most important pieces of data are the fullUrl
 * which is used to retrieve the large version of the image, and the thumbnailUrl, which
 * is used to retrieve a small version of the image.
 * @author Nik Rasband
 *
 */
public class ImageData {
  private String fullUrl;
  private String thumbnailUrl;
  
  /**
   * This constructor creates an image data object by attempting to retrieve 
   * the url and tbUrl from the json object passed in as a parameter.
   * @param json
   */
  public ImageData(JSONObject json) {
    try {
      fullUrl = json.getString("url");
      thumbnailUrl = json.getString("tbUrl");
    }
    catch (JSONException e) {
      fullUrl = null;
      thumbnailUrl = null;
      e.printStackTrace();
    }
  }
  
  public String getFullUrl() {
    return fullUrl;
  }
  
  public String getThumbnailUrl() {
    return thumbnailUrl;
  }
  
  /**
   * This is a helper function for swiftly generating an ArrayList full of ImageData
   * objects created from the supplied JSONArray.
   * @param json - A json array containing the image information.
   * @return
   */
  public static ArrayList<ImageData> getImageDataForJsonArray(JSONArray json) {
    ArrayList<ImageData> images = new ArrayList<ImageData>(json.length());
    for (int i = 0; i < json.length(); ++i) {
      JSONObject obj;
      try {
        obj = (JSONObject)json.getJSONObject(i);
        images.add(i, new ImageData(obj));
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
    return images;
  }
}




Java Source Code List

com.nickrasband.kangarooimagesearchv2.EndlessScrollListener.java
com.nickrasband.kangarooimagesearchv2.FullScreenImageActivity.java
com.nickrasband.kangarooimagesearchv2.ImageDataAdapter.java
com.nickrasband.kangarooimagesearchv2.ImageData.java
com.nickrasband.kangarooimagesearchv2.ImageSearchActivity.java
com.nickrasband.kangarooimagesearchv2.SettingsActivity.java
com.nickrasband.kangarooimagesearchv2.SettingsData.java
com.nickrasband.kangarooimagesearchv2.Utils.java