com.googlecode.flickrjandroid.photos.PhotoList Java Examples

The following examples show how to use com.googlecode.flickrjandroid.photos.PhotoList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlickrApi.java    From GestureViews with Apache License 2.0 5 votes vote down vote up
@Background(singleThread = true)
@Subscribe(LOAD_IMAGES_EVENT)
private static synchronized EventResult loadImages(int count) throws Exception {
    SearchParameters params = new SearchParameters();
    params.setText(SEARCH_QUERY);
    params.setSafeSearch(Flickr.SAFETYLEVEL_SAFE);
    params.setSort(SearchParameters.RELEVANCE);
    params.setLicense(LICENCE_ID);
    params.setExtras(photoParams);

    boolean hasNext = hasNext();

    final PhotosInterface flickrPhotos = new Flickr(API_KEY).getPhotosInterface();
    while (photos.size() < count && hasNext) {
        final PhotoList loaded = flickrPhotos.search(params, PER_PAGE, pages.size() + 1);
        pages.add(loaded);
        photos.addAll(loaded);

        hasNext = hasNext();
    }

    int resultSize;
    if (photos.size() >= count) {
        resultSize = count;
    } else {
        resultSize = photos.size();
    }

    List<Photo> result = new ArrayList<>(photos.subList(0, resultSize));
    if (!hasNext) {
        hasNext = photos.size() > count;
    }

    return EventResult.create().result(result, hasNext).build();
}
 
Example #2
Source File: FlickrApi.java    From GestureViews with Apache License 2.0 5 votes vote down vote up
private static boolean hasNext() {
    if (pages.isEmpty()) {
        return true;
    } else if (pages.size() >= MAX_PAGES) {
        return false;
    } else {
        PhotoList page = pages.get(pages.size() - 1);
        return page.getPage() * page.getPerPage() < page.getTotal();
    }
}
 
Example #3
Source File: PhotoFragment.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mTask = new AsyncTask<Void, Void, PhotoList>() {
        protected PhotoList doInBackground(Void... params) {
            Log.d(TAG, "doInBackground");

            final Flickr f = new Flickr(API_KEY, API_SECRET);

            SearchParameters param = new SearchParameters();
            param.setText("coffee");

            try {
                return f.getPhotosInterface().search(param, 20, 1);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        };

        protected void onPostExecute(PhotoList photolist) {
            if (photolist == null) {
                setEmptyText("load failed.");
            } else {
                ImageAdapter adapter = new ImageAdapter(getActivity(), photolist);
                setListAdapter(adapter);
            }
        };
    }.execute();
}
 
Example #4
Source File: PhotoSearchActivity.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
private void showTextView(PhotoList photos) {
    TextView textView = (TextView) findViewById(R.id.text);
    StringBuilder sb = new StringBuilder();
    for (Photo p : photos) {
        Log.d(TAG, "p:" + p.getSmallUrl());
        sb.append(p.getSmallUrl()).append("\n");
    }
    textView.setText(sb.toString());
}
 
Example #5
Source File: FlickrApi.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isStillOnFlickr(Media media) {
	if (isAuthentified()) {
		String md5tag = media.getMd5Tag();
		SearchParameters params = new SearchParameters();
		params.setUserId(Utils.getStringProperty(STR.userId));
		params.setMachineTags(new String[] { md5tag });
		PhotoList photoList = null;
		int retry = 0;
		while (photoList == null && retry < 3) {
			try {
				photoList = FlickrApi.get().getPhotosInterface().search(params, 1, 1);
				if (photoList != null && !photoList.isEmpty()) {
					Photo photo = photoList.get(0);
					LOG.warn(media + " is uploaded : " + photo.getId() + " = " + md5tag);
					return true;
				}
			} catch (Throwable e) {
				LOG.error(ToolString.stack2string(e));
				try {
					Thread.sleep((long) (Math.pow(4, retry) * 1000L));
				} catch (InterruptedException e1) {
				}
			} finally {
				retry++;
			}
		}
	}
	return false;
}
 
Example #6
Source File: PhotosetsInterface.java    From flickr-uploader with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get a collection of Photo objects for the specified Photoset.
 * 
 * This method does not require authentication.
 * 
 * @see com.gmail.yuyang226.flickr.photos.Extras
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_NO_FILTER
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_PUBLIC
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @param photosetId
 *            The photoset ID
 * @param extras
 *            Set of extra-fields
 * @param privacy_filter
 *            filter value for authenticated calls
 * @param perPage
 *            The number of photos per page
 * @param page
 *            The page offset
 * @return PhotoList The Collection of Photo objects
 * @throws IOException
 * @throws FlickrException
 * @throws JSONException
 */
public PhotoList getPhotos(String photosetId, Set<String> extras, int privacy_filter, int perPage, int page) throws IOException, FlickrException, JSONException {
	PhotoList photos = new PhotoList();
	List<Parameter> parameters = new ArrayList<Parameter>();
	parameters.add(new Parameter("method", METHOD_GET_PHOTOS));
	boolean signed = OAuthUtils.hasSigned();
	if (signed) {
		parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey));
	} else {
		parameters.add(new Parameter("api_key", apiKey));
	}

	parameters.add(new Parameter("photoset_id", photosetId));

	if (perPage > 0) {
		parameters.add(new Parameter("per_page", Integer.valueOf(perPage)));
	}

	if (page > 0) {
		parameters.add(new Parameter("page", Integer.valueOf(page)));
	}

	if (privacy_filter > 0) {
		parameters.add(new Parameter("privacy_filter", "" + privacy_filter));
	}

	if (extras != null && !extras.isEmpty()) {
		parameters.add(new Parameter(Extras.KEY_EXTRAS, StringUtilities.join(extras, ",")));
	}
	if (signed) {
		OAuthUtils.addOAuthToken(parameters);
	}

	Response response = signed ? transportAPI.postJSON(sharedSecret, parameters) : transportAPI.get(transportAPI.getPath(), parameters);
	if (response.isError()) {
		throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
	}

	JSONObject photoset = response.getData().getJSONObject("photoset");
	JSONArray photoElements = photoset.optJSONArray("photo");
	photos.setPage(photoset.getString("page"));
	photos.setPages(photoset.getString("pages"));
	photos.setPerPage(photoset.getString("per_page"));
	photos.setTotal(photoset.getString("total"));

	for (int i = 0; photoElements != null && i < photoElements.length(); i++) {
		JSONObject photoElement = photoElements.getJSONObject(i);
		photos.add(PhotoUtils.createPhoto(photoElement));
	}

	return photos;
}
 
Example #7
Source File: PhotosetsInterface.java    From flickr-uploader with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method.
 * 
 * Calls getPhotos() with Extras.MIN_EXTRAS and Flickr.PRIVACY_LEVEL_NO_FILTER.
 * 
 * This method does not require authentication.
 * 
 * @see com.gmail.yuyang226.flickr.photos.Extras
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_NO_FILTER
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_PUBLIC
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @param photosetId
 *            The photoset ID
 * @param perPage
 *            The number of photos per page
 * @param page
 *            The page offset
 * @return PhotoList The Collection of Photo objects
 * @throws IOException
 * @throws FlickrException
 * @throws JSONException
 */
public PhotoList getPhotos(String photosetId, int perPage, int page) throws IOException, FlickrException, JSONException {
	return getPhotos(photosetId, Extras.MIN_EXTRAS, Flickr.PRIVACY_LEVEL_NO_FILTER, perPage, page);
}