5COSC005W - Tutorial 7 Exercises
As part of this tutorial for this week, you should complete ALL the tasks described below: (make sure that you ask questions to your tutor for anything that you do not understand or if you are stuck at any point):
In this example you will be implementing an Android application which the user utilises to find and prepare coctails. The application will be using the https://www.thecocktaildb.com/api.php Web service.
For all the tasks in this tutorial you should be creating threads for connecting to the internet using the following code (and not using the
AsyncTaskorAsyncTaskLoaderclasses):Thread t1 = new Thread(new Runnable() { @Override public void run() { // ... statements updating the UI thread.. } }); t1.start();The update of the UI should be done by executing the following statement within a thread, sending effectively the execution of the block of code in the UI thread:
runOnUiThread(new Runnable() { @Override public void run() { // ... statements updating the UI thread.. } });Implement an application so that the user can search for the names of all coctails containing an ingredient, e.g. Vodka, by using the following url: https://www.thecocktaildb.com/api/json/v1/1/filter.php?i=Vodka
The user should be see all the names of the coctails containg vodka.
- Extend the application so that the user can enter the name of a
coctail and receive the instructions for the preparation of the
coctail. This should be done by displaying the content of the field
strInstructionsafter a request to the https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita url. - Extend the application so that the it displays a picture for the
coctail (hint: this is the url corresponding to the
strDrinkThumborstrImageSourcekeys of the JSON response in the last subquestion). - Extend your application so that the application allows the user to click on one of the names of the coctails in Question 1 (by using a Spinner widget) and then all of the relevant information for how to prepare it and the picture of the coctail appears.
- Extend your application so that user presses a button and he/she is presented with the full details of a random coctail (including the name, the recipe and its picture). Hint: you need to study the API of the website to make the relevant requests.