提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
Android13_SystemUI下拉框新增音量控制条
- 一、必备知识
- 二、源码分析对比
- 1.brightness模块分析对比
- 2.statusbar/phone 对应模块对比
- 对比初始化类声明
- 对比构造方法
- 三、源码修改
- 四、相关资源
一、必备知识
- 在Android12 版本上面已经完成了功能的实现,目前是在Android13
版本实现此功能,可以参考上一篇文章相关的必备基础知识和实现方式Android12实现SystemUI下拉框新增音量控制条 - 在Android12 基础上对比实现方式,来实现Android13 版本上面的功能
二、源码分析对比
源码对比Android12,
- 音量条功能实现本身是参考下拉框已知的brightness 模块开发,所以需要对brightness模块熟悉;
- SystemUI下拉QS、QQS这些组件包括其它组件是怎么添加到系统里面去,怎么展示的,这个逻辑很重要,也需要和Android12 对比下
1.brightness模块分析对比
Android12源码地址:http://xrefandroid.com/android-12.0.0_r34/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/settings/brightness/
Android13源码地址:http://xrefandroid.com/android-13.0.0_r83/xref/frameworks/base/packages/SystemUI/src/com/android/systemui/settings/brightness/
每个类的定义和作用已经在Android12 中分析过,这里最大的一个类改名了,改的很有意义:
BrightnessSlider.java -> BrightnessSliderController.java ,控制类就是控制类,见名知义!
2.statusbar/phone 对应模块对比
Android13 中 CentralSurfacesImpl 类 替代了StatusBar 类。
对比初始化类声明
如下:一个用继承实现基本功能,一个用接口实现功能
StatusBar.java public class StatusBar extends SystemUI implements DemoMode,ActivityStarter, KeyguardStateController.Callback,OnHeadsUpChangedListener, CommandQueue.Callbacks,ColorExtractor.OnColorsChangedListener, ConfigurationListener,StatusBarStateController.StateListener,LifecycleOwner, BatteryController.BatteryStateChangeCallback,ActivityLaunchAnimator.Callback {public static final boolean MULTIUSER_DEBUG = false;CentralSurfacesImpl.java public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {CentralSurfaces.java
public interface CentralSurfaces extends Dumpable, ActivityStarter, LifecycleOwner {
对比构造方法
如下,构造方法的描述都是一摸一样的,这两个类核心功能一致的,初始化功能和SystemUI入口
找到了初始化地方,音量条实现方式参考Android12 版本,此功能就很容易实现了。
三、源码修改
详细说明如下,参考修改文件和新增文件即可完成功能,实现需求
修改文件:
vendor/mediatek/proprietary/packages/apps/SystemUI/AndroidManifest.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/classifier/Classifier.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/QSAnimator.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/QSPanel.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/QSPanelController.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/settings/brightness/BrightnessSliderController.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java新增文件:
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-hdpi/icon_volume_test.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-mdpi/icon_volume_test.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-xhdpi/icon_volume_test.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-xxhdpi/icon_volume_test.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-xxxhdpi/icon_volume_test.png
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable/volume_progress_drawable.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable/volume_progress_full_drawable.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/quick_settings_volume_dialog.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/settings/volume/VolumeController.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/settings/volume/VolumeSliderController.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/settings/volume/VolumeSliderView.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/util/ApplicationContextProvider.kt
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/util/ContextProvider.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/util/SoundUtils.kt
具体实现方式对比Android12 ,实现参考方式一模一样。
四、相关资源
RK Android12 SystemUI SystemUI源码方便调试
源码在线调试平台
RK/MTK Android13版本可参考修改源码