am 349e3b5a: am f082f898: Merge "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)." into lmp-docs automerge:
* commit '349e3b5ad1e3d2f55fadce05a3726f27c8a2b5d5': 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).
This commit is contained in:
@@ -192,13 +192,14 @@ as described in <a href="#Drawing">Drawing Your Watch Face</a>.</p>
|
||||
|
||||
<h3 id="Timer">Initialize the custom timer</h3>
|
||||
|
||||
<p>As a watch face developer, you can decide how often you want to update your watch face by
|
||||
<p>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
|
||||
<a href="{@docRoot}training/wearables/watch-faces/performance.html">Optimizing Performance and
|
||||
Battery Life</a>.</p>
|
||||
interactive mode. This enables you to create custom animations and other visual effects.
|
||||
</p>
|
||||
|
||||
<p class="note"><strong>Note:</strong> In ambient mode, the system does not reliably call the
|
||||
custom timer. To update the watch face in ambient mode, see <a href="#TimeTick">Update the watch
|
||||
face in ambient mode</a>.</p>
|
||||
|
||||
<p>An example timer definition from the <code>AnalogWatchFaceService</code> class that ticks once
|
||||
every second is shown in <a href="#Variables">Declare variables</a>. In the
|
||||
@@ -210,9 +211,8 @@ conditions apply:</p>
|
||||
<li>The device is in interactive mode.</li>
|
||||
</ul>
|
||||
|
||||
<p>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 <code>AnalogWatchFaceService</code>
|
||||
class schedules the next timer tick if required as follows:</p>
|
||||
<p>The <code>AnalogWatchFaceService</code> class schedules the next timer tick if required as
|
||||
follows:</p>
|
||||
|
||||
<pre>
|
||||
private void updateTimer() {
|
||||
@@ -281,15 +281,15 @@ private void unregisterReceiver() {
|
||||
|
||||
|
||||
|
||||
<h3 id="TimeTick">Invalidate the canvas when the time changes</h3>
|
||||
<h3 id="TimeTick">Update the watch face in ambient mode</h3>
|
||||
|
||||
<p>The system calls the <code>Engine.onTimeTick()</code> 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
|
||||
<p>In ambient mode, the system calls the <code>Engine.onTimeTick()</code> 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
|
||||
<a href="#Timer">Initialize the custom timer</a>.</p>
|
||||
|
||||
<p>Most watch face implementations just invalidate the canvas to redraw the watch face when
|
||||
the time changes:</p>
|
||||
<p>In ambient mode, most watch face implementations simply invalidate the canvas to redraw the watch
|
||||
face in the <code>Engine.onTimeTick()</code> method:</p>
|
||||
|
||||
<pre>
|
||||
@Override
|
||||
@@ -402,20 +402,17 @@ method for the system to redraw the watch face.</p>
|
||||
@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();
|
||||
}
|
||||
</pre>
|
||||
|
||||
@@ -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 +
|
||||
|
||||
@@ -64,42 +64,15 @@ Project</a>.</p>
|
||||
|
||||
<h3 id="Dependencies">Dependencies</h3>
|
||||
|
||||
<p>For the handheld app, edit the <code>build.gradle</code> file in the <code>mobile</code> module
|
||||
to add these dependencies:</p>
|
||||
|
||||
<pre>
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android { ... }
|
||||
|
||||
dependencies {
|
||||
...
|
||||
wearApp project(':wear')
|
||||
compile 'com.google.android.gms:play-services:6.5.+'
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>For the wearable app, edit the <code>build.gradle</code> file in the <code>wear</code> module
|
||||
to add these dependencies:</p>
|
||||
|
||||
<pre>
|
||||
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.+'
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>The Wearable Support Library provides the necessary classes that you extend to create watch
|
||||
face implementations. The Google Play services client libraries (<code>play-services</code> and
|
||||
<code>play-services-wearable</code>) are required to sync data items between the companion device
|
||||
and the wearable with the <a href="{@docRoot}training/wearables/data-layer/index.html">Wearable
|
||||
Data Layer API</a>.</p>
|
||||
|
||||
<p>Android Studio automatically adds the required entries in your <code>build.gradle</code>
|
||||
files when you create the project in the instructions above.</p>
|
||||
|
||||
<h3 id="Reference">Wearable Support Library API Reference</h3>
|
||||
|
||||
<p>The reference documentation provides detailed information about the classes you use to
|
||||
|
||||
Reference in New Issue
Block a user