"Android Development Art Quest" reading notes (eight)--windowmanager

Source: Internet
Author: User

NO1:

Window is an abstract class, and its implementation is Phonewindow. Creating a window is a simple thing to do with WindowManager .

WindowManager is the doorway to the outside window, and the concrete implementation of window is located in windowmanagerservice , Windwomanager and Windowmanagerservice interact with an IPC process.

All views in Android are rendered through window, so window is actually the Direct manager of the view.

The single-machine event is passed to the decorviewby the window and then passed to our view by Decorview.

No2:

There are three types of Windows, namely, the application window, the child window, and the System window.

application Window--an Activity

child window--cannot exist alone and needs to be attached to a particular parent window, such as Dialog

System Window--a window that needs to declare permissions to create, such as Toast and system status bar

No3:

The window is layered, each window has a corresponding z-ordered, and the large level will be covered by the small window of the hierarchy.

Application Layer window hierarchy scope 1~99

Sub window hierarchy range 1000~1999

System window hierarchy range 2000~2999

These level ranges correspond to the type parameters of the windowmanager.layoutparams . If you want the window to be at the top of all windows, use a larger hierarchy .

No4:

WindowManager features are simple, with only three common methods, add Viewaddview, update viewupdateviewlayout , and delete view Removeview, these three methods are defined in Viewmanager, and WindowManager inherits Viewmanager.

NO5:

Window effects that you can drag

 Public BooleanOnTouch (View v,motionevent event) {intRAWX = (int) event.getrawx (); intRawy = (int) Event.getrawy (); Switch(Event.getaction ()) { Casemotionevent.action_move:mlayoutparams.x=rawx; Mlayoutparams.y=Rawy;            Mwindowmanager.updateviewlayout (Mfloationbutton,mlayoutparams);  Break; default:             Break; }    return false;}

NO6:

Window is an abstract concept, and each window corresponds to a view and a viewrootimpl, window and view are connected by Viewrootimpl. So window is not actually there, it is in the form of view .

The window cannot be accessed directly in actual use, and access to the window must be through windowmanager.

No7:

WindowManager is an interface , and its true implementation is the Windowmanagerimpl class. Windowmanagerimpl did not directly realize the three operations of window, but all to the Windowmanagerglobal to deal with.

Windowmanagerimpl This mode of operation is a typical bridging mode .

No8:

The Add Process for window

1. Check whether the parameters are legal, if it is a child window then you need to adjust some layout parameters

2. Create the Viewrootimpl and add the view to the list

3. update the interface via Viewrootimpl and complete the window add process

The drawing process for view is done by Viewrootimpl, which completes the asynchronous refresh request through requestlayout setview,scheduletraversals Actually is the view draws the entrance, then through windowsession finally completes the window's addition process, the real implementation class is the Session, namely window's addition process is an IPC call, Windowmanagerservice is called inside the session to implement window additions.

No9:

Delete process for window

Windowmanagerimpl-->windowmanagerglobal-->viewrootimpl

WindowManager provides two kinds of delete interfaces Removeview and Removeviewimmediate, respectively, for asynchronous deletion and synchronous deletion.

The asynchronous deletion is done by Viewrootimpl's Die method, which sends a message to delete the request, and the handler in Viewrootimpl processes the message and calls the Dodie method. If it is a synchronous deletion, then the Dodie method is called directly without sending a message.

Dodie internal calls the Dispatchdetachedfromwindow method, Dispatchdetachedfromwindow mainly do four things:

1) garbage collection related work, such as purging data and messages, removing callbacks

2) Remove Window:mWindowSession.remove ( Mwindow) through the Remove method of the Session , which is also an IPC process, The Removewindow method of Windowmanagerservice will eventually be called

3) Call the Dispatchdetachedfromwindow method of view, and internally call the view's Ondetachedfromwindow () and ondetachedfromwindowinternal ()。

When the view is removed from the window, this method is called and can be used to do some recycling work, such as terminating the animation, stopping the thread, etc.

4) Call Windowmanagergolbal's Doremoveview method to refresh the data, including Mroots, Mparams, and Mdyingviews, to remove the three types of objects associated with the current window from the list.

No10:

window update process : Still want to see Windowmanagerglobal's updateviewlayout method:

1) Update the view's layoutparams through Viewrootimpl's setlayoutparams and replace the old layoutparams, then update Viewrootimpl

2) in Viewrootimpl, the scheduletraversals method is used to re-layout the view, including measurement, layout, and redrawing of the three processes

3) Viewrootimpl will also update the window view through windowsession , which is eventually implemented by Windowmanagerservice 's Relayoutwindow (). is also an IPC process

NO11:

The creation of the Window object is implemented through the policymanager Makenewwindow method. The real implementation of Policymanager is the Policy class, so the concrete implementation of window is indeed Phonewindow.

No12:

Setcontentview:activity-->window-->phonewindow

NO13:

Decorview is a framelayout, the top viewin activity, typically including the title bar and inner column

NO14:

The creation process of the Activity window

Setcontentview steps for Phonewindow

1) If there is no decorview, then create it

2) Add view to Decorview's mcontentparent ( This is the reason why the setcontentview of activity is not called Setview )

3) callback Activity oncontentchanged method informs activity view has changed

NO15:

In Activitythread 's makevisible() method, the activity's Onresume method is called first, and then the activity's Makevisible(), it is in the Makevisible method, Decorview really completed the addition and display of these two processes, the view of the activity here can be seen by the user.

NO16:

Window creation Process for dialog

1) Create Window

2) Initialize the Decorview and add the dialog view to the Decorview

3) Add the Decorview to the Window and display

NO17:

Ordinary dialog have a special place, is must use Activity of the context, if the use of application context, will error no token, and App tokens generally only activity-owned .

The system window does not require tokens, so you can specify the dialog box as the System type for window

NO18:

Toast has a function of timing cancellation , so the system uses Handler.

There are two types of IPC processes inside a toast, the first of which is toast access Notificationmanagerservice, and the second is the Notificationmanagerservice callback The TN interface inside the toast.

Both show and hide toasts need to be implemented through Notificationmanagerservice because the NMS is running in the system process , so it can only be displayed and hidden by remote invocation. TN is a binder class that runs in the binder thread pool, so it needs handler to switch it to the current thread, where the current thread refers to the thread where the toast request is sent.

NO19:

Enqueuetoast first encapsulates the toast request as a Toastrecord object and adds it to a queue named Mtoastqueue . Mtoastqueue is actually a ArrayList. For non-system applications, there are up to 50 Toastrecord in the Mtoastqueue. If you do not, it will cause other references to have no chance of popping the toast.

NO20:

After the toast has been deferred for a corresponding time, Notificationmanagerservice will hide the toast and remove it from mtoastqueue by means of the canceltoastlocked method. This time if there are other toasts in the Mtoastqueue, the NMS will continue to show other toasts. The Toastrecord of the toast is also done through the callback , which is also an IPC process.

NO21:

The two methods of TN in a toast show and hide are called in the NMS in a cross-process manner, so they run in the binder thread pool .

"Android Development Art Quest" reading notes (eight)--windowmanager

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.