【系统之音】window

window

     flag:设置window的属性,控制其显示特性

     type:表示Window的类型,有三种类型

                应用Window:对应着一个Activity。层级范围:1~99

                子Window:不能独立存在,需要依附于特定的父Window。比如Dialog,PopWindow。层级范围:1000~1999

                系统Window:需要声明权限才能创建的Window。比如Toast,系统状态栏。层级范围:2000~2999

     interface ViewManager

            addView(view,params);

            updateViewLayout(view,params);

            removeView(view);

       interface WindowManager extends ViewManager

       final class WindowManagerImpl implements WindowManager {

             //典型的桥接模式

             WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance(); 

             @override

             addView(view,params){

                  mGlobal.addView(...);

             }

             updateViewLayout(view,params){

                  mGlobal.updateViewLayout(...);

             }

             remove(view){

                  mGlobal.remove(...);

             }

       }

    WindowManagerGlobal.getInstance()的单例实现

private static WindowManagerGlobal sDefaultWindowManager;
public static WindowManagerGlobal getInstance() {
synchronized (WindowManagerGlobal.class) {
if (sDefaultWindowManager == null) {
sDefaultWindowManager = new WindowManagerGlobal();
}
return sDefaultWindowManager;
}
}
如果对单例模式比较了解的话,就能看出这种实现方式是有问题的(对比DCL方式),但不明白系统源码为什么要这样实现。

WindowMangerGlobal.java中的四个非常重要的list
private final ArrayList<View> mViews = new ArrayList<View>();
private final ArrayList<ViewRootImpl> mRoots = new ArrayList<ViewRootImpl>();
private final ArrayList<WindowManager.LayoutParams> mParams = new ArrayList<WindowManager.LayoutParams>;
private final ArraySet<View> mDyingViews = new ArraySet<View>;


原文地址:https://www.cnblogs.com/andy-songwei/p/13295396.html