This lesson teaches you to
The confirmations that are displayed in Wear OS 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.
In addition to the reading the sections below, you should review the Wear OS Design Principles.
The Wearable UI Library helps you show confirmation animations and timers in your apps:
- Confirmation timers
- Automatic confirmation timers show users an animated timer that lets them cancel an action they just performed.
- Confirmation animations
- Confirmation animations give users visual feedback when they complete an action.
The following sections show you how to implement these patterns.
Use Automatic Confirmation Timers
Figure 1: A confirmation timer.
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.
To show a confirmation timer when users complete an action in your app:
- Add a
<CircularProgressLayout>element to your layout. - Implement the
OnTimerFinishedListenerinterface in your activity. - Set the duration of the timer and start it when the user completes an action.
To use CircularProgressLayout in your app, you need to include the following
dependencies (or later versions)
in the build.gradle file of your wear module:
dependencies{
...
compile 'com.android.support:wear:26.0.0'
compile 'com.android.support:support-compat:26.0.0'
compile 'com.android.support:support-core-utils:26.0.0'
compile 'com.android.support:support-core-ui:26.0.0'
...
}
You can add the
<CircularProgressLayout>
element to your layout as follows:
<android.support.wear.widget.CircularProgressLayout
android:id="@+id/circular_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
app:backgroundColor="@color/darkblue"
app:colorSchemeColors="@color/lightblue"
app:strokeWidth="4dp">
<ImageView
android:id="@+id/image_view"
android:src="@drawable/cancel"
android:layout_width="40dp"
android:layout_height="40dp" />
</android.support.wear.widget.CircularProgressLayout>
You can also add any view as a child to CircularProgressLayout to display a progress
timer around it. The above example uses an ImageView, but it could also be a
TextView to show text inside.
Note: The
CircularProgressLayout class replaces a similar,
deprecated class in the Wearable Support Library.
To be notified when the timer finishes or when users tap on it, implement the corresponding listener methods in your activity:
public class WearActivity extends Activity implements
CircularProgressLayout.OnTimerFinishedListener, View.OnClickListener {
private CircularProgressLayout mCircularProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wear_activity);
mCircularProgress =
(CircularProgressLayout) findViewById(R.id.circular_progress);
mCircularProgress.setOnTimerFinishedListener(this);
mCircularProgress.setOnClickListener(this);
}
@Override
public void onTimerFinished(CircularProgressLayout layout) {
// User didn't cancel, perform the action
}
@Override
public void onClick(View view) {
if (view.equals(mCircularProgress)) {
// User canceled, abort the action
mCircularProgress.stopTimer();
}
}
}
To start the timer, add the following code to the point in your activity where users select an action:
// Two seconds to cancel the action mCircularProgress.setTotalTime(2000); // Start the timer mCircularProgress.startTimer();
Figure 2: A confirmation animation.
Show Confirmation Animations
To show a confirmation animation when users complete an action in your app, create an intent
that starts
ConfirmationActivity
from one of your activities. You can specify
one of the these animations with the
EXTRA_ANIMATION_TYPE
intent extra:
You can also add a message that appears under the confirmation icon.
To use the
ConfirmationActivity
in your app, first declare this activity in your manifest file:
<manifest>
<application>
...
<activity
android:name="android.support.wearable.activity.ConfirmationActivity">
</activity>
</application>
</manifest>
Then determine the result of the user action and start the activity with an intent:
Intent intent = new Intent(this, ConfirmationActivity.class);
intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
ConfirmationActivity.SUCCESS_ANIMATION);
intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE,
getString(R.string.msg_sent));
startActivity(intent);
After showing the confirmation animation,
ConfirmationActivity
finishes and your activity resumes.


