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

[Android 15] 在GlobalActionsDialog 中新增项目

需求: 在Power菜单弹出的对话框中新增“Volume/Ship mode/Suspend”

1. 新增ship_mode和suspend图标资源
frameworks/base/core/res/res/drawable/ic_ship_mode.xml

/frameworks/base/core/res/res/drawable/ic_suspend.xml

<!--
Copyright (C) 2024 Your Company/ProjectLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"android:width="32dp"android:height="32dp"android:viewportWidth="32"android:viewportHeight="32"android:tint="?attr/colorControlNormal"><pathandroid:fillColor="#4285F4"android:pathData="M0,22 L32,22 L32,32 L0,32 Z"android:strokeWidth="0"/><pathandroid:fillColor="#5D4037"android:pathData="M10,16 L22,16 L24,20 L8,20 Z"android:strokeWidth="0"/><pathandroid:fillColor="#8D6E63"android:pathData="M12,14 L20,14 L20,16 L12,16 Z"android:strokeWidth="0"/><pathandroid:fillColor="#E53935"android:pathData="M16,8 L22,14 L16,14 Z"android:strokeWidth="0"/><pathandroid:fillColor="#3E2723"android:pathData="M16,14 L16,16"android:strokeWidth="2"android:strokeColor="#3E2723"/>
</vector>
<!--
Copyright (C) 2024 Your Company/ProjectLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"android:width="32dp"android:height="32dp"android:viewportWidth="32"android:viewportHeight="32"android:tint="?attr/colorControlNormal"><pathandroid:fillColor="#000000"android:pathData="M16,2A14,14 0 1,0 16,30 10.5,10.5 0 0,1 16,2Z"android:strokeWidth="0"/><pathandroid:fillColor="#000000"android:pathData="M10,8h6v18h-6z"android:strokeWidth="0"/><pathandroid:fillColor="#000000"android:pathData="M18,8h6v18h-6z"android:strokeWidth="0"/>
</vector>

2.frameworks/base/core/res/res/values/config.xml

<string-array translatable="false" name="config_globalActionsList"><item>emergency</item><item>lockdown</item><item>power</item><item>restart</item><item>logout</item><item>screenshot</item><item>bugreport</item><item>battery_swap</item><!-- add items start--><item>suspend</item><item>adjust_volume</item><item>ship_mode</item><!-- add items end-->
</string-array>

3.frameworks/base/core/res/res/values/strings.xml

    <!-- Notification messages for battery swap not available --><string name="backup_battery_low">Low backup battery</string><string name="backup_battery_charged">Backup battery is charged</string><string name="backup_battery_unavailable">Level of backup battery not available</string><string name="backup_battery_safe">You can safely swap the main battery</string><string name="backup_battery_wait">Please do not swap the main battery now.</string><string name="backup_battery_risky">It is risky to swap the main battery now.</string><!-- add items start --><string name="global_action_suspend">Suspend</string><string name="global_action_volume">Adjust volume</string><string name="global_action_ship_mode">Ship Mode</string><!-- add items end -->

4.frameworks/base/core/res/res/values/symbols.xml

  <java-symbol type="drawable" name="ic_audio_vol" /><!-- add items start --><java-symbol type="drawable" name="ic_suspend" /><java-symbol type="drawable" name="ic_ship_mode" /><!-- add items end --><java-symbol type="drawable" name="ic_audio_vol_mute" /><java-symbol type="string" name="global_action_battery_swap" /><!-- add items start --><java-symbol type="string" name="global_action_suspend" /><java-symbol type="string" name="global_action_volume" /><java-symbol type="string" name="global_action_ship_mode" /><!-- add items end --><java-symbol type="string" name="invalidPuk" />

5.frameworks/base/packages/SystemUI/res/values/strings.xml

 <string name="accessibility_power">Power</string><!-- add items start --><string name="global_action_suspend">Suspend</string><string name="global_action_volume">Adjust volume</string><string name="global_action_ship_mode">Ship Mode</string><!-- add items end -->

6.frameworks/base/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialogLite.java

import android.os.PowerManager;static final String GLOBAL_ACTION_KEY_BATTERY_SWAP = "battery_swap";
// add items start
static final String GLOBAL_ACTION_KEY_SUSPEND = "suspend";
static final String GLOBAL_ACTION_KEY_ADJUST_VOLUME = "adjust_volume";
static final String GLOBAL_ACTION_KEY_SHIP_MODE = "ship_mode";
// add items end@VisibleForTesting
protected void createActionItems() {} else if (GLOBAL_ACTION_KEY_BATTERY_SWAP.equals(actionKey)) {addIfShouldShowAction(tempActions, new BatterySwapAction());
// add items start
} else if (GLOBAL_ACTION_KEY_SUSPEND.equals(actionKey)) {addIfShouldShowAction(tempActions, SuspendAction());
} else if (GLOBAL_ACTION_KEY_ADJUST_VOLUME.equals(actionKey)) {addIfShouldShowAction(tempActions, VolumeAction());
} else if (GLOBAL_ACTION_KEY_SHIP_MODE.equals(actionKey)) {addIfShouldShowAction(tempActions, ShipModeAction());
// add items end
} else {Log.e(TAG, "Invalid global action key " + actionKey);
}
// Add here so we don't add more than one.
addedKeys.add(actionKey);}private Action SuspendAction() {return new SinglePressAction(R.drawable.ic_suspend,R.string.global_action_suspend) {@Overridepublic void onPress() {PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);if (powerManager != null) {powerManager.goToSleep(SystemClock.uptimeMillis());}}@Overridepublic boolean showDuringKeyguard() {return true;}@Overridepublic boolean showBeforeProvisioning() {return true;}};}private Action VolumeAction() {return new SinglePressAction(R.drawable.ic_audio_vol,R.string.global_action_volume) {@Overridepublic void onPress() {mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM,AudioManager.ADJUST_SAME,AudioManager.FLAG_SHOW_UI);}@Overridepublic boolean showDuringKeyguard() {return true;}@Overridepublic boolean showBeforeProvisioning() {return true;}};}private Action ShipModeAction() {return new SinglePressAction(R.drawable.ic_ship_mode,R.string.global_action_ship_mode) {@Overridepublic void onPress() {}@Overridepublic boolean showDuringKeyguard() {return true;}@Overridepublic boolean showBeforeProvisioning() {return true;}};}

http://www.dtcms.com/a/166211.html

相关文章:

  • 国内 AI 发展路线分析
  • Arduino IDE中更新esp32 3.2.0版本的办法
  • 大力探索“AI·Life爱生活”项目峰会暨战略投资签约仪式成功举办
  • ‌阿里云dns服务器不可用怎么办?dns可以随便改吗?
  • 编译原理实验二:构建TINY语言的词法分析器
  • 第15篇:Linux设备驱动程序入门<二>
  • MicroPython 开发ESP32应用教程 之 ADC及应用实例:电池电量检测并显示
  • js闭包概念和使用
  • 从实列中学习linux shell5: 利用shell 脚本 检测硬盘空间容量,当使用量达到80%的时候 发送邮件
  • 安恒安全培训实习生,CTF方向面试题!
  • crashpad 编译
  • MacOS 安装 cocoapods
  • 解读 AI绘画工作流ComfyUI Stable Diffusion
  • react中封装一个预览.doc和.docx文件的组件
  • TCP三次握手、四次挥手+多线程并发处理
  • ceph存储原理
  • 【UE5】“对不起,您的客户端未能传递登录所需的参数”解决办法
  • Linux Quota 显示空间占用远大于实际数据的问题排查记录
  • 01 mysql 安装(Windows)
  • 32单片机——独立看门狗
  • 算法基础学习|03整数二分
  • 如何编制研发部门绩效考核制度
  • 删除k8s某命名空间,一直卡住了怎么办?
  • java之Integer、Double自动拆装箱比较,踩坑值int和Integer比较之空指针异常
  • 垒球世界纪录多少米·棒球1号位
  • 三格电子上新了——超高频RFID读写器
  • 2025最新福昕PDF编辑器,PDF万能处理工具
  • PostgreSQL事务与并发清理
  • Electron Forge【实战】自定义菜单 -- 顶部菜单 vs 右键快捷菜单
  • 力扣HOT100——207.课程表