赞
踩
一.功能需求:
Android 11.0 系统,在系统设置中,有个深色主题的模式,为了方便操作,需要把这个功能的快捷方式添加到下拉状态栏的快捷面板中.
二.涉及的核心代码路径
- frameworks/base/packages/SystemUI/res/values/config.xml
- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
- frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java
三.步骤分析
(1)在配制文件config.xml中,添加"反色"项的配置.
- <!-- The default tiles to display in QuickSettings -->
- <string name="quick_settings_tiles_default" translatable="false">
- wifi,bt,dnd,flashlight,rotation,battery,cell,airplane,cast,screenrecord
- </string>
在quick_settings_tiles_default 中配置的快捷方式图标,是一次按顺序显示的,需要添加的"反色"快捷开关为inversion.如果有排列需要,则可以按要求放在需求的位置,现在我是直接添加到末尾.
- <!-- The default tiles to display in QuickSettings -->
- <string name="quick_settings_tiles_default" translatable="false">
- + wifi,bt,dnd,flashlight,rotation,battery,cell,airplane,cast,screenrecord,inversion
- </string>
(2)"反色"功能的核心代码在ColorInversionTile中实现,现在需要将"反色"添加到QSFactoryImpl.java中,这样,点击快捷面板中"反色"快捷开关时,能实现开启和关闭反正功能.
- @Singleton
- public class QSFactoryImpl implements QSFactory {
-
- private static final String TAG = "QSFactory";
-
- private final Provider<WifiTile> mWifiTileProvider;
- private final Provider<BluetoothTile> mBluetoothTileProvider;
- private final Provider<CellularTile> mCellularTileProvider;
- private final Provider<DndTile> mDndTileProvider;
- private final Provider<ColorInversionTile> mColorInversionTileProvider;
- private final Provider<AirplaneModeTile> mAirplaneModeTileProvider;
- private final Provider<WorkModeTile> mWorkModeTileProvider;
- private final Provider<RotationLockTile> mRotationLockTileProvider;
- private final Provider<FlashlightTile> mFlashlightTileProvider;
- private final Provider<LocationTile> mLocationTileProvider;
- private final Provider<CastTile> mCastTileProvider;
- private final Provider<HotspotTile> mHotspotTileProvider;
- private final Provider<UserTile> mUserTileProvider;
- private final Provider<BatterySaverTile> mBatterySaverTileProvider;
- private final Provider<DataSaverTile> mDataSaverTileProvider;
- private final Provider<NightDisplayTile> mNightDisplayTileProvider;
- private final Provider<NfcTile> mNfcTileProvider;
- private final Provider<GarbageMonitor.MemoryTile> mMemoryTileProvider;
- private final Provider<UiModeNightTile> mUiModeNightTileProvider;
- private final Provider<ScreenRecordTile> mScreenRecordTileProvider;
-
- + private finale Provider<ColorInversionTile> mColorInversionTileProvider;
-
- private final Lazy<QSHost> mQsHostLazy;
-
- @Inject
- public QSFactoryImpl(Lazy<QSHost> qsHostLazy,
- Provider<WifiTile> wifiTileProvider,
- Provider<BluetoothTile> bluetoothTileProvider,
- Provider<CellularTile> cellularTileProvider,
- Provider<DndTile> dndTileProvider,
- Provider<ColorInversionTile> colorInversionTileProvider,
- Provider<AirplaneModeTile> airplaneModeTileProvider,
- Provider<WorkModeTile> workModeTileProvider,
- Provider<RotationLockTile> rotationLockTileProvider,
- Provider<FlashlightTile> flashlightTileProvider,
- Provider<LocationTile> locationTileProvider,
- Provider<CastTile> castTileProvider,
- Provider<HotspotTile> hotspotTileProvider,
- Provider<UserTile> userTileProvider,
- Provider<BatterySaverTile> batterySaverTileProvider,
- Provider<DataSaverTile> dataSaverTileProvider,
- Provider<NightDisplayTile> nightDisplayTileProvider,
- Provider<NfcTile> nfcTileProvider,
- Provider<GarbageMonitor.MemoryTile> memoryTileProvider,
- Provider<UiModeNightTile> uiModeNightTileProvider,
- Provider<ScreenRecordTile> screenRecordTileProvider) {
- mQsHostLazy = qsHostLazy;
- mWifiTileProvider = wifiTileProvider;
- mBluetoothTileProvider = bluetoothTileProvider;
- mCellularTileProvider = cellularTileProvider;
- mDndTileProvider = dndTileProvider;
- mColorInversionTileProvider = colorInversionTileProvider;
- mAirplaneModeTileProvider = airplaneModeTileProvider;
- mWorkModeTileProvider = workModeTileProvider;
- mRotationLockTileProvider = rotationLockTileProvider;
- mFlashlightTileProvider = flashlightTileProvider;
- mLocationTileProvider = locationTileProvider;
- mCastTileProvider = castTileProvider;
- mHotspotTileProvider = hotspotTileProvider;
- mUserTileProvider = userTileProvider;
- mBatterySaverTileProvider = batterySaverTileProvider;
- mDataSaverTileProvider = dataSaverTileProvider;
- mNightDisplayTileProvider = nightDisplayTileProvider;
- mNfcTileProvider = nfcTileProvider;
- mMemoryTileProvider = memoryTileProvider;
- mUiModeNightTileProvider = uiModeNightTileProvider;
- mScreenRecordTileProvider = screenRecordTileProvider;
-
- + mColorInversionTileProvider = colorInversionTileProvider;
-
- }
-
- public QSTile createTile(String tileSpec) {
- QSTileImpl tile = createTileInternal(tileSpec);
- if (tile != null) {
- tile.handleStale(); // Tile was just created, must be stale.
- }
- return tile;
- }
-
- private QSTileImpl createTileInternal(String tileSpec) {
- // Stock tiles.
- switch (tileSpec) {
- case "wifi":
- return mWifiTileProvider.get();
- case "bt":
- return mBluetoothTileProvider.get();
- case "cell":
- return mCellularTileProvider.get();
- case "dnd":
- return mDndTileProvider.get();
- case "inversion":
- return mColorInversionTileProvider.get();
- case "airplane":
- return mAirplaneModeTileProvider.get();
- case "work":
- return mWorkModeTileProvider.get();
- case "rotation":
- return mRotationLockTileProvider.get();
- case "flashlight":
- return mFlashlightTileProvider.get();
- case "location":
- return mLocationTileProvider.get();
- case "cast":
- return mCastTileProvider.get();
- case "hotspot":
- return mHotspotTileProvider.get();
- case "user":
- return mUserTileProvider.get();
- case "battery":
- return mBatterySaverTileProvider.get();
- case "saver":
- return mDataSaverTileProvider.get();
- case "night":
- return mNightDisplayTileProvider.get();
- case "nfc":
- return mNfcTileProvider.get();
- case "dark":
- return mUiModeNightTileProvider.get();
- case "screenrecord":
- return mScreenRecordTileProvider.get();
-
- + case "inversion":
- + return mColorInversionTileProvider.get();
-
- }
-
- // Custom tiles
- if (tileSpec.startsWith(CustomTile.PREFIX)) {
- return CustomTile.create(mQsHostLazy.get(), tileSpec,
- mQsHostLazy.get().getUserContext());
- }
-
- // Debug tiles.
- if (Build.IS_DEBUGGABLE) {
- if (tileSpec.equals(GarbageMonitor.MemoryTile.TILE_SPEC)) {
- return mMemoryTileProvider.get();
- }
- }
-
- // Broken tiles.
- Log.w(TAG, "No stock tile spec: " + tileSpec);
- return null;
- }
-
- @Override
- public QSTileView createTileView(QSTile tile, boolean collapsedView) {
- Context context = new ContextThemeWrapper(mQsHostLazy.get().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);
- }
- }
- }
The end!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。