###########CS176B-hw3-Useful-Emails ##############

----------------------
Project Due

due date is in fact Sunday, March 13th.

----------------------
Android Phone

4-5 android phone will be available on Monday, and other 5-6 phones will be ready after Wednesday. So if you have your android phone for hw3, it is fine to use it. Else, you can get reply this email quickly to get the first batch of android phones.

---------------------
Android Version 

Make sure android verion 2.2 or higher so that you can use Google push (C2DM)

---------------------
C2DM example:

http://code.google.com/p/chrometophone/source/browse/#svn%2Ftrunk%2Fandroid%2Fc2dm%2Fcom%2Fgoogle%2Fandroid%2Fc2dm

you can use the open source package "com.google.android.c2dm", if you don't want bother to write a new one. Just keep all the copyright
statement in the source code, we will be fine.

---------------------
C2DM account

I create the account for the whole Android teams and the server teams to use google C2DM: this is the attached message

package name: edu.ucsb.cs.hw3
account name: ucsb.cs.176b@gmail.com
password: ucsbucsbucsb

PLS read the documents of C2DM and implement 

A new interface for debuging: 
function call: push  parameter: [token] 
When you call push with your token, the server will initial a message and push it back to your phone. This interface is used for testing your C2DM receiver on your phone.

--------------------

Using Emulator to test C2DM:

Note: you must have a newer version of the emulator and sdk, plus register a google account on the emulator. That's done through the accounts page under settings.

---------------------
Android tutorial

There is now an file: AndroidDemo.zip in the lecture directory:
http://www.cs.ucsb.edu/~ravenben/classes/176b/lectures/

---------------------
TJ's Server

TJ: I've put up a super bad early version of my web app at 
http://cs176b.heroku.com/. Please break it (and let me know how you did it).

---------------------
Registration_id and Name

First, the registration_id is used for pushing notification. In fact, registration_id is generated by Google's C2DM service, not the phone itself. After the phone pass this registration_id to our game server
during registration process, the server would be able to push message back to the phone later during the game. Please read through the C2DM
of Google for more detail.

Second, the account is specified for one user on one phone. You can and should use phone's local storage.

---------------------

Checkin Point id:

When the game starts, you will know how many checkin points to find, say N.
Then checkin point ID would be 1, 2, 3, 4 ... N

The previous Doc is not accurate, it is not 0,1,2..N-1.

---------------------
Distance and Angle:

if you get the distance and angle from server: D and G
then the coordinate of checkin point can be calculated: (Latitude, Longitude)

Latitude  = current_latitude + D * cos( G )
Longitude = current_longitude + D * sin( G )

---------------------

Test Server

I wrapped up a test server for hw3, so that the phone teams would have something to test and debug with, before server team works out the feasible game server. The test server uses port 3000 instead 80 for http call. The response of Http call will be in json format. 

http://marrow.cs.ucsb.edu:3000/

basic functions are implemented. I only setup one checkin point in the data base for test purpose. (cid=1)

Examples:
register:

http://marrow.cs.ucsb.edu:3000/register?name=ndddddddddgw&&registration_id=djgfkl&&phonetype=windows

query:
http://marrow.cs.ucsb.edu:3000/query?token=3fcdcf00836d82e87c0b27a0555ca6bb78b6cc28&&longitude=-30.45&&latitude=23.4&&cid=1

checkin:

http://marrow.cs.ucsb.edu:3000/checkin?token=3fcdcf00836d82e87c0b27a0555ca6bb78b6cc28&&longitude=-33&&latitude=123.4&&cid=1

cancel_checkin:

http://marrow.cs.ucsb.edu:3000/cancel_checkin?token=3fcdcf00836d82e87c0b27a0555ca6bb78b6cc28&&cid=1

upload
example code to upload photo. Besides this, there are many different ways.

[image_data] is a Byte Array containing image data.

URI host = new URI("http://marrow.cs.ucsb.edu:3000/upload");
HttpClient client = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost(host);
MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("image", new ByteArrayBody(image_data,"image/jpeg", “name.jpeg"));
entity.addPart("token", new StringBody("your_token"));
entity.addPart("cid", new StringBody("your_checkin_point_id"));
httppost.setEntity(entity);
HttpResponse response = client.execute(httppost);

The [response] will contain the URL to check out your photo.
Attached is the hw3 API specification (draft version). Some of the work could be challenging and please start as soon as possible. 

If you have any questions,  please feel free to email me. Thanks.
---------------------

-