0. UI界面
1. UI入口配置
AndroidManifest.xml
<activity android:name="Settings$PowerUsageSummaryActivity"
android:label="@string/power_usage_summary_title"
android:icon="@drawable/ic_settings_battery"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="android.intent.action.POWER_USAGE_SUMMARY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="8">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.homepage" />
<!-- remove google battery saver @{ -->
<!--<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.PowerUsageSummary" /> -->
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.SprdPowerUsageSummary" />
<!-- @} -->
</activity>
2. 主界面-SprdPowerUsageSummary
package com.android.settings.fuelgauge;
/**
* Displays a list of apps and subsystems that consume power, ordered by how much power was
* consumed since the last time it was unplugged.
*/
public class SprdPowerUsageSummary extends PowerUsageBase implements
AnomalyDialogListener, OnLongClickListener, OnClickListener {
@Override
protected int getPreferenceScreenResId() {
/*SPRD :modified for bug 734194, add Battery Saver @{*/
if (isSupportBMFeature) {
return R.xml.sprd_power_usage_summary;
} else {
return R.xml.power_usage_summary;
}
/*@}*/
}
3. 布局文件-sprd_power_usage_summary
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
Licensed 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 at
http://www.apache.org/licenses/LICENSE-2.0
Unless 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
android:title="@string/power_usage_summary_title"
settings:keywords="@string/keywords_battery">
// 电池电量或耗电详情入口
<com.android.settings.applications.LayoutPreference
android:key="battery_header"
android:selectable="true"
android:layout="@layout/battery_header"/>
// 耗電量高
<Preference
android:key="high_usage"
android:icon="@drawable/ic_battery_alert_24dp"
android:title="@string/power_high_usage_title"/>
<PreferenceCategory
android:key="device_usage_list">
// 上次充滿電
<com.android.settings.fuelgauge.PowerGaugePreference
android:key="last_full_charge"
android:title="@string/battery_last_full_charge"
android:selectable="false"/>
// 充滿電後的螢幕用量
<com.android.settings.fuelgauge.PowerGaugePreference
android:key="screen_usage"
android:title="@string/device_screen_usage"
android:selectable="false"/>
</PreferenceCategory>
// 電量管理
<PreferenceCategory
android:key="power_management"
android:title="@string/battery_power_management">
// 電量百分比
<SwitchPreference
android:key="battery_percentage"
android:title="@string/battery_percentage"
android:summary="@string/battery_percentage_description"/>
// 自动亮度调节
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
<SwitchPreference
android:key="auto_brightness_battery"
android:title="@string/auto_brightness_title"
android:summary="@string/auto_brightness_summary"
settings:keywords="@string/keywords_display_auto_brightness"/>
// 休眠
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
<com.android.settings.TimeoutListPreference
android:key="screen_timeout_battery"
android:title="@string/screen_timeout"
android:entries="@array/screen_timeout_entries"
android:entryValues="@array/screen_timeout_values"/>
// 省电模式选择
<Preference
android:key="battery_saver_mode"
android:title="@string/choose_battery_saver"
android:fragment="com.android.settings.fuelgauge.SprdBatterySaverSettings" />
// 低电量自动省电
<Preference
android:key="auto_low_power"
android:title="@string/auto_low_power"
android:fragment="com.android.settings.fuelgauge.SprdAutoLowPowerFragment" />
// 定时省电
<Preference
android:key="schedule_mode"
android:title="@string/schedule_mode"
android:fragment="com.android.settings.fuelgauge.SprdSchedulePowerFragment" />
</PreferenceCategory>
// 省电设置
<PreferenceCategory
android:key="app_battery_saver_setting"
android:title="@string/app_battery_saving_setting">
// 应用待机优化
<Preference
android:key="app_battery_saver"
android:title="@string/app_battery_saver_manager" />
// 锁屏清理应用
<Preference
android:key="lock_screen_battery_save"
android:title="@string/lock_screen_battery_save" />
// 自启动管理
<Preference
android:key="app_auto_run"
android:title="@string/app_auto_run_management"
android:fragment="com.android.settings.fuelgauge.SprdAppAutoRunFragment" />
// 高耗电应用
<Preference
android:key="power_intensive_apps"
android:title="@string/power_intensive_apps" />
</PreferenceCategory>
// 充满电(xx)后的用电量
<PreferenceCategory
android:key="app_list"
android:title="@string/power_usage_list_summary_title"/>
// 耗电排行
<Preference
android:key="power_usage_list"
android:title="@string/power_usage_ranking"
android:fragment="com.android.settings.fuelgauge.SprdPowerUsageListSummary" />
</PreferenceScreen>