Skip to content

Instantly share code, notes, and snippets.

@nesquena
Last active December 25, 2015 11:48
Show Gist options
  • Save nesquena/07f36d72048725782e57 to your computer and use it in GitHub Desktop.
Save nesquena/07f36d72048725782e57 to your computer and use it in GitHub Desktop.
Project 2: Helpful Hints

Project 2 (Image Search) Helpful Hints

Here's a list of useful notes you may find helps save you time while developing the Image Search or running into problems:

  • Tip #1: This entire app revolves around the Google Image Search API. Make sure to review the API, and what parameters it takes. Also, what the response looks like. Keep in mind there are parameters for each search filter (i.e imgsz), result size (rsz, max 8) and result offset (start) which will all be used.

  • Tip #2: Scrolling vertically on Android emulator is done via pushing down on the left mouse and dragging up as you would do to scroll with your finger on the device.

  • Tip #3: Google Image Search maxes out at about 9 pages of results for a search, that is to be expected. If you try to go more than 9 pages, expect the additional requests for image results to fail. Also, please don't use smoothie for pagination, instead check out the endless pagination cliffnotes (see last bullet point for more information).

  • Problem #1: Can't get back the JSON Response! A number of people always run into issues with their emulator and not being able to access the google image search API. If you are pretty sure you have the code right and you can't seem to get any response back from the API, try these steps:

    • Check the URL to ensure that you have properly formed the query string (i.e rsz should be set to 8)
    • Make sure you have added the internet permission <uses-permission android:name="android.permission.INTERNET" /> to your manifest.
    • If you are getting "Unable to resolve host", Check your WiFi connection and then go to the browser on the phone and verify you can access google. If you cannot, try checking the wifi setting and turning it off and on until the internet works (you may need to restart the emulator)
    • Obtain the exact url (by breakpointing or logging) that you are going to send a request to and paste the url into your browser to verify the API response is coming back correctly.
    • Make sure you are using the new JsonHttpResponseHandler() (docs) in your AsyncHttpClient network call and make sure you are sending client.get(url, new JsonHttpResponseHandler() { ... })
    • Verify that the onSuccess signature is correct. The Image search API returns a JSON dictionary so make sure the onSuccess is using JSONObject and not JSONArray in this case. This is entirely dependent on whether a dictionary or array is the root object i.e public void onSuccess(JSONObject response)
    • Add an onFailure to the JsonHttpResponseHandler callbacks and log there to ensure that its not being hit
    • Check your LogCat to make sure there are no specific error messages (and watch this debugging video for more tips), use filters to more easily read the log.
    • Uninstall the app from the emulator and allow it to be fully re-installed by relaunching it from within eclipse.
    • Restart the Emulator (close and relaunch)
    • Restart Eclipse (completely close and relaunch)
  • Problem #2: Can't get infinite scroll working! This assignment wants us to create an "infinite scroll" feature for our Grid of images so users can scroll through pages of images edasily. Check out the endless pagination cliffnotes for more information on how to get this working.

    • Make sure that as you load more items that you are appending new results to the adapter and not clearing the results every time you paginate. Only clear the results in the adapter when a fresh search is initiated.
    • Keep in mind that the onLoadMore method for the endless pagination doesn't fire very often since it's "smart" and doesn't get called just when you scroll. It tries to be conservative and only calls onLoadMore when new items actually need to be loaded from the server (which means that you have scrolled far enough down and new items have been added already since the last call and now we need to load even more items. So until you start appending items into the gridview, you aren't expected to see multiple calls to scroll.
    • Paginating for infinite scroll requires us to look at the API docs for the parameter start that allows us to pass an "offset" for the results which is what lets us paginate. Make sure your call to load more results properly includes the offset in the url request.
    • If you are having trouble with having more than 8 items loading at a time, ensure that you are not incorrectly clearing the array during pagination. When a new search is initiated (with new search term), we should clear the array of results but on subsequent requests for more results do not clear the array of results, instead you should append to it.
  • Tip #4: This assignment has an optional user story which involves being able to share an image out to other services. Sharing is done through the use of intents as explained in the cliffnotes.

  • Note #1: This assignment requires us to add an clickable icon to the ActionBar, see ActionBar Cliffnotes for more details on this.

    • To create icons that work for your ActionBar, you can use the File => New => Other => Android => Android Icon Set. Check out the step-by-step guide.
  • Note #2: This assignment requires us to launch a new activity using an intent and then somehow communicate the filters to apply back to the search activity. See the intents cliffnotes for a review of that and passing data to and from activities.

  • Note #3: This assignment suggests for us to use dropdown spinners to display options to the user. Check out the input views cliffnotes for more about how to use spinner.

    • Customizing the look of spinner items requires you creating a spinner adapter and supplying your own custom spinner item XML file similar to a custom list adapter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment