您的位置:首页 > 移动开发 > Android开发

android_WallpaperService和Launcher

2013-10-24 12:55 288 查看
CubeWallpaper2Settings的Demo

WallpaperService --> Service --> ContextWrapper --> Context --> Object.

A wallpaper service is responsible for showing a live wallpaper behind applications that would like to sit on top of it. This service object itself does very little -- its only purpose is to generate instances of WallpaperService.Engine as needed. Implementing
a wallpaper thus involves subclassing from this, subclassing an Engine implementation, and implementing onCreateEngine() to return a new instance of your engine.

WallpaperService.Engine类 --> Object.

The actual implementation of a wallpaper. A wallpaper service may have multiple instances running (for example as a real wallpaper and as a preview), each of which is represented by its own Engine instance. You must implement onCreateEngine() to return your
concrete Engine implementation.

canvas.translate(x,y),以原来的原点(偏移后的)再偏移。也就是说原来在(100,100),然后translate(1,1)新的坐标原点在(101,101)而不是(1,1)

去除锯齿有2种方法,mPaint.setAntiAlias(true);canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG|Paint.ANTI_ALIAS_FLAG));

Canvas.rotate与clipRect,将画布进行旋转,达到画布上的图像成旋转的效果。步骤:利用clipRect功能是建立一个裁剪区;保存canvas状态;将该裁剪区进行旋转;进行画布上的操作(必须在3之后);恢复canvas状态

Path类 --> Object.The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.drawPath(path, paint), either filled or stroked (based on the paint's
Style), or it can be used for clipping or to draw text on a path.

Home的Demo:

注册监听壁纸更换Receiver 和 Package包的安装/删除等信息变化的Receiver;

在Android系统中,壁纸窗口和输入法窗口一样,都是一种特殊类型的窗口,而且它们都是喜欢和一个普通的Activity窗口缠绵在一起。大家可以充分地想象这样的一个3W场景:输入法窗口在上面,壁纸窗口在下面,Activity窗口夹在它们的中间。



桌面:android.intent.category.HOME; 设置桌面背景:android.intent.action.SET_WALLPAPER;

在Intent.java(frameworks/base/core/java/android/content/Intent.java)中添加String常量,之后修改framework中和CATEGORY_HOME相关的所有的地方。

frameworks/base/services/java/com/android/server/am/ActivityManagerService.java;

frameworks/base/services/java/com/android/server/am/HistoryRecorder.java;

frameworks/policies/base/mid/com/android/internal/policy/impl/MidWindowManager.java

frameworks/policies/base/mid/com/android/internal/policy/impl/RecentApplicationsDialog.java

frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java

frameworks/policies/base/phone/com/android/internal/policy/impl/RecentApplicationsDialog.java





ContextWrapper类,Proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context.

mContextWrapper.databaseList(),Returns an array of strings naming the private databases associated with this Context's application package.

mContextWrapper.fileList(),Returns an array of strings naming the private files associated with this Context's application package.

mContextWrapper.getClassLoader(),Return a class loader you can use to retrieve classes in this package.

mContextWrapper.getMainLooper(),Return the Looper for the main thread of the current process.

mContextWrapper.isRestricted(),Indicates whether this Context is restricted.

WallpaperManager类,Provides access to the system wallpaper. With WallpaperManager, you can get the current wallpaper, get the desired dimensions for the wallpaper, set the wallpaper, and more. Get an instance of WallpaperManager with getInstance().

罗升阳博客:http://blog.csdn.net/luoshengyang/article/details/8550820

在Android系统中,壁纸窗口和输入法窗口一样,都是一种特殊类型的窗口,而且它们都是喜欢和一个普通的Activity窗口缠绵在一起。大家可以充分地想象这样的一个3W场景:输入法窗口在上面,壁纸窗口在下面,Activity窗口夹在它们的中间。

一个Activity窗口如果需要显示壁纸,那么它必须满足以下两个条件:背景是半透明的;窗口属性中的WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER位设置为1;

首先分析两个需要调整壁纸窗口在窗口堆栈中的位置的情景,然后再分析壁纸窗口在X轴和Y轴上的偏移位置的调整过程,最后分析壁纸窗口在窗口堆栈中的位置调整过程。

一,调整壁纸窗口在窗口堆栈中的位置的情景:

第一个需要调整壁纸窗口在窗口堆栈中的位置的情景是增加一个窗口到WindowManagerService服务去的时候。调用WindowManagerService类的成员函数addWindow来实现的。

WindowManagerService extends IWindowManager.Stub implements Watchdog.Monitor{ *** }

如果前面增加到窗口堆栈中的窗口是一个壁纸窗口,即参数attrs所描述的一个WindowManager.LayoutParams对象的成员变量type的值等于TYPE_WALLPAPER,或者是一个需要显示壁纸的窗口,即参数attrs所描述的一个WindowManager.LayoutParams对象的成员变量flags的值的FLAG_SHOW_WALLPAPER位等于1,那么就说明需要调整壁纸窗口在窗口堆栈中的位置,使得它位于需要显示壁纸的窗口的下面,这是通过调用WindowManagerService类的成员函数adjustWallpaperWindowsLocked来实现的。

在这个情景中,主要涉及到了WindowManagerService类的三个成员函数addWindowToListInOrderLocked、adjustWallpaperWindowsLocked和assignLayersLocked;

第二个需要调整壁纸窗口在窗口堆栈中的位置的情景是一个应用程序进程请求WindowManagerService服务重新布局一个窗口的时候。通过调用WindowManagerService类的成员函数relayoutWindow来实现的。

要涉及到了WindowManagerService类的四个成员函数adjustWallpaperWindowsLocked、updateWallpaperOffsetLocked、performLayoutAndPlaceSurfacesLocked和assignLayersLocked;

二,调整壁纸窗口在X轴和Y轴上的偏移位置:

壁纸窗口的大小是可以大于屏幕大小的。在这种情况下,需要显示壁纸的Activity窗口就需要指定壁纸在X轴和Y轴上的偏移位置,以便可以将壁纸的某一部分作为窗口的背景。

三,调整壁纸窗口在窗口堆栈中的位置:

调整壁纸窗口在窗口堆栈中的位置实际上就是将壁纸窗口放置在需要显示壁纸的窗口的下面,这是是通过调用WindowManagerService类的成员函数adjustWallpaperWindowsLocked来实现的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: