adroid Wear-Designing Watch Faces and Building a Watch Face Service
Android Wear enables you to create custom watch faces for Wear devices. When users install a handheld app that contains awearable app with watch faces, they become available in the Android Wear companion app on the handheld device and in the watch face picker on the wearable device.
Note: We recommend
using Android Studio for
Android Wear development, as it provides project setup, library inclusion, and packaging conveniences.
> Designing Watch Faces
Similar to the process of designing a traditional watch face, creating one for Android Wear is an
exercise in visualizing time clearly. Android Wear devices provide advanced capabilities for watch faces that you can leverage in your designs, such as vibrant colors, dynamic backgrounds, animations, and data integration. However, there are also many design
considerations that you must take into account.
> As you plan the look of your watch face and what kind of information it should present to users, consider these design guidelines:
- Plan for square and round devices
- Your design should work for both square and round Android Wear devices, including devices with insets on the bottom of the screen.
- Support all display modes
- Your watch face should support ambient mode with limited color and interactive mode with full color and animations.
- Optimize for special screen technologies
- In ambient mode, your watch face should keep most pixels black. Depending on the screen technology, you may need to avoid large blocks of white pixels, use only black and white, and disable anti-aliasing.
- Accommodate system UI elements
- Your design should ensure that system indicators remain visible and that users can still read the time when notification cards appear on the screen.
- Integrate data
- Your watch face can leverage sensors and cellular connectivity on the companion mobile device to show user data relevant to the context, such as the weather for the day or their next calendar event.
- Provide configuration options
- You can let users configure some aspects of your design (like colors and sizes) on the wearable or on the Android Wear companion app.
To increase battery life, the application code that draws your watch face in ambient mode should
be relatively simple. You usually draw outlines of shapes using a limited set of colors in this mode. In interactive mode, you can use full color, complex shapes, gradients, and animations to draw your watch face.
> Building a Watch Face Service
Watch faces in Android Wear are implemented asservices and
packaged inside a wearable app.
When users install a handheld app that contains a wearable app with watch faces, these watch faces become available in the Android
Wear companion app on the handheld device and in the watch face picker on the wearable. When users select one of the available watch faces, the wearable device shows the watch
face and invokes its service callback methods as required.
Android Studio creates a project with the wear
and mobile
modules.
The Wearable Support Library provides the necessary classes that you extend to create
watch face implementations. The Google Play services client libraries (play-services
and play-services-wearable
) are required to sync data items between the companion device and the wearable with the Wearable
Data Layer API.
Android Studio automatically adds the required entries in your build.gradle
files when you create the project in the instructions above.
>Watch faces require the PROVIDE_BACKGROUND
and WAKE_LOCK
permissions.
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" /> <uses-permission android:name="android.permission.WAKE_LOCK" />> To implement a watch face, you extend the
CanvasWatchFaceService
and CanvasWatchFaceService.Engine
classes,
and then you override the callback methods in the CanvasWatchFaceService.Engine
class.
These classes are included in the Wearable
Support Library.
The following snippet outlines the key methods you need to implement:
public class AnalogWatchFaceService extends CanvasWatchFaceService { @Override public Engine onCreateEngine() { /* provide your watch face implementation */ return new Engine(); } /* implement service callback methods */ private class Engine extends CanvasWatchFaceService.Engine { @Override public void onCreate(SurfaceHolder holder) { super.onCreate(holder); /* initialize your watch face */ } @Override public void onPropertiesChanged(Bundle properties) { super.onPropertiesChanged(properties); /* get device features (burn-in, low-bit ambient) */ } @Override public void onTimeTick() { super.onTimeTick(); /* the time changed */ } @Override public void onAmbientModeChanged(boolean inAmbientMode) { super.onAmbientModeChanged(inAmbientMode); /* the wearable switched between modes */ } @Override public void onDraw(Canvas canvas, Rect bounds) { /* draw your watch face */ } @Override public void onVisibilityChanged(boolean visible) { super.onVisibilityChanged(visible); /* the watch face became visible or invisible */ } } }
The CanvasWatchFaceService
class
provides an invalidate mechanism similar to the View.invalidate()
method.
You can call the invalidate()
method
throughout your implementation when you want the system to redraw the watch face. You can only use the invalidate()
method
in the main UI thread. To invalidate the canvas from another thread, call the postInvalidate()
method.
>how to register a watch face implementation under the application
element:
<service android:name=".AnalogWatchFaceService" android:label="@string/analog_name" android:allowEmbedded="true" android:taskAffinity="" android:permission="android.permission.BIND_WALLPAPER" > <meta-data android:name="android.service.wallpaper" android:resource="@xml/watch_face" /> <meta-data android:name="com.google.android.wearable.watchface.preview" android:resource="@drawable/preview_analog" /> <meta-data android:name="com.google.android.wearable.watchface.preview_circular" android:resource="@drawable/preview_analog_circular" /> <intent-filter> <action android:name="android.service.wallpaper.WallpaperService" /> <category android:name= "com.google.android.wearable.watchface.category.WATCH_FACE" /> </intent-filter> </service>
The android.service.wallpaper
metadata entry specifies the watch_face.xml
resource file, which contains a wallpaper
element:
<?xml version="1.0" encoding="UTF-8"?> <wallpaper xmlns:android="http://schemas.android.com/apk/res/android" />
Your wearable app can contain more than one watch face. You must add a service entry to the manifest file of the wearable app for each of your watch face implementations.
相關文章
- android wear-Showing Information in Watch Faces and Creating InteractiveWatch Faces, Providing ConfiAndroidORM
- android wear-Drawing Watch FacesAndroid
- computed watcher和user watcher的區別
- Apple Watch 學習之路 初見Watch 應用APP
- vue 3 學習筆記 (六)——watch 、watchEffect 新用法Vue筆記
- WatchKit程式設計指南:WatchKit Apps–表格程式設計APP
- tmpwatch 命令整理
- Vue watch選項Vue
- linux watch命令Linux
- FileSystemWatch使用示例
- PHP的Ev教程二(watcher和watche回撥等)PHP
- 華為Watch 3智慧手錶曝光:或將命名為Watch X
- vue3如何進行資料監聽watch/watchEffectVue
- 【Zookeeper】原始碼分析之Watcher機制(二)之WatchManager原始碼
- 蘋果手錶APPLE WATCH露出 iwatch又添新功能蘋果APP
- WatchKit程式設計指南:WatchKit Apps–App概要程式設計APP
- Apple Watch軟體更新將帶來“Find my Watch”功能APP
- Apple Watch watch OS 3更新 九大新特性彙總APP
- watchOS 4釋出,我們來聊聊Apple Watch設計APP
- apple watch升級watch os3教程(圖文詳解)APPS3
- WatchKit程式設計指南:WatchKit Apps–介面導航程式設計APP
- 華碩釋出ZenWatch 2手錶 多處效仿Apple WatchAPP
- apple watch 2有哪些功能 apple watch 2功能介紹APP
- [nodemon] Internal watch failed: watch ENOSPC錯誤解決辦法AI
- PostgreSQL DBA(185) - watchSQL
- Zookeeper--Watch機制
- Zookeeper watch機制原理
- vue之watch的用法Vue
- ZooKeeper Watcher機制
- Apple watch 入門APP
- tailf報錯limitofinotifywatcheswasreachedAIMIT
- Oracle OS Watcher 工具Oracle
- System.Diagnostics.Stopwatch
- tmpwatch命令詳解
- Hyperf - 熱更新Watcher
- (AirWatch系列之三)Airwatch的移動應用程式管理概述AI
- Apple Watch watchOS 3智慧手錶系統亮點介紹APP
- Apple Watch升級體驗watchOS 3 Beta1安裝APP