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.
164 Window w = PolicyManager.makeNewWindow(mContext);
二、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)
public void show() {
mWindowManager.addView(mDecor, l);
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.