Wearable Support Library 库提供了一些必须的类,你可以继承这些类去实现表盘。Google play services 客户端库(play-services 和 play-services-wearable)库是用来同步手机APP和手表APP之间数据。可以参见 Wearable Data Layer API
publicclassAnalogWatchFaceServiceextendsCanvasWatchFaceService {@Overridepublic Engine onCreateEngine() {
/* provide your watch face implementation */returnnew Engine();
}
/* implement service callback methods */privateclassEngineextendsCanvasWatchFaceService.Engine {@OverridepublicvoidonCreate(SurfaceHolder holder) {
super.onCreate(holder);
/* initialize your watch face */
}
@OverridepublicvoidonPropertiesChanged(Bundle properties) {
super.onPropertiesChanged(properties);
/* get device features (burn-in, low-bit ambient) */
}
@OverridepublicvoidonTimeTick() {
super.onTimeTick();
/* the time changed */
}
@OverridepublicvoidonAmbientModeChanged(boolean inAmbientMode) {
super.onAmbientModeChanged(inAmbientMode);
/* the wearable switched between modes */
}
@OverridepublicvoidonDraw(Canvas canvas, Rect bounds) {
/* draw your watch face */
}
@OverridepublicvoidonVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
/* the watch face became visible or invisible */
}
}
}