WatchFaceService

public abstract class WatchFaceService
extends WallpaperService

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.wallpaper.WallpaperService
           ↳ android.support.wearable.watchface.WatchFaceService
Known Direct Subclasses


WallpaperService的子类, WallpaperService包含WallpaperService.Engine ,用于显示表盘生命周期的回调。 如果你想为可穿戴设备创建一个表盘,你应该用这个来代替香草WallpaperService

与壁纸服务类似,表面服务必须仅实现一种方法: onCreateEngine() 但是,它也必须创建一个内部类WatchFaceService.Engine的子类。 大多数表盘引擎将实施以下方法:

大多数表盘引擎也将执行 onInterruptionFilterChanged(int)以根据用户请求的 onInterruptionFilterChanged(int)来更新视图。

对于在环境模式下发生的更新,将会保持唤醒锁,以便设备在表面完成绘制之前不会进入休眠状态。

在您的应用程序中注册表盘表面与使用其他几个步骤注册壁纸类似。 首先,表面需要唤醒锁定权限:

 <uses-permission android:name="android.permission.WAKE_LOCK" />
 

其次,您的表盘服务声明需要预览元数据:

 <meta-data
     android:name="com.google.android.wearable.watchface.preview"
     android:resource="@drawable/preview_face" />
 <meta-data
     android:name="com.google.android.wearable.watchface.preview_circular"
     android:resource="@drawable/preview_face_circular" />
 

最后,您需要添加一个特殊的意图过滤器,以便您的表盘可以被检测到:

 <intent-filter>
     <action android:name="android.service.wallpaper.WallpaperService" />
     <category
         android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
 </intent-filter>
 

欲了解更多信息,请咨询: https://developer.android.com/training/wearables/watch-faces/index.html

Summary

Nested classes

class WatchFaceService.Engine

表盘的实际执行情况。

@interface WatchFaceService.TapType

 

Constants

int INTERRUPTION_FILTER_ALARMS

getInterruptionFilter()返回并传递给 onInterruptionFilterChanged(int)

int INTERRUPTION_FILTER_ALL

getInterruptionFilter()返回并传递给 onInterruptionFilterChanged(int)

int INTERRUPTION_FILTER_NONE

getInterruptionFilter()返回并传递给 onInterruptionFilterChanged(int)

int INTERRUPTION_FILTER_PRIORITY

getInterruptionFilter()返回并传递给 onInterruptionFilterChanged(int)

int INTERRUPTION_FILTER_UNKNOWN

getInterruptionFilter()返回并传递给 onInterruptionFilterChanged(int)

String PROPERTY_BURN_IN_PROTECTION

传递给 onPropertiesChanged(Bundle)包中的属性指示是否需要 onPropertiesChanged(Bundle)烧保护。

String PROPERTY_LOW_BIT_AMBIENT

传递给 onPropertiesChanged(Bundle)包中的属性指示设备是否具有低位环境模式。

int TAP_TYPE_TAP

用于onTapCommaned表示发生了尚未被其他活动消耗的表盘上的“向上”事件。

int TAP_TYPE_TOUCH

在onTapCommand中用于指示表盘上的“向下”触摸事件。

int TAP_TYPE_TOUCH_CANCEL

在onTapCaommand中用于指示先前的TAP_TYPE_TOUCH触摸事件已被取消。

Inherited constants

From class android.service.wallpaper.WallpaperService
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2

Public constructors

WatchFaceService()

Public methods

abstract WatchFaceService.Engine onCreateEngine()

Inherited methods

From class android.service.wallpaper.WallpaperService
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

INTERRUPTION_FILTER_ALARMS

int INTERRUPTION_FILTER_ALARMS

getInterruptionFilter()返回并传递给onInterruptionFilterChanged(int) 该值表示用户请求仅被警报中断。

常量值:4(0x00000004)

INTERRUPTION_FILTER_ALL

int INTERRUPTION_FILTER_ALL

getInterruptionFilter()返回并传递给onInterruptionFilterChanged(int) 此值表示用户请求查看所有通知。

常数值:1(0x00000001)

INTERRUPTION_FILTER_NONE

int INTERRUPTION_FILTER_NONE

getInterruptionFilter()返回并传递给onInterruptionFilterChanged(int) 这个值意味着用户请求不要看到任何通知。

常量值:3(0x00000003)

INTERRUPTION_FILTER_PRIORITY

int INTERRUPTION_FILTER_PRIORITY

getInterruptionFilter()返回并传递给onInterruptionFilterChanged(int) 该值表示用户请求仅查看高优先级通知。

常量值:2(0x00000002)

INTERRUPTION_FILTER_UNKNOWN

int INTERRUPTION_FILTER_UNKNOWN

getInterruptionFilter()返回并传递给onInterruptionFilterChanged(int) 该值表示中断过滤器不可用。

常量值:0(0x00000000)

PROPERTY_BURN_IN_PROTECTION

String PROPERTY_BURN_IN_PROTECTION

捆绑中的属性传递给onPropertiesChanged(Bundle)以指示是否需要onPropertiesChanged(Bundle)烧保护。 当此属性设置为true时,视图会在环境模式下周期性移动。 为确保内容不会偏离屏幕,观看脸部应避免将内容放置在屏幕边缘的10个像素内。 手表表面还应该避免白色的纯色区域,以防止像素老化。 这两个要求仅适用于环境模式,并且只有当此属性设置为true时才适用。

常量值:“burn_in_protection”

PROPERTY_LOW_BIT_AMBIENT

String PROPERTY_LOW_BIT_AMBIENT

传递给onPropertiesChanged(Bundle)包中的属性指示设备是否具有低位环境模式。 当此属性设置为true时,屏幕支持环境模式下每种颜色的较少位数。 在这种情况下,表盘应在环境模式下禁用消除锯齿功能。

常量值:“low_bit_ambient”

TAP_TYPE_TAP

int TAP_TYPE_TAP

用于onTapCommaned表示发生了尚未被其他活动消耗的表盘上的“向上”事件。 TAP_TYPE_TOUCH将始终首先发生。 如果发送TAP_TYPE_TOUCH_CANCEL,则不会发生此事件。

常量值:2(0x00000002)

TAP_TYPE_TOUCH

int TAP_TYPE_TOUCH

在onTapCommand中用于指示表盘上的“向下”触摸事件。

常量值:0(0x00000000)

TAP_TYPE_TOUCH_CANCEL

int TAP_TYPE_TOUCH_CANCEL

在onTapCaommand中用于指示先前的TAP_TYPE_TOUCH触摸事件已被取消。 这通常发生在手表表面被触摸但发生移动或长按时。

常数值:1(0x00000001)

Public constructors

WatchFaceService

WatchFaceService ()

Public methods

onCreateEngine

WatchFaceService.Engine onCreateEngine ()

Returns
WatchFaceService.Engine