在Activity 从加载布局文件到显示的过程分析文中最后介绍到,承载了布局文件的DecorView通过ViewManger添加进行显示,那添加之后的显示过程又是怎么样的呢?本篇文章主要分析它接下来显示的过程。
ViewManager WindowManger WindowMangerImpl
activity的makeVisible()还是ActivityThread的handleResumeActivity()函数中,都出现过下面这段代码
if (!mWindowAdded) {
ViewManager wm = getWindowManager();
wm.addView(mDecor, getWindow().getAttributes());
mWindowAdded = true;
}
将mDecorView添加到wm中,先来看看ViewManger
public interface ViewManager{
public void addView(View view, ViewGroup.LayoutParams params);
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
public void removeView(View view);
}
ViewManger是一个接口,里面包含三个函数的定义,用于添加、删除、更新view
那接下来看看getWindowManger()函数
public WindowManager getWindowManager() {
return mWindowManager;
}
直接返回mWindowManger,那继续查找mWindowManger是在哪里初始化的。
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config, String referrer, IVoiceInteractor voiceInteractor) {
attachBaseContext(context);
mWindow = new PhoneWindow(this);
mWindow.setCallback(this);
mWindow.setOnWindowDismissedCallback(this);
//省略部分代码
mWindow.setWindowManager(
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
mToken, mComponent.flattenToString(),
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
}
//mWindowManager初始化
mWindowManager = mWindow.getWindowManager();
mCurrentConfig = config;
}
在activity的attach()方法中对mWindowManager通过mWindow.getWindowManager()获取。那继续看mWindow.getWindowManager()代码
public WindowManager getWindowManager() {
return mWindowManager;
}
也是直接返回mWindowManager,那在Window中查找mWindowManager的初始化
public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
boolean hardwareAccelerated) {
mAppToken = appToken;
mAppName = appName;
mHardwareAccelerated = hardwareAccelerated
|| SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, fals