口袋模式
任务详述
设置页面 添加智能控制 -> 口袋模式 -> 节省功耗
(手机在口袋中 如果wifi 蓝牙未连接 自动关闭WLAN和蓝牙)拿出口袋恢复
概要设计
- 添加设置的各级菜单
- 获取距离传感器以及功能实现
功能实现
添加各级菜单以及 Fragment
各级菜单的定义以及其界面的实现,主要是对交互界面的实现,除数据库的存储外,不涉及到逻辑的处理。
一级菜单
路径: res/xml/top_level_settings.xml
<!-- add by xxx for pocket mode 2022.08.29 start-->
<Preference
android:key="top_level_smart_control"
android:summary="@string/smart_control_summary"
android:title="@string/smart_control_title"
android:icon="@drawable/ic_settings_smart_controls"
android:order="0"
android:fragment="com.android.settings.smartcontrol.SmartControlFragment" />
<!-- add by xxx for pocket mode 2022.09.02 end-->
二级菜单
路径:res/xml/custom_pocket_mode.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- add by xxx for pocket mode 2022.08.29 start-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="custom_pocket_mode_settings"
android:title="@string/custom_pocket_mode_settings_title"
settings:keywords="@string/keywords_custom_pocket_mode">
<Preference
android:key="custom_pocket_mode"
android:title="@string/custom_pocket_mode_title"
android:summary="@string/custom_pocket_mode_summary"
android:fragment="com.android.settings.smartcontrol.SavingPowerFragment" />
</PreferenceScreen>
<!-- add by xxx for pocket mode 2022.09.02 end-->
三级菜单
路径:res/xml/saving_power.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- add by xxx for pocket mode 2022.08.29 start-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="saving_power_settings"
android:title="@string/saving_power_settings_title"
settings:keywords="@string/keywords_saving_power">
<SwitchPreference
android:key="saving_power"
android:title="@string/saving_power_title"
android:summary="@string/saving_power_summary" />
</PreferenceScreen>
<!-- add by xxx for pocket mode 2022.09.02 end-->
二级菜单 Fragment
路径:src/com/android/settings/smartcontrol/SmartControlFragment.java
// add by xxx for pocket mode 2022.08.29 start
package com.android.settings.smartcontrol;
import android.os.Bundle;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
public class SmartControlFragment extends DashboardFragment {
private static final String TAG = "SmartControlFragment";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
}
@Override
public int getMetricsCategory() {
return 0;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.custom_pocket_mode;