Android Open Source - MyFlickrSearch Search Flickr Task






From Project

Back to project page MyFlickrSearch.

License

The source code is released under:

MIT License

If you think the Android project MyFlickrSearch 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.devng.flickrsearch.task;
/*  www.j  a v a2 s.c  o  m*/
import android.os.AsyncTask;
import android.util.Log;

import com.devng.flickrsearch.common.Config;
import com.devng.flickrsearch.common.Enums;
import com.devng.flickrsearch.common.Helpers;
import com.devng.flickrsearch.model.FlickrImgRef;
import com.devng.flickrsearch.model.FlickrImgRoot;

import java.util.Collections;
import java.util.List;

public class SearchFlickrTask extends AsyncTask<String, Void, List<FlickrImgRef>> {

  private static final String LOG_TAG = SearchFlickrTask.class.getSimpleName();

  private final SearchFlickrResultHadler handler;

  private final Enums.SortOrder sortOrder;

  public SearchFlickrTask(SearchFlickrResultHadler handler, Enums.SortOrder sortOrder) {
    this.handler = handler;
    this.sortOrder = sortOrder;
  }

  @Override
  protected List<FlickrImgRef> doInBackground(String... words) {
    Log.d(LOG_TAG, "Do a search for " + words[0]);

    String encodedSearch = Helpers.encodeUrlString(words[0]);
    String searchURL = String.format(Config.API_URL, sortOrder, encodedSearch);
    byte[] response = Helpers.doGet(searchURL);
    if (response == null || response.length == 0) {
      return Collections.emptyList();
    }

    String jsonString = new String(response);
    Log.d(LOG_TAG, "Response: " + jsonString);

    FlickrImgRoot imgRoot = Helpers.fromJson(jsonString, FlickrImgRoot.class);
    Log.d(LOG_TAG, "Object Response: " + imgRoot);
    if (imgRoot != null && imgRoot.getPhotos() != null && imgRoot.getPhotos().getPhoto() != null) {
      return imgRoot.getPhotos().getPhoto();
    }

    return Collections.emptyList();
  }


  @Override
  protected void onPostExecute(List<FlickrImgRef> result) {
    super.onPostExecute(result);
    handler.onSearchFlickrResult(result);

  }

}




Java Source Code List

com.devng.flickrsearch.AbstractBackButtonActivity.java
com.devng.flickrsearch.ImageViewerActivity.java
com.devng.flickrsearch.MainActivity.java
com.devng.flickrsearch.MainModule.java
com.devng.flickrsearch.SearchResultsActivity.java
com.devng.flickrsearch.SearchResultsListAdapter.java
com.devng.flickrsearch.common.Config.java
com.devng.flickrsearch.common.Enums.java
com.devng.flickrsearch.common.Helpers.java
com.devng.flickrsearch.model.FlickrImgContainer.java
com.devng.flickrsearch.model.FlickrImgRef.java
com.devng.flickrsearch.model.FlickrImgRoot.java
com.devng.flickrsearch.task.DownloadFlickrImagesHandler.java
com.devng.flickrsearch.task.DownloadFlickrImagesTask.java
com.devng.flickrsearch.task.SearchFlickrResultHadler.java
com.devng.flickrsearch.task.SearchFlickrTask.java