热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Androidgraphics:Howanalertwindowisdisplayed?

Androidgraphics:Howanalertwindowisdisplayed?一、initilizationanddatastructure.AlertDialoginh

Android graphics: How an alert window is displayed?

 

一、initilization and data structure.

AlertDialog inherites from Dialog and it hold a member of AlertController mAlert.

 

 

In dialog.java, Dialog in constrcuted. it creates a new phoneWindow, and store it in it's mWindow member.

 the window is registered in WMS. so it can interact with WMS to handle the input from users.

 

 

frameworks/base/policy/src/com/android/internal/policy/impl/Policy.java
frameworks/base/core/java/android/view/Window.java

 

 

164 Window w = PolicyManager.makeNewWindow(mContext);

mWindow = w;
w.setWindowManager(mWindowManager, null, null);
in AlertDiaog constructor, Dialog's phoneWindow will be passed to AlertController's mWindow
alertDialog.java
AlertDialog(Context context, int theme, boolean createThemeContextWrapper) {
mAlert = new AlertController(getContext(), this, getWindow());
}

 

 

二、show() function.

how the dialog window is shown??

you need to invoke the dialog.show() to display the dialog window, before this, you need to 

setup the contents of dialog.

the code snippet is like:

1 AlertDialog.Builder ad = new AlertDialog.Builder(cxt);
2
3 ad.setTitle(title);
4 ad.setMessage(message);
5
6 ad.setPositiveButton(
7 b1string,
8 new DialogInterface.OnClickListener() {
9
10 @Override
11 public void onClick(DialogInterface arg0, int arg1) {
12 // TODO Auto-generated method stub
13
14 }
15 }
16 );
17
18 ad.show();

 

I add a function to print the call stack :

E/SS ( 1973): com.android.internal.policy.impl.PhoneWindow$DecorView.setWindowBackground(PhoneWindow.java:2348)

 

E/SS ( 1973): com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2843)
E/SS ( 1973): com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2884)
E/SS ( 1973): com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
E/SS ( 1973): com.android.internal.app.AlertController.installContent(AlertController.java:262)
E/SS ( 1973): android.app.AlertDialog.onCreate(AlertDialog.java:337)
E/SS ( 1973): android.app.Dialog.dispatchOnCreate(Dialog.java:355)
E/SS ( 1973): android.app.Dialog.show(Dialog.java:260)

 

in the show() , 
1) it first invokes the AlertDialog.onCreate function to installDecor(), which generates the new decorview(), and inflate the view with the contents
2)
the decorView which acts as the root of the view, is registered to the Window manager.

public void show() {

             mWindowManager.addView(mDecor, l);

}
addview里面会生成新的viewroot
frameworks/base/core/java/android/view/WindowManagerGlobal.java

public void addView(View view, ViewGroup.LayoutParams params,

            Display display, Window parentWindow) {

         root = new ViewRootImpl(view.getContext(), display);

}

the role of viewroot is to interact with WMS, so it can receives key input from users, also it can request WMS to do something.

a Viewroot has a new layer, surface , phone window here. After this, it can invoke performTraversal() to ask Choreographer to draw the image.


转:https://www.cnblogs.com/geeks/p/3266051.html



推荐阅读
author-avatar
神秘的绝代双角
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有