diff options
author | Dianne Hackborn <> | 2009-03-24 19:36:34 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-24 19:36:34 -0700 |
commit | 99f095dfde9dd7c95fd0b9b555b02b85594495b2 (patch) | |
tree | f5237b7083f2f55103a7106d83d1cc6db7d2ee94 /src | |
parent | e32e8efcb90c57c44f252f1b5ca32a67fc87789b (diff) | |
download | packages_apps_Settings-99f095dfde9dd7c95fd0b9b555b02b85594495b2.tar.gz packages_apps_Settings-99f095dfde9dd7c95fd0b9b555b02b85594495b2.tar.bz2 packages_apps_Settings-99f095dfde9dd7c95fd0b9b555b02b85594495b2.zip |
Automated import from //branches/cupcake/...@142391,142391
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/battery_history/BatteryHistory.java | 81 | ||||
-rw-r--r-- | src/com/android/settings/battery_history/GraphableButton.java | 4 |
2 files changed, 70 insertions, 15 deletions
diff --git a/src/com/android/settings/battery_history/BatteryHistory.java b/src/com/android/settings/battery_history/BatteryHistory.java index dcf6cbf78..ad6479aff 100644 --- a/src/com/android/settings/battery_history/BatteryHistory.java +++ b/src/com/android/settings/battery_history/BatteryHistory.java @@ -18,6 +18,7 @@ package com.android.settings.battery_history; import java.util.ArrayList; import java.util.Collections; +import java.util.Formatter; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -73,7 +74,7 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS private BatteryStats mStats; private int mWhich = BatteryStats.STATS_UNPLUGGED; - private int mType = CPU_USAGE; + private int mType = MISC_USAGE; private GraphableButton[] mButtons; IBatteryStats mBatteryInfo; @@ -401,6 +402,7 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS class MiscUsage extends Graphable { int mInfoLabelRes; + String mInfoLabel; double[] mUsage; double mTotalRealtime; @@ -415,6 +417,17 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS mTotalRealtime = totalRealtime; } + public MiscUsage(String name, String infoLabel, long value, + long totalRealtime) { + mName = name; + + mInfoLabel = infoLabel; + + mUsage = new double[2]; + mUsage[0] = value; + mTotalRealtime = totalRealtime; + } + public String getLabel() { return mName; } @@ -432,7 +445,7 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS } public void getInfo(StringBuilder info) { - info.append(getString(mInfoLabelRes)); + info.append(mInfoLabel != null ? mInfoLabel : getString(mInfoLabelRes)); info.append(' '); formatTime(mUsage[0], info); info.append(" ("); @@ -656,6 +669,19 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS Collections.sort(mWakelockUsage); } + private final StringBuilder mFormatBuilder = new StringBuilder(8); + private final Formatter mFormatter = new Formatter(mFormatBuilder); + + private final String formatRatio(long num, long den) { + if (den == 0L) { + return "---%"; + } + float perc = ((float)num) / ((float)den) * 100; + mFormatBuilder.setLength(0); + mFormatter.format("%.1f%%", perc); + return mFormatBuilder.toString(); + } + private void processMiscUsage() { mMiscUsage.clear(); @@ -666,7 +692,8 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS long time = mStats.computeBatteryUptime(SystemClock.uptimeMillis() * 1000, mWhich) / 1000; if (time > 0) { mMiscUsage.add(new MiscUsage(getString( - R.string.battery_history_awake_label), + R.string.battery_history_awake_label) + + " (" + formatRatio(time, whichRealtime) + ")", R.string.battery_history_awake, time, whichRealtime)); } @@ -674,7 +701,8 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS time = mStats.getScreenOnTime(batteryRealtime, mWhich) / 1000; if (time > 0) { mMiscUsage.add(new MiscUsage(getString( - R.string.battery_history_screen_on_label), + R.string.battery_history_screen_on_label) + + " (" + formatRatio(time, whichRealtime) + ")", R.string.battery_history_screen_on, time, whichRealtime)); } @@ -682,11 +710,36 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS time = mStats.getPhoneOnTime(batteryRealtime, mWhich) / 1000; if (time > 0) { mMiscUsage.add(new MiscUsage(getString( - R.string.battery_history_phone_on_label), + R.string.battery_history_phone_on_label) + + " (" + formatRatio(time, whichRealtime) + ")", R.string.battery_history_phone_on, time, whichRealtime)); } + time = mStats.getWifiOnTime(batteryRealtime, mWhich) / 1000; + if (time > 0) { + mMiscUsage.add(new MiscUsage("Wifi On (" + + formatRatio(time, whichRealtime) + ")", + "Time spent with Wifi on:", + time, whichRealtime)); + } + + time = mStats.getWifiRunningTime(batteryRealtime, mWhich) / 1000; + if (time > 0) { + mMiscUsage.add(new MiscUsage("Wifi Running (" + + formatRatio(time, whichRealtime) + ")", + "Time spent with Wifi running:", + time, whichRealtime)); + } + + time = mStats.getBluetoothOnTime(batteryRealtime, mWhich) / 1000; + if (time > 0) { + mMiscUsage.add(new MiscUsage("Bluetooth On (" + + formatRatio(time, whichRealtime) + ")", + "Time spent with Bluetooth on:", + time, whichRealtime)); + } + Collections.sort(mMiscUsage); } @@ -815,12 +868,22 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS setContentView(R.layout.battery_history); + mStats = (BatteryStats)getLastNonConfigurationInstance(); + if (icicle != null) { + if (mStats == null) { + mStats = (BatteryStats)icicle.getParcelable("stats"); + } + mType = icicle.getInt("type"); + mWhich = icicle.getInt("which"); + } + mGraphLayout = (LinearLayout) findViewById(R.id.graphLayout); mTextLayout = (LinearLayout) findViewById(R.id.textLayout); mDetailsText = (TextView) findViewById(R.id.detailsText); mMessageText = (TextView) findViewById(R.id.messageText); mTypeSpinner = (Spinner) findViewById(R.id.typeSpinner); + mTypeSpinner.setSelection(mType); mTypeSpinner.setOnItemSelectedListener(this); mWhichSpinner = (Spinner) findViewById(R.id.whichSpinner); @@ -845,14 +908,6 @@ public class BatteryHistory extends Activity implements OnClickListener, OnItemS mBatteryInfo = IBatteryStats.Stub.asInterface( ServiceManager.getService("batteryinfo")); - mStats = (BatteryStats)getLastNonConfigurationInstance(); - if (icicle != null) { - if (mStats == null) { - mStats = (BatteryStats)icicle.getParcelable("stats"); - } - mType = icicle.getInt("type"); - mWhich = icicle.getInt("which"); - } if (mStats == null) { load(); } diff --git a/src/com/android/settings/battery_history/GraphableButton.java b/src/com/android/settings/battery_history/GraphableButton.java index 39028d036..fb90a0d1c 100644 --- a/src/com/android/settings/battery_history/GraphableButton.java +++ b/src/com/android/settings/battery_history/GraphableButton.java @@ -15,11 +15,11 @@ public class GraphableButton extends Button { static { sPaint[0] = new Paint(); sPaint[0].setStyle(Paint.Style.FILL); - sPaint[0].setColor(Color.BLUE); + sPaint[0].setColor(0xFF0080FF); sPaint[1] = new Paint(); sPaint[1].setStyle(Paint.Style.FILL); - sPaint[1].setColor(Color.RED); + sPaint[1].setColor(0xFFFF6060); } double[] mValues; |