android Wearable-Creating Wearable Apps and Creating Custom Layouts
2016-01-12 09:19
288 查看
>Creating Wearable Apps:
These are the main differences between handheld and wearable apps:
Wearable apps are relatively small in size and functionality compared to handheld apps. They contain only what makes sense on the wearable, which is usually a small subset of the corresponding handheld app. In general, you should
carry out operations on the handheld when possible and send the results to the wearable.
Users don't download apps directly onto the wearable. Instead, you bundle the wearable app inside the handheld app. When users install the handheld app, the system automatically installs the wearable app. However, for development
purposes, you can still install the wearable app directly to the wearable.
Wearable apps can access much of the standard Android APIs, but don't support the following APIs:
> The following describes the two modes of operation for always-on apps:
InteractiveUse full color with fluid animation in this mode. The app is also responsive to input.AmbientRender the screen with grayscale graphics and do not present any input cues in this mode. This display mode is only supported on devices running Android 5.1 or higher.
If you need to show persistent content on versions prior to Android 5.1, create a notification in the context stream instead.
Note: We recommend using Android Studio for Android Wear development, as it provides project
setup, library inclusion, and packaging conveniences. The rest of this training assumes you're using Android Studio.
> Wearable apps run directly on the wearable device, giving you access to low-level hardware such as sensors, activities, services, and more, right on the wearable.
Before you begin building wearable apps, you must:
Update your SDK tools to version 23.0.0 or higher
The updated SDK tools enable you to build and test wearable apps.
Update your SDK with Android 4.4W.2 (API 20) or higher
The updated platform version provides new APIs for wearable apps.
android手持设备AVD的端口号:5037为adb默认端口
Note: If you can not connect your wearable to your machine via USB, you can try connecting
over Bluetooth.
>As you follow the wizard, enter the following information:
In the Configure your Project window, enter a name for your app and a package name.
In the Form Factors window:
Select Phone and Tablet and select API 9: Android 2.3 (Gingerbread) under Minimum
SDK.
Select Wear and select API 20: Android 4.4 (KitKat Wear) under Minimum
SDK.
In the first Add an Activity window, add a blank activity for mobile.
In the second Add an Activity window, add a blank activity for Wear.
Note: The wear module
also contains a "Hello World" activity that uses a
This class inflates a layout based on whether the device's screen is round or square. The
is one of the UI widgets that the wearable
support library provides.
The Android
v4 support library (or v13, which includes v4) contains the APIs to extend your existing notifications on handhelds to support wearables.
>
Creating Custom Layouts
You should create custom layouts only when necessary. Read the design
guidelines for information on how to design great wearable apps.
Note: When the notification is peeking on the homescreen, the system displays it with a standard
template that it generates from the notification's semantic data. This template works well on all watchfaces. When users swipe the notification up, they'll then see the custom activity for the notification.
> Here are some of the major classes in the Wearable UI Library:
and can box its children in the center square of a round screen.
to generate the pages that the view shows.
that represents each page as a fragment.
that identifies the current page in relation to all available pages on the current row.
is optimized for ease of use on small screen wearable devices. It displays a vertically scrollable list of items, and automatically snaps to the nearest item when the user stops scrolling.
Android Wear apps can control what’s displayed on the wearable device screen while the device is in a low-power ambient mode. Wear apps that run in both ambient and interactive
mode are called always-onapps.
After you complete the project configuration, extend the
which provides all the methods you need to enable ambient mode in your app.
To realize battery savings, updates should be no more than once every 10 seconds. In practice, however, you should update your app less frequently than that.
》 For apps that require more frequent updates, such as a fitness, time-keeping, and travel information apps, use an
to wake the processor and update the screen more frequently.
To implement an alarm that updates content more frequently in ambient mode, follow these steps:
Prepare the alarm manager.
Set the frequency of the updates.
Schedule the next update when the activity switches to ambient mode or is currently in ambient mode.
Cancel the alarm when the activity switches to interactive mode or the activity is stopped
Note: The alarm manager may create new instances of your activity as they are triggered. To prevent this situation, ensure that your activity is declared with the
When the device switches to interactive mode, cancel the alarm in the
These are the main differences between handheld and wearable apps:
Wearable apps are relatively small in size and functionality compared to handheld apps. They contain only what makes sense on the wearable, which is usually a small subset of the corresponding handheld app. In general, you should
carry out operations on the handheld when possible and send the results to the wearable.
Users don't download apps directly onto the wearable. Instead, you bundle the wearable app inside the handheld app. When users install the handheld app, the system automatically installs the wearable app. However, for development
purposes, you can still install the wearable app directly to the wearable.
Wearable apps can access much of the standard Android APIs, but don't support the following APIs:
android.webkit
android.print
android.app.backup
android.appwidget
android.hardware.usb
> The following describes the two modes of operation for always-on apps:
InteractiveUse full color with fluid animation in this mode. The app is also responsive to input.AmbientRender the screen with grayscale graphics and do not present any input cues in this mode. This display mode is only supported on devices running Android 5.1 or higher.
If you need to show persistent content on versions prior to Android 5.1, create a notification in the context stream instead.
Note: We recommend using Android Studio for Android Wear development, as it provides project
setup, library inclusion, and packaging conveniences. The rest of this training assumes you're using Android Studio.
> Wearable apps run directly on the wearable device, giving you access to low-level hardware such as sensors, activities, services, and more, right on the wearable.
Before you begin building wearable apps, you must:
Update your SDK tools to version 23.0.0 or higher
The updated SDK tools enable you to build and test wearable apps.
Update your SDK with Android 4.4W.2 (API 20) or higher
The updated platform version provides new APIs for wearable apps.
adb -d forward tcp:5601 tcp:5601
android手持设备AVD的端口号:5037为adb默认端口
Note: If you can not connect your wearable to your machine via USB, you can try connecting
over Bluetooth.
>As you follow the wizard, enter the following information:
In the Configure your Project window, enter a name for your app and a package name.
In the Form Factors window:
Select Phone and Tablet and select API 9: Android 2.3 (Gingerbread) under Minimum
SDK.
Select Wear and select API 20: Android 4.4 (KitKat Wear) under Minimum
SDK.
In the first Add an Activity window, add a blank activity for mobile.
In the second Add an Activity window, add a blank activity for Wear.
Note: The wear module
also contains a "Hello World" activity that uses a
WatchViewStub.
This class inflates a layout based on whether the device's screen is round or square. The
WatchViewStubclass
is one of the UI widgets that the wearable
support library provides.
The Android
v4 support library (or v13, which includes v4) contains the APIs to extend your existing notifications on handhelds to support wearables.
>
Creating Custom Layouts
You should create custom layouts only when necessary. Read the design
guidelines for information on how to design great wearable apps.
Note: When the notification is peeking on the homescreen, the system displays it with a standard
template that it generates from the notification's semantic data. This template works well on all watchfaces. When users swipe the notification up, they'll then see the custom activity for the notification.
> Here are some of the major classes in the Wearable UI Library:
BoxInsetLayoutA
FrameLayoutobject that's aware of screen shape
and can box its children in the center square of a round screen.
CardFragmentA fragment that presents content within an expandable, vertically scrollable card.
CircledImageViewAn image view surrounded by a circle.
ConfirmationActivityAn activity that displays confirmation animations after the user completes an action.
CrossFadeDrawableA drawable that contains two child drawables and provides methods to directly adjust the blend between the two.
DelayedConfirmationViewA view that provides a circular countdown timer, typically used to automatically confirm an operation after a short delay has elapsed.
DismissOverlayViewA view for implementing long-press-to-dismiss.
GridViewPagerA layout manager that allows the user to navigate both vertically and horizontally through pages of data. You supply an implementation of a
GridPagerAdapterinstance
to generate the pages that the view shows.
GridPagerAdapterAn adapter that supplies pages to a
GridViewPagerobject.
FragmentGridPagerAdapterAn implementation of a
GridPagerAdapterinstance
that represents each page as a fragment.
DotsPageIndicatorA page indicator for a
GridViewPagerimplementation
that identifies the current page in relation to all available pages on the current row.
WatchViewStubA class that can inflate a specific layout, depending on the shape of the device's screen.
WearableListViewAn alternative version of a
ListViewobject that
is optimized for ease of use on small screen wearable devices. It displays a vertically scrollable list of items, and automatically snaps to the nearest item when the user stops scrolling.
Android Wear apps can control what’s displayed on the wearable device screen while the device is in a low-power ambient mode. Wear apps that run in both ambient and interactive
mode are called always-onapps.
After you complete the project configuration, extend the
WearableActivityclass,
which provides all the methods you need to enable ambient mode in your app.
To realize battery savings, updates should be no more than once every 10 seconds. In practice, however, you should update your app less frequently than that.
》 For apps that require more frequent updates, such as a fitness, time-keeping, and travel information apps, use an
AlarmManagerobject
to wake the processor and update the screen more frequently.
To implement an alarm that updates content more frequently in ambient mode, follow these steps:
Prepare the alarm manager.
Set the frequency of the updates.
Schedule the next update when the activity switches to ambient mode or is currently in ambient mode.
Cancel the alarm when the activity switches to interactive mode or the activity is stopped
Note: The alarm manager may create new instances of your activity as they are triggered. To prevent this situation, ensure that your activity is declared with the
android:launchMode="singleInstance"parameter in the manifest.
private AlarmManager mAmbientStateAlarmManager; private PendingIntent mAmbientStatePendingIntent; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAmbientEnabled(); mAmbientStateAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent ambientStateIntent = new Intent(getApplicationContext(), MainActivity.class); mAmbientStatePendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, ambientStateIntent, PendingIntent.FLAG_UPDATE_CURRENT); ... }
@Override public void onDestroy() { mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent); super.onDestroy(); }
When the device switches to interactive mode, cancel the alarm in the
onExitAmbient()method:
@Override public void onExitAmbient() { super.onExitAmbient(); mAmbientStateAlarmManager.cancel(mAmbientStatePendingIntent); }
If your app should not be installed or updated on devices with Android versions prior to 5.1, update your manifest with the following:
<uses-library android:name="com.google.android.wearable" android:required="true" />
相关文章推荐
- Android资源目录文件夹介绍
- 推荐提升Android性能的建议
- Android简介
- Android编程经典代码集锦(复制,粘贴,浏览器调用,Toast显示,自定义Dialog等)
- Android手机多媒体的应用
- 微信应用号QQ群(321518204)欢迎大家加入紧跟潮流
- 《Android源码设计模式解析与实战》读书笔记(十九)
- 最优雅退出 Android 应用程序的 6 种方式
- 推荐提升 Android 性能的建议
- Android 自己定义ScrollView ListView 体验各种纵向滑动的需求
- ios去时间戳
- Android开发之浏览器用法实例详解(调用uc,opera,qq浏览器访问网页)
- 推荐提升 Android 性能的建议
- android WindowManager解析与骗取QQ密码案例分析
- 推荐提升 Android 性能的建议
- Android之Animation-list实现逐帧动画
- IOS-调用系统资源
- android surfaceview播放视频前,出现黑屏
- android 选择图片 剪裁 拍照 兼容所有版本的代码
- 微信公众号开发(十六):微信的一些其他的常用接口测试代码