当前位置:   article > 正文

Android 11.0 SystemUI 状态栏下拉快捷面板,添加“反色“快捷开关_androidsystemui下拉快捷键

androidsystemui下拉快捷键

一.功能需求:

Android 11.0 系统,在系统设置中,有个深色主题的模式,为了方便操作,需要把这个功能的快捷方式添加到下拉状态栏的快捷面板中.

二.涉及的核心代码路径

  1. frameworks/base/packages/SystemUI/res/values/config.xml
  2. frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
  3. frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ColorInversionTile.java

三.步骤分析

(1)在配制文件config.xml中,添加"反色"项的配置.

  1. <!-- The default tiles to display in QuickSettings -->
  2. <string name="quick_settings_tiles_default" translatable="false">
  3. wifi,bt,dnd,flashlight,rotation,battery,cell,airplane,cast,screenrecord
  4. </string>

在quick_settings_tiles_default 中配置的快捷方式图标,是一次按顺序显示的,需要添加的"反色"快捷开关为inversion.如果有排列需要,则可以按要求放在需求的位置,现在我是直接添加到末尾.

  1. <!-- The default tiles to display in QuickSettings -->
  2. <string name="quick_settings_tiles_default" translatable="false">
  3. + wifi,bt,dnd,flashlight,rotation,battery,cell,airplane,cast,screenrecord,inversion
  4. </string>

(2)"反色"功能的核心代码在ColorInversionTile中实现,现在需要将"反色"添加到QSFactoryImpl.java中,这样,点击快捷面板中"反色"快捷开关时,能实现开启和关闭反正功能.

  1. @Singleton
  2. public class QSFactoryImpl implements QSFactory {
  3. private static final String TAG = "QSFactory";
  4. private final Provider<WifiTile> mWifiTileProvider;
  5. private final Provider<BluetoothTile> mBluetoothTileProvider;
  6. private final Provider<CellularTile> mCellularTileProvider;
  7. private final Provider<DndTile> mDndTileProvider;
  8. private final Provider<ColorInversionTile> mColorInversionTileProvider;
  9. private final Provider<AirplaneModeTile> mAirplaneModeTileProvider;
  10. private final Provider<WorkModeTile> mWorkModeTileProvider;
  11. private final Provider<RotationLockTile> mRotationLockTileProvider;
  12. private final Provider<FlashlightTile> mFlashlightTileProvider;
  13. private final Provider<LocationTile> mLocationTileProvider;
  14. private final Provider<CastTile> mCastTileProvider;
  15. private final Provider<HotspotTile> mHotspotTileProvider;
  16. private final Provider<UserTile> mUserTileProvider;
  17. private final Provider<BatterySaverTile> mBatterySaverTileProvider;
  18. private final Provider<DataSaverTile> mDataSaverTileProvider;
  19. private final Provider<NightDisplayTile> mNightDisplayTileProvider;
  20. private final Provider<NfcTile> mNfcTileProvider;
  21. private final Provider<GarbageMonitor.MemoryTile> mMemoryTileProvider;
  22. private final Provider<UiModeNightTile> mUiModeNightTileProvider;
  23. private final Provider<ScreenRecordTile> mScreenRecordTileProvider;
  24. + private finale Provider<ColorInversionTile> mColorInversionTileProvider;
  25. private final Lazy<QSHost> mQsHostLazy;
  26. @Inject
  27. public QSFactoryImpl(Lazy<QSHost> qsHostLazy,
  28. Provider<WifiTile> wifiTileProvider,
  29. Provider<BluetoothTile> bluetoothTileProvider,
  30. Provider<CellularTile> cellularTileProvider,
  31. Provider<DndTile> dndTileProvider,
  32. Provider<ColorInversionTile> colorInversionTileProvider,
  33. Provider<AirplaneModeTile> airplaneModeTileProvider,
  34. Provider<WorkModeTile> workModeTileProvider,
  35. Provider<RotationLockTile> rotationLockTileProvider,
  36. Provider<FlashlightTile> flashlightTileProvider,
  37. Provider<LocationTile> locationTileProvider,
  38. Provider<CastTile> castTileProvider,
  39. Provider<HotspotTile> hotspotTileProvider,
  40. Provider<UserTile> userTileProvider,
  41. Provider<BatterySaverTile> batterySaverTileProvider,
  42. Provider<DataSaverTile> dataSaverTileProvider,
  43. Provider<NightDisplayTile> nightDisplayTileProvider,
  44. Provider<NfcTile> nfcTileProvider,
  45. Provider<GarbageMonitor.MemoryTile> memoryTileProvider,
  46. Provider<UiModeNightTile> uiModeNightTileProvider,
  47. Provider<ScreenRecordTile> screenRecordTileProvider) {
  48. mQsHostLazy = qsHostLazy;
  49. mWifiTileProvider = wifiTileProvider;
  50. mBluetoothTileProvider = bluetoothTileProvider;
  51. mCellularTileProvider = cellularTileProvider;
  52. mDndTileProvider = dndTileProvider;
  53. mColorInversionTileProvider = colorInversionTileProvider;
  54. mAirplaneModeTileProvider = airplaneModeTileProvider;
  55. mWorkModeTileProvider = workModeTileProvider;
  56. mRotationLockTileProvider = rotationLockTileProvider;
  57. mFlashlightTileProvider = flashlightTileProvider;
  58. mLocationTileProvider = locationTileProvider;
  59. mCastTileProvider = castTileProvider;
  60. mHotspotTileProvider = hotspotTileProvider;
  61. mUserTileProvider = userTileProvider;
  62. mBatterySaverTileProvider = batterySaverTileProvider;
  63. mDataSaverTileProvider = dataSaverTileProvider;
  64. mNightDisplayTileProvider = nightDisplayTileProvider;
  65. mNfcTileProvider = nfcTileProvider;
  66. mMemoryTileProvider = memoryTileProvider;
  67. mUiModeNightTileProvider = uiModeNightTileProvider;
  68. mScreenRecordTileProvider = screenRecordTileProvider;
  69. + mColorInversionTileProvider = colorInversionTileProvider;
  70. }
  71. public QSTile createTile(String tileSpec) {
  72. QSTileImpl tile = createTileInternal(tileSpec);
  73. if (tile != null) {
  74. tile.handleStale(); // Tile was just created, must be stale.
  75. }
  76. return tile;
  77. }
  78. private QSTileImpl createTileInternal(String tileSpec) {
  79. // Stock tiles.
  80. switch (tileSpec) {
  81. case "wifi":
  82. return mWifiTileProvider.get();
  83. case "bt":
  84. return mBluetoothTileProvider.get();
  85. case "cell":
  86. return mCellularTileProvider.get();
  87. case "dnd":
  88. return mDndTileProvider.get();
  89. case "inversion":
  90. return mColorInversionTileProvider.get();
  91. case "airplane":
  92. return mAirplaneModeTileProvider.get();
  93. case "work":
  94. return mWorkModeTileProvider.get();
  95. case "rotation":
  96. return mRotationLockTileProvider.get();
  97. case "flashlight":
  98. return mFlashlightTileProvider.get();
  99. case "location":
  100. return mLocationTileProvider.get();
  101. case "cast":
  102. return mCastTileProvider.get();
  103. case "hotspot":
  104. return mHotspotTileProvider.get();
  105. case "user":
  106. return mUserTileProvider.get();
  107. case "battery":
  108. return mBatterySaverTileProvider.get();
  109. case "saver":
  110. return mDataSaverTileProvider.get();
  111. case "night":
  112. return mNightDisplayTileProvider.get();
  113. case "nfc":
  114. return mNfcTileProvider.get();
  115. case "dark":
  116. return mUiModeNightTileProvider.get();
  117. case "screenrecord":
  118. return mScreenRecordTileProvider.get();
  119. + case "inversion":
  120. + return mColorInversionTileProvider.get();
  121. }
  122. // Custom tiles
  123. if (tileSpec.startsWith(CustomTile.PREFIX)) {
  124. return CustomTile.create(mQsHostLazy.get(), tileSpec,
  125. mQsHostLazy.get().getUserContext());
  126. }
  127. // Debug tiles.
  128. if (Build.IS_DEBUGGABLE) {
  129. if (tileSpec.equals(GarbageMonitor.MemoryTile.TILE_SPEC)) {
  130. return mMemoryTileProvider.get();
  131. }
  132. }
  133. // Broken tiles.
  134. Log.w(TAG, "No stock tile spec: " + tileSpec);
  135. return null;
  136. }
  137. @Override
  138. public QSTileView createTileView(QSTile tile, boolean collapsedView) {
  139. Context context = new ContextThemeWrapper(mQsHostLazy.get().getContext(), R.style.qs_theme);
  140. QSIconView icon = tile.createTileView(context);
  141. if (collapsedView) {
  142. return new QSTileBaseView(context, icon, collapsedView);
  143. } else {
  144. return new com.android.systemui.qs.tileimpl.QSTileView(context, icon);
  145. }
  146. }
  147. }

The end!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/111497
推荐阅读
相关标签
  

闽ICP备14008679号