当前位置: 首页 > article >正文

Android 14 SPRD 下拉菜单中增加自动亮度调节按钮

为了在 Android 14 的下拉菜单中增加自动亮度调节按钮,可以按照以下步骤进行代码修改。

1. 添加图标资源

SystemUI 资源文件夹中添加自动亮度图标:

文件路径:

frameworks/base/packages/SystemUI/res/drawable/ic_settings_display_white.xml

文件内容:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:pathData="M20.31,9V4.31H15.62L12.31,1L9,4.31H4.31V9L1,12.31L4.31,15.62V20.31H9L12.31,23.62L15.62,20.31H20.31V15.62L23.62,12.31L20.31,9ZM18.31,14.79V18.31H14.79L12.31,20.79L9.83,18.31H6.31V14.79L3.83,12.31L6.31,9.83V6.31H9.83L12.31,3.83L14.79,6.31H18.31V9.83L20.79,12.31L18.31,14.79ZM17.31,12.31C17.31,15.07 15.07,17.31 12.31,17.31V7.31C15.07,7.31 17.31,9.55 17.31,12.31Z"
        android:fillType="evenOdd"
        android:fillColor="?android:attr/colorPrimary"/>
</vector>
2. 更新字符串资源

strings.xml 中添加自动亮度调节的标题:

文件路径:

frameworks/base/packages/SystemUI/res/values/strings.xml
frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml

strings.xml 中新增:

<string name="autobrightness_title">AutoBrightness</string>

strings.xml (zh-rCN) 中新增:

<string name="autobrightness_title">自动亮度调节</string>
3. 配置快速设置中的自动亮度 Tile

config.xml 中将自动亮度添加到快速设置面板的默认项目中:

文件路径:

frameworks/base/packages/SystemUI/res/values/config.xml

修改内容:

<string name="quick_settings_tiles_stock" translatable="false">
    internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,autobrightness,superbattery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,color_correction,dream,font_scaling
</string>
4. 创建 AutoBrightnessTile 类

创建 AutoBrightnessTile.java 实现自动亮度 Tile 的逻辑:

文件路径:

frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/AutoBrightnessTile.java

文件内容:

package com.android.systemui.qs.tiles;

import android.content.ContentResolver;
import android.content.Intent;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.util.Log;
import android.view.View;
import androidx.annotation.Nullable;
import com.android.systemui.R;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import javax.inject.Inject;

public class AutoBrightnessTile extends QSTileImpl<BooleanState> {

    public static final String TILE_SPEC = "autobrightness";

    @Inject
    public AutoBrightnessTile(QSHost host) {
        super(host);
    }

    @Override
    public BooleanState newTileState() {
        BooleanState state = new BooleanState();
        state.handlesLongClick = true;
        return state;
    }

    @Override
    protected void handleClick(@Nullable View view) {
        Log.i("AutoBrightnessTile", "Clicked on AutoBrightness tile");
        toggleBrightnessMode();
        refreshState();
    }

    private void toggleBrightnessMode() {
        ContentResolver resolver = mContext.getContentResolver();
        int currentMode = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, MODE_MANUAL);
        int newMode = (currentMode == MODE_MANUAL) ? MODE_AUTOMATIC : MODE_MANUAL;
        Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, newMode);
    }

    private boolean isAutoBrightnessEnabled() {
        ContentResolver resolver = mContext.getContentResolver();
        int mode = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, MODE_MANUAL);
        return mode == MODE_AUTOMATIC;
    }

    @Override
    public CharSequence getTileLabel() {
        return mContext.getString(R.string.autobrightness_title);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {
        state.label = mContext.getString(R.string.autobrightness_title);
        state.value = isAutoBrightnessEnabled();
        state.contentDescription = state.label;
        state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        state.icon = ResourceIcon.get(R.drawable.ic_settings_display_white);
    }
}
5. 在 PolicyModule 中注册 Tile

确保 AutoBrightnessTile 注册在 PolicyModule 中:

文件路径:

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/PolicyModule.kt

修改内容:

--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/PolicyModule.kt
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/PolicyModule.kt
@@ -20,6 +20,7 @@ import com.android.systemui.qs.tiles.CameraToggleTile
 import com.android.systemui.qs.tiles.DndTile
 import com.android.systemui.qs.tiles.FlashlightTile
+import com.android.systemui.qs.tiles.AutoBrightnessTile
 import com.android.systemui.qs.tiles.LocationTile
 import com.android.systemui.qs.tiles.MicrophoneToggleTile
 import com.android.systemui.qs.tiles.UiModeNightTile
@@ -52,6 +53,12 @@ interface PolicyModule {

+    
+    /** Inject AutoBrightnessTile into tileMap in QSModule */
+    @Binds
+    @IntoMap
+    @StringKey(AutoBrightnessTile.TILE_SPEC)
+    fun bindAutoBrightnessTile(autobrightnessTile: AutoBrightnessTile): QSTileImpl<*>
6. 配置默认快速设置

在特定的 config.xml 覆盖文件中确保默认启用自动亮度:

文件路径:

vendor/partner_gms/unisoc_conf/overlay/gms_overlay_unisoc/frameworks/base/packages/SystemUI/res/values/config.xml

修改内容:

<string name="quick_settings_tiles_default" translatable="false">
    internet,bt,dnd,flashlight,rotation,battery,airplane,autobrightness,night,qr_code_scanner,screenrecord,cast,mictoggle,cameratoggle
</string>

以上步骤完成后,重新编译并安装系统镜像。此改动将会在 Android 14 的 SPRD 下拉菜单中增加自动亮度调节的快捷开关。


http://www.kler.cn/a/388226.html

相关文章:

  • Elasticsearch(ES)简介
  • 管家婆财贸ERP BB059.银行流水导入对账
  • 【大数据技术基础 | 实验十】Hive实验:部署Hive
  • 7天用Go从零实现分布式缓存GeeCache(学习)(3)
  • Qwen2 系列大型语言模型
  • 【Xrdp联机Ubuntu20.04实用知识点补充】
  • 鸿蒙系统:智能设备新时代的技术驱动
  • MySQL:数据类型建表
  • system generator结合高版本matlab的使用
  • 【Linux】进程创建/等待/替换相关知识详细梳理
  • 查缺补漏----用户上网过程(HTTP,DNS与ARP)
  • 信息安全工程师(79)网络安全测评概况
  • 架构师备考-架构基本概念
  • Diving into the STM32 HAL-----DMA笔记
  • 【科普小白】LLM大语言模型的基本原理
  • 《Linux运维总结:基于银河麒麟V10+ARM64架构CPU部署redis 6.2.14 TLS/SSL哨兵集群》
  • Ubuntu学习笔记 - Day3
  • excel常用技能
  • C++ | 表示移动函数move()的基本用法
  • 【Golang】Go语言教程
  • 【leetcode练习·二叉树】用「分解问题」思维解题 I
  • mysql 配置文件 my.cnf 增加 lower_case_table_names = 1 服务启动不了
  • 【前端】JavaScript 方法速查大全-DOM、BOM、时间、处理JS原生问题(三)
  • C++学习笔记----11、模块、头文件及各种主题(一)---- 模板概览与类模板(1)
  • python opencv灰度变换
  • Docker部署Oracle 11g