Thursday, July 22, 2010

Journal entries

Updated Android Keas app to handle journals (a.k.a. Observations of Daily Living, or "ODLs"), Meals, Exercise, Mood.

To do this added machinery to process 2D dataTable data from Keas API, and evolved ExpandableListView to show 2nd row for journal data, sorted chronologically starting with most recent entry.

The displayed columns and 'Name' column are specified in the loadData method, example:
"odl_exercise.*","Exercise", true, "",

Download signed apk here (try test user name:jim pw:jim)
Download Eclipse project here. Enjoy.

Friday, July 9, 2010

Porting Android code to Google App Engine /J

One of the advantages of working in Java on Android is much of the back-end code can be transported to Google App Engine/Java (GAE/J) without much effort. This is quite nice as one can rev/iterate/test backend code quickly on GAE/J and then move it to Android once solid. It's also nice as one can remain in the same frame of mind while coding front and backend.

In the case of Keas API code for Android, the backend is comprised mostly for API calls and XML processing. Most of the code remains consistent between Android and GAE/J, with some subtle differences in 'framing' and underlying class assumptions.

You can see the Keas API application on GAE/J here:
The Elipse project files can be found here.

Here is one example, establishing an http connection, note the differences in http class interfaces and the details of setting header data.

Http connection from within Android:

public void getData(String username, String password, String partnerId,
String namespace) {

try {
HttpGet get = new HttpGet(""+namespace);
get.setHeader(new BasicHeader("username", username));
get.setHeader(new BasicHeader("password", password));
get.setHeader(new BasicHeader("partnerId", partnerId));

HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();

BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"), 1024);

XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
XmlPullParser xpp = xppFact.newPullParser();

Http connection from GAE/J servlet:

private void getData(HttpServletResponse resp, String uid, String pw, String query) {

try {
URL url = new URL(""+query);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("username", uid);
connection.setRequestProperty("password", pw);
connection.setRequestProperty("partnerId", "keas.apitest");

Object content=connection.getContent();

if (content instanceof InputStream || content instanceof Reader) {

XmlPullParserFactory xppFact = XmlPullParserFactory.newInstance();
XmlPullParser xpp = xppFact.newPullParser();