Android Wear allows developers to create three main types of apps: notifications, native watch apps, and watchfaces. Notifications on Android Wear can be expanded to include voice input, multiple pages, and notification stacking. Native watch apps have access to hardware and Android APIs but are optimized for quick interactions. Watchfaces can be customized canvases that display time and other information like weather. The Data Layer API enables communication between wearable and handheld devices to sync data and configurations. Voice input is also an important interaction method for Android Wear apps.
4. What kind of apps?
Launched automatically “suggests”
Context Stream cards
Glanceable
See the content in a split second
All about suggest and demand
A personal assistant: it interrupts only when necessary
Zero or low interaction
User input only when necessary: touch, swipes, voice
5. What kind of apps?
Three ways to develop for Android Wear
Android notifications
Native android wear apps
Watchfaces
7. Notifications
It is standard notifications but…
You have to use NotificationCompat
NotificationCompat.WearableExtender
Helper class to add wearable extensions,
actions...
8. Notifications - Voice
We want to dictate to the watch
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)...build()
NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, getString(R.string.label), intent)
.addRemoteInput(remoteInput)
.build();
Your Android phone receives it:
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
CharSequence reply = remoteInput.getCharSequence(EXTRA_VOICE_REPLY);
10. Notifications - Pages
NotificationWearableExtender:
addPage(Notification notif)
// Create a big text style for the second page
BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2").bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification = new NotificationCompat.Builder(this).setStyle(secondPageStyle).build();
// Extend the notification builder with the second page
Notification notification = notificationBuilder.extend(new NotificationCompat.WearableExtender()
.addPage(secondPageNotification)).build();
13. Wear Apps
Direct access to HW of the watch
Timeout period after which watch goes to sleep
Bundled within a bigger app
Access to all Android APIs except:
webkit, print, backup, appwidgets and usb
15. Wear App UI
BoxInsetLayout - A FrameLayout that's aware of screen shape
CardFragment - Vertically scrollable card.
CircledImageView
ConfirmationActivity - An activity that displays confirmation animations
CrossFadeDrawable
DelayedConfirmationView - Circular countdown timer
DismissOverlayView - Long-press-to-dismiss.
DotsPageIndicator - Page indicator for GridViewPager that identifies the current page
GridViewPager: GridPagerAdapter, FragmentGridPagerAdapter
WatchViewStub - A class that can inflate a specific layout, based on the device's screen.
WearableListView - An alternative version of ListView
16. Wear App UI
Since the library is not supported, it can change
(and it does break pretty badly)
https://developer.android.com/reference/android/support/wearable/view/package-summary.html
17. Voice
Voice is an important part of Android Wear
Two types of voice actions:
System provided
Task based build in the OS ("OK Google, what’s my bpm?")
App provided
App based (‘Start’+Activity Name)
19. Form free speech input
Speech Recogniser, useful for dictating text
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);
…
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
}
20. Data layer API
To communicate with the watch:
Create an instance of GoogleApiClient
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new ConnectionCallbacks() {...})
.addOnConnectionFailedListener(new OnConnectionFailedListener() {...})
// Request access only to the Wearable API
.addApi(Wearable.API)
.build();
Use one separate instance for Android Wear!
21. Data layer API
Data Items
Data storage with automatic syncing.
MessageApi
Good for remote procedure calls (RPC)
Fire and Forget commands
Asset
Sending binary blobs of data, such as images.
With caching for large assets (to avoid Bluetooth bandwith issues)
22. Data layer API
WearableListenerService (for services)
Listen for important data layer events in a service. The system manages
its lifecycle binding to the service when it needs to send data items or
messages and unbinding the service when no work is needed.
DataListener (for foreground activities)
Listen for important data layer events when an activity is in the
foreground. Using this instead of the WearableListenerService lets you
listen for changes only when the user is actively using your app.
23. Watch Faces
Plan for square and round devices
Support all display modes (ambient, interactive)
Support special screen technologies
Make sure indicators are visible
Integrate data like calendar requests or weather
Provide configuration options
24. Watch Faces
They are services… wait… what?
CanvasWatchFaceService
Equivalent to View class
CanvasWatchFaceService.Engine
onDraw and callbacks of time, properties,
configurations changes
25. Watch Faces - Drawing
Create a timer that invalidates the engine
(ambient mode has system timer with callback onTimerTick)
Engine.onVisibilityChanged()
Where you start the timer and update the time zone
Engine.onAmbientModeChanged
Time to disable antialiasing, for example
Engine.onDraw(Canvas canvas, Rect bounds)
… where the fun starts
26. Lets say we want to show the weather…
Create a class inside your CanvasWatchFaceService.Engine implementation that extends AsyncTask
and add the code to retrieve the data you’re interested in.
Engine.onVisibilityChanged(boolean visible)
This method initializes the timer when the watch face becomes visible
Quite a manual process
Watch Faces - Show Info
27. Watch Faces - Configuration
Create a Wearable Configuration Activity
Runs in the watch: do not make it too complex
Create a Companion Configuration Activity
This runs on the device within the Android Wear app - It can be as complex as you want
Create a Listener Service in the Wearable App
...because we have to sync configurations between device and watch
Use the WearableListenerService interface from the Wearable Data Layer API
The Watchface will redraw itself when the configuration changes