blob: 07a352f9239f89d29edf7f931c626befef570fbf [file] [log] [blame]
page.title=Showing Confirmations
<div id="tb-wrapper">
<div id="tb">
<h2>This lesson teaches you to</h2>
<li><a href="#confirmation-timers">Use Automatic Confirmation Timers</a></li>
<li><a href="#show-confirmation">Show Confirmation Animations</a></li>
<h2>You should also read</h2>
<li><a href="{@docRoot}design/wear/index.html">Android Wear Design Principles</a></li>
<p><a href="{@docRoot}design/wear/patterns.html#Countdown">Confirmations</a> in Android Wear apps
use the whole screen or a larger portion of it than those in handheld apps. This ensures that
users can see these confirmations by just glancing at the screen and that they have large enough
touch targets to cancel an action.</p>
<p>The Wearable UI Library helps you show confirmation animations and timers in your
Android Wear apps:</p>
<dt><em>Confirmation timers</em></dt>
<dd>Automatic confirmation timers show users an animated timer that lets them cancel an action
they just performed.</dd>
<dt><em>Confirmation animations</em></dt>
<dd>Confirmation animations give users visual feedback when they complete an action.</dd>
<p>The following sections show you how to implement these patterns.</p>
<h2 id="confirmation-timers">Use Automatic Confirmation Timers</h2>
<div style="float:right;margin-left:25px;width:230px;margin-top:10px">
<img src="{@docRoot}wear/images/09_uilib.png" width="230" height="230" alt=""/>
<p class="img-caption" style="text-align:center"><strong>Figure 1:</strong>
A confirmation timer.</p>
<p>Automatic confirmation timers let users cancel an action they just performed. When the user
performs the action, your app shows a button to cancel the action with a timer animation and
starts the timer. The user has the option to cancel the action until the timer finishes. Your app
gets notified if the user cancels the action and when the timer expires.</p>
<p>To show a confirmation timer when users complete an action in your app:</p>
<li>Add a <code>DelayedConfirmationView</code> element to your layout.</li>
<li>Implement the <code>DelayedConfirmationListener</code> interface in your activity.</li>
<li>Set the duration of the timer and start it when the user completes an action.</li>
<p>Add the <code>DelayedConfirmationView</code> element to your layout as follows:</p>
<p>You can assign a drawable resource to display inside the circle with the
<code>android:src</code> attribute and configure the parameters of the circle directly on the
layout definition.</p>
<p>To be notified when the timer finishes or when users tap on it, implement the corresponding
listener methods in your activity:</p>
public class WearActivity extends Activity implements
DelayedConfirmationView.DelayedConfirmationListener {
private DelayedConfirmationView mDelayedView;
protected void onCreate(Bundle savedInstanceState) {
mDelayedView =
(DelayedConfirmationView) findViewById(;
public void onTimerFinished(View view) {
// User didn't cancel, perform the action
public void onTimerSelected(View view) {
// User canceled, abort the action
<p>To start the timer, add the following code to the point in your activity where users select
an action:</p>
// Two seconds to cancel the action
// Start the timer
<div style="float:right;margin-left:25px;width:210px;margin-top:15px">
<img src="{@docRoot}wear/images/08_uilib.png" width="200" height="200" alt=""/>
<p class="img-caption" style="text-align:center;margin-left:-5px"><strong>Figure 2:</strong>
A confirmation animation.</p>
<h2 id="show-confirmation">Show Confirmation Animations</h2>
<p>To show a confirmation animation when users complete an action in your app, create an intent
that starts <code>ConfirmationActivity</code> from one of your activities. You can specify
one of the these animations with the <code>EXTRA_ANIMATION_TYPE</code> intent extra:</p>
<p>You can also add a message that appears under the confirmation icon.</p>
<p>To use the <code>ConfirmationActivity</code> in your app, first declare this activity in your
manifest file:</p>
<p>Then determine the result of the user action and start the activity with an intent:</p>
Intent intent = new Intent(this, ConfirmationActivity.class);
<p>After showing the confirmation animation, <code>ConfirmationActivity</code> finishes and your
activity resumes.</p>