生活随笔
收集整理的這篇文章主要介紹了
Android 动态壁纸
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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的狀態 |
附錄
- GURU - Android Live wallpaper Tutorial
總結
以上是生活随笔為你收集整理的Android 动态壁纸的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。