Android 4.0 ICS SystemUI浅析——StatusBar加载流程分析

        前面两篇文章《Android 4.0 ICS SystemUI浅析——SystemUI启动流程》、《Android 4.0 ICS SystemUI浅析——StatusBar结构分析》SystemUI和StatusBar的冰山一角,那么本文将从代码的角度来分析StatusBar的加载流程。

       本文来自:http://blog.csdn.net/yihongyuelan 欢迎转载 请务必注明出处!

        在《Android 4.0 ICS SystemUI浅析——SystemUI启动流程》中,我们提到了在Phone中,整个StatusBar和NavigationBar都是在/SourceCode/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java的start()方法中,完成初始化并显示到界面上的。因此,我们回到这段代码中查看:

    @Override
    public void start() {
        mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();

        mWindowManager = IWindowManager.Stub.asInterface(
                ServiceManager.getService(Context.WINDOW_SERVICE));

        super.start(); // calls makeStatusBarView() 这里会调用父类StatusBar.java中的start()方法

        addNavigationBar();//加载导航栏,本文因以StatusBar为主,因此暂不分析NavigationBar

        //addIntruderView();

        // Lastly, call to the icon policy to install/update all the icons.
        mIconPolicy = new PhoneStatusBarPolicy(mContext);//用于初始化以及更新StatusBar上的icons
    }

       我们继续跟踪super.start()方法,来到/SourceCode/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java的start()方法中,如代码所示:

    
         public void start() {
        // First set up our views and stuff.首先准备我们需要显示的view以及原材料
        //我们先跟踪这里的makeStatusBarView
        View sb = makeStatusBarView();
        // Connect in to the status bar manager service
        StatusBarIconList iconList = new StatusBarIconList();
        ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
        ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
       ... ...
    }

       通过Open Implementation跳转到makeStatusBarView的实现,因为我们是针对Phone来分析的,因此选择PhoneStatusBar,代码如下:

    // ================================================================================
    // Constructing the view
    // ================================================================================
    protected View makeStatusBarView() {

        final Context context = mContext;

        Resources res = context.getResources();
        //获取ExpandedView的尺寸
        updateDisplaySize(); // populates mDisplayMetrics
        //定义icon的大小,缩放率和彼此间距
        loadDimens();
        mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
        //设置ExpandedView的布局
        ExpandedView expanded = (ExpandedView)View.inflate(context,
                R.layout.status_bar_expanded, null);
        if (DEBUG) {
            expanded.setBackgroundColor(0x6000FF80);
        }
        expanded.mService = this;
        //前面已注释,以下三段代码没有用到
        mIntruderAlertView = View.inflate(context, R.layout.intruder_alert, null);
        mIntruderAlertView.setVisibility(View.GONE);
        mIntruderAlertView.setClickable(true);
        PhoneStatusBarView sb;
        //这里根据是否是双卡来加载不同的布局文件
        if (TelephonyManager.getDefault().isMultiSimEnabled()) {
            sb = (PhoneStatusBarView)View.inflate(context,
                    R.layout.msim_status_bar, null);
        } else {
            sb = (PhoneStatusBarView)View.inflate(context,
                    R.layout.status_bar, null);
        }
        sb.mService = this;
        mStatusBarView = sb;
        //是否显示NavigationBar
        try {
            boolean showNav = mWindowManager.hasNavigationBar();
            if (showNav) {
                mNavigationBarView =
                    (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);

                mNavigationBarView.setDisabledFlags(mDisabled);
            }
        } catch (RemoteException ex) {
            // no window manager? good luck with that
        }

        // figure out which pixel-format to use for the status bar.
        mPixelFormat = PixelFormat.OPAQUE;
        //系统状态图标布局初始化
        mStatusIcons = (LinearLayout)sb.findViewById(R.id.statusIcons);
        //通知图标布局初始化
        mNotificationIcons = (IconMerger)sb.findViewById(R.id.notificationIcons);
        mMoreIcon = sb.findViewById(R.id.moreIcon);
        mNotificationIcons.setOverflowIndicator(mMoreIcon);
        //icons布局初始化,该布局用于装载除开tiker外的所有控件
        mIcons = (LinearLayout)sb.findViewById(R.id.icons);
        //ticker布局初始化
        mTickerView = sb.findViewById(R.id.ticker);
        //以上几个重要布局的关系在上一篇文章有详细分析

        //以下几段代码是在设置ExpandedView,ExpandedDialog通过加载ExpandedView显示,其中包括了ExpanedView上的清除按钮,
        //设置按钮,滚动条,日期显示等等
        mExpandedDialog = new ExpandedDialog(context);
        mExpandedView = expanded;
        mPile = (NotificationRowLayout)expanded.findViewById(R.id.latestItems);
        mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout);
        mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle);
        mNoNotificationsTitle.setVisibility(View.GONE); // disabling for no
  • 24
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 31
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 31
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值