“The API surface of GDK Glassware is not limited to the classes contained in the GDK Add-on. The GDK Add-on merely closes the gaps between the Android SDK and features that are unique to Glass. This means, in general, given a problem that isn't covered by the GDK library directly, just attempt the Android solution.”
Live cards appear in the present and future section of the timeline and display information that is relevant at the current time.
onStartCommand() { if (liveCard == null) { liveCard = new LiveCard(context, LIVE_CARD_TAG);
liveCard.setAction(menuActivityPendingIntent);
// set up UI for LiveCard and then... liveCard.publish(SILENT or REVEAL);
} else { // See LIVE CARD LIFECYCLE - NAVIGATE slide }
return START_STICKY;}
liveCard.navigate();
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
case R.id.action_stop:
// Stop the Service which will also unpublish the LiveCard
stopService(new Intent(this, LiveCardService.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
onDestroy() {
if (liveCard.isPublished()) { liveCard.unpublish(); }
}
Live cards can update frequently with custom graphics to show users real-time information. This functionality is great for UIs that need to constantly update based on some user data.
surfaceCreated(SurfaceHolder holder)
surfaceChanged(SurfaceHolder holder)
surfaceDestroyed(SurfaceHolder holder)
public class MenuActivity extends Activity {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
openOptionsMenu();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.stopwatch, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.stop:
stopService(new Intent(this, StopwatchService.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onOptionsMenuClosed(Menu menu) {
// Nothing else to do, closing the activity.
finish();
}
}
liveCard.setVoiceActionEnabled(true);
boolean fromLiveCardVoice = getIntent().getBooleanExtra(LiveCard.EXTRA_FROM_LIVECARD_VOICE, false);
if (fromLiveCardVoice) {
// When activated by voice from a live card, enable voice commands. The menu
// will automatically "jump" ahead to the items (skipping the guard phrase
// that was already said at the live card).
getWindow().requestFeature(WindowUtils.FEATURE_VOICE_COMMANDS);
}
luisdelarosa.com/glass