没有合适的资源?快使用搜索试试~ 我知道了~
首页android systemUI 学习资料
资源详情
资源评论
资源推荐

http://blog.csdn.net/andyhuabing/article/details/12851825
android SystemUI 流程分析
什么是 SystemUI?
对于 Phone 来说 SystemUI 指的是:StatusBar(状态栏)、NavigationBar(导航栏)。而对于
Tablet 或者是 TV 来说 SystemUI 指的是:
CombinedBar(包括了 StatusBar 和 NavigationBar)。
启动后 Phone 界面上的信号,蓝牙标志,Wifi 标志等等这些状态显示标志都会在
StatusBar 上显示。当我们的设备开机后,首先
需要给用户呈现的就是各种界面同时也包括了我们的 SystemUI,因此对于整个 Android 系
统来说,SystemUI 都有举足轻重的作用。
现在就从代码开始一步步的分析
1、启动流程
代码路径:fameworks/base/packages/SystemUI 建立工程导入到 eclipse 中代码具体图示:
先从

AndroidManifest.xml 看看有哪些东东,以前说过 android 中有四大组件,这里就有如下的
三大部分:
系统服务 Service :
SystemUIService
TakeScreenshotService
LoadAverageService
广播接收器 BroadcastReceive:
BootReceiver
Activity 应用:
USB 的挺多哟...
UsbStorageActivity
UsbConfirmActivity
UsbPermissionActivity
UsbStorageActivity
UsbAccessoryUriActivity
NetworkOverLimitActivity
<!-- started from ... somewhere -->
Nyandroid
具体定义请看 AndroidManifest.xml 文件,上面只是简单的列一下
先看第一个 Activity -- Nyandroid 这里做了什么呢?
就是网上传说中的 好多安卓机器人飞过去。。。。其中代码很简单,简单说一下动画效果
的代码:
[java] view plain copy print ?

1 <span style="font-size:14px">public class FlyingCat extends ImageView
{
2
3 public FlyingCat(Context context, AttributeSet as) {
4 super(context, as);
5 setImageResource(R.drawable.nyandroid_anim); // @@@
6
7 if (DEBUG) setBackgroundColor(0x80FF0000);
8 }
9 ...
10 }</span>
定义在 frameworks\base\packages\SystemUI\res\drawable\nyandroid_anim.xml
[html] view plain copy print ?
11 <span style="font-size:14px"><animation-list
12 xmlns:android="http://schemas.android.com/apk/res/android"
13 android:oneshot="false">
14 <item android:drawable="@drawable/nyandroid00"
android:duration="80" />
15 <item android:drawable="@drawable/nyandroid01"
android:duration="80" />
16 <item android:drawable="@drawable/nyandroid02"
android:duration="80" />
17 <item android:drawable="@drawable/nyandroid03"
android:duration="80" />
18 <item android:drawable="@drawable/nyandroid04"
android:duration="80" />
19 <item android:drawable="@drawable/nyandroid05"
android:duration="80" />
20 <item android:drawable="@drawable/nyandroid06"
android:duration="80" />
21 <item android:drawable="@drawable/nyandroid07"
android:duration="80" />
22 <item android:drawable="@drawable/nyandroid08"
android:duration="80" />
23 <item android:drawable="@drawable/nyandroid09"
android:duration="80" />
24 <item android:drawable="@drawable/nyandroid10"
android:duration="80" />
25 <item android:drawable="@drawable/nyandroid11"

android:duration="80" />
26 </animation-list></span>
相关图片在: frameworks\base\packages\SystemUI\res\drawable-nodpi 如图示:
然后再看最重要的服务:SystemUIService
一般来说,Service 启动一般由开机广播或者 StartService/BindService 这几种方式来启动。
既然这个 Service 是一个系统
服务,应该是由系统这边启动,那么看下 SystemServer.java ,果然发现如下启动代码:
[java] view plain copy print ?
27 <span style="font-size:14px">startSystemUi(contextF);
28
29 static final void startSystemUi(Context context) {
30 Intent intent = new Intent();
31 intent.setComponent(new ComponentName("com.android.systemui",
32 "com.android.systemui.SystemUIService"));
33 Slog.d(TAG, "Starting service: " + intent);
34 context.startService(intent);
35 }</span>
对于 Android 启动流程请看如下系统文章:
http://blog.csdn.net/andyhuabing/article/details/7346203 android 启动--深入理解 init 进程
http://blog.csdn.net/andyhuabing/article/details/7349986 android 启动--深入理解 zygote
http://blog.csdn.net/andyhuabing/article/details/7351691 android 启动--深入理解 zygote
(II)
http://blog.csdn.net/andyhuabing/article/details/7353910 android 启动--深入理解启动
HOME
那么就继续跟踪 SystemUIService 中代码:
[java] view plain copy print ?
36 <span style="font-size:14px">/**

37 * The class names of the stuff to start.
38 */
39 final Object[] SERVICES = new Object[] {
40 0, // system bar or status bar, filled in below.
41 com.android.systemui.power.PowerUI.class,
42 };
43
44 @Override
45 public void onCreate() {
46 // Pick status bar or system bar.
47 IWindowManager wm = IWindowManager.Stub.asInterface(
48 ServiceManager.getService(Context.WINDOW_SERVICE));
49 try {
50 SERVICES[0] = wm.canStatusBarHide()
51 ? R.string.config_statusBarComponent
52 : R.string.config_systemBarComponent;
53 } catch (RemoteException e) {
54 Slog.w(TAG, "Failing checking whether status bar can hide",
e);
55 }
56
57 final int N = SERVICES.length;
58 mServices = new SystemUI[N];
59 for (int i=0; i<N; i++) {
60 Class cl = chooseClass(SERVICES[i]);
61 Slog.d(TAG, "loading: " + cl);
62 try {
63 mServices[i] = (SystemUI)cl.newInstance();
64 } catch (IllegalAccessException ex) {
65 throw new RuntimeException(ex);
66 } catch (InstantiationException ex) {
67 throw new RuntimeException(ex);
68 }
69 mServices[i].mContext = this;
70 Slog.d(TAG, "running: " + mServices[i]);
71 mServices[i].start();
72 }
73 }</span>
在这代码中:[java] view plain copy print ?
74 <span style="font-size:14px">SERVICES[0] = wm.canStatusBarHide()
75 ? R.string.config_statusBarComponent
剩余27页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论2