From 46e804d2a730042fbf4824459cdcf2592d310abd Mon Sep 17 00:00:00 2001
From: Luan Nguyen
As a watch face developer, you can decide how often you want to update your watch face by +
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. In -ambient mode, you should disable the timer to let the CPU sleep and update the watch face -only when the time changes. For more information, see -Optimizing Performance and -Battery Life.
+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
@@ -210,9 +211,8 @@ conditions apply:
The timer should not run under any other conditions, since this watch face does not
-draw the second hand in ambient mode to conserve power. The AnalogWatchFaceService
-class schedules the next timer tick if required as follows:
The AnalogWatchFaceService class schedules the next timer tick if required as
+follows:
private void updateTimer() {
@@ -281,15 +281,15 @@ private void unregisterReceiver() {
-Invalidate the canvas when the time changes
+Update the watch face in ambient mode
-The system calls the Engine.onTimeTick() method every minute. In ambient mode,
-it is usually sufficient to update your watch face once per minute. To update your watch face
-more often while in interactive mode, you provide a custom timer as described in
+
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.
-Most watch face implementations just invalidate the canvas to redraw the watch face when
-the time changes:
+In ambient mode, most watch face implementations simply invalidate the canvas to redraw the watch
+face in the Engine.onTimeTick() method:
@Override
@@ -402,20 +402,17 @@ method for the system to redraw the watch face.
@Override
public void onAmbientModeChanged(boolean inAmbientMode) {
- boolean wasInAmbientMode = isInAmbientMode();
super.onAmbientModeChanged(inAmbientMode);
- if (inAmbientMode != wasInAmbientMode) {
- if (mLowBitAmbient) {
- boolean antiAlias = !inAmbientMode;
- mHourPaint.setAntiAlias(antiAlias);
- mMinutePaint.setAntiAlias(antiAlias);
- mSecondPaint.setAntiAlias(antiAlias);
- mTickPaint.setAntiAlias(antiAlias);
- }
- invalidate();
- updateTimer();
+ if (mLowBitAmbient) {
+ boolean antiAlias = !inAmbientMode;
+ mHourPaint.setAntiAlias(antiAlias);
+ mMinutePaint.setAntiAlias(antiAlias);
+ mSecondPaint.setAntiAlias(antiAlias);
+ mTickPaint.setAntiAlias(antiAlias);
}
+ invalidate();
+ updateTimer();
}
@@ -478,7 +475,7 @@ public void onDraw(Canvas canvas, Rect bounds) {
float hrLength = centerX - 80;
// Only draw the second hand in interactive mode.
- if (!mAmbient) {
+ if (!isInAmbientMode()) {
float secX = (float) Math.sin(secRot) * secLength;
float secY = (float) -Math.cos(secRot) * secLength;
canvas.drawLine(centerX, centerY, centerX + secX, centerY +
diff --git a/docs/html/training/wearables/watch-faces/service.jd b/docs/html/training/wearables/watch-faces/service.jd
index 7ab575e..35366c5 100644
--- a/docs/html/training/wearables/watch-faces/service.jd
+++ b/docs/html/training/wearables/watch-faces/service.jd
@@ -64,42 +64,15 @@ Project.
Dependencies
-For the handheld app, edit the build.gradle file in the mobile module
-to add these dependencies:
-
-
-apply plugin: 'com.android.application'
-
-android { ... }
-
-dependencies {
- ...
- wearApp project(':wear')
- compile 'com.google.android.gms:play-services:6.5.+'
-}
-
-
-For the wearable app, edit the build.gradle file in the wear module
-to add these dependencies:
-
-
-apply plugin: 'com.android.application'
-
-android { ... }
-
-dependencies {
- ...
- compile 'com.google.android.support:wearable:1.1.+'
- compile 'com.google.android.gms:play-services-wearable:6.5.+'
-}
-
-
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
Data Layer API.
+Android Studio automatically adds the required entries in your build.gradle
+files when you create the project in the instructions above.
+
Wearable Support Library API Reference
The reference documentation provides detailed information about the classes you use to
--
cgit v1.1