[Android FrameWork 6.0 Source Learning] The AddView method of WindowManager of the redraw process of view

Source: Internet
Author: User

Blog home: http://www.cnblogs.com/kezhuang/p/


About the activity of the Contentview construction process, I have analyzed in my blog, I do not know can go to see

"[Android FrameWork 6.0 Source Learning] Window Windows class analysis"

This chapter blog is followed by the above blog analysis, the purpose is to elicit analysis of Viewrootimpl this class. Now it's just a parse of the window and Activitythread call procedure.

From Activitythread to WindowManager to viewrootimpl this piece still belongs to the blank part, so to fill this blog

At the end of the last blog, it was mentioned that the WindowManager AddView to request the display interface, then we went on to analyze

WindowManager This is an interface, he inherits the Viewmanager this interface, therefore has the ability to manage the view

WindowManager This example is obtained through the Activity.getwindowmanager method, we first find his example, in the gradual look at the AddView function

     Public WindowManager Getwindowmanager () {        return  mwindowmanager;    }

This function, defined in activity, returns the Mwindowmanager, and then looks for the place where the Mwindowmanager object is assigned.

    Final voidAttach (context context, Activitythread Athread, Instrumentation instr, IBinder token,intident, application application, Intent Intent, activityinfo info, charsequence title, Activity Parent, String ID, nonconfigurationinstances lastnonconfigurationinstances, Configuration config, St Ring referrer, Ivoiceinteractor voiceinteractor) {Mwindow=NewPhonewindow ( This); Mwindow.setcallback ( This); Mwindow.setonwindowdismissedcallback ( This); Mwindow.getlayoutinflater (). Setprivatefactory ( This); Mwindow.setwindowmanager (WindowManager) Context.getsystemservice (Context.window_service), M Token, Mcomponent.flattentostring (), (Info.flags& activityinfo.flag_hardware_accelerated)! = 0); if(Mparent! =NULL) {Mwindow.setcontainer (Mparent.getwindow ()); } Mwindowmanager=Mwindow.getwindowmanager (); }

We see that the Mwindowmanager method is assigned to the attach method called during activity initialization, but this value is obtained from the Mwindow object, and we go to look

     Public WindowManager Getwindowmanager () {        return  mwindowmanager;    }

This is also defined in window, returning Mwindowmanager

     Public voidSetwindowmanager (WindowManager wm, IBinder Apptoken, String appName,Booleanhardwareaccelerated) {Mapptoken=Apptoken; Mappname=AppName; Mhardwareaccelerated=hardwareaccelerated|| Systemproperties.getboolean (PROPERTY_HARDWARE_UI,false); if(WM = =NULL) {WM=(WindowManager) Mcontext.getsystemservice (Context.window_service); } Mwindowmanager= ((Windowmanagerimpl) WM). Createlocalwindowmanager ( This); }

The Mwindowmanager in window is created in Setwindowmanager, and this setwindowmanager is actually called in the attach method of the activity.
You can see that the system service is actually used WindowManager strong turn into Windowmanagerimpl and then call the Createlocalwindowmanager method to get the object

     Public Windowmanagerimpl Createlocalwindowmanager (Window parentwindow) {        returnnew  Windowmanagerimpl (Mdisplay, ParentWindow);    }

This method is also very simple, is new a bit Windowmanagerimpl

OK, until now we can know that the WindowManager implementation class is Windowmanagerimpl, then we continue to analyze the AddView method it implements

    @Override    publicvoid  AddView (@NonNull view view, @NonNull Viewgroup.layoutparams params) {        applydefaulttoken (params);        Mglobal.addview (view, params, mdisplay, Mparentwindow);    }

The method is defined in Windowmanagerimpl, Mglobal is a Windowmanagerglobal object, and is a system singleton object

     Public voidAddView (view view, Viewgroup.layoutparams params, display display, Window parentwindow) {if(View = =NULL) {            Throw NewIllegalArgumentException ("View must not is null"); }        if(Display = =NULL) {            Throw NewIllegalArgumentException ("Display must not is null"); }        if(! (paramsinstanceofwindowmanager.layoutparams)) {Throw NewIllegalArgumentException ("Params must be Windowmanager.layoutparams"); }        FinalWindowmanager.layoutparams Wparams =(windowmanager.layoutparams) params; if(ParentWindow! =NULL) {Parentwindow.adjustlayoutparamsforsubwindow (wparams); } Else {            //If There ' s no parent, then hardware acceleration for this view is//set from the application ' s hardware acceleration setting.            FinalContext context =View.getcontext (); if(Context! =NULL&&(Context.getapplicationinfo (). Flags& applicationinfo.flag_hardware_accelerated)! = 0) {Wparams.flags|=WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;        }} Viewrootimpl root; View Panelparentview=NULL; synchronized(mLock) {//Start watching for system property changes.            if(Msystempropertyupdater = =NULL) {Msystempropertyupdater=NewRunnable () {@Override Public voidrun () {synchronized(mLock) { for(inti = Mroots.size ()-1; I >= 0; --i) {mroots.get (i). Loadsystemproperties ();                }                        }                    }                };            Systemproperties.addchangecallback (Msystempropertyupdater); }            intindex = findviewlocked (view,false); if(Index >= 0) {                if(Mdyingviews.contains (view)) {//Don ' t wait for Msg_die to make it's the through root ' s queue.mroots.get (Index). Dodie (); } Else {                    Throw NewIllegalStateException ("View" +View+ "have already been added to the window manager."); }                //The previous removeview () had not completed executing. Now it has.            }            //If This is a panel window and then find the window it is being//Attached to for the future reference.            if(Wparams.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&Wparams.type<=WindowManager.LayoutParams.LAST_SUB_WINDOW) {                Final intCount =mviews.size ();  for(inti = 0; I < count; i++) {                    if(Mroots.get (i). Mwindow.asbinder () = =wparams.token) {Panelparentview=Mviews.get (i); }                }            }                    //created a new Viewrootimpl object .Root =NewViewrootimpl (View.getcontext (), display);            View.setlayoutparams (Wparams); //Save Viewrootimpl and view for the current interface and add layout parametersmviews.add (view);            Mroots.add (root);        Mparams.add (Wparams); }        //because it fires off messages to start doing things        Try {        //call the Setview method in Viewrootimpl, prepare the view redraw process, and draw to the interfaceRoot.setview (view, Wparams, Panelparentview); } Catch(RuntimeException e) {//badtokenexception or invaliddisplayexception, clean up.            synchronized(mLock) {Final intindex = findviewlocked (view,false); if(Index >= 0) {removeviewlocked (index,true); }            }            Throwe; }    }

This is the end of the blog, and then I summarize the next process
1.Activity initialization creates a WindowManager object (and the system's WindowManager service is a bit different)
2. Use this activity-specific WindowManager object request to add a view to the current interface
3.WindowManager find its own implementation class Windowmanagerimpl, and then delegate to the system Singleton class Windowmanagerglobal processing
4.WindowManagerGlobal creates a Viewrootimpl object.
The 5.ViewRootImpl object calls the Setview method, and then the interface is redrawn and finally presented to surface for the interface


OK, very clear analysis of the process from WindowManager to Viewrootimpl, then you can analyze Viewrootimpl.setview and Viewrootimpl Performtraversals method

[Android FrameWork 6.0 Source Learning] The AddView method of WindowManager of the redraw process of view

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.