The introduction

  • This is the seventh article in the Android 10 source code analysis series
  • Branches: android – 10.0.0 _r14
  • Read the full text for about 10 minutes

In the previous article 0xA06 Android 10 source code analysis: WindowManager View Binding and Architecture introduces the relationship between Activity, Window, PhoneWindow, WindowManager, and the process of view binding between Activity and Dialog. This article has two main purposes:

  1. Learn more about Windows Manager view binding and architecture from the previous article 0xA06 Android 10 source code analysis
  2. Setting the stage for the next article, “How to add custom Views to An Android system”, etc

You will learn the following in this article, and the answers will be given in the summary section at the end of the article

  • What common parameters does Window have?
  • What are the types of Windows? What does each type mean? And function?
  • Window’s outdated apis and solutions?
  • How is the Window view hierarchy determined?
  • What flags do Windows have? What does each flag mean? And function?
  • Windows soft keyboard mode? What does each pattern mean? And how to use it?
  • Kotlin tip?

Before we start our analysis, let’s take a look at a diagram to familiarize ourselves with some of the basic concepts that will accompany this article

  • The interface we see on our phones is two-dimensional, but it’s actually three-dimensional, as shown above
  • Window: An abstract class that is added to WindowManager as a top-level View. The View is attached to the Window and manages the View
  • WindowManager: It is an interface that inherits from the ViewManager interface to manage Windows
  • PhoneWindow: Windows unique implementation class added to the root container of WindowManager
  • WindowManagerService: WindowManager is a container for Windows. It manages Windows, adds and deletes them, and is handled by WindowManagerService. WindowManager and WindowManagerService communicate across processes through Binder, and WindowManagerService is the ultimate manager of Windows

The important knowledge point of this article is how to determine the hierarchy order of Window view. Other contents are some concepts, you can read selectively. After understanding the basic concepts, we will enter the core content of this article

Windows has the usual parameters

Window parameters are defined in the static inner class LayoutParams of WindowManager frameworks/base/core/java/android/view/WindowManager#LayoutParams.java

Public static class LayoutParams extends ViewGroup.LayoutParams implements Parcelable {// Window implements Parcelable public int x; Public int y; // Window type public inttype; // Window flag is used to control the display of Window public int flags; Public int softInputMode; public int softInputMode; // Window transparency. The value is 0-1 publicfloatAlpha = 1.0 f; Public int gravity; // window PixelFormat, value defined in PixelFormat public int format; }Copy the code

Next we will mainly introduce the Window type, Window view hierarchy, Window flag, and Window soft keyboard mode

Windows has all those types and functions

The types of Windows can be roughly divided into three categories: Application Window (Application Window), sub-window (Sub Windwow), and System Window (System Window). The type of Window is represented by type value. Each large type contains multiple small types. They are defined in the WindowManager static inner class LayoutParams frameworks/base/core/Java/android/view/WindowManager# LayoutParams. Java

public static class LayoutParams extends ViewGroup.LayoutParams implements Parcelable {
    public int type; Public static final int FIRST_APPLICATION_WINDOW = 1; Public static final int LAST_APPLICATION_WINDOW = 99; Public static final int FIRST_SUB_WINDOW = 1000; Public static final int LAST_SUB_WINDOW = 1999; Public static final int FIRST_SYSTEM_WINDOW = 2000; Public static final int LAST_SYSTEM_WINDOW = 2999; }Copy the code
type value note
FIRST_APPLICATION_WINDOW 1 The start value of the application Window
LAST_APPLICATION_WINDOW 99 The end value of the application Window
FIRST_SUB_WINDOW 1000 The starting value of the child Window
LAST_SUB_WINDOW 1999 The end value of the child Window
FIRST_SYSTEM_WINDOW 2000 The start value of the system Window
LAST_SYSTEM_WINDOW 2999 End value of system Window

Tip: if the level is below 2000 (FIRST_SYSTEM_WINDOW), there is no need to apply for popover permission

  • Application Window (Application Window) 13 [1], the scope of its range, for example the Activity frameworks/base/core/Java/android/view/WindowManager# LayoutParams. Java
Public static final int FIRST_APPLICATION_WINDOW = 1; Public static final int TYPE_BASE_APPLICATION = 1; public static final int TYPE_BASE_APPLICATION = 1; Public static final int TYPE_APPLICATION = 2; Public static final int TYPE_APPLICATION_STARTING = 3; public static final int TYPE_APPLICATION_STARTING = 3; public static final int TYPE_APPLICATION_STARTING = 3; Public static final int TYPE_DRAWN_APPLICATION = 4; // A variant of TYPE_APPLICATION, where WindowManager waits for the Window to be drawn before the application is displayed. Public static final int LAST_APPLICATION_WINDOW = 99;Copy the code
type
note
FIRST_APPLICATION_WINDOW The start value of the application Window
TYPE_BASE_APPLICATION The base value of the application Window
TYPE_APPLICATION Generic applications
TYPE_APPLICATION_STARTING Special application Window, used when the application can display Window before

Window to display something
TYPE_DRAWN_APPLICATION Variants of TYPE_APPLICATION before the application is displayed,

WindowManager waits for the Window to finish drawing
LAST_APPLICATION_WINDOW The end value of the application Window
  • Sub Window (Sub Windwow) : Its interval range [1000,1999], these Windows are attached to the parent Window in z-order, and their coordinate space is relative to that of the parent Window, for example: PopupWindow frameworks/base/core/java/android/view/WindowManager#LayoutParams.java
Public static final int FIRST_SUB_WINDOW = 1000; // The panel on top of the application Window. These Windows appear at the top of their attached Windows. public static final int TYPE_APPLICATION_PANEL = FIRST_SUB_WINDOW; // Window used to display media such as video. These Windows appear after their attached Windows. public static final int TYPE_APPLICATION_MEDIA = FIRST_SUB_WINDOW + 1; // Subpanel at the top of the application Window. Public static final int TYPE_APPLICATION_SUB_PANEL = FIRST_SUB_WINDOW + 2; Public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3; public static final int TYPE_APPLICATION_ATTACHED_DIALOG = FIRST_SUB_WINDOW + 3; Public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4; public static final int TYPE_APPLICATION_MEDIA_OVERLAY = FIRST_SUB_WINDOW + 4;  // The subpanel is at the top of the application Window, which is displayed at the top of its attached Window, Public static final int TYPE_APPLICATION_ABOVE_SUB_PANEL = FIRST_SUB_WINDOW + 5; Public static final int LAST_SUB_WINDOW = 1999;Copy the code
type
note
FIRST_SUB_WINDOW The starting value of the child Window
TYPE_APPLICATION_PANEL The panel at the top of the application Window that appears at the top of its attached Window
TYPE_APPLICATION_MEDIA Windows used to display media, such as video, that appear after their attached Windows
TYPE_APPLICATION_SUB_PANEL The subpanel at the top of the application Window that appears on top of its attached Window and any Window
TYPE_APPLICATION_ATTACHED_DIALOG The current Window layout is identical to the top-level Window layout and cannot be used as a child container
TYPE_APPLICATION_MEDIA_OVERLAY Overlay the Window at the top with the display media Window, which is the system’s hidden API
TYPE_APPLICATION_ABOVE_SUB_PANEL The subpanel is at the top of the application Window, which is displayed at the top of its attached Window, which is the system’s hidden API
LAST_SUB_WINDOW The end value of the child Window
  • System Window: Its range [2000299], for example: Toast, input window, window system volume, system error window frameworks/base/core/Java/android/view/WindowManager# LayoutParams. Java
Public static final int FIRST_SYSTEM_WINDOW = 2000; Public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW; public static final int TYPE_STATUS_BAR = FIRST_SYSTEM_WINDOW; Public static final int TYPE_SEARCH_BAR = FIRST_SYSTEM_WINDOW+1; Public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2; public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2; Public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3; public static final int TYPE_SYSTEM_ALERT = FIRST_SYSTEM_WINDOW+3;  Public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4; public static final int TYPE_KEYGUARD = FIRST_SYSTEM_WINDOW+4; Public static final int TYPE_TOAST = FIRST_SYSTEM_WINDOW+5; @deprecated // API is Deprecated, public static final int type_overlay = FIRST_SYSTEM_WINDOW+5; @deprecated // API is Deprecated, Public static final int TYPE_SYSTEM_OVERLAY = first_system_overlay +6; @deprecated // API is Deprecated, Public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7; public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7; Public static final int TYPE_SYSTEM_DIALOG = FIRST_SYSTEM_WINDOW+8; Public static final int TYPE_KEYGUARD_DIALOG = FIRST_SYSTEM_WINDOW+9; @deprecated // API is Deprecated, Public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10; public static final int TYPE_SYSTEM_ERROR = FIRST_SYSTEM_WINDOW+10; Public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11; public static final int TYPE_INPUT_METHOD = FIRST_SYSTEM_WINDOW+11; Public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12; public static final int TYPE_INPUT_METHOD_DIALOG= FIRST_SYSTEM_WINDOW+12; // Wallpaper public static final int TYPE_WALLPAPER = FIRST_SYSTEM_WINDOW; Public static final int TYPE_STATUS_BAR_PANEL = FIRST_SYSTEM_WINDOW+14; Public static final int TYPE_APPLICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 38; Public static final int LAST_SYSTEM_WINDOW = 2999;Copy the code
type
note
FIRST_SYSTEM_WINDOW The start value of the system Window type
TYPE_STATUS_BAR System status bar, there can be only one status bar, it is placed at the top of the screen, all other Windows are moved down
TYPE_SEARCH_BAR The system search window, which can have only one search bar, is placed at the top of the screen
TYPE_PHONE The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_SYSTEM_ALERT The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_KEYGUARD Has been removed from the system and can be replaced with TYPE_KEYGUARD_DIALOG
TYPE_TOAST The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_SYSTEM_OVERLAY The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_PRIORITY_PHONE The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_SYSTEM_ERROR The API is obsolete, use TYPE_APPLICATION_OVERLAY instead
TYPE_APPLICATION_OVERLAY The application Overlay window is displayed on top of all Windows
TYPE_SYSTEM_DIALOG System dialog box window
TYPE_KEYGUARD_DIALOG A dialog box that is displayed when the screen is locked
TYPE_INPUT_METHOD An input window that sits on top of the normal UI and allows applications to be rearranged so as not to be overlaid by it
TYPE_INPUT_METHOD_DIALOG Input method dialog box, displayed above the current input method window
TYPE_WALLPAPER The wallpaper
TYPE_STATUS_BAR_PANEL Sliding panel for status bar
LAST_SYSTEM_WINDOW The end value of the system Window type

Note that:

  1. TYPE_PHONE, TYPE_SYSTEM_ALERT, TYPE_TOAST, TYPE_SYSTEM_OVERLAY, TYPE_PRIORITY_PHONE, and TYPE_SYSTEM_ERROR are listed in API 26 Have been out of date, in using TYPE_APPLICATION_OVERLAY instead of, need to apply for the Manifest. Permission. SYSTEM_ALERT_WINDOW permissions

  2. TYPE_KEYGUARD has been removed from the system and can be replaced with TYPE_KEYGUARD_DIALOG

Window view hierarchy order

What we see on our phones is two-dimensional, but it’s actually a three-dimensional display, as shown below

At the beginning of the article, it was introduced that parameter types include the X-axis coordinates of Window and the Y-axis coordinates of Window. Since it is a three-dimensional coordinate system, where is the z-axis coordinate? WindowManagerService is a very important class to look at. When adding a Window, the hierarchy of the Window is specified. When displaying the Window, the hierarchy is specified

WindowManager is a container that manages Windows, adds and removes them, and uses the Binder to communicate with WMS across processes. WMS is the ultimate administrator of Windows, I’ll look at some of the WMS addWindow methods frameworks/base/services/core/Java/com/android/server/wm/WindowManagerService. Java

public int addWindow(Session session, IWindow client, int seq, LayoutParams attrs, int viewVisibility, int displayId, Rect outFrame, Rect outContentInsets, Rect outStableInsets, Rect outOutsets, DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, InsetsState outInsetsState) { final WindowState win = new WindowState(this, session, client, token, parentWindow, appOp[0], seq, attrs, viewVisibility, session.mUid, session.mCanAddInternalSystemWindow); . win.mToken.addWindow(win); . win.getParent().assignChildLayers(); . }Copy the code
  • WindowState computes the current Window hierarchy
  • The win.mtoken. addWindow method puts the current Win into a WindowList, which is an ArrayList
  • DisplayContent. AssignWindowLayers method to calculate the z – the order value, z – the bigger the order value, the more, the more close to the user

Window view hierarchy order by Z – order, Z – order corresponds to the WindowManager. LayoutParams type value, Z – the order can be understood as Android view hierarchy concept, and value the bigger the front, the more close to the user.

A WindowState is a window in a windowManager, and a WindowState is a window

So the calculation logic for z-order is in the WindowState class, and the WindowState constructor initializes the current mBaseLayer and mSubLayer, These two parameters should be decided to z – order two factors frameworks/base/services/core/Java/com/android/server/wm/WindowState. Java

static final int TYPE_LAYER_MULTIPLIER = 10000; static final int TYPE_LAYER_OFFSET = 1000; WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token, WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a, int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow, PowerManagerWrapper PowerManagerWrapper) {// determine if this is in the type range of a child Window [1000,1999]if(mattrs.type >= FIRST_SUB_WINDOW && mattrs.type <= LAST_SUB_WINDOW) {// call getWindowLayerLw and return the value between [1,33], MBaseLayer = mPolicy. GetWindowLayerLw (parentWindow) * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;  / / / / mSubLayer child window order call getSubWindowLayerFromTypeLw method return values between [2.3], Returns the position of the Window relative to the parent Window mSubLayer = mPolicy. GetSubWindowLayerFromTypeLw (a.t ype); . }else{ mBaseLayer = mPolicy.getWindowLayerLw(this) * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET; mSubLayer = 0; . }}Copy the code
  • MBaseLayer is the basic order, corresponding interval range [1,33]
  • MSubLayer Order of sub-windows in the same group, corresponding interval range [-2.3]
  • Check whether this is in the type range of the child Window [1000,1999]
  • If it is a child Window, call getWindowLayerLw method, calculating the value of mBaseLayer, return a used to prioritize the arbitrary integer, Window call getSubWindowLayerFromTypeLw method, Evaluates the value of mSubLayer and returns the position of the child Window relative to the parent Window
  • If it is not a child Window, the getWindowLayerLw method is called to calculate the value of mBaseLayer, which returns an arbitrary integer used to sort the Window. MSubLayer has a value of 0

Calculates the value of mBaseLayer

Call the WindowManagerPolicy getWindowLayerLw method, Calculating the value of mBaseLayer frameworks/base/services/core/Java/com/android/server/policy/WindowManagerPolicy. Java

int APPLICATION_LAYER = 2; int APPLICATION_MEDIA_SUBLAYER = -2; int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; int APPLICATION_PANEL_SUBLAYER = 1; int APPLICATION_SUB_PANEL_SUBLAYER = 2; int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; */ default int getWindowLayerFromTypeLw(int getWindowLayerFromTypeLw(int getWindowLayerFromTypeLw(int getWindowLayerFromTypeLw)type, Boolean canAddInternalSystemWindow) {/ / determine whether within the scope of application Window type almost [1]if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
        return APPLICATION_LAYER;
    }


    switch (type) {
        caseTYPE_WALLPAPER: // Wallpaper, delete it through Window Managerreturn  1;
        caseTYPE_PHONE: / / phonereturn  3;
        caseTYPE_SEARCH_BAR: // Search barreturn  6;
        caseTYPE_SYSTEM_DIALOG: // System dialogreturn7.caseTYPE_TOAST: // System toastreturn  8;
        caseTYPE_INPUT_METHOD: // Input methodreturn15.caseTYPE_STATUS_BAR: // Status barreturn17.caseTYPE_KEYGUARD_DIALOG: / / lock screenreturn20; .case TYPE_POINTER:
            // the (mouse) pointer layer
            return  33;
        default:
            returnAPPLICATION_LAYER; }}Copy the code

Return an arbitrary integer used to sort Windows. The smaller the number, the smaller the value. Calculate its base order by the following formula. Let’s take an Activity as an example:

The Activity belongs to the application layer Window and its value ranges from [1,99]. Call getWindowLayerLw and return APPLICATION_LAYER with value 2

static final int TYPE_LAYER_MULTIPLIER = 10000;
static final int TYPE_LAYER_OFFSET = 1000;

mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
                * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Copy the code

So the final Activity’s mBaseLayer value is 21000

Computes the value of mSubLayer

Call getSubWindowLayerFromTypeLw method, the incoming WindowManager. LayoutParams instance of a type of value, Calculating the value of mSubLayer frameworks/base/services/core/Java/com/android/server/policy/WindowManagerPolicy. Java

int APPLICATION_LAYER = 2; int APPLICATION_MEDIA_SUBLAYER = -2; int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; int APPLICATION_PANEL_SUBLAYER = 1; int APPLICATION_SUB_PANEL_SUBLAYER = 2; int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3; /** * Evaluates the position of the Window relative to the parent Window * returns an integer with positive values in front indicating above the parent Window and negative values in back, Said in the parent Window of the following * / default int getSubWindowLayerFromTypeLw (inttype) {
    switch (type) {
        case TYPE_APPLICATION_PANEL: // 1000
        case TYPE_APPLICATION_ATTACHED_DIALOG: // 1003
            return APPLICATION_PANEL_SUBLAYER; // return 1
        case TYPE_APPLICATION_MEDIA:// 1001
            returnAPPLICATION_MEDIA_SUBLAYER; //return2 -case TYPE_APPLICATION_MEDIA_OVERLAY:
            return APPLICATION_MEDIA_OVERLAY_SUBLAYER; // return- 1case TYPE_APPLICATION_SUB_PANEL:// 1002
            returnAPPLICATION_SUB_PANEL_SUBLAYER; //return 2
        case TYPE_APPLICATION_ABOVE_SUB_PANEL:
            returnAPPLICATION_ABOVE_SUB_PANEL_SUBLAYER; //return3}return 0;
}
Copy the code

Calculates the position of the child Window relative to the parent Window and returns an integer with a positive value above the parent Window and a negative value below the parent Window

The Window of the flag

The Window flag controls the display of the Window, Their values are defined in the interior of the WindowManager type of LayoutParams frameworks/base/core/Java/android/view/WindowManager# LayoutParams. Java

Public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001; public static final int FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001; Public static final int FLAG_DIM_BEHIND = 0x00000002; Public static final int FLAG_BLUR_BEHIND = 0x00000004 public static final int FLAG_BLUR_BEHIND = 0x00000004; // Window does not receive input focus, that is, it does not accept any key or button events. For example, if the Window has an EditView, clicking EditView will not pop up the soft keyboard. For example, if you click on the view outside the window, you will still get a response. FLAG_NOT_TOUCH_MODAL public static final int FLAG_NOT_FOCUSABLE = 0x00000008 is enabled whenever this Flag is set; // Views outside the Window can respond to touch events. // Views outside the Window can respond to touch events. public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020; // If this Flag is set, the Window will not receive any touch events. For example, clicking on the Window will not receive a response, but only the Window with focus below. public static final int FLAG_NOT_TOUCHABLE = 0x00000010; Public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; public static final int FLAG_KEEP_SCREEN_ON = 0x00000080; Public static final int FLAG_LAYOUT_IN_SCREEN = 0x00000100; Public static final int FLAG_LAYOUT_NO_LIMITS = 0x00000200; Public static final int FLAG_FULLSCREEN = 0x00000400; Public static final int FLAG_FORCE_NOT_FULLSCREEN = 0x00000800; Public static final int FLAG_IGNORE_CHEEK_PRESSES = 0x00008000; // A motionEvent.action_outside event is received when the keystroke action occurs outside the Window. public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000; Deprecated // Windows can be displayed on locked Windows, using Activity#setShowWhenLocked(Boolean) method insteadpublic static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000; // Is responsible for drawing the system bar background. If set, the system bar will be drawn with a transparent background, and the corresponding area in this Window will be filled with the color specified in Windows # getStatusBarColor () and Windows # getNavigationBarColor (). public static final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000; Public static final int FLAG_SHOW_WALLPAPER = 0x00100000; public static final int FLAG_SHOW_WALLPAPER = 0x00100000;Copy the code
flag
note
FLAG_ALLOW_LOCK_WHILE_SCREEN_ON Allows screen lock while Window is visible
FLAG_DIM_BEHIND Everything behind the Window goes dark
FLAG_BLUR_BEHIND The API is out of date and everything behind the Window is blurred
FLAG_NOT_FOCUSABLE The Window cannot receive input focus, that is, it does not accept any key or button events. For example, if the Window has an EditView, clicking the EditView will not pop up the soft keyboard, and events outside the Window will still be processed by the original Window. For example, if you click on the view outside the window, you will still get a response. In addition, whenever this Flag is set, FLAG_NOT_TOUCH_MODAL will be enabled
FLAG_NOT_TOUCH_MODAL If this Flag is set, the button events outside the Window will be sent to the next Window for processing, and it will only process the touch events in the Window area, and the view outside the Window can also respond to the touch events
FLAG_NOT_TOUCHABLE If this Flag is set, the Window will not receive any touch events. For example, clicking on the Window will not receive a response, but only the Window with focus below
FLAG_KEEP_SCREEN_ON The screen stays on as long as the Window is visible
FLAG_LAYOUT_IN_SCREEN Allows Windows to fill the entire screen
FLAG_LAYOUT_NO_LIMITS Allows Windows to go beyond the screen
FLAG_FULLSCREEN Full screen display, hiding all Window decorations, such as full screen display in games and players
FLAG_FORCE_NOT_FULLSCREEN FLAG_FULLSCREEN is one level lower than FLAG_FULLSCREEN and displays the status bar
FLAG_IGNORE_CHEEK_PRESSES When the user’s face is close to the screen (such as making a phone call), this event is not responded to
FLAG_WATCH_OUTSIDE_TOUCH A motionEvent.action_outside event is received when the keystroke action occurs outside the Window
FLAG_SHOW_WHEN_LOCKED Windows can be displayed above the Window on the lock screen using the Active #setShowWhenLocked(Boolean) method instead
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS Represents responsible for drawing the system bar background. If set, the system bar will be drawn on a transparent background,

The corresponding area in this Window will be filled with the colors specified in Windows # getStatusBarColor () and Windows # getNavigationBarColor ()
FLAG_SHOW_WALLPAPER The Window surface must be translucent in order to see the wallpaper behind it

Window soft keyboard mode

Represents the display mode of the input area of the window soft keyboard. In common cases, the window soft keyboard will occupy the whole screen when opened, blocking the View behind. For example, when watching live broadcast, there is an input box at the bottom, and the input box comes up with the keyboard when clicked. The interface stays fixed and so on

Soft keyboard mode (SoftInputMode) value, and the attribute of the Activity in the AndroidManifest android: windowSoftInputMode is the corresponding, So you can set android: for the Activity in the AndroidManifest file windowSoftInputMode

 <activity android:windowSoftInputMode="adjustNothing" />
Copy the code

You can also set SoftInputMode for Windows in Java code

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
Copy the code

The SoftInputMode values are as follows

Public static final int SOFT_INPUT_STATE_UNCHANGED = 1; Public static final int SOFT_INPUT_STATE_HIDDEN = 2; public static final int SOFT_INPUT_STATE_HIDDEN = 2; Public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3; public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3; Public static final int SOFT_INPUT_STATE_VISIBLE = 4; public static final int SOFT_INPUT_STATE_VISIBLE = 4; Public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5; public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5; Public static final int SOFT_INPUT_MASK_ADJUST = 0xf0; Public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00; Adjust_pan (adjust_pan, adjust_pan, adjust_pan, adjust_pan, adjust_pan, adjust_pan, adjust_pan) // If the window's layout parameter flag contains FLAG_FULLSCREEN, this value is ignored and the window does not resize, but remains full-screen. public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10; For example, there are two EditView input boxes, one is Ev1 and the other is Ev2. When you click Ev1 to enter data, Public static final int SOFT_INPUT_ADJUST_PAN = 0x20; Public static final int SOFT_INPUT_ADJUST_NOTHING = 0x30;Copy the code
model
note
SOFT_INPUT_STATE_UNCHANGED Does not change the state of the soft keyboard
SOFT_INPUT_STATE_VISIBLE When the user enters the window, the soft keyboard is displayed
SOFT_INPUT_STATE_HIDDEN Hide the soft keyboard when the user enters the window
SOFT_INPUT_STATE_ALWAYS_HIDDEN Hide the soft keyboard when the window gets focus
SOFT_INPUT_STATE_ALWAYS_VISIBLE A soft keyboard is displayed when the window gets focus
SOFT_INPUT_MASK_ADJUST The window is resized to fit the soft keyboard window
SOFT_INPUT_ADJUST_UNSPECIFIED If no state is specified, the system selects an appropriate state or subject-dependent setting
SOFT_INPUT_ADJUST_RESIZE 1. When the soft keyboard pops up, the window will be resized, such as clicking an EditView, and the entire layout will be visible and placed on top of the software disk

2. This mode can not be used in combination with SOFT_INPUT_ADJUST_PAN

3. If the window’s layout parameter flag contains FLAG_FULLSCREEN, this value is ignored and the window does not resize, but remains full screen
SOFT_INPUT_ADJUST_PAN 1. When the soft keyboard pops up, the window does not need to be resized. Make sure that the input focus is visible

2. For example, if you have two EditView input boxes, one is Ev1 and the other is Ev2, when you click Ev1 to enter data, the current Ev1 input box will move to the top of the soft keyboard

3. This mode cannot be used in combination with SOFT_INPUT_ADJUST_RESIZE
SOFT_INPUT_ADJUST_NOTHING Will not resize and overwrite the window directly

Kotlin tip

Apply plus (+) and plus (-) to the Map set, as follows:

fun main() {
    val numbersMap = mapOf("one" to 1, "two" to 2, "three" to 3)

    // plus (+)
    println(numbersMap + Pair("four", 4)) // {one=1, two=2, three=3, four=4}
    println(numbersMap + Pair("one", 10)) // {one=10, two=2, three=3}
    println(numbersMap + Pair("five", 5) + Pair("one", 11)) // {one=11, two=2, three=3, five=5}

    // plus (-)
    println(numbersMap - "one") // {two=2, three=3}
    println(numbersMap - listOf("two"."four")) // {one=1, three=3}
}
Copy the code

conclusion

This article mainly introduces the types of Windows, which can be divided into three categories: Application Window (Application Window), sub-window (Sub Windwow) and System Window (System Window). The type of Window, the hierarchical order of Window view, the flag of Window, and the Window soft keyboard mode are respectively introduced to pave the way for the following content

What common parameters does Window have?

parameter note
x Window’s top left x-coordinate
y The y coordinate at the top left corner of window
type The type of the Window
flag The Window flag controls the display of the Window
softInputMode Window Displays the input area of the soft keyboard
alpha Window transparency. The value is 0-1
gravity Position of Window in the screen
alpha Window transparency. The value is 0-1
format Window PixelFormat. The value is defined in PixelFormat

What types do Windows have?

The Application Window (Application Window), the child Window (Sub Windwow), the System Window (System Window), the child Window is attached to the parent Window, And their coordinate space relative to the parent Window, each large type contains multiple small types, each of which is listed in the table above.

Window’s outdated apis and solutions?

  1. TYPE_PHONE, TYPE_SYSTEM_ALERT, TYPE_TOAST, TYPE_SYSTEM_OVERLAY, TYPE_PRIORITY_PHONE, and TYPE_SYSTEM_ERROR are listed in API 26 Have been out of date, in using TYPE_APPLICATION_OVERLAY instead of, need to apply for the Manifest. Permission. SYSTEM_ALERT_WINDOW permissions

  2. TYPE_KEYGUARD has been removed from the system and can be replaced with TYPE_KEYGUARD_DIALOG

How is the Window view hierarchy determined?

The parameters x and y of Window respectively represent the x coordinate of the upper left corner of Window and the Y coordinate of the upper left corner of Window. The hierarchical order of Window view is represented by z-order. Z – order corresponds to the WindowManager. LayoutParams type value of Z – the order can be understood as Android view hierarchy concept, and the larger the value, the more, the more close to the user. MBaseLayer and mSubLayer determine the two factors of z-order

What flags do Windows have?

The Window flag controls the display of the Window. The parameters of flag are as follows:

flag
note
FLAG_ALLOW_LOCK_WHILE_SCREEN_ON Allows screen lock while Window is visible
FLAG_DIM_BEHIND Everything behind the Window goes dark
FLAG_BLUR_BEHIND The API is out of date and everything behind the Window is blurred
FLAG_NOT_FOCUSABLE The Window cannot receive input focus, that is, it does not accept any key or button events. For example, if the Window has an EditView, clicking the EditView will not pop up the soft keyboard, and events outside the Window will still be processed by the original Window. For example, if you click on the view outside the window, you will still get a response. In addition, whenever this Flag is set, FLAG_NOT_TOUCH_MODAL will be enabled
FLAG_NOT_TOUCH_MODAL If this Flag is set, the button events outside the Window will be sent to the next Window for processing, and it will only process the touch events in the Window area, and the view outside the Window can also respond to the touch events
FLAG_NOT_TOUCHABLE If this Flag is set, the Window will not receive any touch events. For example, clicking on the Window will not receive a response, but only the Window with focus below
FLAG_KEEP_SCREEN_ON The screen stays on as long as the Window is visible
FLAG_LAYOUT_IN_SCREEN Allows Windows to fill the entire screen
FLAG_LAYOUT_NO_LIMITS Allows Windows to go beyond the screen
FLAG_FULLSCREEN Full screen display, hiding all Window decorations, such as full screen display in games and players
FLAG_FORCE_NOT_FULLSCREEN FLAG_FULLSCREEN is one level lower than FLAG_FULLSCREEN and displays the status bar
FLAG_IGNORE_CHEEK_PRESSES When the user’s face is close to the screen (such as making a phone call), this event is not responded to
FLAG_WATCH_OUTSIDE_TOUCH A motionEvent.action_outside event is received when the keystroke action occurs outside the Window
FLAG_SHOW_WHEN_LOCKED Windows can be displayed above the Window on the lock screen using the Active #setShowWhenLocked(Boolean) method instead
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS Represents responsible for drawing the system bar background. If set, the system bar will be drawn on a transparent background,

The corresponding area in this Window will be filled with the colors specified in Windows # getStatusBarColor () and Windows # getNavigationBarColor ()
FLAG_SHOW_WALLPAPER The Window surface must be translucent in order to see the wallpaper behind it

Window soft keyboard mode?

Window soft keyboard mode Indicates the display mode of the Window soft keyboard input area

model
note
SOFT_INPUT_STATE_UNCHANGED Does not change the state of the soft keyboard
SOFT_INPUT_STATE_VISIBLE When the user enters the window, the soft keyboard is displayed
SOFT_INPUT_STATE_HIDDEN Hide the soft keyboard when the user enters the window
SOFT_INPUT_STATE_ALWAYS_HIDDEN Hide the soft keyboard when the window gets focus
SOFT_INPUT_STATE_ALWAYS_VISIBLE A soft keyboard is displayed when the window gets focus
SOFT_INPUT_MASK_ADJUST The window is resized to fit the soft keyboard window
SOFT_INPUT_ADJUST_UNSPECIFIED If no state is specified, the system selects an appropriate state or subject-dependent setting
SOFT_INPUT_ADJUST_RESIZE 1. When the soft keyboard pops up, the window will be resized, such as clicking an EditView, and the entire layout will be visible and placed on top of the software disk

2. This mode can not be used in combination with SOFT_INPUT_ADJUST_PAN

3. If the window’s layout parameter flag contains FLAG_FULLSCREEN, this value is ignored and the window does not resize, but remains full screen
SOFT_INPUT_ADJUST_PAN 1. When the soft keyboard pops up, the window does not need to be resized. Make sure that the input focus is visible

2. For example, if you have two EditView input boxes, one is Ev1 and the other is Ev2, when you click Ev1 to enter data, the current Ev1 input box will move to the top of the soft keyboard

3. This mode cannot be used in combination with SOFT_INPUT_ADJUST_RESIZE
SOFT_INPUT_ADJUST_NOTHING Will not resize and overwrite the window directly

reference

  • developer.android.google.cn/… / WindowM…
  • www.jianshu.com/p/352825547…

conclusion

Dedicated to sharing a series of Android system source code, reverse analysis, algorithm, translation, Jetpack source code related articles, if you like me like Android source code, you can follow me, if you like this article welcome star, come to learn together, looking forward to growing with you

The article lists

algorithm

Since LeetCode has a large question bank, hundreds of questions can be selected for each category. Due to the limited energy of each person, it is impossible to brush all the questions. Therefore, I sorted the questions according to the classic types and the difficulty of the questions

  • Data structures: arrays, stacks, queues, strings, linked lists, trees…
  • Algorithms: Search algorithm, search algorithm, bit operation, sorting, mathematics,…

Each problem will be implemented in Java and Kotlin, and each problem has a solution idea. If you like algorithms and LeetCode like me, you can pay attention to my Solution of LeetCode problem on GitHub: Leetcode-Solutions-with-Java-And-Kotlin, come to learn together And look forward to growing with you

Android 10 source code series

I’m writing a series of Android 10 source code analysis articles. Knowing the system source code is not only helpful in analyzing problems, but also very helpful in the interview process. If you like to study Android source code as MUCH as I do, You can follow my Android10-source-Analysis on GitHub, and all articles will be synchronized to this repository

  • How is APK generated
  • APK installation process
  • 0xA03 Android 10 source code analysis: APK loading process of resource loading
  • Android 10 source code: APK
  • Dialog loading and drawing process and use in Kotlin, DataBinding
  • WindowManager View binding and architecture
  • More and more

Android Apps

  • How to get video screenshots efficiently
  • How to package Kotlin + Android Databinding in your project
  • [Google engineers] just released a new Fragment feature, “New ways to transfer Data between Fragments” and source code analysis
  • [2.4K Start] Drop Dagger to Koin
  • [5K +] Kotlin’s performance optimization stuff
  • How does FragmentFactory elegantly use Koin and partial source code analysis
  • Decrypt RxJava’s exception handling mechanism
  • Bye-bye buildSrc, embrace Composing builds for faster Android builds

Tool series

  • Shortcuts to AndroidStudio that few people know
  • Shortcuts to AndroidStudio that few people know
  • All you need to know about ADB commands
  • 10 minutes introduction to Shell scripting

The reverse series

  • Dynamically debug APP based on Smali file Android Studio
  • The Android Device Monitor tool cannot be found in Android Studio 3.2