Back to project page KangarooImageSearch.
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.
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; } }