deep dive into google glass live cards


Luis de la Rosa

Lead Application Developer

   please ask questions   

glanceable ui


Fundamentally different from phone and tablet UI

Less content

Quicker

Bigger

Now

GDK vs ANDROID SDK


6 new packages

19 new classes

No emulator

Activities + Services play special roles

synergy

“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.”
- Jenny Murphy
Staff Developer Programs Engineer on Google Glass

what is a live card?


Live cards appear in the present and future section of the timeline and display information that is relevant at the current time.


Access to GDK API (vs static cards)

Exist in Timeline (vs Immersions)

Continue to run in background

low vs high frequency


Two types of live cards:

Low frequency (every few seconds)

High frequency (real-time)

Refers to rendering speed

services + live cards


Integral

Handles lifecycle

Key to background

live card lifecycle - start

Voice Trigger

Service starts
onStartCommand() {    liveCardInstance = Timeline.createLiveCard(LIVE_CARD_TAG);    liveCardInstance.setAction(menuActivityPendingIntent);    // set up UI for LiveCard and then...
    liveCardInstance.publish(SILENT or REVEAL);    return START_STICKY;}

live card lifecycle - stopping

Menu Activity
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);    }} 
Service stops
onDestroy() {    liveCardInstance.unpublish(); }

low frequency live card


Likely to be most common

Restricted to RemoteViews

Must call setViews to update

Cousin to App Widget

remoteviews


Subset of all Views

4 Layouts

7 Views

5 ViewGroups

Update only occurs when setViews is called

layouts


FrameLayout

LinearLayout

GridLayout

RelativeLayout

views


AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView

viewgroups


GridView
ListView
StackView

AdapterViewFlipper
ViewFlipper

working around lack of remote views


Example: RatingBar

Option 1: use ImageView

Option 2: switch to High-Frequency and
render onto Surface

example: stack overflow profile


Useful to see inbox and also track score

Stack Overflow rep changes relatively infrequently

Lots of data -> Glanceable

Low frequency Live Card

Menu for actions

   any questions so far?  

high-frequency live card


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.

Uses a Surface

surface


Callbacks

surfaceCreated(SurfaceHolder holder)surfaceChanged(SurfaceHolder holder)surfaceDestroyed(SurfaceHolder holder) 

Use background Thread

Custom drawing

Rendering of common Views

example: audio visualizer


Uses microphone

Samples audio

FFT

Draws waveform on Surface

dissecting the gdk samples


Compass

Stopwatch

Timer

gdk samples


High-Frequency Live Cards

Use the layout rendered to Surface trick

Sensors

Service - Drawer/Renderer - View pattern

menu


PendingIntent as Action

Activity hosts menu items

Register the Activity

onAttachedToWindow

Transparency via style

Must have at least Stop menu item

menu activity

    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();
        }
    } 

timeline


Publishing: Silent or Reveal

Pair Silent with boot up Services

Overrides some gestures

vs immersions


Can't control dimming

Can't have a bundle of cards

Starts back up after wake

Not as much control over touch / gestures

gotchas


Menu Activity required to publish
- not declaring in AndroidManifest.xml
- transparent theme
- onAttachedToWindow

setViews to refresh

setString vs setCharSequence

No callback when low frequency Live Card viewed

Tips


Auto-start after reboot

Jump to existing Live Card

Use Surface callbacks

NEXT Steps


https://developers.google.com/glass/community

Tag [google-gdk] on Stack Overflow

File Bugs / Feature requests

Join local Glass meetups

Please give feedback via the app at
eventmobi.com/wearablesdevcon

   slides and code are available via   

   luisdelarosa.com   

deep dive into google glass live cards

By Luis de la Rosa

deep dive into google glass live cards

  • 1,934
Loading comments...

More from Luis de la Rosa