一,实现环境
1.软件环境
Android8.1系统
2.硬件环境
google手机msm8996
二,分析
1.android 8.0之后有了新的改变,开光布局与之前不太一样。布局文件还是\frameworks\base\packages\SystemUI\res\layout\qs_panel.xml。 qs_panel布局中:
QSPanel、qs_footer_impl、quick_status_bar_expanded_header等。
QSPanel是开关二级界面,是开关展开后的界面。
<com.android.systemui.qs.QSPanel
android:id="@+id/quick_settings_panel"
android:layout_marginTop="28dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginBottom="48dp" />
<include layout="@layout/quick_status_bar_expanded_header" />
<include layout="@layout/qs_footer_impl" />
在布局quick_status_bar_expanded_header中,QuickQSPanel就是下拉开关的布局,而 quick_status_bar_header_system_icons布局是下拉开关顶部的时间、日期、开关编辑按钮等。
<include layout="@layout/quick_status_bar_header_system_icons" />
<com.android.systemui.qs.QuickQSPanel
android:id="@+id/quick_qs_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:accessibilityTraversalAfter="@+id/date_time_group"
android:accessibilityTraversalBefore="@id/expand_indicator"
android:clipChildren="false"
android:clipToPadding="false"
android:clickable="false"
android:focusable="false"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="yes" />
android 8.0 PhoneStatusBar也换成了StatusBar。也没有QuickSettings、QuickSettingsModel等文件了。变得更加的模块化管理了。这里有一点说一下。android 8.0之前的版本 在qs_panel中添加控件、布局等,在PhoneStatusBar中是可以通过findViewById获取到,可以操作的。android 8.0是获取不到的,所以如果你在qs_panel.xml中加了一些自己的东西,最好是在QSfragement中对它进行一系列操作,我当时可是被这个坑惨了。
QuickQSPanel 继承 QSPanel ,QSPanel 中添加了亮度调节开关、开关页面计数器、开关展开页面等等。
文件路径:
frameworks\base\packages\SystemUI\src\com\android\systemui\qs\QSPanel.java
frameworks\base\packages\SystemUI\src\com\android\systemui\qs\QuickQSPanel.java
~
~
2.下拉开关的创建:
在frameworks\base\packages\SystemUI\src\com\android\systemui\qs\tileimpl\QSFactoryImpl.java中进行开关的创建。
public QSTile createTile(String tileSpec) {
if (tileSpec.equals("wifi")) return new WifiTile(mHost);
else if (tileSpec.equals("bt")) return new BluetoothTile(mHost);
else if (tileSpec.equals("cell")) return new CellularTile(mHost);
else if (tileSpec.equals("dnd")) return new DndTile(mHost);
else if (tileSpec.equals("inversion")) return new ColorInversionTile(mHost);
else if (tileSpec.equals("airplane")) return new AirplaneModeTile(mHost);
else if (tileSpec.equals("work")) return new WorkModeTile(mHost);
else if (tileSpec.equals("rotation")) return new RotationLockTile(mHost);
else if (tileSpec.equals("flashlight")) return new FlashlightTile(mHost);
else if (tileSpec.equals("location")) return new LocationTile(mHost);
else if (tileSpec.equals("cast")) return new CastTile(mHost);
else if (tileSpec.equals("hotspot")) return new HotspotTile(mHost);
else if (tileSpec.equals("user")) return new UserTile(mHost);
else if (tileSpec.equals("battery")) return new BatterySaverTile(mHost);
else if (tileSpec.equals("saver")) return new DataSaverTile(mHost);
else if (tileSpec.equals("night")) return new NightDisplayTile(mHost);
else if (tileSpec.equals("nfc")) return new NfcTile(mHost);
// Intent tiles.
else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(mHost, tileSpec);
else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(mHost, tileSpec);
else {
Log.w(TAG, "Bad tile spec: " + tileSpec);
return null;
}
}
@Override
public QSTileView createTileView(QSTile tile, boolean collapsedView) {
Context context = new ContextThemeWrapper(mHost.getContext(), R.style.qs_theme);
QSIconView icon = tile.createTileView(context);
if (collapsedView) {
return new QSTileBaseView(context, icon, collapsedView);
} else {
return new com.android.systemui.qs.tileimpl.QSTileView(context, icon);
}
}
3.如果想去掉quick settings中不需要的图标,可以直接返回null。