Courtesy: GitHub

Android Wear watch face codelab

In this codelab you'll learn how to create an analog watch face and customize it to our needs, keeping best practices for the platform in mind.

This is the code part of the watch face codelab. The code lab consists of 5 steps.

A site to guide you through the code lab is available.

To get started open the site and follow the instructions.

Pre-requisites

  • Android SDK v21
  • Android Build Tools v21.1.1
  • Android Support Repository

Getting Started

This code lab uses the Gradle build system. To build this project, use the "./gradlew build" command or use "Import Project" in Android Studio.

Support

If you've found an error in this code lab, please file an issue

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see CONTRIB.md for more details.

License

Copyright 2015 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compileSdkVersion 21

applicationId "com.android.example.watchface"

minSdkVersion 21

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile 'com.google.android.support:wearable:1.1.0'

compile 'com.google.android.gms:play-services-wearable:6.5.87'

compileSdkVersion 21

applicationId "com.android.example.watchface"

minSdkVersion 21

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile 'com.android.support:palette-v7:21.0.0'

compile 'com.google.android.support:wearable:1.1.0'

compile 'com.google.android.gms:play-services-wearable:6.5.87'

compileSdkVersion 21

applicationId "com.android.example.watchface"

minSdkVersion 21

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile 'com.google.android.support:wearable:1.1.0'

compile 'com.google.android.gms:play-services-wearable:6.5.87'

compileSdkVersion 21

applicationId "com.android.example.watchface"

minSdkVersion 21

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile 'com.google.android.support:wearable:1.1.0'

compile 'com.google.android.gms:play-services-wearable:6.5.87'

compileSdkVersion 21

applicationId "com.android.example.watchface"

minSdkVersion 21

targetSdkVersion 21

versionCode 1

versionName "1.0"

compile 'com.google.android.support:wearable:1.1.0'

compile 'com.google.android.gms:play-services-wearable:6.5.87'

package com.android.example.watchface

uses-permission

  • com.google.android.permission.PROVIDE_BACKGROUND
  • android.permission.WAKE_LOCK

package com.android.example.watchface

uses-permission

  • com.google.android.permission.PROVIDE_BACKGROUND
  • android.permission.WAKE_LOCK

package com.android.example.watchface

uses-permission

  • com.google.android.permission.PROVIDE_BACKGROUND
  • android.permission.WAKE_LOCK

package com.android.example.watchface

uses-permission

  • com.google.android.permission.PROVIDE_BACKGROUND
  • android.permission.WAKE_LOCK

package com.android.example.watchface

uses-permission

  • com.google.android.permission.PROVIDE_BACKGROUND
  • android.permission.WAKE_LOCK

MyWatchFaceService

Analog watch face with a ticking second hand. In ambient mode, the second hand isn't shown. On devices with low-bit ambient mode, the hands are drawn without anti-aliasing in ambient mode.

Update rate in milliseconds for interactive mode. We update once a second to advance the second hand.

Returns whether the {@link #mUpdateTimeHandler} timer should be running. The timer should only run when we're visible and in interactive mode.

MyWatchFaceService

Analog watch face with a ticking second hand. In ambient mode, the second hand isn't shown. On devices with low-bit ambient mode, the hands are drawn without anti-aliasing in ambient mode.

Update rate in milliseconds for interactive mode. We update once a second to advance the second hand.

Whether the display supports fewer bits for each color in ambient mode. When true, we disable anti-aliasing in ambient mode.

Whether the display supports burn in protection in ambient mode. When true, remove the background in ambient mode.

Returns whether the {@link #mUpdateTimeHandler} timer should be running. The timer should only run when we're visible and in interactive mode.

MyWatchFaceService

Analog watch face with a ticking second hand. In ambient mode, the second hand isn't shown. On devices with low-bit ambient mode, the hands are drawn without anti-aliasing in ambient mode.

Update rate in milliseconds for interactive mode. We update once a second to advance the second hand.

Whether the display supports fewer bits for each color in ambient mode. When true, we disable anti-aliasing in ambient mode.

Whether the display supports burn in protection in ambient mode. When true, remove the background in ambient mode.

Returns whether the {@link #mUpdateTimeHandler} timer should be running. The timer should only run when we're visible and in interactive mode.

MyWatchFaceService

Analog watch face with a ticking second hand. In ambient mode, the second hand isn't shown. On devices with low-bit ambient mode, the hands are drawn without anti-aliasing in ambient mode.

Update rate in milliseconds for interactive mode. We update once a second to advance the second hand.

Returns whether the {@link #mUpdateTimeHandler} timer should be running. The timer should only run when we're visible and in interactive mode.

MyWatchFaceService

Analog watch face with a ticking second hand. In ambient mode, the second hand isn't shown. On devices with low-bit ambient mode, the hands are drawn without anti-aliasing in ambient mode.

Update rate in milliseconds for interactive mode. We update once a second to advance the second hand.

Returns whether the {@link #mUpdateTimeHandler} timer should be running. The timer should only run when we're visible and in interactive mode.