Add high power whitelist for apps

- Strings not final!
 - New UX for power usage details (more preferency)
 - Add high power apps list shows on/off and screen to
   change (when possible)
 - Link from power usage summary to high power list
 - Link from advanced apps to high power list

Bug: 19991702
Change-Id: I97c927ed82d3b89041e4429b427508545763d66c
This commit is contained in:
Jason Monk
2015-04-29 12:46:42 -04:00
parent a283e6e325
commit 1eb54eb2ff
29 changed files with 952 additions and 597 deletions

View File

@@ -19,10 +19,16 @@ package com.android.settings.fuelgauge;
import android.content.Context;
import android.content.Intent;
import android.os.BatteryStats;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
/**
* Custom preference for displaying power consumption as a bar and an icon on the left for the
@@ -31,38 +37,60 @@ import com.android.settings.R;
*/
public class BatteryHistoryPreference extends Preference {
final private BatteryStats mStats;
final private Intent mBatteryBroadcast;
protected static final String BATTERY_HISTORY_FILE = "tmp_bat_history.bin";
private BatteryStats mStats;
private Intent mBatteryBroadcast;
private boolean mHideLabels;
private View mLabelHeader;
private BatteryHistoryChart mChart;
private BatteryStatsHelper mHelper;
public BatteryHistoryPreference(Context context, BatteryStats stats, Intent batteryBroadcast) {
super(context);
setLayoutResource(R.layout.preference_batteryhistory);
mStats = stats;
mBatteryBroadcast = batteryBroadcast;
public BatteryHistoryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void performClick(PreferenceScreen preferenceScreen) {
if (!isEnabled()) {
return;
}
mHelper.storeStatsHistoryInFile(BATTERY_HISTORY_FILE);
Bundle args = new Bundle();
args.putString(BatteryHistoryDetail.EXTRA_STATS, BATTERY_HISTORY_FILE);
args.putParcelable(BatteryHistoryDetail.EXTRA_BROADCAST,
mHelper.getBatteryBroadcast());
if (getContext() instanceof SettingsActivity) {
SettingsActivity sa = (SettingsActivity) getContext();
sa.startPreferencePanel(BatteryHistoryDetail.class.getName(), args,
R.string.history_details_title, null, null, 0);
}
}
public void setStats(BatteryStatsHelper batteryStats) {
// Clear out the chart to receive new data.
mChart = null;
mHelper = batteryStats;
mStats = batteryStats.getStats();
mBatteryBroadcast = batteryStats.getBatteryBroadcast();
if (getLayoutResource() != R.layout.battery_history_chart) {
// Now we should have some data, set the layout we want.
setLayoutResource(R.layout.battery_history_chart);
}
notifyChanged();
}
BatteryStats getStats() {
return mStats;
}
public void setHideLabels(boolean hide) {
if (mHideLabels != hide) {
mHideLabels = hide;
if (mLabelHeader != null) {
mLabelHeader.setVisibility(hide ? View.GONE : View.VISIBLE);
}
}
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
BatteryHistoryChart chart = (BatteryHistoryChart)view.findViewById(
if (mStats == null) {
return;
}
BatteryHistoryChart chart = (BatteryHistoryChart) view.findViewById(
R.id.battery_history_chart);
if (mChart == null) {
// First time: use and initialize this chart.
@@ -71,15 +99,13 @@ public class BatteryHistoryPreference extends Preference {
} else {
// All future times: forget the newly inflated chart, re-use the
// already initialized chart from last time.
ViewGroup parent = (ViewGroup)chart.getParent();
ViewGroup parent = (ViewGroup) chart.getParent();
int index = parent.indexOfChild(chart);
parent.removeViewAt(index);
if (mChart.getParent() != null) {
((ViewGroup)mChart.getParent()).removeView(mChart);
((ViewGroup) mChart.getParent()).removeView(mChart);
}
parent.addView(mChart, index);
}
mLabelHeader = view.findViewById(R.id.labelsHeader);
mLabelHeader.setVisibility(mHideLabels ? View.GONE : View.VISIBLE);
}
}