Skip to content

Most visited

Recently visited


Drawing Watch Faces

After you have configured your project and added a class that implements the watch face service, you can start writing code to initialize and draw your custom watch face.

This lesson includes examples from the WatchFace sample to show how the system uses the watch face service. Many aspects of the service implementations described here (such as initialization and device features detection) apply to any watch face, so you can reuse some of the code in your own watch faces.

Figure 1. The analog and digital watch faces in the WatchFace sample.

Initialize your watch face

When the system loads your service, you should allocate and initialize most of the resources that your watch face needs, including loading bitmap resources, creating timer objects to run custom animations, configuring paint styles, and performing other computations. You can usually perform these operations only once and reuse their results. This practice improves the performance of your watch face and makes it easier to maintain your code.

To initialize your watch face, follow these steps:

  1. Declare variables for a custom timer, graphic objects, and other elements.
  2. Initialize the watch face elements in the Engine.onCreate() method.
  3. Initialize the custom timer in the Engine.onVisibilityChanged() method.

The following sections describe these steps in detail.

Declare variables

The resources that you initialize when the system loads your service need to be accessible at different points throughout your implementation, so you can reuse them. You achieve this by declaring member variables for these resources in your WatchFaceService.Engine implementation.

Declare variables for the following elements:

Graphic objects
Most watch faces contain at least one bitmap image used as the background of the watch face, as described in Create an Implementation Strategy. You can use additional bitmap images that represent clock hands or other design elements of your watch face.
Periodic timer
The system notifies the watch face once a minute when the time changes, but some watch faces run animations at custom time intervals. In these cases, you need to provide a custom timer that ticks with the frequency required to update your watch face.
Time zone change receiver
Users can adjust their time zone when they travel, and the system broadcasts this event. Your service implementation must register a broadcast receiver that is notified when the time zone changes and update the time accordingly.

The following snippet shows how to define these variables:

private class Engine extends CanvasWatchFaceService.Engine {
    static final int MSG_UPDATE_TIME = 0;

    Calendar mCalendar;

    // device features
    boolean mLowBitAmbient;

    // graphic objects
    Bitmap mBackgroundBitmap;
    Bitmap mBackgroundScaledBitmap;
    Paint mHourPaint;
    Paint mMinutePaint;

    // handler to update the time once a second in interactive mode
    final Handler mUpdateTimeHandler = new Handler() {
        public void handleMessage(Message message) {
            switch (message.what) {
                case MSG_UPDATE_TIME:
                    if (shouldTimerBeRunning()) {
                        long timeMs = System.currentTimeMillis();
                        long delayMs = INTERACTIVE_UPDATE_RATE_MS
                                - (timeMs % INTERACTIVE_UPDATE_RATE_MS);
                            .sendEmptyMessageDelayed(MSG_UPDATE_TIME, delayMs);

    // receiver to update the time zone
    final BroadcastReceiver mTimeZoneReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {

    // service methods (see other sections)

In the example above, the custom timer is implemented as a Handler instance that sends and processes delayed messages using the thread's message queue. For this particular watch face, the custom timer ticks once every second. When the timer ticks, the handler calls the invalidate() method and the system then calls the onDraw() method to redraw the watch face.

Initialize watch face elements

After declaring member variables for bitmap resources, paint styles, and other elements that you reuse every time you redraw your watch face, initialize them when the system loads your service. Initializing these elements only once and reusing them improves performance and battery life.

In the Engine.onCreate() method, initialize the following elements:

The following snippet shows how to initialize these elements:

public void onCreate(SurfaceHolder holder) {

    // configure the system UI (see next section)

    // load the background image
    Resources resources = AnalogWatchFaceService.this.getResources();
    Drawable backgroundDrawable = resources.getDrawable(, null);
    mBackgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();

    // create graphic styles
    mHourPaint = new Paint();
    mHourPaint.setARGB(255, 200, 200, 200);

    // allocate a Calendar to calculate local time using the UTC time and time zone
    mCalendar = Calendar.getInstance();

The background bitmap is loaded only once when the system initializes the watch face. The graphic styles are instances of the Paint class. Use these styles to draw the elements of your watch face inside the Engine.onDraw() method, as described in Drawing Your Watch Face.

Initialize the custom timer

As a watch face developer, you decide how often you want to update your watch face by providing a custom timer that ticks with the required frequency while the device is in interactive mode. This enables you to create custom animations and other visual effects.

Note: In ambient mode, the system does not reliably call the custom timer. To update the watch face in ambient mode, see Update the watch face in ambient mode.

An example timer definition from the AnalogWatchFaceService class that ticks once every second is shown in Declare variables. In the Engine.onVisibilityChanged() method, start the custom timer if these two conditions apply:

The AnalogWatchFaceService class schedules the next timer tick if required as follows:

private void updateTimer() {
    if (shouldTimerBeRunning()) {

private boolean shouldTimerBeRunning() {
    return isVisible() && !isInAmbientMode();

This custom timer ticks once every second, as described in Declare variables.

In the onVisibilityChanged() method, start the timer if required and register the receiver for time zone changes as follows:

public void onVisibilityChanged(boolean visible) {

    if (visible) {

        // Update time zone in case it changed while we weren't visible.
    } else {

    // Whether the timer should be running depends on whether we're visible and
    // whether we're in ambient mode, so we may need to start or stop the timer

When the watch face is visible, the onVisibilityChanged() method registers the receiver for time zone changes. If the device is in interactive mode, this method also starts the custom timer. When the watch face is not visible, this method stops the custom timer and unregisters the receiver for time zone changes. The registerReceiver() and unregisterReceiver() methods are implemented as follows:

private void registerReceiver() {
    if (mRegisteredTimeZoneReceiver) {
    mRegisteredTimeZoneReceiver = true;
    IntentFilter filter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
    AnalogWatchFaceService.this.registerReceiver(mTimeZoneReceiver, filter);

private void unregisterReceiver() {
    if (!mRegisteredTimeZoneReceiver) {
    mRegisteredTimeZoneReceiver = false;

Update the watch face in ambient mode

In ambient mode, the system calls the Engine.onTimeTick() method every minute. It is usually sufficient to update your watch face once per minute in this mode. To update your watch face while in interactive mode, you must provide a custom timer as described in Initialize the custom timer.

In ambient mode, most watch face implementations simply invalidate the canvas to redraw the watch face in the Engine.onTimeTick() method:

public void onTimeTick() {


Configure the system UI

Watch faces should not interfere with system UI elements, as described in Accommodate System UI Elements. If your watch face has a light background or shows information near the bottom of the screen, you may have to configure the size of notification cards or enable background protection.

Android Wear enables you to configure the following aspects of the system UI when your watch face is active:

To configure these aspects of the system UI, create a WatchFaceStyle instance and pass it to the Engine.setWatchFaceStyle() method.

The AnalogWatchFaceService class configures the system UI as follows:

public void onCreate(SurfaceHolder holder) {

    // configure the system UI
    setWatchFaceStyle(new WatchFaceStyle.Builder(AnalogWatchFaceService.this)

The code snippet above configures the system time not to be shown (since this watch face draws its own time representation).

You can configure the style of the system UI at any point in your watch face implementation. For example, if the user selects a white background, you can add background protection for the system indicators.

For more details about configuring the system UI, see the Wear API reference documentation.

Managing the unread notification indicator

Users often want to have a clear indication that there are unread notifications. Therefore an unread notification indicator is provided. This indicator appears as an encircled dot at the bottom of the screen. It is displayed if there is more than one unread notification in the stream.

unread notification indicator

Figure 2. Unread notification indicator.

Note: The unread notifications indicator is not enabled in the production version of Wear 2.8.0. Developers are advised to test their implementation using the latest Wear emulator instead. This feature will be displayed by default starting from the next consumer release of Wear (version 2.9.0).

By default, the indicator will be added to your watch face. We strongly recommend that you leave the indicator available to your users. However, if your watch face already provides an indication of unread notifications, or if the position of the new indicator clashes with an element of the watch face, you can opt out of having the system indicator displayed. Use one of the following methods when you build the watch style:

provide a custom unread notifications count provide an unread notifications count in the status bar

Figure 3. Custom notification count or status bar notification count.

If you choose to allow the unread notification indicator to be displayed on your watch face, you can customize the color of its outer ring. Call WatchFaceStyle.Builder.setAccentColor and specify the desired color. By default, the outer ring is white.

Obtain information about the device screen

The system calls the Engine.onPropertiesChanged() method when it determines the properties of the device screen, such as whether the device uses low-bit ambient mode and whether the screen requires burn-in protection.

The following code snippet shows how to obtain these properties:

public void onPropertiesChanged(Bundle properties) {
    mLowBitAmbient = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
    mBurnInProtection = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION,

You should take these device properties into account when drawing your watch face:

For more information about low-bit ambient mode and burn-in protection, see Optimize for Special Screens. For more information on how to disable bitmap filtering, see Bitmap Filtering.

Respond to changes between modes

When the device switches between ambient and interactive modes, the system calls the Engine.onAmbientModeChanged() method. Your service implementation should make any necessary adjustments to switch between modes and then call the invalidate() method for the system to redraw the watch face.

The following snippet shows how to implement this method:

public void onAmbientModeChanged(boolean inAmbientMode) {


    if (mLowBitAmbient) {
        boolean antiAlias = !inAmbientMode;

This example makes adjustments to some graphic styles and invalidates the canvas so the system can redraw the watch face.

Draw your watch face

To draw a custom watch face, the system calls the Engine.onDraw() method with a Canvas instance and the bounds in which you should draw your watch face. The bounds take into account any inset areas, such as the "chin" on the bottom of some round devices. You can use this canvas to draw your watch face directly as follows:

  1. Override the onSurfaceChanged() method to scale your background to fit the device any time the view changes.
    public void onSurfaceChanged(
            SurfaceHolder holder, int format, int width, int height) {
        if (mBackgroundScaledBitmap == null
                || mBackgroundScaledBitmap.getWidth() != width
                || mBackgroundScaledBitmap.getHeight() != height) {
            mBackgroundScaledBitmap = Bitmap.createScaledBitmap(mBackgroundBitmap,
                    width, height, true /* filter */);
        super.onSurfaceChanged(holder, format, width, height);
  2. Check whether the device is in ambient mode or interactive mode.
  3. Perform any required graphic computations.
  4. Draw your background bitmap on the canvas.
  5. Use the methods in the Canvas class to draw your watch face.

The following snippet shows how to implement the onDraw() method:

public void onDraw(Canvas canvas, Rect bounds) {
    long frameStartTimeMs = SystemClock.elapsedRealtime();

    // Drawing code here

    if (shouldTimerBeRunning()) {
        long delayMs = SystemClock.elapsedRealtime() - frameStartTimeMs;
        if (delayMs > INTERACTIVE_UPDATE_RATE_MS) {
            // This scenario occurs when drawing all of the components takes longer than an actual
            // frame. It may be helpful to log how many times this happens, so you can
            // fix it when it occurs.
            // In general, you don't want to redraw immediately, but on the next
            // appropriate frame (else block below).
            delayMs = 0;
        } else {
            // Sets the delay as close as possible to the intended framerate.
            // Note that the recommended interactive update rate is 1 frame per second.
            // However, if you want to include the sweeping hand gesture, set the
            // interactive update rate up to 30 frames per second.
            delayMs = INTERACTIVE_UPDATE_RATE_MS - delayMs;
        updateTimeHandler.sendEmptyMessageDelayed(MSG_CODE_UPDATE_TIME, delayMs);

For more information about drawing on a Canvas instance, see Canvas and Drawables.

The WatchFace sample includes additional watch faces that you can refer to as examples of how to implement the onDraw() method.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)