Homework 5

Due: Tuesday May 29

In this homework, you have to create an app that keeps a local to-do list in synch with a remote server. 
We have implemented the server, and provide you with the code to run it locally, and with a running instance. 
The homework consists in writing the Android app that connects to the server. 

The Server


The server is implemented as a web2py app.  To get it to work, install web2py, and then upload and install the ToDoListServer packed application.  It is really a one-click process.  This gives you a local version of the server running on your laptop/PC, which is very useful for development. 
We have also set up an online server: you can access it here (you can also use HTTP).  Note that it has URLs of the following form:
In addition to the above URL, the server has also Json-serving URLs that are used to communicate with Android.  These URLs are to be used with POST methods with some variables set; the list of the URLs, the variables that must be set, and the values returned (all returned values are Json-encoded) are described below:
  • https://crowdlab.soe.ucsc.edu/ToDoListServer/default/android_get_items.json
    • Input variables:
      • username
      • password
    • Return result:  The Json list of items added by the user. 
  • https://crowdlab.soe.ucsc.edu/ToDoListServer/default/android_add_item.json
    • Input variables:
      • username
      • password
      • title (the item title)
      • content (the item content)
    • Return result: None, or the id of the item that has just been added.
  • https://crowdlab.soe.ucsc.edu/ToDoListServer/default/android_del_item.json
    • Input variables:
      • username
      • password
      • id (id of the item to be deleted)
    • Return result: {result: 'Success'} or {'result': 'Fail'}
An example of how to use these calls from Python is provided in two scripts to get the list of all items, and add items, attached.
Note that you have to edit these scripts, filling in the correct URLs, usernames, and passwords as appropriate. 
You are strongly encouraged to study the server code (the main file is .../ToDoListServer/controllers/default.py).

Should the server go down for any reason, or become unresponsive, please write a message on the class discussion group, and we will take care of it.  In any case, for development, you should be able to run a local version of it.

The Android App


This is what you have to write.  When your app is started, it should check that it has, among the shared preferences, your username and password.  If not, the app must start a new activity that: 
  • Prompts the user for username and password. 
  • Stores them in the shared preferences.
Once this is taken care of, your app should ask the server for the list of todo items, and display them. 
At the top or bottom of the list of todo items, there should be a button that lets you add a new item (you don't need to switch activity, you can do as in the ToDo List apps in the book).   
If you long-press on an item, it should be possible to delete that item (via a context menu). 

Thus, you need a minimum of two activities. 

You don't need to define a local database to store the items, since they are stored on the server.  You need to communicate to the server item additions and deletions, so that the local and remote lists stay in synch. 

If you like to provide additional functionality for the server, contact me with a proposed implementation (of a method in default/android... . json), and I can add it to the server for all of us to use. 

Some resources you might find useful:
Please, do use the class discussion group for asking for help and clarifications.

Homework Submission

  • Please submit the .apk and the .zip files, as usual.  Please name these files lastname_firstname.X where X is the appropriate extension (where lastname and firstname are your last and first names, obviously). 
  • Please change the app_name in your Android app to be lastname_firstname_hw5.  This is very important to allow for easy grading; we will take points off for students who fail to do this.
  • Please target Android API level 7 or 8.

Č
ċ
ď
add_item.py
(0k)
Luca de Alfaro,
May 16, 2012, 1:39 PM
ċ
ď
get_items.py
(0k)
Luca de Alfaro,
May 16, 2012, 1:39 PM
ċ
ď
web2py.app.ToDoListServer.w2p
(143k)
Luca de Alfaro,
May 22, 2012, 2:14 PM
Comments