From cce9c74f4ea3649f4539c2d624deeafe1170664c Mon Sep 17 00:00:00 2001
From: Luan Nguyen Related Samples
+
+
You should also read
The digital watch face from the WatchFace sample in the Android SDK demonstrates how to +
The digital watch face from the
+WatchFace sample demonstrates how to
implement handheld and wearable configuration activities and how to update a watch face in
-response to configuration changes. This sample is located in the
-android-sdk/samples/android-21/wearable/WatchFace
directory.
For more details, see the DigitalWatchFaceWearableConfigActivity
and
-DigitalWatchFaceUtil
classes in the WatchFace sample.
DigitalWatchFaceUtil
classes in the
+WatchFace sample.
@@ -141,17 +147,20 @@ href="{@docRoot}training/wearables/data-layer/index.html">Wearable Data Layer AP
communicate the configuration change to the watch face activity.
For more details, see the DigitalWatchFaceCompanionConfigActivity
class in the
-WatchFace sample.
To receive updated configuration parameters from the configuration activities, create a
-service that implements the WearableListenerService
interface from the Wearable Data Layer API in your
+service that implements the
+WearableListenerService
+interface from the
+Wearable Data Layer API in your
wearable app. Your watch face implementation can redraw the watch face when the configuration
parameters change.
For more details, see the DigitalWatchFaceConfigListenerService
and
-DigitalWatchFaceService
classes in the WatchFace sample.
DigitalWatchFaceService
classes in the
+WatchFace sample.
diff --git a/docs/html/training/wearables/watch-faces/information.jd b/docs/html/training/wearables/watch-faces/information.jd
index 41319a1..ed0cc22 100644
--- a/docs/html/training/wearables/watch-faces/information.jd
+++ b/docs/html/training/wearables/watch-faces/information.jd
@@ -9,6 +9,11 @@ page.title=Showing Information in Watch Faces
Figure 2. The calendar watch face.
-The WatchFace sample in the Android SDK demonstrates how to obtain calendar data
-from the user’s profile in the CalendarWatchFaceService
class and shows how many
-meetings there are in the following twenty-four hours. This sample is located in the
-android-sdk/samples/android-21/wearable/WatchFace
directory.
The
+WatchFace
+sample demonstrates how to obtain calendar data from the user’s profile in the
+CalendarWatchFaceService
class and shows how many
+meetings there are in the following twenty-four hours.
To implement a watch face that incorporates contextual data, follow these steps:
@@ -95,9 +101,10 @@ meetings there are in the following twenty-four hours. This sample is located inCreate a class inside your CanvasWatchFaceService.Engine
implementation that
-extends {@link android.os.AsyncTask} and add the code to retrieve the data you’re interested
-in.
Create a class inside your
+CanvasWatchFaceService.Engine
+implementation that extends {@link android.os.AsyncTask} and add the code to retrieve the data
+you’re interested in.
The CalendarWatchFaceService
class obtains the number of meetings in the next
day as follows:
The WearableCalendarContract
class from the Wearable Support Library provides
-direct access to the user's calendar events from the companion device.
The
+WearableCalendarContract
+class from the Wearable Support Library provides direct access to the user's calendar events from
+the companion device.
When the task finishes retrieving data, your code invokes a callback method. The following sections describe how to implement the callback method in detail.
@@ -189,9 +198,12 @@ section.When the task that retrieves your data finishes, call the invalidate()
method
-so the system redraws your watch face. Store your data inside member variables of the
-Engine
class so you can access it inside the onDraw()
method.
When the task that retrieves your data finishes, call the
+invalidate()
+method so the system redraws your watch face. Store your data inside member variables of the
+Engine
class so you can access it inside the
+onDraw()
+method.
The CalendarWatchFaceService
class provides a callback method for the task to
invoke when it finishes retrieving calendar data:
Android Wear lets your watch face determine the screen shape at runtime. To detect whether
-the screen is square or round, override the onApplyWindowInsets()
method in the
-CanvasWatchFaceService.Engine
class as follows:
onApplyWindowInsets()
+method in the
+CanvasWatchFaceService.Engine
+class as follows:
private class Engine extends CanvasWatchFaceService.Engine { @@ -75,7 +78,9 @@ the notification card is present. down the watch face to fit inside the portion of the screen not covered by the peek card. Digital watch faces that display the time in the area of the screen not covered by peek cards do not usually require adjustments. To determine the free space above the peek card so you can adapt -your watch face, use theWatchFaceService.getPeekCardPosition()
method. +your watch face, use the +WatchFaceService.Engine.getPeekCardPosition()
+method.In ambient mode, peek cards have a transparent background. If your watch face contains details near the card in ambient mode, consider drawing a black rectangle over them to ensure that users @@ -93,16 +98,21 @@ can read the contents of the card.
To ensure that the system indicators remain visible, you can configure their position on the -screen and whether they need background protection when you create a
WatchFaceStyle
+screen and whether they need background protection when you create a +WatchFaceStyle
instance:
setStatusBarGravity()
method.setHotwordIndicatorGravity()
+setStatusBarGravity()
+method.setHotwordIndicatorGravity()
method.setViewProtection()
method. This is usually necessary if your watch face has a
-light background, since the system indicators are white.setViewProtection()
+method. This is usually necessary if your watch face has a light background, since the system
+indicators are white.
For more information about the system indicators, see
Many watch faces consist of a background image and other graphic assets that are transformed
and overlapped on top of the background image, such as clock hands and other elements of the design
that move over time. Typically these graphic elements are rotated (and sometimes scaled) inside the
- The larger these graphic assets are, the more computationally expensive it is to transform them.
-Transforming large graphic assets in the Engine.onDraw()
method every time the system redraws the watch face, as described in
+Engine.onDraw()
+method every time the system redraws the watch face, as described in
Draw Your Watch
Face.Engine.onDraw()
method drastically reduces
-the frame rate at which the system can run your animations.Engine.onDraw()
+method drastically reduces the frame rate at which the system can run your animations.
The system calls the Engine.onDraw()
method every time it redraws your watch
-face, so you should only include operations that are strictly required to update the watch
-face inside this method to improve performance.
+
The system calls the
+Engine.onDraw()
+method every time it redraws your watch face, so you should only include operations that are
+strictly required to update the watch face inside this method to improve performance.
-
When possible, avoid performing these operations inside the onDraw()
method:
When possible, avoid performing these operations inside the
+Engine.onDraw()
+method:
You can usually perform these operations in the Engine.onCreate()
method instead.
+
You can usually perform these operations in the
+Engine.onCreate()
+method instead.
You can resize images ahead of time in the {@link
android.service.wallpaper.WallpaperService.Engine#onSurfaceChanged(android.view.SurfaceHolder, int, int, int)
Engine.onSurfaceChanged()} method, which provides you with the size of the canvas.
To analyze the performance of your watch face, use the Android Device Monitor. In particular,
-ensure that the execution time for your Engine.onDraw()
implementation is short and
+ensure that the execution time for your
+Engine.onDraw()
+implementation is short and
consistent across invocations. For more information, see
Using DDMS.
The Wearable Support Library provides the necessary classes that you extend to create watch +
The
+Wearable Support Library
+provides the necessary classes that you extend to create watch
face implementations. The Google Play services client libraries (play-services
and
play-services-wearable
) are required to sync data items between the companion device
and the wearable with the Wearable
@@ -116,10 +123,15 @@ or when an important event occurs (like switching to ambient mode or receiving a
notification). The service implementation then draws the watch face on the screen using the
updated time and any other relevant data.
To implement a watch face, you extend the CanvasWatchFaceService
-and CanvasWatchFaceService.Engine
classes, and then you override the callback methods
-in the CanvasWatchFaceService.Engine
class. These classes are included in the
-Wearable Support Library.
To implement a watch face, you extend the
+CanvasWatchFaceService
+and
+CanvasWatchFaceService.Engine
+classes, and then you override the callback methods in the
+CanvasWatchFaceService.Engine
+class. These classes are included in the
+Wearable Support Library.
+
The following snippet outlines the key methods you need to implement:
@@ -173,20 +185,21 @@ public class AnalogWatchFaceService extends CanvasWatchFaceService { } -Note: The WatchFace sample in the Android SDK
-demonstrates how to implement analog and digital watch faces extending the
-CanvasWatchFaceService
class. This sample is located in the
-android-sdk/samples/android-21/wearable/WatchFace
directory.
The CanvasWatchFaceService
class provides an invalidate mechanism similar to
+
The
+CanvasWatchFaceService
+class provides an invalidate mechanism similar to
the {@link android.view.View#invalidate View.invalidate()} method. You can call the
-invalidate()
method throughout your implementation when you want the system to
-redraw the watch face. You can only use the invalidate()
method in the main UI
-thread. To invalidate the canvas from another thread, call the postInvalidate()
+invalidate()
+method throughout your implementation when
+you want the system to redraw the watch face. You can only use the
+invalidate()
+method in the main UI thread. To invalidate the canvas from another thread, call the
+postInvalidate()
method.
For more information about implementing the methods in the
-CanvasWatchFaceService.Engine
class, see CanvasWatchFaceService.Engine
+class, see Drawing Watch Faces.