Due: Friday, Feb 28th by 11:59 PM

This is an individual assignment

Getting Started

Download CS496_Assign02.zip and CS496_Assign02_WebService.zip and import them into the Eclipse workspace you use for Android development. (Use the ADT version of Eclipse.) Also download and import CS496_Jetty.zip if it is not already in your workspace.

This assignment consists of creating a mobile client to access the inventory web service created in Assignment 1. Hence the same Item model object will be used in order to maintain JSON compatibility.

Your Tasks

Your tasks involve:

Implementing the Mobile Client

An example mobile client UI might create:

You may choose to enhance the UI if you wish.

image

The requirements for the mobile client are that it should retrieve the information from the EditText boxes (i.e. the item name and quantity) and produce the appropriate request based on the button clicked as follows:

image

image

image

image

image

Since PUT, POST, and DELETE do not inherently generate output, display a Toast message informing the user as to what action has been performed (and if it was successfully completed)

Hints

In order to test your mobile client, you can run the provided web service implementation by running the Main class in the CS496_Assign02_WebService project as a Java application.

For the URI's, you can access the web service running on localhost through the Android emulator via the IP address 10.0.2.2 and port 8081.

Use separate controller objects for each of the REST requests (similar to server side) that are called from the corresponding button click callbacks. In each class, have a method which instantiates an appropriate HttpGet, HttpPut, HttpPost, or HttpDelete object.

Create two methods for setting the layout - one that loads the initial layout from activity_main.xml and the other which creates a dynamic LinearLayout view. Call each of these methods as needed from button click methods. Have the dynamic layout method take an Item[] parameter (allowing it to be reused for displaying either the entire inventory retrieved from the server or a partial inventory consisting of just a single item).

A JSON object can be created to add to the payload of a request as follows:

// Create JSON object from Item
Item newItem = new Item();
newItem.setName(itemName);
newItem.setQuantity(quantity);
StringWriter sw = new StringWriter();
JSON.getObjectMapper().writeValue(sw, newItem);

// Add JSON object to request
StringEntity reqEntity = new StringEntity(sw.toString());
reqEntity.setContentType("application/json");
request.setEntity(reqEntity);

To populate a ListView from an array of strings (named listArray) and add it to a dynamic layout

ListAdapter la = new ArrayAdapter<String>(this, R.layout.list_item, listArray);
ListView lv = new ListView(this);
lv.setAdapter(la);      
layout.addView(lv);

Grading

Your grade will be assigned as follows:

Extra Credit: When the entire inventory is displayed, allow the user to select a row from the list which then returns to the data entry view with the item's name and quantity in the EditText boxes.

Submitting

Select the CS496_Assign02 project, then click the blue up arrow icon, and enter your Marmoset username and password when prompted.

Alternatively, export the CS496_Assign02 project to a zipfile, and upload the zipfile to Marmoset as assign02:

https://cs.ycp.edu/marmoset

Important: please do not submit the CS496_Jetty or CS496_Assign02_WebService projects as part of your submission. Only submit CS496_Assign02.