Android 4.4 SystemUI 状态栏和导航栏加载流程

wuchangjian2021-11-04 20:01:42编程学习

代码路径:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
frameworks/base/packages/SystemUI/res/layout/status_bar.xml
frameworks/base/packages/SystemUI/res/layout/super_status_bar.xml
一、状态栏加载流程
在PhoneStatusBar.java文件中addStatusBarWindow() 方法中添加窗口

private void addStatusBarWindow() {
    // Put up the view
    final int height = getStatusBarHeight();

    // Now that the status bar window encompasses the sliding panel and its
    // translucent backdrop, the entire thing is made TRANSLUCENT and is
    // hardware-accelerated.
    final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            height,
            WindowManager.LayoutParams.TYPE_STATUS_BAR,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);

    lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;

    lp.gravity = getStatusBarGravity();
    lp.setTitle("StatusBar");
    lp.packageName = mContext.getPackageName();

    makeStatusBarView();
    if (DEBUG_THEME) Log.d(TAG, "add StatusBarWindow now");
    mWindowManager.addView(mStatusBarWindow, lp);
}

在PhoneStatusBar.java文件中makeStatusBarView()方法中加载状态栏super_status_bar.xml布局文件

protected PhoneStatusBarView makeStatusBarView() {
    final Context context = mContext;

Resources res = context.getResources();

updateDisplaySize(); // populates mDisplayMetrics
loadDimens();

mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
    mStatusBarWindow = (StatusBarWindowView) View.inflate(context,
            R.layout.super_status_bar, null);
    mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
    //设置状态栏背景
    mStatusBarView.setBackground(mContext.getResources().getDrawable(R.drawable.statusbarbackground));
}

在PhoneStatusBar.java文件中getStatusBarHeight()方法中获取状态栏的高度

public int getStatusBarHeight() {
    if (mNaturalBarHeight < 0) {
        final Resources res = mContext.getResources();
        mNaturalBarHeight =
                res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
    }
    return mNaturalBarHeight;
}

在PhoneStatusBarView.java文件中加载status_bar.xml和super_status_bar.xml布局文件

mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
mStatusBarWindow = (StatusBarWindowView) View.inflate(context,
        R.layout.super_status_bar, null);

相关文章

Java变量命名网站

Java变量命名网站

CODELFBest GitHub stars, repositories tagger...

数据库常用的事务隔离级别都有哪些?都是什么原理?

数据库常用的事务隔离级别都有哪些?都是什么原理?

什么是事务隔离? 事务ACID特性 任何支持事务的数据库,...

pandas 获取不符合条件/不包含某个字符串的dataframe

工作中数据的处理中往往会遇到筛选出不符合条件的或者不包含某个字符的dataframe&#...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。