From 46e804d2a730042fbf4824459cdcf2592d310abd Mon Sep 17 00:00:00 2001 From: Luan Nguyen Date: Tue, 20 Jan 2015 08:41:51 -0800 Subject: docs: Fix conditional in ambient mode check method (18832168). Fix issue with non existent variable (18832287). Fix issue with outdated instructions (18832293). Fix issue with misleading time tick (18832171). bug: 18832168 bug: 18832171 bug: 18832287 bug: 18832293 Change-Id: I4f071846589ba7edda500342ccd5fac6ecca3161 --- .../html/training/wearables/watch-faces/drawing.jd | 51 ++++++++++------------ .../html/training/wearables/watch-faces/service.jd | 33 ++------------ 2 files changed, 27 insertions(+), 57 deletions(-) (limited to 'docs/html/training') diff --git a/docs/html/training/wearables/watch-faces/drawing.jd b/docs/html/training/wearables/watch-faces/drawing.jd index 9afdd80..3c5da34 100644 --- a/docs/html/training/wearables/watch-faces/drawing.jd +++ b/docs/html/training/wearables/watch-faces/drawing.jd @@ -192,13 +192,14 @@ as described in Drawing Your Watch Face.

Initialize the custom timer

-

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 device is in interactive mode.
  • -

    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