The path of Android experts-WindowManager and Android windowmanager

Source: Internet
Author: User

The path of Android experts-WindowManager and Android windowmanager

Images in Android are not purely composed of windows. Instead, the organization mode of window + view is changed. Window is the concept of a top-level window. View is equivalent to a control in a window. While subwindow is attached to some dialog boxes of window. When Android manages windows, it divides windows into multiple layers. Different layers correspond to different window types. The following figure illustrates this concept:



Android first layer the window according to the layer, and then each layer has many windows. Each window contains many views and sublayers. These hierarchical concepts are transparent to the user end. The user end only knows windowType, so that the user can pass

The windowType name intuitively defines what the window looks like. Below is the conversion of windowTYpe

Layer functions:

 

 

Java code  
  1. Public int windowTypeToLayerLw (int type ){
  2. If (type> = FIRST_APPLICATION_WINDOW & type <= LAST_APPLICATION_WINDOW ){
  3. Return APPLICATION_LAYER;
  4. }
  5. Switch (type ){
  6. Case TYPE_STATUS_BAR:
  7. Return STATUS_BAR_LAYER; // 14
  8. Case TYPE_STATUS_BAR_PANEL:
  9. Return STATUS_BAR_PANEL_LAYER; // 15
  10. Case TYPE_STATUS_BAR_SUB_PANEL:
  11. Return STATUS_BAR_SUB_PANEL_LAYER; // 13
  12. Case TYPE_SYSTEM_DIALOG:
  13. Return SYSTEM_DIALOG_LAYER; // 5
  14. Case TYPE_SEARCH_BAR:
  15. Return SEARCH_BAR_LAYER; // 4 // 4
  16. Case TYPE_PHONE:
  17. Return PHONE_LAYER; // 3 // 3
  18. Case TYPE_KEYGUARD:
  19. Return KEYGUARD_LAYER; // 11
  20. Case TYPE_KEYGUARD_DIALOG:
  21. Return KEYGUARD_DIALOG_LAYER; // 12
  22. Case TYPE_SYSTEM_ALERT:
  23. Return SYSTEM_ALERT_LAYER; // 8
  24. Case TYPE_SYSTEM_ERROR:
  25. Return SYSTEM_ERROR_LAYER; // 19
  26. Case TYPE_INPUT_METHOD:
  27. Return INPUT_METHOD_LAYER; // 9
  28. Case TYPE_INPUT_METHOD_DIALOG:
  29. Return INPUT_METHOD_DIALOG_LAYER; // 10
  30. Case TYPE_VOLUME_OVERLAY:
  31. Return VOLUME_OVERLAY_LAYER; // 16
  32. Case TYPE_SYSTEM_OVERLAY:
  33. Return SYSTEM_OVERLAY_LAYER; // 17
  34. Case TYPE_SECURE_SYSTEM_OVERLAY:
  35. Return SECURE_SYSTEM_OVERLAY_LAYER; // 21
  36. Case TYPE_PRIORITY_PHONE:
  37. Return PRIORITY_PHONE_LAYER; // 7
  38. Case TYPE_TOAST:
  39. Return TOAST_LAYER; // 6
  40. Case TYPE_WALLPAPER:
  41. Return WALLPAPER_LAYER; // 2
  42. Case TYPE_DRAG:
  43. Return DRAG_LAYER; // 20
  44. Case TYPE_POINTER:
  45. Return POINTER_LAYER; // 23
  46. Case TYPE_NAVIGATION_BAR:
  47. Return NAVIGATION_BAR_LAYER; // 18
  48. Case TYPE_BOOT_PROGRESS:
  49. Return BOOT_PROGRESS_LAYER; // 22
  50. Case TYPE_HIDDEN_NAV_CONSUMER:
  51. Return HIDDEN_NAV_CONSUMER_LAYER; // 24
  52. }
  53. Log. e (TAG, "Unknown window type:" + type );
  54. Return APPLICATION_LAYER;
  55. }

 

Many people don't know how to analyze this, and they are suddenly frightened by the structure from Layer 2 to layer 24. Let me analyze these hierarchies. We only need to find a breakthrough point, that is, the layer where the lock screen is located. Do not worry about the layer above the lock screen temporarily:

Case TYPE_KEYGUARD:
Return KEYGUARD_LAYER; // 11

The layers under the screen lock are:

// Input Method dialog box

Case TYPE_INPUT_METHOD_DIALOG:
Return INPUT_METHOD_DIALOG_LAYER; // 10

// Input Method

Case TYPE_INPUT_METHOD:
Return INPUT_METHOD_LAYER; // 9

// System warning [low power, etc.]

Case TYPE_SYSTEM_ALERT:
Return SYSTEM_ALERT_LAYER; // 8

 

 

// Case TYPE_PRIORITY_PHONE:
Return PRIORITY_PHONE_LAYER; // 7

 

 

Case TYPE_TOAST:
Return TOAST_LAYER; // 6

 

Case TYPE_SYSTEM_DIALOG:
Return SYSTEM_DIALOG_LAYER; // 5

 

Case TYPE_SEARCH_BAR:
Return SEARCH_BAR_LAYER; // 4 // 4

Case TYPE_PHONE:
Return PHONE_LAYER; // 3 // 3

 

If (type> = FIRST_APPLICATION_WINDOW & type <= LAST_APPLICATION_WINDOW ){
Return APPLICATION_LAYER;
}

 

Case TYPE_WALLPAPER:
Return WALLPAPER_LAYER; // 2

Most of them are understandable. There are only two hard-to-understand methods:

TYPE_PHONE 3 and TYPE_PRIORITY_PHONE 7 are obviously related to the phone number.

 

TYPE_PHONE 3 is basically not used only when CompatModeDialog is used, while TYPE_PRIORITY_PHONE is used to lock the network. This will bring more benefits to operators.

 

 

2. What is above KEYGUARD_LAYER? As follows:

 

Case TYPE_KEYGUARD_DIALOG:
Return KEYGUARD_DIALOG_LAYER; // 12 used when Shutdown

 

Case TYPE_STATUS_BAR_SUB_PANEL:
Return STATUS_BAR_SUB_PANEL_LAYER; // 13

Case TYPE_STATUS_BAR:
Return STATUS_BAR_LAYER; // 14

Case TYPE_STATUS_BAR_PANEL:
Return STATUS_BAR_PANEL_LAYER; // 15

Case TYPE_VOLUME_OVERLAY:
Return VOLUME_OVERLAY_LAYER; // 16

Case TYPE_SYSTEM_OVERLAY:
Return SYSTEM_OVERLAY_LAYER; // 17

 

These are of the first type and are easy to understand. From SYSTEM_OVERLAY_LAYER, it is basically uncommon.

 

Case TYPE_NAVIGATION_BAR:
Return NAVIGATION_BAR_LAYER; // 18

 

Case TYPE_SYSTEM_ERROR:
Return SYSTEM_ERROR_LAYER; // 19

 

Case TYPE_DRAG:
Return DRAG_LAYER; // 20

 

Case TYPE_SECURE_SYSTEM_OVERLAY:
Return SECURE_SYSTEM_OVERLAY_LAYER; // 21

Case TYPE_BOOT_PROGRESS:
Return BOOT_PROGRESS_LAYER; // 22

 

Case TYPE_POINTER:
Return POINTER_LAYER; // 23

Case TYPE_HIDDEN_NAV_CONSUMER:
Return HIDDEN_NAV_CONSUMER_LAYER; // 24

 

We can see that most of the dialogs cannot be added to the screen lock. In this case, some dialog boxes can be displayed when the screen is locked. At the same time, they can be processed in the normal dialog box when the screen is not locked. What should we do? For example, telephone, alarm, etc. The first method dynamically changes the type of the window. Set different layers based on whether the screen is being locked. Second, when the screen is locked, if this window is enabled, the screen will be hidden. After the window is removed, the screen lock is displayed.


What is the difference between androidviewIWindowManager and WindowManager?

This is in the source code.
 
The android service dialog box is displayed through windowmanager.

Generally, the Service should not have an interface to interact with the user. You can use icationicationmanager to notify the user of an event.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.