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

[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.xdnf.cn/news/3276.html

相关文章:

  • 业务部绩效考核关键指标与数据分析
  • 使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第十讲)
  • 第六部分:实战项目与拓展
  • Windows下Dify安装及使用
  • 【AI提示词】SWOT分析师
  • Qt快速上手:QSettings高效配置读写实战指南
  • 解锁Windows异步黑科技:IOCP从入门到精通
  • 基于SpringBoot的母婴商城系统设计与实现(附源码+PPT+论文)
  • 电脑重复图片太多?推荐一款开源的图片去重工具ImageContrastTools
  • 你的Java项目经历,是金子还是沙子?
  • 快充诱骗协议芯片的工作原理及应用场景
  • 可视化网页自动化流程管理工具
  • 混合开发与平台集成:自定义插件开发
  • 【C++QT】Combo Box 组合框控件详解
  • intellij idea最新版git开启Local Changes
  • VARIAN安捷伦真空泵维修清洁保养操作SOP换油操作流程内部转子图文并茂内部培训手侧
  • 算法设计:分治法的基础原理与应用
  • 【C/C++】线程池_学习笔记
  • 对于C++中的STL,push_back()和emplace_back()有什么区别?
  • 深度估计研究方向常用数据集介绍
  • PID控制中,一阶低通滤波算法
  • 08 Python集合:数据 “去重神器” 和运算魔法
  • 机器指标监控技术方案
  • 基于5G AIOT技术的未来社区解决方案PPT(45页)
  • ubuntu22.04 qemu arm64 环境搭建
  • 数据编码(Encoding)
  • vllm部署--Qwen2.5VL-7B
  • SpringMVC框架(一)
  • Tomcat 服务频繁崩溃的排查与解决方法
  • 【人工智能】解锁边缘智能:Ollama 模型压缩技术与 DeepSeek 边缘部署深度解析