首先通过看android的启动流程,系统跑起来先加载system_progress后加载systemui。当时在改的时候systemui改错过导致启动不了,但看机器的启动过程会抛出异常后加载后面的进程,过会有重行回到system_progerss再次加载一遍(不知为什么暂不深究)。深入看看systemui启动过程,首先启动SystemUIService.java,在onCreate()方法中看到
public void onCreate() {
// Pick status bar or system bar.
IWindowManager wm = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
try {
SERVICES[0] = wm.canStatusBarHide()
? R.string.config_statusBarComponent
//跳转到phone
systemui
: R.string.config_systemBarComponent;
//启动为tablet systembar
} catch (RemoteException e) {
Slog.w(TAG, "Failing checking whether status bar can hide", e);
}
代码中看到通过AIDL的方式获取了WindowManager的对象wm,并调用其方法canStatusBarHide()来判断当前设备的类型,也就是说如果我们使用的Phone那么后续就会加载StatusBar和NivagationBar;而如果我们设备类型是Tablet,就会加载systemBar。
继续跟进到PhoneWindowManager找到canStatusBarHide()方法并查找获得返回值的地方
// Determine whether the status bar can hide based on the size
// of the screen.
We assume sizes > 600dp are tablets where we
// will use the system bar.
int shortSizeDp = shortSize
* DisplayMetrics.DENSITY_DEFAULT
/ DisplayMetrics.DENSITY_DEVICE;
mStatusBarCanHide = shortSizeDp < 320; //源码是600
mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
mStatusBarCanHide
? com.android.internal.R.dimen.status_bar_height
: com.android.internal.R.dimen.system_bar_height);
mHasNavigationBar = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_showNavigationBar);
// Allow a system property to override this. Used by the emulator.
// See also hasNavigationBar().
String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
if (! "".equals(navBarOverride)) {
if
(navBarOverride.equals("1")) mHasNavigationBar = false;
else if (navBarOverride.equals("0")) mHasNavigationBar = true;
}
mNavigationBarHeight = mHasNavigationBar
? mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.navigation_bar_height)
: 0;
mNavigationBarWidth = mHasNavigationBar
? mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.navigation_bar_width)
: 0;
看到了shortSizeDp的值正是计算device的dp值得公式,根据判断屏幕是否小于临界值,当小于就显示为statue bar 和navigationbar,否则显示为systembar。当然要显示navigationbar 记得要在config.xml文件中把true 设为true。
剩下的工作就是要改systemui的布局文件啊,伤不起啊!!本来是为600dp设计的布局被我强行改为320,改起来才知道看起来短短一排图标布局真心麻烦,配置文件写了代码里面还要动态设计,改的过程也走了不少弯路啊。布局位置调不动居然是背景太大了,最郁闷的是看了几天还是对systemui里的各个细节功能的看的云里雾里的。真心希望测试大哥不要测出些莫名奇妙的bug了,要不然到时我又要各种挠头了!!身为一名android菜鸟后面的路还有很长啊,以后也要坚持写写自己的学习心得,争取早日成为一名合格的程序猿,啷哩个浪!!