Android WindowManager窗口类型

WindowManager

WindowManager继承自ViewManager,主要用来管理窗口的一些状态、属性、view增加、删除、更新、窗口顺序、消息收集和处理等。应用获取方法:

Context.getSystemService(Context.WINDOW_SERVICE);

Window

表示顶级窗口,也就是主窗口,它有两个实现类,PhoneWindow和MidWindow,一般的 activity对应的主要是PhoneWindow,在activity中经常使用的setContentView等方法就是在Window里面实现。

从WindowManagerService角度看,一个窗口并不是Window类,而是一个View类。WindowManagerService收到用户消息后,需要把消息派发到窗口,View类本身并不能直接接收WindowManagerService传递过来的消息,真正接收用户消息的必须是IWindow类,而实现IWindow类的是ViewRoot.W类,每一个W内部都包含了一个View变量。
WmS并不介意该窗口(View)是属于哪个应用程序的,WmS会按一定的规则判断哪个窗口处于活动状态,然后把用户消息给W类,W类再把用户消息传递给内部的View变量,剩下的消息处理就由View对象完成。
WindowManager的LayoutParams中窗口类型与定义:

frameworks\base\core\java\android\view\WindowManager.java

/** * Start of window types that represent normal application windows. * * ZMS:首个普通应用窗口 */
public static final int FIRST_APPLICATION_WINDOW = 1;

/** * Window type: an application window that serves as the "base" window * of the overall application; all other application windows will * appear on top of it. * In multiuser systems shows only on the owning user's window. * * ZMS:基础窗口-其他应用窗口会显示在此窗口之上 */
public static final int TYPE_BASE_APPLICATION   = 1;

/** * Window type: a normal application window. The {@link #token} must be * an Activity token identifying who the window belongs to. * In multiuser systems shows only on the owning user's window. * * ZMS:普通应用窗口-此窗口需要归属于Activity,多用户系统中仅仅在对应用户的窗口中显示 */
public static final int TYPE_APPLICATION        = 2;

/** * Window type: special application window that is displayed while the * application is starting. Not for use by applications themselves; * this is used by the system to display something until the * application can show its own windows. * In multiuser systems shows on all users' windows. * * ZMS:应用启动窗口-应用启动显示的窗口,不受应用本身控制。由系统在应用显示应用本身的窗口之前显示。 */
public static final int TYPE_APPLICATION_STARTING = 3;

/** * End of types of application windows. * * ZMS:终极应用窗口-所有Activity默认的窗口类型都是TYPE_APPLICATION, * WindowManagerService在进行窗口叠加时,会动态改变应用窗口的层值,但不会大于99。 */
public static final int LAST_APPLICATION_WINDOW = 99;

/** * Start of types of sub-windows. The {@link #token} of these windows * must be set to the window they are attached to. These types of * windows are kept next to their attached window in Z-order, and their * coordinate space is relative to their attached window. * * ZMS:首个子窗口-依附于父窗口。子窗口在Z轴上邻接父窗口,且协调空间与父窗口相关。 * 子窗口是指该窗口必须要有一个父窗口,父窗口可以是一个应用类型窗口,也可以是任何其他类型的窗口。 */
public static final int FIRST_SUB_WINDOW        = 1000;

/** * Window type: a panel on top of an application window. These windows * appear on top of their attached window. * * ZMS:应用窗口子窗口-PopupWindow的默认类型 */
public static final int TYPE_APPLICATION_PANEL  = FIRST_SUB_WINDOW;

/** * Window type: window for showing media (such as video). These windows * are displayed behind their attached window. * * ZMS:用来显示Media的窗口 */
public static final int TYPE_APPLICATION_MEDIA  = FIRST_SUB_WINDOW+1;

/** * Window type: a sub-panel on top of an application window. These * windows are displayed on top their attached window and any * {@link #TYPE_APPLICATION_PANEL} panels. * * ZMS:TYPE_APPLICATION_PANEL的子窗口 */
public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW+2;

/** Window type: like {@link #TYPE_APPLICATION_PANEL}, but layout * of the window happens as that of a top-level window, <em>not</em> * as a child of its container. * * ZMS:OptionMenu、ContextMenu的默认类型 */
public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW+3;

/** * Window type: window for showing overlays on top of media windows. * These windows are displayed between TYPE_APPLICATION_MEDIA and the * application window. They should be translucent to be useful. This * is a big ugly hack so: * @hide * * ZMS:TYPE_APPLICATION_MEDIA的重影窗口,显示在TYPE_APPLICATION_MEDIA和应用窗口之间 */
public static final int TYPE_APPLICATION_MEDIA_OVERLAY  = FIRST_SUB_WINDOW+4;

/** * End of types of sub-windows. * * ZMS:最后一个子窗口-创建子窗口时,客户端可以指定窗口类型介于1000-1999之间, * 而WindowManagerService在进行窗口叠加时,会动态调整层值。 */
public static final int LAST_SUB_WINDOW         = 1999;

/** * Start of system-specific window types. These are not normally * created by applications. * * ZMS:首个系统窗口-系统窗口,系统窗口不需要对应任何Activity,也不需要有父窗口, * 对于应用程序而言,理论上是无法创建系统窗口的,因为所有的应用程序都没有这个权限, * 然而系统进程却可以创建系统窗口。 */
public static final int FIRST_SYSTEM_WINDOW     = 2000;

/** * Window type: the status bar. There can be only one status bar * window; it is placed at the top of the screen, and all other * windows are shifted down so they are below it. * In multiuser systems shows on all users' windows. * * ZMS:状态栏窗口,层值2000。 */
public static final int TYPE_STATUS_BAR         = FIRST_SYSTEM_WINDOW;

/** * Window type: the search bar. There can be only one search bar * window; it is placed at the top of the screen. * In multiuser systems shows on all users' windows. * * ZMS:搜索条窗口,层值2001。 */
public static final int TYPE_SEARCH_BAR         = FIRST_SYSTEM_WINDOW+1;

/** * Window type: phone. These are non-application windows providing * user interaction with the phone (in particular incoming calls). * These windows are normally placed above all applications, but behind * the status bar. * In multiuser systems shows on all users' windows. * * ZMS:来电显示窗口 */
public static final int TYPE_PHONE              = FIRST_SYSTEM_WINDOW+2;

/** * Window type: system window, such as low power alert. These windows * are always on top of application windows. * In multiuser systems shows only on the owning user's window. * * ZMS:警告对话框 */
public static final int TYPE_SYSTEM_ALERT       = FIRST_SYSTEM_WINDOW+3;

/** * Window type: keyguard window. * In multiuser systems shows on all users' windows. * @removed * * ZMS:锁屏 */
public static final int TYPE_KEYGUARD           = FIRST_SYSTEM_WINDOW+4;

/** * Window type: transient notifications. * In multiuser systems shows only on the owning user's window. * * ZMS:Toast窗口 */
public static final int TYPE_TOAST              = FIRST_SYSTEM_WINDOW+5;

/** * Window type: system overlay windows, which need to be displayed * on top of everything else. These windows must not take input * focus, or they will interfere with the keyguard. * In multiuser systems shows only on the owning user's window. * * ZMS:系统覆盖窗口,显示在所有窗口之上 */
public static final int TYPE_SYSTEM_OVERLAY     = FIRST_SYSTEM_WINDOW+6;

/** * Window type: priority phone UI, which needs to be displayed even if * the keyguard is active. These windows must not take input * focus, or they will interfere with the keyguard. * In multiuser systems shows on all users' windows. * * ZMS:在屏幕保护下的来电显示窗口 */
public static final int TYPE_PRIORITY_PHONE     = FIRST_SYSTEM_WINDOW+7;

/** * Window type: panel that slides out from the status bar * In multiuser systems shows on all users' windows. * * ZMS:滑动状态栏后出现的窗口 */
public static final int TYPE_SYSTEM_DIALOG      = FIRST_SYSTEM_WINDOW+8;

/** * Window type: dialogs that the keyguard shows * In multiuser systems shows on all users' windows. * * ZMS:锁屏弹出的对话框 */
public static final int TYPE_KEYGUARD_DIALOG    = FIRST_SYSTEM_WINDOW+9;

/** * Window type: internal system error windows, appear on top of * everything they can. * In multiuser systems shows only on the owning user's window. * * ZMS:系统错误窗口 */
public static final int TYPE_SYSTEM_ERROR       = FIRST_SYSTEM_WINDOW+10;

/** * Window type: internal input methods windows, which appear above * the normal UI. Application windows may be resized or panned to keep * the input focus visible while this window is displayed. * In multiuser systems shows only on the owning user's window. * * ZMS:输入法窗口 */
public static final int TYPE_INPUT_METHOD       = FIRST_SYSTEM_WINDOW+11;

/** * Window type: internal input methods dialog windows, which appear above * the current input method window. * In multiuser systems shows only on the owning user's window. * * ZMS:输入法中备选框对应的窗口 */
public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12;

/** * Window type: wallpaper window, placed behind any window that wants * to sit on top of the wallpaper. * In multiuser systems shows only on the owning user's window. * * ZMS:墙纸对应的窗口 */
public static final int TYPE_WALLPAPER          = FIRST_SYSTEM_WINDOW+13;

/** * Window type: panel that slides out from over the status bar * In multiuser systems shows on all users' windows. * * ZMS:滑动状态栏后出现的面板窗口 */
public static final int TYPE_STATUS_BAR_PANEL   = FIRST_SYSTEM_WINDOW+14;

/** * Window type: secure system overlay windows, which need to be displayed * on top of everything else. These windows must not take input * focus, or they will interfere with the keyguard. * * This is exactly like {@link #TYPE_SYSTEM_OVERLAY} except that only the * system itself is allowed to create these overlays. Applications cannot * obtain permission to create secure system overlays. * * In multiuser systems shows only on the owning user's window. * @hide * * ZMS:安全系统覆盖窗口,显示在所有窗口之上。 */
public static final int TYPE_SECURE_SYSTEM_OVERLAY = FIRST_SYSTEM_WINDOW+15;

/** * Window type: the drag-and-drop pseudowindow. There is only one * drag layer (at most), and it is placed on top of all other windows. * In multiuser systems shows only on the owning user's window. * @hide * * ZMS:拖动放开窗口。 */
public static final int TYPE_DRAG               = FIRST_SYSTEM_WINDOW+16;

/** * Window type: panel that slides out from under the status bar * In multiuser systems shows on all users' windows. * @hide * * ZMS:滑动状态栏显示的面板窗口。 */
public static final int TYPE_STATUS_BAR_SUB_PANEL = FIRST_SYSTEM_WINDOW+17;

/** * Window type: (mouse) pointer * In multiuser systems shows on all users' windows. * @hide * * ZMS:鼠标窗口。 */
public static final int TYPE_POINTER = FIRST_SYSTEM_WINDOW+18;

/** * Window type: Navigation bar (when distinct from status bar) * In multiuser systems shows on all users' windows. * @hide * * ZMS:导航栏窗口 */
public static final int TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;

/** * Window type: The volume level overlay/dialog shown when the user * changes the system volume. * In multiuser systems shows on all users' windows. * @hide * * ZMS:音量调节窗口 */
public static final int TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20;

/** * Window type: The boot progress dialog, goes on top of everything * in the world. * In multiuser systems shows on all users' windows. * @hide * * ZMS:系统启动进程对话框窗口-在其他内容之上。 */
public static final int TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;

/** * Window type: Fake window to consume touch events when the navigation * bar is hidden. * In multiuser systems shows on all users' windows. * @hide * * ZMS:隐藏导航栏时消化触摸事件窗口-当导航栏隐藏时,用来处理消费触摸事件的模拟窗口。 */
public static final int TYPE_HIDDEN_NAV_CONSUMER = FIRST_SYSTEM_WINDOW+22;

/** * Window type: Dreams (screen saver) window, just above keyguard. * In multiuser systems shows only on the owning user's window. * @hide * * ZMS:LDreams屏保窗口,仅在锁屏窗口之上。 */
public static final int TYPE_DREAM = FIRST_SYSTEM_WINDOW+23;

/** * Window type: Navigation bar panel (when navigation bar is distinct from status bar) * In multiuser systems shows on all users' windows. * @hide * * ZMS:导航栏面板窗口 */
public static final int TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24;

/** * Window type: Behind the universe of the real windows. * In multiuser systems shows on all users' windows. * @hide * * ZMS:全局背景窗口 */
public static final int TYPE_UNIVERSE_BACKGROUND = FIRST_SYSTEM_WINDOW+25;

/** * Window type: Display overlay window. Used to simulate secondary display devices. * In multiuser systems shows on all users' windows. * @hide * * ZMS:显示重绘窗口,用来模拟第二屏显示设备。 */
public static final int TYPE_DISPLAY_OVERLAY = FIRST_SYSTEM_WINDOW+26;

/** * Window type: Magnification overlay window. Used to highlight the magnified * portion of a display when accessibility magnification is enabled. * In multiuser systems shows on all users' windows. * @hide * * ZMS:放大Overlay窗口-当辅助功能放大开启时,用来放大高亮显示。 */
public static final int TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27;

/** * Window type: keyguard scrim window. Shows if keyguard needs to be restarted. * In multiuser systems shows on all users' windows. * @hide * * ZMS:锁屏遮罩窗口,在锁屏需要重启时显示。 */
public static final int TYPE_KEYGUARD_SCRIM           = FIRST_SYSTEM_WINDOW+29;

/** * Window type: Window for Presentation on top of private * virtual display. * * ZMS:安全信息窗口。 */
public static final int TYPE_PRIVATE_PRESENTATION = FIRST_SYSTEM_WINDOW+30;

/** * Window type: Windows in the voice interaction layer. * @hide * * ZMS:语音交互窗口。 */
public static final int TYPE_VOICE_INTERACTION = FIRST_SYSTEM_WINDOW+31;

/** * Window type: Windows that are overlaid <em>only</em> by an {@link * android.accessibilityservice.AccessibilityService} for interception of * user interactions without changing the windows an accessibility service * can introspect. In particular, an accessibility service can introspect * only windows that a sighted user can interact with which is they can touch * these windows or can type into these windows. For example, if there * is a full screen accessibility overlay that is touchable, the windows * below it will be introspectable by an accessibility service regardless * they are covered by a touchable window. * * ZMS:辅助功能窗口。 */
public static final int TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32;

/** * M: * Window type: Top most * @hide * * ZMS:TopMost窗口。 */
public static final int TYPE_TOP_MOST = FIRST_SYSTEM_WINDOW + 33;

/** * End of types of system windows. * * ZMS:终极系统窗口。 */
public static final int LAST_SYSTEM_WINDOW      = 2999;
    原文作者:周木水
    原文地址: https://blog.csdn.net/zhoumushui/article/details/52067348
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞