[Android FrameWork 6.0 source code learning] The setView method of repainting ViewRootImpl of View,

Source: Internet
Author: User

[Android FrameWork 6.0 source code learning] The setView method of repainting ViewRootImpl of View,

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

 

This article analyzes the subsequent work of WindowManager, that is, the work of the setView function of ViewRootImpl.

/I *** We have one child */public void setView (View view, WindowManager. layoutParams attrs, View panelParentView) {synchronized (this) {if (mView = null) {mView = view; // obtain the latest status of the current screen, you can also register a screen listener for the current DecorView to check whether the screen is disabled or the screen is mAttachInfo. mDisplayState = mDisplay. getState (); mDisplayManager. registerDisplayListener (mDisplayListener, mHandler); mviewlayoutdireinitiinitial = mView. getRawLayoutDirection (); mFa LlbackEventHandler. setView (view); m1_wattributes. copyFrom (attrs); if (m1_wattributes. packageName = null) {m?wattributes. packageName = mBasePackageName;} attrs = m?wattributes; // Keep track of the actual window flags supplied by the client. mClientWindowLayoutFlags = attrs. flags; // clear the focus of the auxiliary function setAccessibilityFocus (null, null); if (view instanceof RootViewSurfaceTaker) {mSurfaceHol DerCallback = (RootViewSurfaceTaker) view). willYouTakeTheSurface (); if (mSurfaceHolderCallback! = Null) {mSurfaceHolder = new TakenSurfaceHolder (); mSurfaceHolder. setFormat (PixelFormat. UNKNOWN) ;}}// Compute surface insets required to draw at specified Z value. // TODO: Use real shadow insets for a constant max Z. if (! Attrs. hasManualSurfaceInsets) {final int surfaceInset = (int) Math. ceil (view. getZ () * 2); attrs. surfaceInsets. set (surfaceInset, surfaceInset);} // obtain the screen compatibility mode. Generally, mTranslator is empty CompatibilityInfo compatibilityInfo = mDisplayAdjustments. getCompatibilityInfo (); mTranslator = compatibilityInfo. getTranslator (); // enable hardware acceleration if (mSurfaceHolder = null) {enableHardwareAccele Ration (attrs);} boolean restore = false; // Application does not consider compatibility mode if (mTranslator! = Null) {mSurface. setCompatibilityTranslator (mTranslator); restore = true; attrs. backup (); mTranslator. translateWindowLayout (attrs);} if (DEBUG_LAYOUT) Log. d (TAG, "WindowLayout in setView:" + attrs); // Application does not consider compatibility mode if (! CompatibilityInfo. supportsScreen () {attrs. privateFlags | = WindowManager. layoutParams. PRIVATE_FLAG_COMPATIBLE_WINDOW; mLastInCompatMode = true;} mSoftInputMode = attrs. softInputMode; m?wattributeschanged = true; m=wattributeschangesflag = WindowManager. layoutParams. EVERYTHING_CHANGED; mAttachInfo. mRootView = view; mAttachInfo. mScalingRequired = mTranslator! = Null; mAttachInfo. mApplicationScale = mTranslator = null? 1.0f: mTranslator. applicationScale; if (panelParentView! = Null) {mAttachInfo. mPanelParentWindowToken = panelParentView. getApplicationWindowToken ();} mAdded = true; int res;/* = WindowManagerImpl. ADD_OKAY; * // start to enable the painting thread here. requestLayout will trigger the entire Painting Process requestLayout (); if (m?wattributes. inputFeatures & WindowManager. layoutParams. INPUT_FEATURE_NO_INPUT_CHANNEL) = 0) {mInputChannel = new InputChannel () ;}try {mOrigWindowType = m?wattributes. type; MAttachInfo. mRecomputeGlobalAttributes = true; collectViewAttributes (); // mWindow is a static class in ViewRootImpl, which can be used to interact with WindowSession, indirectly interacting with WindowManagerService // is a bridge class res = mWindowSession. addToDisplay (mWindow, mSeq, m1_wattributes, getHostVisibility (), mDisplay. getDisplayId (), mAttachInfo. mContentInsets, mAttachInfo. mStableInsets, mAttachInfo. mOutsets, mInputChannel);} catch (RemoteException e) {MAdded = false; mView = null; mAttachInfo. mRootView = null; mInputChannel = null; mFallbackEventHandler. setView (null); unscheduleTraversals (); setAccessibilityFocus (null, null); throw new RuntimeException ("Adding window failed", e);} finally {if (restore) {attrs. restore () ;}} if (mTranslator! = Null) {mTranslator. translateRectInScreenToAppWindow (mAttachInfo. mContentInsets);} mPendingOverscanInsets. set (0, 0, 0, 0); mPendingContentInsets. set (mAttachInfo. mContentInsets); mPendingStableInsets. set (mAttachInfo. mStableInsets); mPendingVisibleInsets. set (0, 0, 0, 0); if (DEBUG_LAYOUT) Log. v (TAG, "Added window" + mWindow); // process the processing result of WindowManagerServices here. Here you can see many familiar exceptions if (res <WindowManage RGlobal. ADD_OKAY) {mAttachInfo. mRootView = null; mAdded = false; mFallbackEventHandler. setView (null); unscheduleTraversals (); setAccessibilityFocus (null, null); switch (res) {case WindowManagerGlobal. ADD_BAD_APP_TOKEN: case WindowManagerGlobal. ADD_BAD_SUBWINDOW_TOKEN: throw new WindowManager. badTokenException ("Unable to add window -- token" + attrs. token + "is not valid; is your activity runn Ing? "); Case WindowManagerGlobal. ADD_NOT_APP_TOKEN: throw new WindowManager. badTokenException ("Unable to add window -- token" + attrs. token + "is not for an application"); case WindowManagerGlobal. ADD_APP_EXITING: throw new WindowManager. badTokenException ("Unable to add window -- app for token" + attrs. token + "is exiting"); case WindowManagerGlobal. ADD_DUPLICATE_ADD: throw new WindowManager. badT OkenException ("Unable to add window -- window" + mWindow + "has already been added"); case WindowManagerGlobal. ADD_STARTING_NOT_NEEDED: // Silently ignore -- we wocould have just removed it // right away, anyway. return; case WindowManagerGlobal. ADD_MULTIPLE_SINGLETON: throw new WindowManager. badTokenException ("Unable to add window" + mWindow + "-- another window of this type already exists "); Case WindowManagerGlobal. ADD_PERMISSION_DENIED: throw new WindowManager. badTokenException ("Unable to add window" + mWindow + "-- permission denied for this window type"); case WindowManagerGlobal. ADD_INVALID_DISPLAY: throw new WindowManager. invalidDisplayException ("Unable to add window" + mWindow + "-- the specified display can not be found"); case WindowManagerGlobal. ADD_INVALID_TYPE: thro W new WindowManager. invalidDisplayException ("Unable to add window" + mWindow + "-- the specified window type is not valid ");} throw new RuntimeException ("Unable to add window -- unknown error code" + res);} if (view instanceof RootViewSurfaceTaker) {mInputQueueCallback = (RootViewSurfaceTaker) view ). willYouTakeTheInputQueue ();} if (mInputChannel! = Null) {if (mInputQueueCallback! = Null) {mInputQueue = new InputQueue (); mInputQueueCallback. onInputQueueCreated (mInputQueue);} mInputEventReceiver = new windowinputeventventer (mInputChannel, loput. mylogoff ();} // bind the mParent parameter view to the DecorView. assignParent (this); mAddedTouchMode = (res & WindowManagerGlobal. ADD_FLAG_IN_TOUCH_MODE )! = 0; mAppVisible = (res & WindowManagerGlobal. ADD_FLAG_APP_VISIBLE )! = 0; // determines whether the auxiliary function is available if (mAccessibilityManager. isEnabled () {mAccessibilityInteractionConnectionManager. ensureConnection ();} if (view. getImportantForAccessibility () = View. IMPORTANT_FOR_ACCESSIBILITY_AUTO) {view. setImportantForAccessibility (View. IMPORTANT_FOR_ACCESSIBILITY_YES);} // Set up the input pipeline. charSequence counterSuffix = attrs. getTitle (); response = new SyntheticInputStage (); InputStage viewPostImeStage = new ViewPostImeInputStage (response); InputStage nativePostImeStage = new response (viewPostImeStage, "aq: native-post-ime: "+ counterSuffix); InputStage earlyPostImeStage = new stage (nativePostImeStage); InputStage imeStage = new ImeInputStage (earlyPostImeStage," aq: ime: "+ counterSuffix ); inputStage viewPreImeStage = new stage (imeStage); InputStage stage = new stage (viewPreImeStage, "aq: native-pre-ime:" + counterSuffix); mFirstInputStage = stage; Stage = earlyPostImeStage; mPendingInputEventQueueLengthCounterName = "aq: pending:" + counterSuffix ;}}}

The content of this article is very simple. It is just the initialization of a large drawing process. Next we will focus on the analysis of the javasmtraversals function, which contains the onMeasure, onLayout, and onDraw calls of the View.
It is an important function in the View repainting process.

 

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.