First Impressions of GDK as an Android Developer

funda glass

When one compares Android development paradigms to Glass Development Kit (GDK), the differences seem unnoticeable. Both GDK and Android Development Toolkit (ADT) use activities, views, asynchronous tasks and services.

However the design and development guidelines of Google glass apps are quite different from the Android guidelines. This post will focus on these differences.

Use case and Design challenges

Our use case involved a Google Glass user seeing the nearest house for sale that best matched his search criteria. We wanted the search to trigger upon a custom voice command. The house of interest was required to be shown on a live card with additional actions such as being able to call the realtor, getting the walking route and also seeing additional images of the property.

Due to the abundance of houses for sale in a given neighbourhood, there was a problem implementing the Mirror API since it would lead to an excessive amount of notifications. Hence we chose GDK by allowing houses to be shown only when the users explicitly asked for it.

Services as opposed to activities

Probably one of the biggest differences between Glass and Android development is the use of services. This comes from the inherent necessity of live cards requiring a long running context to own them for the entire time that they are visible. This meant that the service needed to be an intent filter triggered by the voice command.

<meta-data
     android:name="com.google.android.glass.VoiceTrigger"
     android:resource=“@xml/i_wanna_live_here” />

It is important to maintain the life line of live cards within a service. This step ensures that live cards do not stack up in the Glass timeline.

private LiveCard mLiveCard;
private TextToSpeech mSpeech;

public class MainBinder extends Binder {

    public void sayWhateverYouFeelLike() {

        mSpeech.speak(getString(R.string.show_me_the_moneyyy),                      TextToSpeech.QUEUE_FLUSH, null);
    }
}

@Override
public void onCreate() {
    super.onCreate();

    mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener()      {
        @Override
        public void onInit(int status) {
            // do the magic
        }
    });
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    return START_STICKY;
}

@Override
public void onDestroy() {

    //  called when the card is explicitly removed by the user 
        OR once the background service is completed

    if (mLiveCard != null && mLiveCard.isPublished()) {
        mLiveCard.unpublish();
        mLiveCard = null;
    }
    mSpeech.shutdown();

    mSpeech = null;
    super.onDestroy();
}

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

Live cards

Live cards appear in the present section of the timeline and display information that is relevant at the current time. In our case the live card consists of the image of the house, the price, the address and the distance from the user. Since API 19 the creation of the TimelineManager is not necessary for creating live cards.

mLiveCard = new LiveCard(this, LIVE_CARD_TAG);

aRV = new RemoteViews(this.getPackageName(), R.layout.house_details_layout);

aRV.setImageViewBitmap(R.id.house_image, curHouse.getBitmap());
aRV.setTextViewText(R.id.address, curHouse.getAddress());
aRV.setTextViewText(R.id.price, curHouse.getPrice());

mLiveCard.setViews(aRV);

Intent mIntent = new Intent(this, HouseDetailsActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

mLiveCard.setAction(PendingIntent.getActivity(this, 0, mIntent, 0));
mLiveCard.publish(LiveCard.PublishMode.REVEAL)

In conclusion, while the paradigms differ, as an Android developer I found Glass development to be easy and fluid. GDK is quite well documented with a strong user community.

The key takeaways during the development of the funda app for google glass were:

  • The project structure of GDK is identical to a conventional android project
  • It is important to manage live cards in services to avoid cluttering on the timeline. Having access to low-level sensor data like the accelerometer and GPS gives live cards an edge over static cards.

written by Rajat Anantharam, Android Developer at funda.