一:关机菜单添加飞行模式选项

源码路径:frameworks/base/core/res/res/values/config.xml

增加<item>airplane</item>

    <!-- Defines the default set of global actions. Actions may still be disabled or hidden based
on the current state of the device.
Each item must be one of the following strings:
"power" = Power off
"settings" = An action to launch settings
"airplane" = Airplane mode toggle
"bugreport" = Take bug report, if available
"silent" = silent mode
"users" = list of users
"restart" = restart device
-->
<string-array translatable="false" name="config_globalActionsList">
<item>power</item>
<item>restart</item>
<item>airplane</item>
<item>bugreport</item>
<item>users</item>
</string-array>
二:GlobalActionsDialog.java

源码路径:com/android/systemui/globalactions/GlobalActionsDialog.java

主要关注createDialog()方法,如果需要定制Dialog请自行去研究ActionDialog 此处不做过多解释

    /**
* Create the global actions dialog.
*
* @return A new dialog.
*/
private ActionsDialog createDialog() {
// Simple toggle style if there's no vibrator, otherwise use a tri-state
if (!mHasVibrator) {
mSilentModeAction = new SilentModeToggleAction();
} else {
mSilentModeAction = new SilentModeTriStateAction(mContext, mAudioManager, mHandler);
}
mAirplaneModeOn = new ToggleAction(
R.drawable.ic_lock_airplane_mode,
R.drawable.ic_lock_airplane_mode_off,
R.string.global_actions_toggle_airplane_mode,
R.string.global_actions_airplane_mode_on_status,
R.string.global_actions_airplane_mode_off_status) { void onToggle(boolean on) {
if (mHasTelephony && Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
mIsWaitingForEcmExit = true;
// Launch ECM exit dialog
Intent ecmDialogIntent =
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(ecmDialogIntent);
} else {
changeAirplaneModeSystemSetting(on);
}
} @Override
protected void changeStateFromPress(boolean buttonOn) {
if (!mHasTelephony) return; // In ECM mode airplane state cannot be changed
if (!(Boolean.parseBoolean(
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
mState = buttonOn ? State.TurningOn : State.TurningOff;
mAirplaneState = mState;
}
} public boolean showDuringKeyguard() {
return true;
} public boolean showBeforeProvisioning() {
return false;
}
};
onAirplaneModeChanged(); mItems = new ArrayList<Action>();
String[] defaultActions = mContext.getResources().getStringArray(
R.array.config_globalActionsList); ArraySet<String> addedKeys = new ArraySet<String>();
for (int i = 0; i < defaultActions.length; i++) {
String actionKey = defaultActions[i];
if (addedKeys.contains(actionKey)) {
// If we already have added this, don't add it again.
continue;
}
if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
mItems.add(new PowerAction());
} else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
mItems.add(mAirplaneModeOn);
} else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
if (Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
mItems.add(new BugReportAction());
}
} else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
if (mShowSilentToggle) {
mItems.add(mSilentModeAction);
}
} else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
addUsersToMenu(mItems);
}
} else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
mItems.add(getSettingsAction());
} else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
mItems.add(getLockdownAction());
} else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
mItems.add(getVoiceAssistAction());
} else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
mItems.add(getAssistAction());
} else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
mItems.add(new RestartAction());
} else {
Log.e(TAG, "Invalid global action key " + actionKey);
}
// Add here so we don't add more than one.
addedKeys.add(actionKey);
} if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
mItems.add(getEmergencyAction());
} mAdapter = new MyAdapter(); OnItemLongClickListener onItemLongClickListener = new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
long id) {
final Action action = mAdapter.getItem(position);
if (action instanceof LongPressAction) {
mDialog.dismiss();
return ((LongPressAction) action).onLongPress();
}
return false;
}
};
ActionsDialog dialog = new ActionsDialog(mContext, this, mAdapter, onItemLongClickListener);
dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
dialog.setKeyguardShowing(mKeyguardShowing); dialog.setOnDismissListener(this); return dialog;
}

如果关机菜单中显示有问题,请按下面修改,Andnroid8.0代码中有些布局文件同名,可能出现引用错误

@@ -944,8 +944,8 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
LayoutInflater inflater) {
willCreate(); - View v = inflater.inflate(R
- .layout.global_actions_item, parent, false);
+ View v = inflater.inflate(com
+ .android.systemui.R.layout.global_actions_item, parent, false); ImageView icon = (ImageView) v.findViewById(R.id.icon);
TextView messageView = (TextView) v.findViewById(R.id.message);

如果飞行模式功能无效, 尝试下面修改

@@ -1179,7 +1179,7 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn

     private void onAirplaneModeChanged() {
// Let the service state callbacks handle the state.
- if (mHasTelephony) return;
+ if (!mHasTelephony) return; boolean airplaneModeOn = Settings.Global.getInt(
mContext.getContentResolver(),

如果显示样式和开关机选项有差别, 按如下修改,隐藏statusView

@@ -966,7 +966,7 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn

             if (statusView != null) {
statusView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
- statusView.setVisibility(View.VISIBLE);
+ statusView.setVisibility(View.GONE);
statusView.setEnabled(enabled);
}
v.setEnabled(enabled);

喜欢源码分析系列可参考其他文章:

Android源码分析(一)-----如何快速掌握Android编译文件

Android源码分析(二)-----如何编译修改后的framework资源文件

Android源码分析(三)-----系统框架设计思想

Android源码分析(四)-----Android源码编译及刷机步骤

Android源码分析(十)-----关机菜单中如何添加飞行模式选项的更多相关文章

  1. Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果

    一:如何自定义TextView实现滚动效果 继承TextView基类 重写构造方法 修改isFocused()方法,获取焦点. /* * Copyright (C) 2015 The Android ...

  2. Android多线程之(一)View.post()源码分析——在子线程中更新UI

    提起View.post(),相信不少童鞋一点都不陌生,它用得最多的有两个功能,使用简便而且实用: 1)在子线程中更新UI.从子线程中切换到主线程更新UI,不需要额外new一个Handler实例来实现. ...

  3. Android源码分析(十六)----adb shell 命令进行OTA升级

    一: 进入shell命令界面 adb shell 二:创建目录/cache/recovery mkdir /cache/recovery 如果系统中已有此目录,则会提示已存在. 三: 修改文件夹权限 ...

  4. Android源码分析(十五)----GPS冷启动实现原理分析

    一:原理分析 主要sendExtraCommand方法中传递两个参数, 根据如下源码可以知道第一个参数传递delete_aiding_data,第二个参数传递null即可. @Override pub ...

  5. Android源码分析(十一)-----Android源码中如何引用aar文件

    一:aar文件如何引用 系统Settings中引用bidehelper-1.1.12.aar 文件为例 源码地址:packages/apps/Settings/Android.mk LOCAL_PAT ...

  6. Android源码分析(十四)----如何使用SharedPreferencce保存数据

    一:SharedPreference如何使用 此文章只是提供一种数据保存的方式, 具体使用场景请根据需求情况自行调整. EditText添加saveData点击事件, 保存数据. diff --git ...

  7. Android源码分析(六)-----蓝牙Bluetooth源码目录分析

    一 :Bluetooth 的设置应用 packages\apps\Settings\src\com\android\settings\bluetooth* 蓝牙设置应用及设置参数,蓝牙状态,蓝牙设备等 ...

  8. Android源码分析-全面理解Context

    前言 Context在android中的作用不言而喻,当我们访问当前应用的资源,启动一个新的activity的时候都需要提供Context,而这个Context到底是什么呢,这个问题好像很好回答又好像 ...

  9. C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库

    C# DateTime的11种构造函数   别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...

随机推荐

  1. 【使用篇二】SpringBoot服务端数据校验(8)

    对于任何一个应用而言,客户端做的数据有效性验证都不是安全有效的,而数据验证又是一个企业级项目架构上最为基础的功能模块,这时候就要求我们在服务端接收到数据的时候也对数据的有效性进行验证.为什么这么说呢? ...

  2. SysML——CSE 599W: Systems for ML

    CSE 599W: Systems for ML Assignments Materials Projects Schedule Schedule The schedule is tentative ...

  3. LG2852/BZOJ1717 「USACO2006DEC」Milk Patterns 离散化+后缀数组

    问题描述 LG2852 题解 字符串性质:字符串\(s\)的每个字串等于每个后缀的所有前缀 对输入的东西离散化,然后把数值看做\(\mathrm{ASCII}\)后缀排序 二分答案,二分长度. 显然一 ...

  4. Tcp与Http

    TCP协议对应传输层,而HTTP协议对应应用层.Http协议是建立在TCP协议基础之上的.当浏览器需要从服务器获取网页数据的时候,会发出一次Http请求.Http会通过TCP建立起一个到服务器的连接通 ...

  5. 数据结构or算法

    其实长久以来 mrxfyxj一直纠结着数据结构和算法到底有什么区别 只要学了一个算法就在惋惜她为什么不能是数据结构 产生这种想法的原因是mrxf觉得他blog里数据结构的东西很少 而mrxf自身又有一 ...

  6. C语言实现计算器,附源码,超简单!

    #include<stdio.h> #include<math.h> void main() { calculator(); } double calculator() { / ...

  7. 8.18 NOIP模拟测试25(B) 字符串+乌鸦喝水+所驼门王的宝藏

    T1 字符串 卡特兰数 设1为向(1,1)走,0为向(1,-1)走,限制就是不能超过$y=0$这条线,题意转化为从(0,0)出发,走到(n+m,n-m)且不越过$y=0$,然后就裸的卡特兰数,$ans ...

  8. vue_02day

    目录 vue_02 表单指令: 条件指令: 循环指令: 前端数据库: 分隔符: 过滤器: 计算属性: 监听属性: vue编译不生效,闪烁 冒泡排序: vue_02 表单指令: <form act ...

  9. [LeetCode] 189. Rotate Array 旋转数组

    Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: ...

  10. 关于c语言的逻辑短路规则

    原来的代码是 if (temp == 3 && (a % b != 0 || b == 0 )){ printf("go"); } dev-c 报错: progra ...