6. 6
What is Android Wear?
Requires Android 4.3 or iOS 8.2 and above devices
Latest Google Play Services and Android Wear app from
Google Play installed on smartphone
Internet and connectivity over Bluetooth from paired
device
Limited function when the connection with smartphone is
lost
7. 7
Android Wear vs Android Wear 2.0
New revisited interface based on latest version of Material
Design
Native apps
Google Assistant support
Better UI interaction
Expanded notifications and Inline Actions
8. 8
Getting started – install SDK
Install Android Wear SDK Tools from Android Studio
Latest Android Studio version from
https://developer.android.com/studio/index.html
Android Wear ARM EABI v7a System Image
Android Support Library updated
16. Wear apps development
Simple
Launched automatically
Glanceable
Work like a personal butler
Built oround micro-interactions
Very low user interactions
18. Android Wear Interactions
Two ways of interactions
Extension of an existing Android App notifications to work
better on Android Wear (existing notifications on phone that
appears also on Wear)
Standalone Android Wear native app
18
19. Android Notifications
Messages you can display to the user outside of your
application’s normal UI
19
Notifications in the notification area
20. Notifications design considerations
Important part of the
Android user interface
New own design features
added with the Material
Design occurrence
20
Notifications in the notification drawer
21. Build a Notification in Android
You have to specify the UI information and actions for a
notification in a NotificationCompat.Builder object
Call NotificationCompat.Builder.build() which returns a
Notification object containing your specifications
To issue the notification, pass the Notification object to the
system by calling NotificationManager.notify()
21
22. Build a Notification in Android:
Contents and Settings
A Notification object must contains
A small icon set by setSmallIcon()
A title, set by setContentTitle()
Detail text, set by setContentText()
Call The NotificationManager service to notify the event
22
23. Build a Notification in Android:
Actions
Optional functions added to NotificationCompat.Builder
An action allows user to go directly from the notification to an
Activity in the application
A Notification can provide multiple actions
Always define the action that’s triggered when the user clicks the
notification, opening a a binded Activity in your appliocation
Add buttons to the notification that performs additional actions
(without entering in the application to perform some tasks - i.e.,
snoozing an alarm or respond directely to a text message)
23
24. Build a Notification in Android:
Actions
Inside a Notification, the action itself is defined by a
PendingIntent containing an Intent (see Intents slides)
that starts an Activity in your application
24
Explicit Intent
for an Activity
StackBuilder object
that contains a back
stack for the started
Activity to the top of
the stack
Action defined by a
PendingIntent. It is added to
the NotificationCompat.Builder
25. Build a Notification in Android:
Expanded View
Create a NotificationCompat.Builder object with the
normal view
call Build.setStyle() with an expanded layout object as its
argument
25
Moves events into the
expanded layout
Set the expanded layout
object into the notification
object
26. You should avoid making a new notification when you need to issue a
Notification multime times for the same type of event
Consider updating a previous Notification changing some of its values
or by adding to it, or both (i.e., Gmail notification when new emails
have arrived by increasing its count of unreaded messages by adding
a summary of each email to the notification)
26
The same
NotificationCompat.Builder
defined previously
Starts of a loop that processes
data and then notifies the user
Use the same id to update the
already existing notification
Build a Notification in Android:
Update
27. By Android OS when the user clicks on Clear All (if the
notification can be cleared and not locked by Java code)
By calling setAutoCancel(true) in NotificationCompat.Builder
when the user clicks on the notification
By calling cancel() for a specific notification ID deleting also
the ongoing notifications
By calling cancelAll() removing all of the notification
previously issued
Build a Notification in Android:
Remove
28. Respond directely to text messages or update task lists from the
notification dialog (from Android 7.0 - API level 24)
Replying to notifications
29. Create an instance of RemoteInput.Builder that you can
add to your notification action.
Adding inline reply actions 1/3
Key for the
string input
that’s delivered
30. Attach the remote input object to an action using
addRemoteInput()
Adding inline reply actions 2/3
Create the
reply action
and add the
remote input
31. Apply the action to a notification and issue the notification
Adding inline reply actions 3/3
Build the
notification and
add the action
Issue the
notification
32. Adding Wearable Features to
Notifications
32
Use the same structure to build the notification in the current
Android project
Wearable API provided to extends notifications with new features
and personalizations for Wear 2.0
If the Wearable device is connected, the notification is visualized
33. Creating a Notification for Wearables
33
Both the watch and the phone can be sources of notification
Use the NotificationCompat.Builder class to create the
notification
Import the necessary packages in the build.gradle
Import the necessary classes from the support
library
34. Wearable extension: Notification
Builder
34
Create an instance of NotificationCompat.Builder
Issue the notification by passing the Notification object with a
notification ID to notify()
When the notification appears on a handled device, it appears
also on connected Android Wearable
35. Wearable extension: Expanded
notifications
35
Provide substantial additional content and actions for each
notification
Each expanded notification follows Material Design for Android
Wear 2.0 gets an app-like experience
The user can view the notification on Wearable when it is
generated by an app on the paired phone and bridged to Wear
36. Wearable extension: Expanded
notifications
36
Include additional content and actions for a notification choosing the
level of detail that the app’s notifications will provide
Adding additional content
To show additional text in the expanded notification,
use BigTextStyle.
To add images in expanded notification, use
BigPictureStyle. To add more than one image in
the expanded Notification use addPage() method
along with the BigPictureStyle
Primary action
The expanded notificationwill contain on primary
action, which is the first action in the notification
unless a different action is specified using
setContentAction()
Additional actions
To specify additional actions, use addAction() or
addActions(). The action drawer og the expanded
notification contains all available actions
37. Wearable extension: Additional
Actions
37
Is possible to add other actions by passing a PendingIntent to the
setActions() method
Example: same type of previous notification with an action to view the
event location on a map
On smartphone the
action appears as an
additional button
attached to the
notification
On Wearable the
action appears in the
expanded
notification after the
context text
38. Wearable extension: Inline Actions
38
Allows users to take actions on a notification from within the notification
stream card
Appears as an additional button displayed ad the bottom of the
notification
Recommended for cases in which users are likely to take an action on a
notification after viewing the contents in the notification card without
going to the expanded notification
39. Wearable extension: Inline Actions
39
To display it as an additional button in
the notification, set the
setHintDisplayActionInline(true)
When a user taps the inline action, the
system invokes the intent specified in
the notification action
40. Wearable extension: specific features
to a notification
40
Example remove the app icon from the notification card
Create an instance of a WearableExtender defining the wearable-specific
options for the notification
Create an instance of NotificationCompat.Builder defining the desired
properties
Call extend() on the notification and pass in the Wearable Extension
Call build()
41. Wearable only Actions
41
To set Actions on the wearable different from the smartphone
use WearableExtender.addAction()
With this method the wearable does not display any other
actions added with
NotificationCompat.Builder.addAction()
The actions added with WearableExtender.addAction()
appear only on the wearable and not to the smartphone app
42. Wearable only Actions: Example
42
Create an action that
supports voice input
only on wearable
device
Class contructor
accepts a string
that the system
uses as the key
for the voice
input
44. Standalone Wearable apps
44
Apps that work independently of a phone app
User can complete more tasks on a watch without using the phone
Apps not embedded in a phone APK
45. Identification and storage
45
minimum API level 25 (for Wear 2.0), or API level 23 (for Wear 1.0
and 2.0)
Wear 2.0 requires meta-data element called
com.google.android.wearable.standalone in the Android
Manifest as a child of <application> element
true: the Wear pp is available on Play Store if the watch is connected
with an iPhone
Standard storage used for smarpthone APK
SQLite
SharedPreferences
Internal Storage
46. Custom Notifications
46
In general notification are created from the phone app and then visualized on
Android Wear, Auto, TV
To show a notification on a standalone wearable app:
Display an Activity with a custom layout
Define properties for the Activity in the Android Manifest defining
• android:exportable = true;
• android:allowEmbedded = true;
• android:taskAffinity = ‘’;
Create a PendingIntent to call the Notification Activity
Build a default Notification and call setDisplayIntent() providing the
PendingIntent to call the Activity
Call the Notification with the notify() method
47. The UI Library
47
Insert the UI Library in the build.gradle file
Major classes:
BoxInsetLayout: screen shape to box its children views (for round and square
screens)
ConfirmationActivity: displays cnfirmation animations when user finish an action
AnimationSet: group of animations
CircularProgressLayout: progress with a circular timedown timer typically used to
restore an user task
AlertDialog: Dialog with one, two or three buttons
ProgressBar: display to the user how far the operation has progressed
WearableRecyclerView: displaying scrollable lists of items
48. Creating Custom UIs - Defining
Layouts
48
Need to be designed with specific constraints
Wrong approach:
Best approach:
BoxInsetLayout: applies different window insets depending on the shape of the
window screen without having views cropped near the edges of round screen
CurvedLayout: to visualize and manipulate vertical list of items optimized for round
screens
49. Creating Custom UIs - Lists
49
Select an item from a set of choices easily
Extend to the interested Activity the WearableRecyclerView
class to create lists optimized for Wear 2.0
Recommended for a long list of simple items with a simple icon
and a short string associated (i.e., application launcher, list of
contacts...)
50. Creating Custom UIs – Curved Layout
50
Use the WearableRecyclerView extended to the Activity
Set the setEdgeItemsCenteringEnabled(true) to align the first and the
last elements of the list vertically centered on the screen
Use the WearableRecyclerView.setLayoutManager() method to set the
elements
Enabling circular gesture scrolling calling
setCircularScrollingGestureEnabled(true) method
51. Creating Custom UIs – Showing
confirmation Timers
51
Usually use the whole screen ensuring that the user can visualize the
confirmation button larger enough to touch it to cancel an action
Automatic confirmation timers show users an
animated timer that lets them cancel an
action they just performed
The animations give users visual feedback
when they complete an action
52. Creating Custom UIs – Showing
confirmation Timers
52
including the dipendencies in the build.gradle
Add a CircularProgressLayout element to layout
53. Creating Custom UIs – Showing
confirmation Timers
53
Implement the CircularProgressLayout.onTimerFinishedListener
interface in the Activity
54. Creating Custom UIs – Showing
confirmation Timers
54
Set the duration of the timer and start it when the user completes an action
Show the confirmation animations creating an Intent that starts a new
Activity including an EXTRA_ANIMATION_TYPE intent extra and an
EXTRA_MESSAGE string:
SUCCESS_ANIMATION
FAILURE_ANIMATION
OPEN_ON_PHONE_ANIMATION
55. Creating Custom UIs – Wear
Navigation and Actions
55
Two tinteractive Drawers designed in Material Design
Navigation Drawer: switch
between views in the app
• Multi-page navigation
drawer: present the
contents of a navigation
drawer in a single page or
as multiple pages defining
app:navigationStyle=‘’
multipage’’ in the XML
layout
Action Drawer: easy access to
common actions appearing at
the bottom of the screen using
context-specific user actions
(similar to ActionBar to
smartphone). It peeks when the
user reaches the top or bottom
of the scrolling content
56. Create a WearableDrawerLayout
56
Example: declare an interface with a WearableDrawerLayout object as a
root view of the layout supporting the nested scrolling.
The main
content
To add a multi-page
navigation apply the
attribute
navigationStyle=‘’mult
iPage’’ to the drawer
57. Initialize the Drawer contents
57
Initialize the drawers’ lists of items exenting the WearableDrawerAdapter to
populate the navigation drawer contents
Populate the action
drawer contents in
the layout XML file
using
app:actionMenu
attribute
Initialize the
contents of the
drawer
58. Ambient mode
58
Visualize the current Activity in a low-power mode saving battery
on Wear device
• Update dipendencies
to build.gradle
• Add wearable shared
library
• Add WAKE_LOCK
permission
59. Ambient mode - handle transitions
59
If the user covers the screen with their palm, the system switches
the activity to Ambient mode
Note: by default when the app runs on a device, palming the
screen does not switch an app into Ambient mode causing the
Activity to exit and the home screen to appear
60. Ambient mode - handle transitions
60
When the Activity switches to ambient mode, the system calls onEnterAmbient()
method
When the user taps the screen or brings up the wrist, the Activity switches from Ambient
mode to Interactive mode calling onExitAmbient() method
Update the information on the screen using onUpdateAmbient() method
Note: carefully balance display updates to not compromise the battery consumption. To
realize battery savings, updates should be no more than once every 10 seconds. For apps
that have to be updated frequently use an AlarmManager to wake the processor
• Example: change the text color
to white and set the antialias to
false
• Example: change the text color
to green and set the antialias to
true
61. Multi-function Buttons
61
Android Wear supports extra physical buttons in addition to power button
onKeyDown() method
Note: find a method that searches the number of available buttons on wearable
device
Available set of possible
keycodes that the app can
receive and convert them to a
specific in-app actions
62. Using Wrist Gestures
62
Enable quick one-handed interactions with the app when the
touch screen is inconvenient
Example of use:
scroll through notifications with one hand while holding a cup of
coffe with the other
In app for jogging where the navigation through vertical screens
shows the steps, time elapsed
...
To activate them on the Wearable, confirm gestures to turn on by selecting
Settings > Gestures > Wirst Gestures On
63. Using Wrist Gestures
63
Curved layout with predefined gestures
The WaerableRecyclerView class automatically supports wirst
gestures using predefined actions for occurrences when the view
has focus
previous item ReturnSelect an itemNext item
64. Using KeyEvents to customize functions defined by user action
Using KeyEvents The events are delivered to the top Activity that
implements KeyEvent.CallBack that listens the key event related to
the wrist gestures
Using Wrist Gestures
64
65. Android Wear 2.0 allows to communicate with a network directly without
access to an Android or iOS phone
Sending and Sync Data
65
Wearable Data Layer API is used to manage
data between Wear 1.0 and Phone
DataItem provides data storage with automatic syncing
between the phone and wearable
Message good for remote procedure calls for one-way
requests or request/response communication model (i.e.,
controlling the media player from wearable)
Asset for sending bolbs of data conserving Bluetooth
bandwidth (i.e., images) froom phone to wearable
WearableListenerService when it needed to send data
items (i.e., sensors states) or messages in backround
DataListener for important data layer events when the
user is actively using the app in foreground
Channel to transfer large data items (i.e., movies or
music) from phone to wearable
For more details: https://developer.android.com/training/wearables/data-
layer/index.html
66. Cloud Messaging
To send notifications, apps can directely use
Firebase Cloud Messaging (FCM) which replcaes
Google Cloud Messaging (GCM)
FCM is supported on Wear 2.0
For more details see: https://firebase.google.com/docs/cloud-
messaging/concept-options
FMC sends messages to the device by collecting a registration token for it
when the Wear app runs
By default notifications are shared form a phone app to watch. For
standalone Wear apps FMC could be displayed independentlyThe FMC
message is in JSON format including:
Notification payload: when a notifiation payload is received by a watch, the data
is displayed to a user directely in the notification stream. When the user tap the
notification, the app is launched
Data payload: set of custom key/value pairs. The payload is delivered as data to
the Wear app