am e5d948f3: am cbaf6ceb: Add battery history details activity.

Merge commit 'e5d948f333b78061076c7764d641b84c8751b2c9'

* commit 'e5d948f333b78061076c7764d641b84c8751b2c9':
  Add battery history details activity.
This commit is contained in:
Dianne Hackborn
2010-07-26 12:29:35 -07:00
committed by Android Git Automerger
5 changed files with 289 additions and 55 deletions

View File

@@ -801,6 +801,14 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".fuelgauge.BatteryHistoryDetail"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".widget.SettingsAppWidgetProvider" android:label="@string/gadget_title"> <receiver android:name=".widget.SettingsAppWidgetProvider" android:label="@string/gadget_title">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

View File

@@ -2075,6 +2075,14 @@ found in the list of installed applications.</string>
<string name="battery_stats_on_battery"><xliff:g id="time">%1$s</xliff:g> on battery</string> <string name="battery_stats_on_battery"><xliff:g id="time">%1$s</xliff:g> on battery</string>
<!-- Battery usage duration --> <!-- Battery usage duration -->
<string name="battery_stats_duration"><xliff:g id="time">%1$s</xliff:g> since unplugged</string> <string name="battery_stats_duration"><xliff:g id="time">%1$s</xliff:g> since unplugged</string>
<!-- Label for battery stats charging state graph -->
<string name="battery_stats_charging_label">Charging</string>
<!-- Label for battery stats screen on state graph -->
<string name="battery_stats_screen_on_label">Screen on</string>
<!-- Label for battery stats gps on state graph -->
<string name="battery_stats_gps_on_label">GPS on</string>
<!-- Label for battery stats phone signal strength graph -->
<string name="battery_stats_phone_signal_label">Phone signal</string>
<!-- Battery usage during last unplugged period --> <!-- Battery usage during last unplugged period -->
<string name="battery_stats_last_duration">@string/menu_stats_last_unplugged</string> <string name="battery_stats_last_duration">@string/menu_stats_last_unplugged</string>
<!-- CPU awake time title --> <!-- CPU awake time title -->

View File

@@ -28,13 +28,12 @@ import android.graphics.Typeface;
import android.os.BatteryStats; import android.os.BatteryStats;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.BatteryStats.HistoryItem; import android.os.BatteryStats.HistoryItem;
import android.telephony.ServiceState;
import android.text.TextPaint; import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import java.util.ArrayList;
public class BatteryHistoryChart extends View { public class BatteryHistoryChart extends View {
static final int SANS = 1; static final int SANS = 1;
static final int SERIF = 2; static final int SERIF = 2;
@@ -43,12 +42,22 @@ public class BatteryHistoryChart extends View {
static final int BATTERY_WARN = 29; static final int BATTERY_WARN = 29;
static final int BATTERY_CRITICAL = 14; static final int BATTERY_CRITICAL = 14;
// First value if for phone off; sirst value is "scanning"; following values
// are battery stats signal strength buckets.
static final int NUM_PHONE_SIGNALS = 7;
final Paint mBatteryBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mBatteryBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Paint mBatteryGoodPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mBatteryGoodPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Paint mBatteryWarnPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mBatteryWarnPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Paint mBatteryCriticalPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mBatteryCriticalPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
final Paint mChargingPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mChargingPaint = new Paint();
final Paint mScreenOnPaint = new Paint(Paint.ANTI_ALIAS_FLAG); final Paint mScreenOnPaint = new Paint();
final Paint mGpsOnPaint = new Paint();
final Paint[] mPhoneSignalPaints = new Paint[NUM_PHONE_SIGNALS];
final int[] mPhoneSignalColors = new int[] {
0x00000000, 0xffa00000, 0xffa0a000, 0xff808020,
0xff808040, 0xff808060, 0xff008000
};
final TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
final Path mBatLevelPath = new Path(); final Path mBatLevelPath = new Path();
@@ -57,20 +66,40 @@ public class BatteryHistoryChart extends View {
final Path mBatCriticalPath = new Path(); final Path mBatCriticalPath = new Path();
final Path mChargingPath = new Path(); final Path mChargingPath = new Path();
final Path mScreenOnPath = new Path(); final Path mScreenOnPath = new Path();
final Path mGpsOnPath = new Path();
int mFontSize; int mFontSize;
BatteryStats mStats; BatteryStats mStats;
long mStatsPeriod; long mStatsPeriod;
String mDurationString; String mDurationString;
String mTotalDurationString;
int mChargingOffset; String mChargingLabel;
int mScreenOnOffset; String mScreenOnLabel;
int mLevelOffset; String mGpsOnLabel;
String mPhoneSignalLabel;
int mTextAscent; int mTextAscent;
int mTextDescent; int mTextDescent;
int mDurationStringWidth; int mDurationStringWidth;
int mTotalDurationStringWidth;
boolean mLargeMode;
int mLineWidth;
int mThinLineWidth;
int mChargingOffset;
int mScreenOnOffset;
int mGpsOnOffset;
int mPhoneSignalOffset;
int mLevelOffset;
int mLevelTop;
int mLevelBottom;
static final int PHONE_SIGNAL_X_MASK = 0x0000ffff;
static final int PHONE_SIGNAL_BIN_MASK = 0xffff0000;
static final int PHONE_SIGNAL_BIN_SHIFT = 16;
int mNumPhoneSignalTicks;
int[] mPhoneSignalTicks;
int mNumHist; int mNumHist;
BatteryStats.HistoryItem mHistFirst; BatteryStats.HistoryItem mHistFirst;
@@ -85,27 +114,22 @@ public class BatteryHistoryChart extends View {
mBatteryBackgroundPaint.setARGB(255, 128, 128, 128); mBatteryBackgroundPaint.setARGB(255, 128, 128, 128);
mBatteryBackgroundPaint.setStyle(Paint.Style.FILL); mBatteryBackgroundPaint.setStyle(Paint.Style.FILL);
mBatteryGoodPaint.setARGB(128, 0, 255, 0); mBatteryGoodPaint.setARGB(128, 0, 255, 0);
int lineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
2, getResources().getDisplayMetrics());
if (lineWidth <= 0) lineWidth = 1;
mBatteryGoodPaint.setStrokeWidth(lineWidth);
mBatteryGoodPaint.setStyle(Paint.Style.STROKE); mBatteryGoodPaint.setStyle(Paint.Style.STROKE);
mBatteryWarnPaint.setARGB(128, 255, 255, 0); mBatteryWarnPaint.setARGB(128, 255, 255, 0);
mBatteryWarnPaint.setStrokeWidth(lineWidth);
mBatteryWarnPaint.setStyle(Paint.Style.STROKE); mBatteryWarnPaint.setStyle(Paint.Style.STROKE);
mBatteryCriticalPaint.setARGB(192, 255, 0, 0); mBatteryCriticalPaint.setARGB(192, 255, 0, 0);
mBatteryCriticalPaint.setStrokeWidth(lineWidth);
mBatteryCriticalPaint.setStyle(Paint.Style.STROKE); mBatteryCriticalPaint.setStyle(Paint.Style.STROKE);
mChargingPaint.setARGB(255, 0, 128, 0); mChargingPaint.setARGB(255, 0, 128, 0);
mChargingPaint.setStrokeWidth(lineWidth);
mChargingPaint.setStyle(Paint.Style.STROKE); mChargingPaint.setStyle(Paint.Style.STROKE);
mScreenOnPaint.setARGB(255, 0, 0, 255); mScreenOnPaint.setARGB(255, 0, 0, 255);
mScreenOnPaint.setStrokeWidth(lineWidth);
mScreenOnPaint.setStyle(Paint.Style.STROKE); mScreenOnPaint.setStyle(Paint.Style.STROKE);
mGpsOnPaint.setARGB(255, 0, 0, 255);
mScreenOnOffset = lineWidth; mGpsOnPaint.setStyle(Paint.Style.STROKE);
mChargingOffset = lineWidth*2; for (int i=0; i<NUM_PHONE_SIGNALS; i++) {
mLevelOffset = lineWidth*3; mPhoneSignalPaints[i] = new Paint();
mPhoneSignalPaints[i].setColor(mPhoneSignalColors[i]);
mPhoneSignalPaints[i].setStyle(Paint.Style.FILL);
}
mTextPaint.density = getResources().getDisplayMetrics().density; mTextPaint.density = getResources().getDisplayMetrics().density;
mTextPaint.setCompatibilityScaling( mTextPaint.setCompatibilityScaling(
@@ -251,6 +275,10 @@ public class BatteryHistoryChart extends View {
String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000); String durationString = Utils.formatElapsedTime(getContext(), mStatsPeriod / 1000);
mDurationString = getContext().getString(R.string.battery_stats_on_battery, mDurationString = getContext().getString(R.string.battery_stats_on_battery,
durationString); durationString);
mChargingLabel = getContext().getString(R.string.battery_stats_charging_label);
mScreenOnLabel = getContext().getString(R.string.battery_stats_screen_on_label);
mGpsOnLabel = getContext().getString(R.string.battery_stats_gps_on_label);
mPhoneSignalLabel = getContext().getString(R.string.battery_stats_phone_signal_label);
BatteryStats.HistoryItem rec = stats.getHistory(); BatteryStats.HistoryItem rec = stats.getHistory();
mHistFirst = null; mHistFirst = null;
@@ -277,18 +305,27 @@ public class BatteryHistoryChart extends View {
mNumHist = lastInteresting; mNumHist = lastInteresting;
if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1; if (mHistEnd <= mHistStart) mHistEnd = mHistStart+1;
mTotalDurationString = Utils.formatElapsedTime(getContext(), mHistEnd - mHistStart);
} }
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mDurationStringWidth = (int)mTextPaint.measureText(mDurationString); mDurationStringWidth = (int)mTextPaint.measureText(mDurationString);
mTotalDurationStringWidth = (int)mTextPaint.measureText(mTotalDurationString);
mTextAscent = (int)mTextPaint.ascent(); mTextAscent = (int)mTextPaint.ascent();
mTextDescent = (int)mTextPaint.descent(); mTextDescent = (int)mTextPaint.descent();
} }
void addPhoneSignalTick(int x, int bin) {
mPhoneSignalTicks[mNumPhoneSignalTicks]
= x | bin << PHONE_SIGNAL_BIN_SHIFT;
mNumPhoneSignalTicks++;
}
void finishPaths(int w, int h, int levelh, int startX, int y, Path curLevelPath, void finishPaths(int w, int h, int levelh, int startX, int y, Path curLevelPath,
int lastX, boolean lastCharging, boolean lastScreenOn, Path lastPath) { int lastX, boolean lastCharging, boolean lastScreenOn, boolean lastGpsOn,
int lastPhoneSignal, Path lastPath) {
if (curLevelPath != null) { if (curLevelPath != null) {
if (lastX >= 0 && lastX < w) { if (lastX >= 0 && lastX < w) {
if (lastPath != null) { if (lastPath != null) {
@@ -296,28 +333,72 @@ public class BatteryHistoryChart extends View {
} }
curLevelPath.lineTo(w, y); curLevelPath.lineTo(w, y);
} }
curLevelPath.lineTo(w, levelh); curLevelPath.lineTo(w, mLevelTop+levelh);
curLevelPath.lineTo(startX, levelh); curLevelPath.lineTo(startX, mLevelTop+levelh);
curLevelPath.close(); curLevelPath.close();
} }
if (lastCharging && lastX < w) { if (lastCharging) {
mChargingPath.lineTo(w, h-mChargingOffset); mChargingPath.lineTo(w, h-mChargingOffset);
} }
if (lastScreenOn && lastX < w) { if (lastScreenOn) {
mScreenOnPath.lineTo(w, h-mScreenOnOffset); mScreenOnPath.lineTo(w, h-mScreenOnOffset);
} }
if (lastGpsOn) {
mGpsOnPath.lineTo(w, h-mGpsOnOffset);
}
if (lastPhoneSignal != 0) {
addPhoneSignalTick(w, 0);
}
} }
@Override @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
int textHeight = mTextDescent - mTextAscent;
mThinLineWidth = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
2, getResources().getDisplayMetrics());
if (h > (textHeight*6)) {
mLargeMode = true;
mLineWidth = textHeight/2;
mLevelTop = textHeight + mLineWidth;
} else {
mLargeMode = false;
mLineWidth = mThinLineWidth;
mLevelTop = 0;
}
if (mLineWidth <= 0) mLineWidth = 1;
mTextPaint.setStrokeWidth(mThinLineWidth);
mBatteryGoodPaint.setStrokeWidth(mThinLineWidth);
mBatteryWarnPaint.setStrokeWidth(mThinLineWidth);
mBatteryCriticalPaint.setStrokeWidth(mThinLineWidth);
mChargingPaint.setStrokeWidth(mLineWidth);
mScreenOnPaint.setStrokeWidth(mLineWidth);
mGpsOnPaint.setStrokeWidth(mLineWidth);
if (mLargeMode) {
int barOffset = textHeight + mLineWidth;
mScreenOnOffset = mLineWidth;
mGpsOnOffset = mScreenOnOffset + barOffset;
mPhoneSignalOffset = mGpsOnOffset + barOffset;
mChargingOffset = mPhoneSignalOffset + barOffset;
mLevelOffset = mChargingOffset + barOffset + mLineWidth;
mPhoneSignalTicks = new int[w+2];
} else {
mScreenOnOffset = mGpsOnOffset = mLineWidth;
mChargingOffset = mLineWidth*2;
mPhoneSignalOffset = 0;
mLevelOffset = mLineWidth*3;
mPhoneSignalTicks = null;
}
mBatLevelPath.reset(); mBatLevelPath.reset();
mBatGoodPath.reset(); mBatGoodPath.reset();
mBatWarnPath.reset(); mBatWarnPath.reset();
mBatCriticalPath.reset(); mBatCriticalPath.reset();
mScreenOnPath.reset(); mScreenOnPath.reset();
mGpsOnPath.reset();
mChargingPath.reset(); mChargingPath.reset();
final long timeStart = mHistStart; final long timeStart = mHistStart;
@@ -326,19 +407,21 @@ public class BatteryHistoryChart extends View {
final int batLow = mBatLow; final int batLow = mBatLow;
final int batChange = mBatHigh-mBatLow; final int batChange = mBatHigh-mBatLow;
final int levelh = h - mLevelOffset; final int levelh = h - mLevelOffset - mLevelTop;
mLevelBottom = mLevelTop + levelh;
BatteryStats.HistoryItem rec = mHistFirst; BatteryStats.HistoryItem rec = mHistFirst;
int x = 0, y = 0, startX = 0, lastX = -1, lastY = -1; int x = 0, y = 0, startX = 0, lastX = -1, lastY = -1;
int i = 0; int i = 0;
Path curLevelPath = null; Path curLevelPath = null;
Path lastLinePath = null; Path lastLinePath = null;
boolean lastCharging = false, lastScreenOn = false; boolean lastCharging = false, lastScreenOn = false, lastGpsOn = false;
int lastPhoneSignalBin = 0;
final int N = mNumHist; final int N = mNumHist;
while (rec != null && i < N) { while (rec != null && i < N) {
if (rec.cmd == BatteryStats.HistoryItem.CMD_UPDATE) { if (rec.cmd == BatteryStats.HistoryItem.CMD_UPDATE) {
x = (int)(((rec.time-timeStart)*w)/timeChange); x = (int)(((rec.time-timeStart)*w)/timeChange);
y = levelh - ((rec.batteryLevel-batLow)*(levelh-1))/batChange; y = mLevelTop + levelh - ((rec.batteryLevel-batLow)*(levelh-1))/batChange;
if (lastX != x) { if (lastX != x) {
// We have moved by at least a pixel. // We have moved by at least a pixel.
@@ -369,38 +452,70 @@ public class BatteryHistoryChart extends View {
} }
lastX = x; lastX = x;
lastY = y; lastY = y;
}
final boolean charging =
(rec.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) != 0; final boolean charging =
if (charging != lastCharging) { (rec.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) != 0;
if (charging) { if (charging != lastCharging) {
mChargingPath.moveTo(x, h-mChargingOffset); if (charging) {
} else { mChargingPath.moveTo(x, h-mChargingOffset);
mChargingPath.lineTo(x, h-mChargingOffset); } else {
} mChargingPath.lineTo(x, h-mChargingOffset);
lastCharging = charging;
} }
lastCharging = charging;
final boolean screenOn = }
(rec.states&HistoryItem.STATE_SCREEN_ON_FLAG) != 0;
if (screenOn != lastScreenOn) { final boolean screenOn =
if (screenOn) { (rec.states&HistoryItem.STATE_SCREEN_ON_FLAG) != 0;
mScreenOnPath.moveTo(x, h-mScreenOnOffset); if (screenOn != lastScreenOn) {
} else { if (screenOn) {
mScreenOnPath.lineTo(x, h-mScreenOnOffset); mScreenOnPath.moveTo(x, h-mScreenOnOffset);
} } else {
lastScreenOn = screenOn; mScreenOnPath.lineTo(x, h-mScreenOnOffset);
}
lastScreenOn = screenOn;
}
final boolean gpsOn =
(rec.states&HistoryItem.STATE_GPS_ON_FLAG) != 0;
if (gpsOn != lastGpsOn) {
if (gpsOn) {
mGpsOnPath.moveTo(x, h-mGpsOnOffset);
} else {
mGpsOnPath.lineTo(x, h-mGpsOnOffset);
}
lastGpsOn = gpsOn;
}
if (mLargeMode) {
int bin;
if (((rec.states&HistoryItem.STATE_PHONE_STATE_MASK)
>> HistoryItem.STATE_PHONE_STATE_SHIFT)
== ServiceState.STATE_POWER_OFF) {
bin = 0;
} else if ((rec.states&HistoryItem.STATE_PHONE_SCANNING_FLAG) != 0) {
bin = 1;
} else {
bin = (rec.states&HistoryItem.STATE_SIGNAL_STRENGTH_MASK)
>> HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT;
bin += 2;
}
if (bin != lastPhoneSignalBin) {
addPhoneSignalTick(x, bin);
lastPhoneSignalBin = bin;
} }
} }
} }
} else if (curLevelPath != null) { } else if (curLevelPath != null) {
finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX,
lastCharging, lastScreenOn, lastLinePath); lastCharging, lastScreenOn, lastGpsOn, lastPhoneSignalBin,
lastLinePath);
lastX = lastY = -1; lastX = lastY = -1;
curLevelPath = null; curLevelPath = null;
lastLinePath = null; lastLinePath = null;
lastCharging = lastScreenOn = false; lastCharging = lastScreenOn = lastGpsOn = false;
lastPhoneSignalBin = 0;
} }
rec = rec.next; rec = rec.next;
@@ -408,7 +523,7 @@ public class BatteryHistoryChart extends View {
} }
finishPaths(w, h, levelh, startX, lastY, curLevelPath, lastX, finishPaths(w, h, levelh, startX, lastY, curLevelPath, lastX,
lastCharging, lastScreenOn, lastLinePath); lastCharging, lastScreenOn, lastGpsOn, lastPhoneSignalBin, lastLinePath);
} }
@Override @Override
@@ -419,8 +534,15 @@ public class BatteryHistoryChart extends View {
final int height = getHeight(); final int height = getHeight();
canvas.drawPath(mBatLevelPath, mBatteryBackgroundPaint); canvas.drawPath(mBatLevelPath, mBatteryBackgroundPaint);
canvas.drawText(mDurationString, (width/2) - (mDurationStringWidth/2), if (mLargeMode) {
(height/2) - ((mTextDescent-mTextAscent)/2) - mTextAscent, mTextPaint); canvas.drawText(mDurationString, 0, -mTextAscent + (mLineWidth/2),
mTextPaint);
canvas.drawText(mTotalDurationString, (width/2) - (mTotalDurationStringWidth/2),
mLevelBottom - mTextAscent + mThinLineWidth, mTextPaint);
} else {
canvas.drawText(mDurationString, (width/2) - (mDurationStringWidth/2),
(height/2) - ((mTextDescent-mTextAscent)/2) - mTextAscent, mTextPaint);
}
if (!mBatGoodPath.isEmpty()) { if (!mBatGoodPath.isEmpty()) {
canvas.drawPath(mBatGoodPath, mBatteryGoodPaint); canvas.drawPath(mBatGoodPath, mBatteryGoodPaint);
} }
@@ -430,11 +552,46 @@ public class BatteryHistoryChart extends View {
if (!mBatCriticalPath.isEmpty()) { if (!mBatCriticalPath.isEmpty()) {
canvas.drawPath(mBatCriticalPath, mBatteryCriticalPaint); canvas.drawPath(mBatCriticalPath, mBatteryCriticalPaint);
} }
if (!mChargingPath.isEmpty()) { int lastBin=0, lastX=0;
canvas.drawPath(mChargingPath, mChargingPaint); int top = height-mPhoneSignalOffset - (mLineWidth/2);
int bottom = top + mLineWidth;
for (int i=0; i<mNumPhoneSignalTicks; i++) {
int tick = mPhoneSignalTicks[i];
int x = tick&PHONE_SIGNAL_X_MASK;
int bin = (tick&PHONE_SIGNAL_BIN_MASK) >> PHONE_SIGNAL_BIN_SHIFT;
if (lastBin != 0) {
canvas.drawRect(lastX, top, x, bottom, mPhoneSignalPaints[bin]);
}
lastBin = bin;
lastX = x;
} }
if (!mScreenOnPath.isEmpty()) { if (!mScreenOnPath.isEmpty()) {
canvas.drawPath(mScreenOnPath, mScreenOnPaint); canvas.drawPath(mScreenOnPath, mScreenOnPaint);
} }
if (!mChargingPath.isEmpty()) {
canvas.drawPath(mChargingPath, mChargingPaint);
}
if (!mGpsOnPath.isEmpty()) {
canvas.drawPath(mGpsOnPath, mGpsOnPaint);
}
if (mLargeMode) {
canvas.drawText(mPhoneSignalLabel, 0,
height - mPhoneSignalOffset - mTextDescent, mTextPaint);
canvas.drawText(mGpsOnLabel, 0,
height - mGpsOnOffset - mTextDescent, mTextPaint);
canvas.drawText(mChargingLabel, 0,
height - mChargingOffset - mTextDescent, mTextPaint);
canvas.drawText(mScreenOnLabel, 0,
height - mScreenOnOffset - mTextDescent, mTextPaint);
canvas.drawLine(0, mLevelBottom+(mThinLineWidth/2), width,
mLevelBottom+(mThinLineWidth/2), mTextPaint);
canvas.drawLine(0, mLevelTop, 0,
mLevelBottom+(mThinLineWidth/2), mTextPaint);
for (int i=0; i<10; i++) {
int y = mLevelTop + ((mLevelBottom-mLevelTop)*i)/10;
canvas.drawLine(0, y, mThinLineWidth*2, y, mTextPaint);
}
}
} }
} }

View File

@@ -0,0 +1,45 @@
/*
* 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.
*/
package com.android.settings.fuelgauge;
import android.app.Activity;
import android.os.Bundle;
import android.os.Parcel;
import com.android.internal.os.BatteryStatsImpl;
import com.android.settings.R;
public class BatteryHistoryDetail extends Activity {
public static final String EXTRA_STATS = "stats";
private BatteryStatsImpl mStats;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
byte[] data = getIntent().getByteArrayExtra(EXTRA_STATS);
Parcel parcel = Parcel.obtain();
parcel.unmarshall(data, 0, data.length);
parcel.setDataPosition(0);
setContentView(R.layout.preference_batteryhistory);
mStats = com.android.internal.os.BatteryStatsImpl.CREATOR
.createFromParcel(parcel);
BatteryHistoryChart chart = (BatteryHistoryChart)findViewById(
R.id.battery_history_chart);
chart.setStats(mStats);
}
}

View File

@@ -90,6 +90,8 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
mStats = (BatteryStatsImpl)getLastNonConfigurationInstance();
addPreferencesFromResource(R.xml.power_usage_summary); addPreferencesFromResource(R.xml.power_usage_summary);
mBatteryInfo = IBatteryStats.Stub.asInterface( mBatteryInfo = IBatteryStats.Stub.asInterface(
ServiceManager.getService("batteryinfo")); ServiceManager.getService("batteryinfo"));
@@ -97,6 +99,11 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
mPowerProfile = new PowerProfile(this); mPowerProfile = new PowerProfile(this);
} }
@Override
public Object onRetainNonConfigurationInstance() {
return mStats;
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@@ -115,6 +122,15 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference instanceof BatteryHistoryPreference) {
Parcel hist = Parcel.obtain();
mStats.writeToParcelWithoutUids(hist, 0);
byte[] histData = hist.marshall();
Intent intent = new Intent(this, BatteryHistoryDetail.class);
intent.putExtra(BatteryHistoryDetail.EXTRA_STATS, histData);
startActivity(intent);
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
if (!(preference instanceof PowerGaugePreference)) { if (!(preference instanceof PowerGaugePreference)) {
return false; return false;
} }