`
carywei
  • 浏览: 188530 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

statusbar icon update 转

阅读更多

公司前些天发现一个状态栏显示图标不正确的Bug,昨天也转给我,看我能帮上什么忙,我对状态栏完全没有接触,正好趁这个机会,粗略看了下相关的代码,记下来一些自己的理解。希望能对以后有些帮助。 
由于同事的帮助,我不需要从头开始找起,我对StatusBar Service的理解是从StatusBarPolicy开始的。 
--StatusBarPolicy-- 
    包含了所有在启动时安装在StatusBar上图标的策略。看了一下这个类的属性值,基本我们显示的图标信息都有定义,例如:时钟,电池电量,手机信号, 蓝牙,Wifi,gps等。在类的内部有一个变量 mIntentReceiver,它是BroadcastReceiver类型。它接受各种Intent信息,然后调用本类的update*函数,对 StatusBar的各种图标进行更新。它是如何更新的呢?原来在它的属性值中保存了StatusBarService 的引用mService!它对图标的更新都会转化为StatusBarService 对updateIcon等方法的调用。 
总体来说StatusBarPolicy保存了图标的引用,根据各种策略计算出现在应该显示的图标,然后将图标的资源ID等信息进行封装后,传递给StatusBarService。 
--StatusBarService-- 
在 此服务中updateIcon 转化为对addPendingOp调用,这里需要注意addPendingOp 参数code,这个参数给出了具体执行的逻辑分支,并将我们的调用封装为了PendingOp类型,然后加到mQueue队列中,看到这里我立刻就想到去 寻找Handler,果真在类中有一个成员变量H 为Handler类型; 现在在H 的handleMessage方法中寻找我们更新的code类型OP_UPDATE_ICON,在这种情况下会调用 performAddUpdateIcon()。 
   在performAddUpdateIcon类中会区分两种情况进行处理,一种是notification,一种是icon,从我们刚才哪个路径进来的函数if (n != null) 判断为false,不会走入,接着看icon分支。 
    StatusBarIcon icon = mIconMap.get(key); 这个的意义是看Icon是否已经加在了StatusBar上了,如果icon ==null表明StatusBar没有相应图标需要增加,否则可能需要更新图标。具体将Icon增加到 StatusBar上的是这个语句: mStatusIcons.addView(icon.view, pos); Icon进行更新的是icon.update(mContext, data);

 

 

 

 

 

==========================

以前我的文章分析过  StatusBar上图标显示的流程,现在分析一下在  Android2.3中,  StatusBar的架构,其实  StatusBar的实现方法还是进行了许多大的修正的,比如原来  StatusBar的操作都是在  Service进程中,现在许多图标显示更新等的操作都移到了应用进程中。

代码目录结构  :

主要位于两个目录中

1,frameworks/base/services/java/com/android/server

这个目录在以前版本中也有

2,frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar

这个目录是  2.3版本新增加的,把许多界面的操作做到了应用里。

主要架构:

1  StatusBarManager是供应用层调用的接口,它会通过  Binder机制调用到  StatusBarManagerService

2  StatusBarMangerService位于  Service进程中,是由  ServerThread创建的,它与  NotificationManagerService InputMethodManagerService进行交互。

3  StatusBarManagerService在被创建的时候会启动一个应用层的  Service -StatusBarService,创建  StatusBarView,增加减少  Icon等等的处理,都是在这个  Service中。

分享到:
评论

相关推荐

    Visual C++ 编程资源大全(英文源码 表单)

    29.zip Using Buttons on a Dialog Bar with CCmdUI 通过CCmdUI在对话框条中使用按纽(19KB)<END><br>30,30.zip Display help for dialog controls on the status bar 在状态条中显示对话框中控件的帮助...

    类似qq的开发

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in ChatClient.rc to add ...

    细胞识别统计系统

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in Cell.rc to add ...

    mydraw绘图软件

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in MyDraw.rc to add ...

    华科VC++画图应用程序

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in MyPen.rc to add ...

    用OpenGL 导入 3DS 源文件

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in 3DSLoader.rc to add ...

    基于VC++的绘图程序

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in DrawDemo.rc to add ...

    细胞模式统计识别的VC++实现

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in Cell.rc to add toolbar...

    MouseDemo鼠标作图

    The initial toolbar and status bar are constructed in the CMainFrame class. Edit this toolbar bitmap using the resource editor, and update the IDR_MAINFRAME TOOLBAR array in MouseDemo.rc to add ...

    plsqldev12.0.6.1832x32主程序+ v12中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    plsqldev12.0.6.1832x64主程序+ v12中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    PLSQL.Developer(X32) v12.0.1.1814主程序+ v11中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    plsqldev12.0.4.1826x32主程序+ v12中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    PLSQL.Developer(X64) v12.0.1.1814 主程序+ v11中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    plsqldev12.0.4.1826x64主程序+ v12中文包+keygen

    The transaction status is now visible in the status bar of a window, next to the "Saved" and "Executing" indicators. Added user interface preference "Preselect current user for object selection lists...

    深入浅出MFC【侯捷】

    Document Template的意义 Scribble的Document/View设计 主窗口的诞生 工具栏和状态栏的诞生(Toolbar&Status bar) 鼠标拖放(Drag and Drop) 消息映射(Message Map) 标准菜单File/Edit/View/Window/Help 对话框...

    深入浅出MFC 2e

    工具栏和状态栏的诞生(Toolbar&Status bar) 鼠标拖放(Drag and Drop) 消息映射(Message Map) 标准菜单File/Edit/View/Window/Help 对话框 改用CEditView 第四篇 深入MFC程序设计 第8章 Document-View深入探讨 ...

    侯捷- -深入浅出MFC

    工具栏和状态栏的诞生(Toolbar&Status bar) 鼠标拖放(Drag and Drop) 消息映射(Message Map) 标准菜单File/Edit/View/Window/Help 对话框 改用CEditView 第四篇 深入MFC程序设计 第8章 Document-View深入探讨 ...

    Sublime Text 3 (Build 3143)

    New icon Added alternate theme, Adaptive, that inherits colors from the color scheme Added new color schemes Breakers, Mariana and Sixteen, derived from the excellent work of Chris Kempson and Dmitri ...

    VB编程资源大全(英文源码 API)

    <END><br>64,TransIco.zip An update to my previous code : Added a couple of features some ppl asked me for...like the ability to change the text colour of the icon and also keep the background ...

Global site tag (gtag.js) - Google Analytics