Android Wear 进阶 - 3 Creating Custom UIs for Wear Devices 创建自定义的手表设备UIs

Creating Custom UIs for Wear Devices

<翻译>创建自定义的手表设备UIs
Previous Next Get started

Dependencies and Prerequisites

  • Android 4.4W (API level 20) or higher on the wearable device

User interfaces for wearable apps differ significantly from those built for handheld devices. Apps for wearables should follow the Android Weardesign principles and implement the recommendedUI patterns, which ensure a consistent user experience across apps that is optimized for wearables.

This class teaches you how to create custom UIs for your wearable apps and custom notifications that look good on any Android Wear device by implementing these UI patterns:

  • Cards
  • Countdowns and confirmations
  • Long press to dismiss
  • 2D Pickers
  • Selection lists

The Wearable UI Library, which is part of the Google Repository in the Android SDK, provides classes that help you implement these patterns and create layouts that work on both round and square Android Wear devices.

Note: We recommend using Android Studio for Android Wear development, as it provides project setup, library inclusion, and packaging conveniences. This training assumes you are using Android Studio.

<翻译>依赖和前提准备
手表设备版本为Android 4.4(API level 20)或者更高
手表应用的用户界面和建立在手机上麦你的用户界面有着本质的区别。手表端的应用应该遵循 design principles原则并且实现推荐的 UI patterns,这些保证了为手表端优化过的应用的用户体验始终如一。

这个课程教你如何给  wearable apps 和  custom notifications 创建自定义的UIs,这个UIs通过实现了下面的UI 模式让他们在android wear设备上面显示的很好:
1:卡片
2:读秒Countdowns和确认。
3:长按去解除
4:2D Pickers
5:选择列表

手表UI的库,是Android SDK 中Google 资源库(Repository)中的一部分,提供了一些类,这些类帮助你实现这些模版并且创建可以在圆形和方形的手表设备上面都能运行的布局。
注意:我们建议使用Android Studio 去开发Android Wear。

Lessons



Defining Layouts
Learn how to create layouts that look good on round and square Android Wear devices.
Creating Cards
Learn how to create cards with custom layouts.
Creating Lists
Learn how to create lists that are optimized for wearable devices.
Creating a 2D Picker
Learn how to implement the 2D Picker UI pattern to navigate through pages of data.
Showing Confirmations
Learn how to display confirmation animations when users complete actions.
Exiting Full-Screen Activities
Learn how to implement the long-press-to-dismiss UI pattern to exit full-screen activities.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1: 展示确认窗口

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Showing Confirmations

Previous Next

This lesson teaches you to

  1. Use Automatic Confirmation Timers
  2. Show Confirmation Animations

You should also read

  • Android Wear Design Principles

Confirmations 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.

<翻译>在android 手表应用的确认页使用整个屏幕或者一个比手机端应用大的份额( portion)。这个保证了用户可以看到确认也通过看手机屏幕,并且用户有足够大的目标去取消一个action。(就像我们说出了语音以后,他会有一个取消的按钮)

The Wearable UI Library helps you show confirmation animations and timers in your Android Wear apps:<翻译>手表UI库帮助你显示确认的动画和倒计时在你的android 手表应用中。

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使用自动的确认倒计时



Android Wear 进阶 - 3 Creating Custom UIs for Wear Devices 创建自定义的手表设备UIs_第8张图片

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:

  1. Add a  element to your layout.
  2. Implement the DelayedConfirmationListener interface in your activity.
  3. Set the duration of the timer and start it when the user completes an action.

Add the  element to your layout as follows:

<翻译>为了当用户在你的应用中完成了操作后显示一个确认的动画:

1:添加一个  项目到你的布局中

2:在你的activity 中实现 的接口

3:设置倒计时并且在用户完成了操作后开始及时。

DelayedConfirmationView
    android:id="@+id/delayed_confirm"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:src="@drawable/cancel_circle"
    app:circle_border_color="@color/lightblue"
    app:circle_border_width="4dp"
    app:circle_radius="16dp">

You can assign a drawable resource to display inside the circle with the android:src attribute and configure the parameters of the circle directly on the layout definition.

To be notified when the timer finishes or when users tap on it, implement the corresponding listener methods in your activity:

<翻译>你可以通过android:src 属性来将一个drawable 的资源分配显示在圆圈中,并且配置圆圈的参数在布局中。

为了在倒计时完成后或者用户取消了之后收到通知,就要实现相应的监听方法。

public class WearActivity extends Activity implements
                           DelayedConfirmationView.DelayedConfirmationListener {

    private DelayedConfirmationView mDelayedView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wear_activity);

        mDelayedView =
                (DelayedConfirmationView) findViewById(R.id.delayed_confirm);
        mDelayedView.setListener(this);
    }

    @Override
    public void onTimerFinished(View view) {
        // User didn't cancel, perform the action
    }

    @Override
    public void onTimerSelected(View view) {
        // User canceled, abort the action
    }
}

To start the timer, add the following code to the point in your activity where users select an action:

为了启动倒计时,添加下面的代码到你的actiivty的用户选择action的点。

// Two seconds to cancel the action
mDelayedView.setTotalTimeMs(2000);
// Start the timer
mDelayedView.start();
Android Wear 进阶 - 3 Creating Custom UIs for Wear Devices 创建自定义的手表设备UIs_第9张图片

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 theEXTRA_ANIMATION_TYPE intent extra:

  • SUCCESS_ANIMATION
  • FAILURE_ANIMATION
  • OPEN_ON_PHONE_ANIMATION

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:

<翻译>当用户完成了应用中的一个action的时候,为了显示确认的动画,在你的额activit中创建一个intent去启动 ConfirmationActivity 。

你可以通过EXTRA_ANIMATION_TYPE intent extra指定下面的动画。

你也可以在确认的icon 下面添加信息。

为了使用ConfirmationActivity 在你的应用中,首先在清单文件中声明这个actiivty 


  
    ...
    
        android:name="android.support.wearable.activity.ConfirmationActivity">
    
  

Then determine the result of the user action and start the activity with an intent:

然后确定用户的动作结果并且通过intent来启动activity

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.

当显示确认的界面以后,   ConfirmationActivity  完成了,并且你的acitivyt 会resume。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1: 推出全屏的activity

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Exiting Full-Screen Activities


Previous Next

This lesson teaches you to

  1. Disable the Swipe-To-Dismiss Gesture
  2. Implement the Long Press to Dismiss Pattern

You should also read

  • Android Wear Design Principles

By default, users exit Android Wear activities by swiping from left to right. If the app contains horizontally scrollable content, users first have to navigate to the edge of the content and then swipe again from left to right to exit the app.

For more immersive experiences, like an app that can scroll a map in any direction, you can disable the swipe to exit gesture in your app. However, if you disable it, you must implement the long-press-to-dismiss UI pattern to let users exit your app using the DismissOverlayView class from the Wearable UI Library. You must also inform your users the first time they run your app that they can exit using a long press.

For design guidelines about exiting Android Wear activities, see Breaking out of the card.

<翻译> 默认的情况下,用户推出了android 的手机activity通过从左向右的滑动(swip)。如果应用包含了水平的可滑动的内容,用户首先要滑动到内容的边缘,然后在从左向右滑动。

为了真实的体验,例如一个应用可以在地图上面随便的滑动方向,你要在你的应用中禁用滑动退出的手势。然而,如果你禁用了这个,你必须要实现长按取消的UI 模式,这个模式让用户可以通过手表UI库中的 DismissOverlayView 类来退出你的应用。

关于推出android 手表actiivty的设计的向导,请查看Breaking out of the card.

Disable the Swipe-To-Dismiss Gesture禁用互动取消的手势



If the user interaction model of your app interferes with the swipe-to-dismiss gesture, you can disable it for your app. To disable the swipe-to-dismiss gesture in your app, extend the default theme and set theandroid:windowSwipeToDismiss attribute to false:

<翻译>如果你应用的用户的交互模式和滑动取消的手势有冲去,你可以在你的app中禁用这个手势。为了在你的应用中禁用滑动取消的手势,集成默认的主题并且设置属性android:windowSwipeToDismiss为false

 name="AppTheme" parent="Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">falseitem>

If you disable this gesture, you must implement the long-press-to-dismiss UI pattern to let users exit your app, as described in the next section.

<翻译>如果你禁用了这个手势,你必须实现长按取消的UI模式来用用户推出你的应用。

Implement the Long Press to Dismiss Pattern 实现长按取消的模式



To use the DismissOverlayView class in your activity, add this element to your layout definition such that it covers the whole screen and is placed above all other views.

The following example shows how to add the  element:

<翻译> 为了在你的activity 中使用 DismissOverlayView 类,添加这个类型到你的布局定义中。并且这个是覆盖整个界面同时被放在所有的view 的最上面。

下面的例子展示了怎么去添加 项目:


    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    

    DismissOverlayView
        android:id="@+id/dismiss_overlay"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

In your activity, obtain the  element and set some introductory text. This text is shown to users the first time they run your app to inform them that they can exit the app using a long press gesture. Then use a GestureDetector to detect a long press:

<翻译>在你的activity 中,获取  项目然后设置一些介绍的文字。这个文字在用户第一次运行你的app的时候展示给用户通知他们他们可以通过长按的手势来推出。然后使用来检测手势。

public class WearActivity extends Activity {

    private DismissOverlayView mDismissOverlay;
    private GestureDetector mDetector;

    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        setContentView(R.layout.wear_activity);

        // Obtain the DismissOverlayView element
        mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
        mDismissOverlay.setIntroText(R.string.long_press_intro);
        mDismissOverlay.showIntroIfNecessary();

        // Configure a gesture detector
        mDetector = new GestureDetector(this, new SimpleOnGestureListener() {
            public void onLongPress(MotionEvent ev) {
                mDismissOverlay.show();
            }
        });
    }

    // Capture long presses
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return mDetector.onTouchEvent(ev) || super.onTouchEvent(ev);
    }
}

When the system detects a long press gesture, the  element shows an Exit button, which terminates your activity if the user presses it.

<翻译>当系统检测到了一个长按的手势的时候,  会显示一个推出的按钮,如果用户按了这个按钮会将你的actiivty 结束



你可能感兴趣的:(Android,Wear,Develope,Guider)