Monday, June 21, 2010

Keas Droid v0.9

v0.9 KeasDroid project, an Android app using the Keas API to show Health Profile data and color indicators.

Features:


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

Saturday, June 19, 2010

Toast

Toast is quite a useful and compact widget class to provide a temporal notification for the user.

Toast.makeText(KeasDroid.this,
"Here you can maintain your user credentials.",
Toast.LENGTH_LONG).show();



This is the equivalent of a modal dialog box, a timer and a dismiss of the dialog. There doesn't appear to be a reasonable way of prolonging the length of display beyond a few secs.

To notify on the status bar requires more work, here's a simple example:

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);


int icon = R.drawable.icon;
CharSequence tickerText = "Click Menu to set username";
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Keas notification";
CharSequence contentText = "Please click Menu to set username";
Intent notificationIntent = new Intent(this, KeasDroid.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);


notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);

final int HELLO_ID = 1;

mNotificationManager.notify(HELLO_ID, notification);

Wednesday, June 16, 2010

ExpandableListView with dynamic images

ExpandableListViews are great, but less great without images within them, particularly dynamic images (set at the time of creation for the list). The examples (here's one that was a reasonable starting point) and snippets on the Web left a lot to be desired, but what I was aiming for was this:


Note the color 'indicator' (in this case) changes based on variables for the child row. Very useful. This is a key feature of a health attribute (eg. weight) and a color indicator (eg. red for overweight).

To accomplish such a thing one needs to do a number of things in concert within the project, the instantiation of the ExpandableListView and the project's resources, hence the difficulties of trying to grok this solely from one code snippet or another. As an added bonus my example includes a ClickListener to detect clicks within the list.

The sample Eclipse project can be downloaded here. Enjoy.

Thursday, June 10, 2010

Rendering an ExpandableListActivity

Most Android code snippets are about one Activity class or other derivative, like ExpandableListActivity. But what if you have multiple classes that you want to render in some orchestrated fashion?

If you have an ExpandableListActivity called healthProfile, and you need to render it from a main class called KeasDroid, this will get it done:

Intent myIntent = new Intent(KeasDroid.this, healthProfile.class); KeasDroid.this.startActivity(myIntent);

But remember you have to add the activity in the manifest file, as shown below:

Wednesday, June 9, 2010

Keas API documentation

Reference materials can be found here...

Android threads - the basics

Often you have a need to spawn a thread in which to do something useful, like load data from an external API.

You can handle events from the spawned thread and alert the user. In this case we'll use a ProgressDialog while at work...

Here are the basics. First your class must implement Runnable:
public class FooClass extends Activity implements Runnable {

When you are ready to create the thread:

public void loadData() {
pd = ProgressDialog.show(this, "Working..", "Accessing data...", true,
false);
Thread thread = new Thread(this);
thread.start();
}

Then your code is in the run() method:

public void run() {
// do something time intensive or asynchronous
handler.sendEmptyMessage(0);
}

private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
pd.dismiss(); // dismiss the progress dialog
}
};

The Handler override method handles the end of the thread.
That's it.

Accessing Keas API and data from Android


An Eclipse project "KeasAPI" that accesses data from Keas' API for a given test user and specified namespace. Download the project here.


NOTE: the API works with a "test" partner ID against test data. Real patient data is not accessible without consent from user and a legitimate Keas approved partner ID.

Using the "labs.*" namespace (all lab data), reply from API appears as follows within Eclipse's LogCat window:

Icons on Android

Using an icon with your Android app isn't intuitive within the current eclipse environment, there are a few steps to follow and here they are:

- make sure your icon is in .png image format
- copy (drag & drop) your icon(s) to each of the /res/drawable folders (hdpi, ldpi, mdpi) in eclipse
- make sure its name is in lower case (there's no rename, need to copy then rename w/paste)
- refer to an icon ("icon") in the project manifest as: android:src="@drawable/icon"

The icon will be available for ImageView UI components and will be the iconic representation for the application within the Android application picker.

Using LogCat with filters

You can manage your application output logs nicely within Eclipse and the Android extensions.

Open the "LogCat" view alongside Properties, Console, etc. as shown below. Set filters to capture Log.i() calls. Now your runtime logging is organized and not crowded within the usual SysOut stream...

Triggering events after Menu closes

Often you need to check something and/or take action once a menu closes. The examples on this topic seem sparse.

One way to achieve this is to use methods of the Activity class:
startActivityForResult(Intent, int)
and a corresponding:
onActivityResult(int requestCode, int resultCode, Intent data)

The requestCode is an int you define to correlate between activities...

Here's an example:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.preferences:
// Launch Preference activity
Intent i = new Intent(HelloPreferences.this, Preferences.class);
startActivityForResult(i,REQUEST_CODE_PREFERENCE);
break;
}
return true;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// do something here when menu closes
}

Setting up Eclipse and Android SDK


Thank you Lars Vogel for a step-by-step guide to getting set up with Eclipse and the Android SDK and its emulator...

Signing your apps

There are several useful sites on signing your apk for release to the public. Here's one.

With Eclipse there's an export function which one might assume is for "exporting" a project, and it is, but when the context is an Android Project this is setup for exporting a signed .apk

-> File, Export, Android/Export Android Application ... follow the wizard

It will even create a keystore for you :-)

Monday, June 7, 2010

Android on Keas

Adventures developing health care applications for Android with the Keas platform.

Keas is a platform (PaaS) for patient-facing health care applications. Developers are encouraged to look at author.keas.com for Keas' authoring environment.

Why develop healthcare apps on mobile? Because this is the ideal medium for journaling, for social networking, for inquiries about diet and exercise, for reminders about medications and health regiments. Mobile devices increasingly have accelerometers on board, making them capable of pedometer readings.

Why Droid? My hope is for these source code projects to act as samples and as a starting point for others that wish to enable healthcare mobile applications. The Android framework and tools are at a maturity level where this is now productive and where reasonably ambitious applications can be achieved.

One must start somewhere...