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

源码路径: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. Vi编辑网卡

    Vi /etc/sysconfig/network-scripts/ifcfg-ens33  1.光标定位到BOOTPROTO=后面 2.然后按x键进行删除 3.按i键打开编辑模式,输入BOOTPRO ...

  2. Spring事务异常rollback-only 笔记

    造成以上异常的原因情形: 在spring里面我们配置了事务的传播机制是REQUIRED,所以这两个事务最终会合并成一个事务.当a方法调用b方法时,程序中a方法中由于某某原因导致抛出异常(或者明确将该事 ...

  3. Oracle工具PLSQL

    2018版的PLSQL美化工具在Tools中的PL/SQL Beautifier中 如下:

  4. <binary search> 154 162

    154. Find Minimum in Rotated Sorted Array II 当数组中存在大量的重复数字时,就会破坏二分查找法的机制,将无法取得 O(lgn) 的时间复杂度,又将会回到简单 ...

  5. Npcap:Nmap项目里一个为Windows而生的嗅探库 Npcap: Nmap Project's packet sniffing library for Windows

    如果有人知道Npcap与libpcap对应的头文件列表,请告诉我,非常感谢 Introduction介绍 This Manual describes the programming interface ...

  6. oracle--drop user 和 drop user cascade 的区别【转载】

    drop user : 仅仅是删除用户, drop user ×× cascade :会删除此用户名下的所有表和视图. user Specify the user to be dropped. Ora ...

  7. VUE引入jq bootstrap 之终极解决方案(测试)

    初入VUE遇见的一些问题,在网上找了些方法,再根据自己的实际项目解决的问题写得此文,,希望对你有所帮助. vue-cli快速构建项目以及引入boostrap.jq各种插件配置 vue-cli脚手架工具 ...

  8. 【记录】【idea】【mysql】Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.解决问题

    idea连接mysql报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property ...

  9. 企业微信同步LDAP

    1.需求 定期同步企业微信的用户信息到 LDAP 中,当有新用户时,会自动发送LDAP的账号密码给该用户邮箱. 2.环境 python 3.x 需要安装两个模块 pip install ldap3 r ...

  10. 代码实现一个蛇形led走马灯

    什么叫走马灯? 走马灯又叫流水灯,灯不断的走动,像流水一样,动态显示. makecode图形化编程见:http://bbs.kittenbot.cn/forum.php?mod=viewthread& ...