QSPanel加载流程
首先通过一张图了解一下,如图红色区域就是QSPanel:包含亮度条和Quick Settings;本节的重点是后者。
QSPanel是StatusBar的一部分,自然是随着StatusBar的加载而加载,SystemUI 7.0学习笔记二-状态栏和导航栏介绍了状态栏的加载实在PhoneStatusBar的makeStatusBarView()中完成的;其实,这个方法完成了很多systemui重要组件的加载工作。再来回顾一下代码。
PhoneStatusBar.makeStatusBarView():
protected PhoneStatusBarView makeStatusBarView() {
final Context context = mContext;
inflateStatusBarWindow(context);
......
// 这里完成了许多systemui关键组件的view创建
......
// Set up the quick settings tile panel
AutoReinflateContainer container = (AutoReinflateContainer) mStatusBarWindow.findViewById(
R.id.qs_auto_reinflate_container);
if (container != null) {
final QSTileHost qsh = SystemUIFactory.getInstance().createQSTileHost(mContext, this,
mBluetoothController, mLocationController, mRotationLockController,
mNetworkController, mZenModeController, mHotspotController,
mCastController, mFlashlightController,
mUserSwitcherController, mUserInfoController, mKeyguardMonitor,
mSecurityController, mBatteryController, mIconController,
mNextAlarmController);
mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindow);
container.addInflateListener(new InflateListener() {
@Override
public void onInflated(View v) {
QSContainer qsContainer = (QSContainer) v.findViewById(
R.id.quick_settings_container);
qsContainer.setHost(qsh);
mQSPanel = qsContainer.getQsPanel();
mQSPanel.setBrightnessMirror(mBrightnessMirrorController);
mKeyguardStatusBar.setQSPanel(mQSPanel);
mHeader = qsContainer.getHeader();
initSignalCluster(mHeader);
mHeader.setActivityStarter(PhoneStatusBar.this);
}
});
}
......
}
这里发现了mQSPanel,它是在QSContainer的onFinishInflate()中inflate的,接着SystemUIFactory通过createQSTileHost()调用new QSTileHost(…)创建了QSTileHost对象。
QSTileHost的继承关系及构造方法:
public class QSTileHost implements QSTile.Host, Tunable {
public QSTileHost(Context context, PhoneStatusBar statusBar, ...) {
......
TunerService.get(mContext).addTunable(this, TILES_SETTING);
}
}
注意:这里的TunerService是在SystemUI学习总结一-SystemUI的启动中和SystemBars等服务一起在SystemUIApplication开启的。
看到SERVICES 就想起来了吧!
private final Class<?>[] SERVICES = new Class[] {
com.android.systemui.tuner.TunerService.class,
com.android.systemui.keyguard.KeyguardViewMediator.class,
com.android.systemui.recents.Recents.class,
com.android.systemui.volume.VolumeUI.class,
Divider.class,
com.android.systemui.statusbar.SystemBars.class,
com.android.systemui.usb.StorageNotification.class,
com.android.systemui.power.PowerUI.class,
com.android.systemui.media.RingtonePlayer.class,
com.android.systemui.keyboard.KeyboardUI.class,
com.android.systemui.tv.pip.PipUI.class,
com.android.systemui.shortcut.ShortcutKeyDispatcher.class,
com.android.systemui.VendorServices.clas