Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 27  Search


Now add methods to kick off the download by building a URL and calling
downloadGalleryItems(String).


Listing 27.4  Adding methods to get recents and search (FlickrFetchr.java)


public class FlickrFetchr {
...
public String getUrlString(String urlSpec) throws IOException {
return new String(getUrlBytes(urlSpec));
}


public List fetchRecentPhotos() {
String url = buildUrl(FETCH_RECENTS_METHOD, null);
return downloadGalleryItems(url);
}


public List searchPhotos(String query) {
String url = buildUrl(SEARCH_METHOD, query);
return downloadGalleryItems(url);
}


private List downloadGalleryItems(String url) {
List items = new ArrayList<>();
...
return items;
}
...
}


FlickrFetchr is now equipped to handle both searching and getting recent photos. The
fetchRecentPhotos() and searchPhotos(String) methods serve as the public interface for getting a
list of GalleryItems from the Flickr web service.

Free download pdf