WallpaperService
继承关系
- java.lang.Object
- ↳android.content.Context
- ↳android.content.ContextWrapper
- ↳android.app.Service
- ↳android.service.wallpaper.WallpaperService
概述
这是一个用于显示动态壁纸的Wallpaper Service。这个Service本身做的事情很少,它仅仅是在需要的时候创建一个WallpaperService.Engine对象而已。因此,当需要自定义动态壁纸的时候,我们需要创建一个Wallpaper Service的子类,同时重写包含在WallpaperService其中的Engine子类的onCreateEngine()方法。
方法
内部类
类型 | 方法名 | 介绍 |
---|
class | WallpaperService.Engine | The actual implementation of a wallpaper.真正实现动态壁纸渲染的功能类 |
公有方法
类型 | 方法名 | 介绍 |
---|
final IBinder | onBind(Intent intent) | Implement to return the implementation of the internal accessibility service interface.提供接口供用户使用 |
void | onCreate() | 开始创建的时候被调用 |
abstact WallpaperService.Engine | onCreateEngine() | 当需要返回一个新的WallpaperService.Engine对象的时候被调用 |
void | onDestory() | 当不被使用的时候将会被调用。 |
保护方法
类型 | 方法名 | 介绍 |
---|
void | dump(FileDescriptor fd,PrintWriter out,String[] args) | 向流中写入WallpaperService的状态 |
WallpaperService.Engine
继承关系
- java.lang.Object
- ↳android.service.wallpaper.WallpaperService.Engine
概述
动态壁纸的渲染实现主要靠这个内部类来实现。一个动态壁纸服务(Wallpaper Service)需要考虑多个对象(instances)同时运行的情况(例如:该动态壁纸正在应用且用户在动态壁纸设置中预览该动态壁纸)。因此,你需要使用onCreateEngine()来返回明确的具体的Engine对象。
方法
公有类
类型 | 方法名 | 介绍 |
---|
int | getDesiredminimunHeight() | 返回壁纸需要的最小高度,假如返回的值小于等于0,就返回默认显示的高度 |
int | getDesiredminimunWidth() | 返回壁纸需要的最小宽度,假如返回的值小于等于0,就返回默认显示的宽度 |
SurfaceHolder | getSurfaceHolder() | 可以在Wallpaper渲染时候进行一系列设置,如设置样式、设置宽高、设置透明度、保持屏幕常亮、锁定画布、解锁画布等等。 |
boolean | isPreview() | 当处于预览界面的时候,返回true。 |
boolean | isVisible() | 返回当前动态壁纸的状态。可视为真,不可视为假 |
Bundle | onCommand(String action,int x,int y,int z,Bundle extras,boolean resultRequested) | 执行发送到Wallpaper的指令(Command),默认返回null。 |
void | onCreate(SurfaceHolder surfaceHolder) | 当刚创建Engine的时候被调用 |
void | onDesiredSizeChanged(int desiredWidth,int desireHeight) | 当要求的宽高变化的时候被调用。 |
void | onDestroy() | 当Engine被销毁的时候被调用。 |
void | onOffsetsChanged(float xOffsets,float yOffsets,float xOffsetStep,float yOffsetStep,int xPixelOffset,int yPixelOffset) | 提供页面容器中的wallpaper的偏移量变化参数。 |
void | onSurfaceChanged(SurfaceHolder holder,int format,int width,int height) | 当SurfaceHolder的宽高发生变化的时候被调用。 |
void | onSurfaceCreated(SurfaceHolder surfaceHolder) | Surface被创建的时候被调用。 |
void | surfaceDestroyed(SurfaceHolder surfaceHolder) | Surface被销毁的时候被调用。 |
void | onSurfaceRedrawNeeded() | 当需要重新绘制Surface的时候被调用。 |
void | onTouchEvent() | 当有点击事件发生的时候被调用。 |
void | onVisibility() | 当从可视状态变为隐藏状态,或者隐藏状态变为可视状态的时候被调用。 |
void | setOffsetNotificationsEnabled() | 是否接收wallpaper的偏移通知。 |
void | setTouchEventsEnabled() | 是否接收点击事件 |
保护类
类型 | 方法名 | 介绍 |
---|
void | dump(String prefix,FileDescriptor fd,PrintWriter out,String[] args) | 向流中写入WallpaperService的状态 |
附录