热门标签 | 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



推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 本文介绍了在MFC下利用C++和MFC的特性动态创建窗口的方法,包括继承现有的MFC类并加以改造、插入工具栏和状态栏对象的声明等。同时还提到了窗口销毁的处理方法。本文详细介绍了实现方法并给出了相关注意事项。 ... [详细]
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社区 版权所有